test(editor): reference dialog, filter and the owner journey, specs follow the dialog
This commit is contained in:
1 parent
7a64daf251
commit
8b42816270
20 files changed
+1546
-1171
No files matched your search
@@ -10,7 +10,6 @@ import {
|
||||
within,
|
||||
} from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
|
||||
import EditorTabBody from '@/components/editor/EditorTabBody'
|
||||
import KeptPlace from '@/components/editor/KeptPlace'
|
||||
import { useSheetDocument } from '@/editor/sheetDocument'
|
||||
@@ -36,7 +35,6 @@ import {
|
||||
versionAnswer,
|
||||
} from '../helpers/editorHarness'
|
||||
import { testLayer } from '../helpers/findingsHost'
|
||||
import { openFinding } from '../helpers/findingDialog'
|
||||
import { mountDraft, setWidth } from '../helpers/editorRoute'
|
||||
|
||||
vi.mock('@/lib/supabase', () => ({ getSupabaseClient: () => ({}) }))
|
||||
@@ -112,26 +110,6 @@ function findingsText(from = baseText(), nodeRefs?: string[]): string {
|
||||
})
|
||||
}
|
||||
|
||||
function referenceText(): string {
|
||||
return insert(baseText(), {
|
||||
kind: 'reference',
|
||||
value: {
|
||||
id: 'ref-1',
|
||||
type: 'journal',
|
||||
citation: 'Doe 2020',
|
||||
url: null,
|
||||
doi: null,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** Constats, the node selected, its « 1 référence » trigger pressed. */
|
||||
async function openCitations(user: Awaited<ReturnType<typeof mount>>) {
|
||||
await user.click(tab('Constats'))
|
||||
await openFinding(user, /Node A/)
|
||||
await user.click(screen.getByRole('button', { name: '1 référence' }))
|
||||
}
|
||||
|
||||
async function mount(text = baseText()) {
|
||||
serverHas(text, 3)
|
||||
const user = userEvent.setup()
|
||||
@@ -199,22 +177,17 @@ describe('text typed in a place that is left', () => {
|
||||
expect(store.getState().unsaved).toBe(false)
|
||||
})
|
||||
|
||||
it('the reference add form survives leaving and returning to the Références tab', async () => {
|
||||
it('the references search survives leaving and returning to the Références tab', async () => {
|
||||
const user = await mount()
|
||||
await user.click(tab('Références'))
|
||||
await user.click(
|
||||
inPlace('references').getByRole('button', {
|
||||
name: 'Ajouter une référence',
|
||||
}),
|
||||
)
|
||||
const field = inPlace('references').getByLabelText('Citation', {
|
||||
selector: '#tab-reference-new-citation',
|
||||
const box = inPlace('references').getByRole('searchbox', {
|
||||
name: 'Rechercher une référence',
|
||||
})
|
||||
await user.type(field, 'Smith 1999')
|
||||
await user.type(box, 'Smith 1999')
|
||||
await user.click(tab('Annotations'))
|
||||
expect(place('references')).not.toBeVisible()
|
||||
await user.click(tab('Références'))
|
||||
expect(field).toHaveValue('Smith 1999')
|
||||
expect(box).toHaveValue('Smith 1999')
|
||||
expect(store.getState().unsaved).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -328,67 +301,6 @@ describe('a field still focused while a place is left', () => {
|
||||
act(() => void store.getState().undoStep())
|
||||
expect(store.getState().documentText).toBe(before)
|
||||
})
|
||||
|
||||
it('a tab click without a focus move commits the Références text, as one undo entry', async () => {
|
||||
const user = await mount(referenceText())
|
||||
const before = store.getState().documentText
|
||||
await user.click(tab('Références'))
|
||||
await user.click(inPlace('references').getByRole('button', { name: /Doe/ }))
|
||||
await user.click(
|
||||
inPlace('references').getByRole('button', { name: 'Modifier' }),
|
||||
)
|
||||
const field = inPlace('references').getByLabelText('Citation', {
|
||||
selector: '#tab-reference-0-ref-1-citation',
|
||||
})
|
||||
await user.click(field)
|
||||
fireEvent.change(field, { target: { value: 'Doe 2023' } })
|
||||
fireEvent.click(tab(/Vérification/))
|
||||
expect(
|
||||
JSON.parse(store.getState().documentText).references[0].citation,
|
||||
).toBe('Doe 2023')
|
||||
expect(store.getState().unsaved).toBe(true)
|
||||
expect(place('references')).not.toBeVisible()
|
||||
act(() => void store.getState().undoStep())
|
||||
expect(store.getState().documentText).toBe(before)
|
||||
})
|
||||
|
||||
/** The panel's first tile opened in edit, its citation field typed in (not blurred). */
|
||||
async function typeInPanelTile(user: Awaited<ReturnType<typeof mount>>) {
|
||||
await openCitations(user)
|
||||
const panel = inPlace('citations')
|
||||
await user.click(panel.getByRole('button', { name: /Doe/ }))
|
||||
await user.click(panel.getByRole('button', { name: 'Modifier' }))
|
||||
const field = panel.getByLabelText('Citation', {
|
||||
selector: '#panel-reference-0-ref-1-citation',
|
||||
})
|
||||
await user.click(field)
|
||||
fireEvent.change(field, { target: { value: 'Doe 2021' } })
|
||||
return field
|
||||
}
|
||||
|
||||
const savedCitation = () =>
|
||||
(JSON.parse(store.getState().documentText) as AnatomicalSheetDocument)
|
||||
.references[0].citation
|
||||
|
||||
it('Escape in a field of a panel tile neither closes the panel nor commits the text (A5)', async () => {
|
||||
const user = await mount(findingsText(referenceText(), ['ref-1']))
|
||||
const before = store.getState().documentText
|
||||
await typeInPanelTile(user)
|
||||
await user.keyboard('{Escape}')
|
||||
expect(screen.getByTestId('editor-citations-panel')).toBeInTheDocument()
|
||||
expect(store.getState().documentText).toBe(before)
|
||||
})
|
||||
|
||||
it('the scrim (no focus move) commits the typed text, then closes the panel after its exit', async () => {
|
||||
const user = await mount(findingsText(referenceText(), ['ref-1']))
|
||||
await typeInPanelTile(user)
|
||||
fireEvent.click(screen.getByTestId('references-scrim'))
|
||||
expect(savedCitation()).toBe('Doe 2021')
|
||||
await waitFor(() =>
|
||||
expect(screen.queryByTestId('editor-citations-panel')).toBeNull(),
|
||||
)
|
||||
expect(store.getState().unsaved).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('ids and parses', () => {
|
||||
|
||||
Reference in new issue
Block a user