From 87c376ff99ea8aad5077dece40c54f0a090eafea Mon Sep 17 00:00:00 2001 From: Jordan Lawrence Date: Mon, 25 Nov 2024 19:30:31 +0000 Subject: [PATCH] test: coverage for add document button in release summary --- .../detail/__tests__/ReleaseSummary.test.tsx | 106 ++++++++++++------ 1 file changed, 72 insertions(+), 34 deletions(-) diff --git a/packages/sanity/src/core/releases/tool/detail/__tests__/ReleaseSummary.test.tsx b/packages/sanity/src/core/releases/tool/detail/__tests__/ReleaseSummary.test.tsx index 1c6f00e03dd..a235f7b3a1d 100644 --- a/packages/sanity/src/core/releases/tool/detail/__tests__/ReleaseSummary.test.tsx +++ b/packages/sanity/src/core/releases/tool/detail/__tests__/ReleaseSummary.test.tsx @@ -5,7 +5,11 @@ import {beforeEach, describe, expect, it, vi} from 'vitest' import {getByDataUi} from '../../../../../../test/setup/customQueries' import {createTestProvider} from '../../../../../../test/testUtils/TestProvider' import {DefaultPreview} from '../../../../components/previews/general/DefaultPreview' -import {activeASAPRelease} from '../../../__fixtures__/release.fixture' +import { + activeASAPRelease, + archivedScheduledRelease, + scheduledRelease, +} from '../../../__fixtures__/release.fixture' import {releasesUsEnglishLocaleBundle} from '../../../i18n' import {ReleaseSummary, type ReleaseSummaryProps} from '../ReleaseSummary' import {type DocumentInRelease} from '../useBundleDocuments' @@ -177,56 +181,90 @@ const renderTest = async (props: Partial) => { } describe('ReleaseSummary', () => { - beforeEach(async () => { - vi.clearAllMocks() + describe('for an active release', () => { + beforeEach(async () => { + vi.clearAllMocks() - await renderTest({}) - await vi.waitFor(() => screen.getByTestId('document-table-card')) - }) + await renderTest({}) + await vi.waitFor(() => screen.getByTestId('document-table-card')) + }) - it('shows list of all documents in release', async () => { - const documents = screen.getAllByTestId('table-row') + it('shows list of all documents in release', async () => { + const documents = screen.getAllByTestId('table-row') - expect(documents).toHaveLength(2) - }) + expect(documents).toHaveLength(2) + }) - it('allows for document to be discarded', () => { - const [firstDocumentRow] = screen.getAllByTestId('table-row') + it('allows for document to be discarded', () => { + const [firstDocumentRow] = screen.getAllByTestId('table-row') - fireEvent.click(getByDataUi(firstDocumentRow, 'MenuButton')) - fireEvent.click(screen.getByText('Discard version')) - }) + fireEvent.click(getByDataUi(firstDocumentRow, 'MenuButton')) + fireEvent.click(screen.getByText('Discard version')) + }) + + it('allows for sorting of documents', () => { + const [initialFirstDocument, initialSecondDocument] = screen.getAllByTestId('table-row') + + within(initialFirstDocument).getByText('First document') + within(initialSecondDocument).getByText('Second document') - it('allows for sorting of documents', () => { - const [initialFirstDocument, initialSecondDocument] = screen.getAllByTestId('table-row') + fireEvent.click(within(screen.getByRole('table')).getByText('Edited')) - within(initialFirstDocument).getByText('First document') - within(initialSecondDocument).getByText('Second document') + const [sortedCreatedAscFirstDocument, sortedCreatedAscSecondDocument] = + screen.getAllByTestId('table-row') - fireEvent.click(within(screen.getByRole('table')).getByText('Edited')) + within(sortedCreatedAscFirstDocument).getByText('Second document') + within(sortedCreatedAscSecondDocument).getByText('First document') - const [sortedCreatedAscFirstDocument, sortedCreatedAscSecondDocument] = - screen.getAllByTestId('table-row') + fireEvent.click(within(screen.getByRole('table')).getByText('Edited')) - within(sortedCreatedAscFirstDocument).getByText('Second document') - within(sortedCreatedAscSecondDocument).getByText('First document') + const [sortedEditedDescFirstDocument, sortedEditedDescSecondDocument] = + screen.getAllByTestId('table-row') + + within(sortedEditedDescFirstDocument).getByText('First document') + within(sortedEditedDescSecondDocument).getByText('Second document') + }) - fireEvent.click(within(screen.getByRole('table')).getByText('Edited')) + it('allows for searching documents', async () => { + await act(() => { + fireEvent.change(screen.getByPlaceholderText('Search documents'), { + target: {value: 'Second'}, + }) + }) - const [sortedEditedDescFirstDocument, sortedEditedDescSecondDocument] = - screen.getAllByTestId('table-row') + const [searchedFirstDocument] = screen.getAllByTestId('table-row') - within(sortedEditedDescFirstDocument).getByText('First document') - within(sortedEditedDescSecondDocument).getByText('Second document') + within(searchedFirstDocument).getByText('Second document') + }) + + it('Allows for adding a document to an active release', () => { + screen.getByText('Add document') + }) }) - it('allows for searching documents', async () => { - await act(() => { - fireEvent.change(screen.getByPlaceholderText('Search documents'), {target: {value: 'Second'}}) + describe('for an archived release', () => { + beforeEach(async () => { + vi.clearAllMocks() + + await renderTest({release: archivedScheduledRelease}) + await vi.waitFor(() => screen.getByTestId('document-table-card')) + }) + + it('does not allow for adding documents', () => { + expect(screen.queryByText('Add document')).toBeNull() }) + }) - const [searchedFirstDocument] = screen.getAllByTestId('table-row') + describe('for a scheduled release', () => { + beforeEach(async () => { + vi.clearAllMocks() - within(searchedFirstDocument).getByText('Second document') + await renderTest({release: scheduledRelease}) + await vi.waitFor(() => screen.getByTestId('document-table-card')) + }) + + it('does not allow for adding documents', () => { + expect(screen.queryByText('Add document')).toBeNull() + }) }) })