Skip to content

Commit

Permalink
fix(structure): update documentHeaderTitle tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobonamin committed Sep 25, 2024
1 parent 814d6d8 commit 534d6e3
Showing 1 changed file with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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(<DocumentHeaderTitle />)
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(<DocumentHeaderTitle />)
await waitFor(() => expect(getByText('Test Value')).toBeInTheDocument())
})

it('should return the title if it is provided', async () => {
mockUseDocumentPane.mockReturnValue({
...defaultProps,
Expand All @@ -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()
Expand Down Expand Up @@ -146,7 +163,7 @@ describe('DocumentHeaderTitle', () => {
expect(mockUseValuePreview).toHaveBeenCalledWith({
enabled: true,
schemaType: defaultProps.schemaType,
value: defaultProps.value,
value: defaultProps.editState.draft,
}),
)
})
Expand Down

0 comments on commit 534d6e3

Please sign in to comment.