Skip to content

Commit

Permalink
fix(sanity): issue with the publish chip disable + update tests (#7968)
Browse files Browse the repository at this point in the history
  • Loading branch information
RitaDias authored Dec 6, 2024
1 parent 5677b53 commit 351a6a4
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
<VersionChip
Expand All @@ -114,7 +129,7 @@ export const DocumentPerspectiveList = memo(function DocumentPerspectiveList() {
)}
</Text>
}
disabled={editState?.liveEdit || !editState?.published}
disabled={isPublishedChipDisabled}
onClick={handleBundleChange('published')}
selected={
/** the publish is selected when:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(<DocumentPerspectiveList />, {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(<DocumentPerspectiveList />, {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(<DocumentPerspectiveList />, {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)')
})
})

0 comments on commit 351a6a4

Please sign in to comment.