Skip to content

Commit

Permalink
test: coverage for add document button in release summary
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanl17 committed Nov 25, 2024
1 parent 5be6f9c commit 87c376f
Showing 1 changed file with 72 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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

View workflow job for this annotation

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

TestingLibraryElementError: Unable to find an element by: [data-testid="document-table-card"] Ignored nodes: comments, script, style <body> <div> <div class="sc-etPtWW jFVRoR" data-testid="loading-block" > <div class="sc-dpBQxM koegQW sc-cEzcPc iBCSov sc-iPHsxv jXHsCg" data-ui="Spinner" > <span> <svg data-sanity-icon="spinner" fill="none" height="1em" viewBox="0 0 25 25" width="1em" xmlns="http://www.w3.org/2000/svg" > <path d="M4.5 12.5C4.5 16.9183 8.08172 20.5 12.5 20.5C16.9183 20.5 20.5 16.9183 20.5 12.5C20.5 8.08172 16.9183 4.5 12.5 4.5" stroke="currentColor" stroke-linejoin="round" stroke-width="1.2" /> </svg> </span> </div> </div> </div> </body> ❯ Object.getElementError ../../node_modules/.pnpm/@testing-library+dom@10.4.0/node_modules/@testing-library/dom/dist/config.js:37:19 ❯ ../../node_modules/.pnpm/@testing-library+dom@10.4.0/node_modules/@testing-library/dom/dist/query-helpers.js:76:38 ❯ ../../node_modules/.pnpm/@testing-library+dom@10.4.0/node_modules/@testing-library/dom/dist/query-helpers.js:52:17 ❯ ../../node_modules/.pnpm/@testing-library+dom@10.4.0/node_modules/@testing-library/dom/dist/query-helpers.js:95:19 ❯ src/core/releases/tool/detail/__tests__/ReleaseSummary.test.tsx:189:37
})

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()
})
})
})

0 comments on commit 87c376f

Please sign in to comment.