From 534d6e3b20d5c126aefb0cf0673e2016e4b55fd0 Mon Sep 17 00:00:00 2001 From: pedrobonamin Date: Wed, 25 Sep 2024 11:00:41 +0200 Subject: [PATCH] fix(structure): update documentHeaderTitle tests --- .../header/DocumentHeaderTitle.test.tsx | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/packages/sanity/src/structure/panes/document/documentPanel/header/DocumentHeaderTitle.test.tsx b/packages/sanity/src/structure/panes/document/documentPanel/header/DocumentHeaderTitle.test.tsx index d34ec969a32..048bec4c3e8 100644 --- a/packages/sanity/src/structure/panes/document/documentPanel/header/DocumentHeaderTitle.test.tsx +++ b/packages/sanity/src/structure/panes/document/documentPanel/header/DocumentHeaderTitle.test.tsx @@ -39,7 +39,7 @@ describe('DocumentHeaderTitle', () => { const defaultProps = { connectionState: 'connected', schemaType: {title: 'Test Schema', name: 'testSchema'}, - value: {title: 'Test Value'}, + editState: {draft: {title: 'Test Value'}}, } const defaultValue = { @@ -63,16 +63,33 @@ describe('DocumentHeaderTitle', () => { await waitFor(() => expect(getByText('Untitled')).toBeInTheDocument()) }) - it('should return an empty fragment when connectionState is not "connected"', async () => { + it('should return an empty fragment when connectionState is not "connected" and editState is empty', async () => { mockUseDocumentPane.mockReturnValue({ ...defaultProps, connectionState: 'connecting', + editState: null, } as unknown as DocumentPaneContextValue) const {container} = render() await waitFor(() => expect(container.firstChild).toBeNull()) }) + it('should render the header title when connectionState is not "connected" and editState has values', async () => { + mockUseDocumentPane.mockReturnValue({ + ...defaultProps, + connectionState: 'connecting', + } as unknown as DocumentPaneContextValue) + + mockUseValuePreview.mockReturnValue({ + ...defaultValue, + error: undefined, + value: {title: 'Test Value'}, + }) + + const {getByText} = render() + await waitFor(() => expect(getByText('Test Value')).toBeInTheDocument()) + }) + it('should return the title if it is provided', async () => { mockUseDocumentPane.mockReturnValue({ ...defaultProps, @@ -89,7 +106,7 @@ describe('DocumentHeaderTitle', () => { it('should return "New {schemaType?.title || schemaType?.name}" if documentValue is not provided', async () => { mockUseDocumentPane.mockReturnValue({ ...defaultProps, - value: null, + editState: null, } as unknown as DocumentPaneContextValue) const client = createMockSanityClient() @@ -146,7 +163,7 @@ describe('DocumentHeaderTitle', () => { expect(mockUseValuePreview).toHaveBeenCalledWith({ enabled: true, schemaType: defaultProps.schemaType, - value: defaultProps.value, + value: defaultProps.editState.draft, }), ) })