test(editor): keep-alive paths, neutral place visibility
Place visibility context moves to lib/placeVisibility.ts so the catalogue
no longer imports from components/editor. Adds tests: selection survival,
unmeasured hint round trip, keyboard tab move and « Aller à » with a field
focused, replace-tracing kept, announcements. Parse-sharing test uses
object identity. Early exits are two statements; shortcut comment on the
parse cache.
R-24:
- editor-equine.spec.ts:118, editor-geometry.spec.ts:376,
editor-recovery.spec.ts:39, editor-signout.spec.ts:26: page.getByLabel
('Nom (FR)') -> place(page, 'general').getByLabel(...)
- editor-shell.spec.ts: toHaveCount(0) on the visible query -> count 1
on the raw selector and toBeHidden()
- editor-keep-alive.test.tsx: JSON.parse stack-trace count -> same
object reference across places
This commit is contained in:
1 parent
6689827a8d
commit
79a09f8b25
12 files changed
+192
-46
No files matched your search
@@ -12,7 +12,9 @@ import {
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
|
||||
import EditorTabBody from '@/components/editor/EditorTabBody'
|
||||
import KeptPlace, { usePlaceVisible } from '@/components/editor/KeptPlace'
|
||||
import KeptPlace from '@/components/editor/KeptPlace'
|
||||
import { useSheetDocument } from '@/editor/sheetDocument'
|
||||
import { usePlaceVisible } from '@/lib/placeVisibility'
|
||||
import { FocusConsumedContext } from '@/editor/focusRequest'
|
||||
import { targetOfKey } from '@/editor/navigation'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
@@ -21,6 +23,7 @@ import {
|
||||
ASSET,
|
||||
drawnText,
|
||||
edit,
|
||||
emptyText,
|
||||
insert,
|
||||
point,
|
||||
} from '../helpers/editorFixtures'
|
||||
@@ -228,6 +231,35 @@ describe('findings and canvas state across a tab change', () => {
|
||||
'true',
|
||||
)
|
||||
expect(layer().style.transform).toBe(zoomed)
|
||||
const list = drawing.getByRole('list', { name: 'Annotations de la vue' })
|
||||
await user.click(within(list).getAllByRole('button')[0])
|
||||
const marker = () =>
|
||||
drawing
|
||||
.getByTestId('annotation-canvas-drawing')
|
||||
.querySelector('[data-anno-id="anno-a"]')
|
||||
const stillSelected = () =>
|
||||
waitFor(() => expect(marker()).toHaveAttribute('data-state', 'current'))
|
||||
await stillSelected()
|
||||
await user.click(tab('Général'))
|
||||
await user.click(tab('Annotations'))
|
||||
await stillSelected()
|
||||
expect(drawing.getByTestId('annotation-properties')).toBeVisible()
|
||||
})
|
||||
|
||||
it('the unmeasured hint opens the views section and « Retour au dessin » restores the same canvas', async () => {
|
||||
serverHas(emptyText(), 3, false)
|
||||
const user = userEvent.setup()
|
||||
mountDraft()
|
||||
await ready()
|
||||
await user.click(tab('Annotations'))
|
||||
const drawing = inPlace('annotations.drawing')
|
||||
const canvas = drawing.getByTestId('annotation-canvas')
|
||||
await user.click(drawing.getByRole('button', { name: 'Vues' }))
|
||||
expect(place('annotations.views')).toBeVisible()
|
||||
expect(place('annotations.drawing')).not.toBeVisible()
|
||||
await user.click(screen.getByRole('button', { name: 'Retour au dessin' }))
|
||||
expect(place('annotations.drawing')).toBeVisible()
|
||||
expect(drawing.getByTestId('annotation-canvas')).toBe(canvas)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -255,6 +287,49 @@ describe('a field still focused while a place is left', () => {
|
||||
expect(store.getState().documentText).toBe(before)
|
||||
})
|
||||
|
||||
it('an arrow key on the tab list commits it first, as one undo entry', async () => {
|
||||
const user = await mount()
|
||||
const before = store.getState().documentText
|
||||
const field = await generalNameField(user)
|
||||
fireEvent.keyDown(tab('Général'), { key: 'ArrowRight' })
|
||||
expect(tab('Annotations')).toHaveAttribute('aria-selected', 'true')
|
||||
expect(JSON.parse(store.getState().documentText).name.fr).toBe('Nom saisi')
|
||||
expect(field).toHaveValue('Nom saisi')
|
||||
expect(store.getState().unsaved).toBe(true)
|
||||
act(() => void store.getState().undoStep())
|
||||
expect(store.getState().documentText).toBe(before)
|
||||
})
|
||||
|
||||
it('« Aller à » activated without a focus move commits it, as one undo entry', async () => {
|
||||
const bare = point('anno-bare', 10, 10, 2)
|
||||
const value = { ...bare.value, geometry: null, name: name('Sans tracé') }
|
||||
const text = insert(referenceText(), {
|
||||
kind: 'annotation',
|
||||
value,
|
||||
} as typeof bare)
|
||||
const user = await mount(text)
|
||||
const before = store.getState().documentText
|
||||
await user.click(tab(/Vérification/))
|
||||
await user.click(referencesButton())
|
||||
const field = inPlace('references').getByLabelText('Citation', {
|
||||
selector: '#reference-ref-1-citation',
|
||||
})
|
||||
await user.click(field)
|
||||
fireEvent.change(field, { target: { value: 'Doe 2023' } })
|
||||
fireEvent.click(
|
||||
inPlace('verification').getAllByRole('button', {
|
||||
name: 'Aller à Sans tracé',
|
||||
})[0],
|
||||
)
|
||||
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)
|
||||
})
|
||||
|
||||
it('Escape in a reference field commits the text before the panel hides', async () => {
|
||||
const user = await mount(referenceText())
|
||||
await user.click(referencesButton())
|
||||
@@ -357,20 +432,22 @@ describe('ids and parses', () => {
|
||||
expect(ids.some((id) => id.includes('body'))).toBe(true)
|
||||
})
|
||||
|
||||
it('one JSON.parse per document text across the places', async () => {
|
||||
const user = await mount()
|
||||
for (const name of ['Général', 'Constats', /Vérification/]) {
|
||||
await user.click(tab(name))
|
||||
it('every place reads the same parsed document per text', async () => {
|
||||
await mount()
|
||||
const seen: unknown[] = []
|
||||
function Probe() {
|
||||
seen.push(useSheetDocument())
|
||||
return null
|
||||
}
|
||||
await user.click(tab('Annotations'))
|
||||
const original = JSON.parse
|
||||
const fromPlaces: string[] = []
|
||||
const parse = vi.spyOn(JSON, 'parse').mockImplementation((...args) => {
|
||||
if (new Error().stack?.includes('parseDocument')) {
|
||||
fromPlaces.push(String(args[0]))
|
||||
}
|
||||
return original(...args)
|
||||
})
|
||||
const first = render(
|
||||
<>
|
||||
<Probe />
|
||||
<Probe />
|
||||
</>,
|
||||
)
|
||||
expect(seen[0]).not.toBeNull()
|
||||
expect(seen[1]).toBe(seen[0])
|
||||
first.unmount()
|
||||
act(() => {
|
||||
store.getState().commit({
|
||||
op: 'insert',
|
||||
@@ -380,8 +457,19 @@ describe('ids and parses', () => {
|
||||
},
|
||||
})
|
||||
})
|
||||
parse.mockRestore()
|
||||
expect(fromPlaces).toEqual([store.getState().documentText])
|
||||
seen.length = 0
|
||||
render(
|
||||
<>
|
||||
<Probe />
|
||||
<Probe />
|
||||
</>,
|
||||
)
|
||||
expect(seen[1]).toBe(seen[0])
|
||||
expect(seen[0]).toMatchObject({
|
||||
categories: expect.arrayContaining([
|
||||
expect.objectContaining({ id: 'cat-z' }),
|
||||
]),
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -439,6 +527,9 @@ describe('a request reaches only its owner', () => {
|
||||
})
|
||||
|
||||
describe('« Aller à » while a creation or a tracing is in progress', () => {
|
||||
const liveText = () =>
|
||||
document.querySelector('p[aria-live="polite"]')?.textContent ?? ''
|
||||
|
||||
function bareAnnotationText(): string {
|
||||
const bare = point('anno-bare', 10, 10, 2)
|
||||
const value = { ...bare.value, geometry: null, name: name('Sans tracé') }
|
||||
@@ -478,6 +569,35 @@ describe('« Aller à » while a creation or a tracing is in progress', () => {
|
||||
const bar = within(place('annotations.drawing')).getByTestId('tracing-bar')
|
||||
expect(bar).toBeVisible()
|
||||
await waitFor(() => expect(document.activeElement).toBe(bar))
|
||||
expect(liveText()).toContain('tracé est en cours')
|
||||
})
|
||||
|
||||
it('a « Remplacer par un polygone » tracing is kept and focused (it cannot coexist with a pending creation)', async () => {
|
||||
const zone = point('zone-a', 0, 0, 1)
|
||||
const zoneValue = {
|
||||
...zone.value,
|
||||
kind: 'zone',
|
||||
geometry: { type: 'path', d: 'M 20 20 L 80 20 L 50 80 Z' },
|
||||
}
|
||||
const text = insert(bareAnnotationText(), {
|
||||
kind: 'annotation',
|
||||
value: zoneValue,
|
||||
} as typeof zone)
|
||||
const user = await mount(text)
|
||||
await gotoBare(user, async () => {
|
||||
const drawing = inPlace('annotations.drawing')
|
||||
const list = drawing.getByRole('list', { name: 'Annotations de la vue' })
|
||||
await user.click(within(list).getAllByRole('button')[0])
|
||||
await user.click(
|
||||
await drawing.findByRole('button', {
|
||||
name: 'Remplacer par un polygone',
|
||||
}),
|
||||
)
|
||||
expect(drawing.getByTestId('tracing-bar')).toBeVisible()
|
||||
})
|
||||
const bar = within(place('annotations.drawing')).getByTestId('tracing-bar')
|
||||
await waitFor(() => expect(document.activeElement).toBe(bar))
|
||||
expect(liveText()).toContain('tracé est en cours')
|
||||
})
|
||||
|
||||
it('a pending creation is kept and focused', async () => {
|
||||
|
||||
Reference in new issue
Block a user