-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: coverage for add document button in release summary
- Loading branch information
Showing
1 changed file
with
72 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<ReleaseSummaryProps>) => { | |
} | ||
|
||
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')) | ||
Check failure on line 189 in packages/sanity/src/core/releases/tool/detail/__tests__/ReleaseSummary.test.tsx GitHub Actions / Test (ubuntu-latest / node 18)src/core/releases/tool/detail/__tests__/ReleaseSummary.test.tsx > ReleaseSummary > for an active release > shows list of all documents in release
|
||
}) | ||
|
||
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() | ||
}) | ||
}) | ||
}) |