diff --git a/packages/sanity/src/structure/panes/document/documentPanel/header/perspective/DocumentPerspectiveList.tsx b/packages/sanity/src/structure/panes/document/documentPanel/header/perspective/DocumentPerspectiveList.tsx index 8f3bddecafe..de60f77983b 100644 --- a/packages/sanity/src/structure/panes/document/documentPanel/header/perspective/DocumentPerspectiveList.tsx +++ b/packages/sanity/src/structure/panes/document/documentPanel/header/perspective/DocumentPerspectiveList.tsx @@ -98,6 +98,21 @@ export const DocumentPerspectiveList = memo(function DocumentPerspectiveList() { [setPerspective], ) + const isPublishedChipDisabled = useMemo(() => { + if (editState?.liveEdit) { + if (!editState?.published) { + return true + } + + return false + } + + if (!editState?.published) { + return true + } + return false + }, [editState?.liveEdit, editState?.published]) + return ( <> } - disabled={editState?.liveEdit || !editState?.published} + disabled={isPublishedChipDisabled} onClick={handleBundleChange('published')} selected={ /** the publish is selected when: diff --git a/packages/sanity/src/structure/panes/document/documentPanel/header/perspective/__tests__/DocumentPerspectiveList.test.tsx b/packages/sanity/src/structure/panes/document/documentPanel/header/perspective/__tests__/DocumentPerspectiveList.test.tsx index 9d352c9b3d8..ddedc4ca737 100644 --- a/packages/sanity/src/structure/panes/document/documentPanel/header/perspective/__tests__/DocumentPerspectiveList.test.tsx +++ b/packages/sanity/src/structure/panes/document/documentPanel/header/perspective/__tests__/DocumentPerspectiveList.test.tsx @@ -99,32 +99,76 @@ describe('DocumentPerspectiveList', () => { }) describe('disabled chips', () => { - it('should disable the "Published" chip when there is no published document', async () => { + const mockUsePane = { + documentVersions: [mockCurrent], + editState: { + id: 'document-id', + type: 'document-type', + transactionSyncLock: {enabled: false}, + draft: null, + published: null, // make sure that there is no published doc in the mock + liveEdit: false, + ready: true, + version: { + _id: 'versions.release.document-id', + _type: 'document-type', + _createdAt: '2023-01-01T00:00:00Z', + _updatedAt: '2023-01-01T00:00:00Z', + _rev: '1', + }, + liveEditSchemaType: false, + }, + } + + it('should disable the "Published" chip when there is no published document and not live edit', async () => { + mockUseDocumentPane.mockReturnValue(mockUsePane) + + const wrapper = await createTestProvider() + render(, {wrapper}) + + expect(screen.getByRole('button', {name: 'Published'})).toBeDisabled() + }) + + it('should disable the "Published" chip when there is no published document and IS live edit', async () => { mockUseDocumentPane.mockReturnValue({ - documentVersions: [mockCurrent], + ...mockUsePane, + editState: {...mockUsePane.editState, liveEdit: true}, + }) + + const wrapper = await createTestProvider() + render(, {wrapper}) + + expect(screen.getByRole('button', {name: 'Published'})).toBeDisabled() + }) + + it('should enable the "Published" chip when the document is "liveEdit"', async () => { + mockUseDocumentPane.mockReturnValue({ + ...mockUsePane, editState: { - id: 'document-id', - type: 'document-type', - transactionSyncLock: {enabled: false}, - draft: null, - published: null, // make sure that there is no published doc in the mock - liveEdit: false, - ready: true, - version: { - _id: 'versions.release.document-id', + ...mockUsePane.editState, + published: { + _id: 'published-document-id', _type: 'document-type', _createdAt: '2023-01-01T00:00:00Z', _updatedAt: '2023-01-01T00:00:00Z', _rev: '1', }, - liveEditSchemaType: false, }, }) const wrapper = await createTestProvider() render(, {wrapper}) - expect(screen.getByRole('button', {name: 'Published'})).toBeDisabled() + expect(screen.getByRole('button', {name: 'Published'})).toBeEnabled() }) }) + + describe('selected chips', () => { + it.todo('the draft is selected when the document displayed is a draft') + it.todo('the draft is selected when the perspective is null') + it.todo( + 'the draft is selected when when the document is not published and the displayed version is draft,', + ) + it.todo('when there is no draft (new document)') + }) })