U2 Task 6 (A1, A2, A3, A9, A10, R-3, R-5, R-6, R-14, R-16). - Dialog: `anchor` places the panel at the column's left and width, from its top, under a 22 % ink veil that ignores clicks; the visual viewport below 320 px; centred without an anchor box. - Navigation: `annotation` layer (LAYERS, EditorView, history entry, leave guards, left-draft flag); Back closes, Forward reopens. - AnnotationDialog: read body, « Modifier » form (CreationFields with « Couleur », missingFields, R-3 messages), one `update` on the current annotation by id, « Marquer comme relu », « Modifier la forme », « Supprimer »; read-only flip keeps the draft. - The column always shows the overview, selected row marked; Enter on it, a second click or a double click, the strip's « Propriétés » open the dialog. « Aller à » focuses the row (R-5). - Read-only twin: strip and read-only dialog at 1 024 px and wider, inline read body below. PropertiesPanel and AnnotationFields gone. - Strip lead 256 px and a fixed status slot, so the commands fit at 1 024 px and a status change moves nothing. - e2e: `aside-content` exemption removed; scroll-to-top workarounds of editor-geometry, editor-zones and editor-journey removed. Removed assertions mapped: editor-annotations-tab.test.tsx: - selectFromList waited for `annotation-properties` -> waits for the strip's « Propriétés » (selection without dialog, A1) - refused place: issues block `annotation-geometry-issues` in the panel -> the strip notice alert (present, then gone) - keyboard creation / C26 confirmation: `annotation-properties` after create -> strip « Propriétés » (new element selected) - Désélectionner from the panel -> « Désélectionner » in the strip (all 7 tests); « panel closes » -> strip has no « Propriétés » - undo after deselect (typed name) -> handle key series then deselect then undo - commits a valid typed value once without blur (name field) -> a pending handle key series committed once by the strip deselect - a refused typed value: the panel closes (two tests: strip deselect, tap deselect) -> removed: no field outside the dialog; the dialog's draft writes nothing before « Enregistrer » (new dialog tests) - not offered while a replace tracing runs: panel's Désélectionner absent -> strip offers neither « Désélectionner » nor « Propriétés » during the tracing - tap: isDeselected read `annotation-properties` -> strip « Propriétés » absent; link select -> strip title data-selection - tap: undo after tap deselect (typed name) -> handle series; typed value committed on blur -> handle series committed on blur - strip geometry issues: list read in the panel -> list read in the properties dialog's issues block - a new commit replaces the message (typed name) -> « Marquer comme relu » in the dialog editor-escape.test.tsx: - `panel()` = `annotation-properties` -> the strip's « Propriétés » or the phone twin's inline read body - Escape from a panel button (« Marquer comme relu ») -> from the selected row in the side column: focus on the row - after A then B from the panel (via « Toutes les annotations ») -> select A, select B, Escape from a button of the side column: focus on B's row - a text field (panel « Nom (FR) ») -> the overview « Filtrer par nom » - redraw via the panel's « Remplacer par un polygone » -> the strip's command - modal / delete dialog opened by the panel's « Supprimer » -> « Supprimer » of the properties dialog - read-only width: hidden `annotation-properties` -> hidden strip « Propriétés » of the kept edit body editor-history-buttons.test.tsx (typed text and the press, 8 tests): the annotation's committed « Nom (FR) » field of the panel -> the sheet's committed « Nom (FR) » on Général (same TextField commit-on-blur path; annotation fields are now a dialog draft) editor-focus-request.test.tsx: « Aller à » focuses `data-properties-heading` inside `annotation-properties` -> focuses the annotation's row, marked aria-current, no dialog (R-5) editor-sections.test.tsx: « Aller à » with nothing in progress focused the properties heading -> focuses the row (R-5); creation kept: no `annotation-properties` -> no strip « Propriétés » editor-overview.test.tsx (edit and read-only): row opens `annotation-properties`, « Toutes les annotations » returns -> row selects, stays marked aria-current, no dialog; strip « Désélectionner » returns focus to the row; filter kept across select and « Désélectionner » editor-citations-guards.test.tsx: LAYERS_TOP_DOWN gains 'annotation' at the bottom editor-keep-alive.test.tsx: `annotation-properties` visible after the round trip -> the strip's « Propriétés » visible (selection kept) editor-no-loss.test.tsx: ids `ro-annotation-name-fr` and `annotation-name-fr` (both panels' fields) -> the twin's inline read body (no ids), then the dialog edit form's `annotation-edit-fr`, kept through a flip to 800 px, no duplicate id; « Aller à » visible `annotation-properties` -> visible `annotation-read` (inline twin), none at 1 280 editor-point-edit.test.tsx / editor-zone-edit.test.tsx: `select()` waited for `annotation-properties` and returned it -> waits for the strip's « Propriétés » and returns the strip (its « Désélectionner » and « Remplacer par un polygone » moved there) - move mode Escape: `annotation-properties` still there -> the strip's « Propriétés » back after the mode - « Toutes les annotations » asks first during a started move -> Enter on the selected row asks first (no dialog), and the strip offers neither « Propriétés » nor « Désélectionner » during the mode - Escape from the handle / slider: `annotation-properties` gone -> the strip's « Propriétés » gone - I-3 touch tap: `annotation-properties` gone -> the strip's « Propriétés » gone e2e (sandbox): - support/layout.ts: `aside-content` exemption removed (ShiftExemption type, the loose compare); every `swaps`/`SWAPS` argument removed (editor-annotations, editor-zones, editor-geometry) - support/editor.ts pickAnnotation: clicked « Toutes les annotations » first when the panel showed -> the overview is always shown: clicks the row, then scrolls back to the top (the page no longer shortens) - editor-annotations: `annotation-properties` visible after a creation -> strip with « Propriétés »; review toggle and « Supprimer » of the panel -> the properties dialog's; a jitter click on the selected point now opens the dialog (A1), closed by Escape before the drag; handle names exact (the marked row shares the prefix); trace close moved out of expectNoShift (creation panel until Task 7, shortcut + TODO) - editor-deselect: `annotation-properties` -> the strip with « Propriétés » or the twin's inline read body; Escape in a field: panel « Nom (FR) » -> overview filter; delete dialog from the panel -> from the properties dialog (Escape closes it, then the dialog); « a typed value is applied by the click that deselects » (name field, refused blank) -> a pending point-handle key series applied by the deselecting click and by « Désélectionner » (refused value: no field outside the dialog); « the selected one stays » -> a second click, double click and jitter open the dialog, Escape closes it, selection kept - editor-geometry: `annotation-geometry-issues` in the panel -> read in the properties dialog, then the strip notice; after the refusal the error count unchanged; scroll-to-top workaround removed - editor-zones: panel « Désélectionner » -> strip; scroll-to-top after pickAnnotation removed (helper does it) - editor-structures: panel « Supprimer » -> properties dialog « Supprimer », confirmation over it - editor-journey: `#annotation-name-fr` committed field + `#annotation-laterality` -> the dialog's edit form, one « Enregistrer »; scroll-to-top removed - editor-shell / editor-shell-journeys: « Aller à » focus on `data-properties-heading` -> the annotation's row (aria-current), no dialog (R-5) - editor-shell-layout: focus kind `annotation-properties` -> removed (the overview is the side)
562 lines
19 KiB
TypeScript
562 lines
19 KiB
TypeScript
/** Lot E: the header « Défaire » / « Refaire », the save line's announcements, discard. */
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import {
|
|
act,
|
|
cleanup,
|
|
fireEvent,
|
|
render,
|
|
screen,
|
|
waitFor,
|
|
within,
|
|
} from '@testing-library/react'
|
|
import userEvent from '@testing-library/user-event'
|
|
import DeleteDialog from '@/components/editor/DeleteDialog'
|
|
import { en } from '@/i18n/en'
|
|
import { fr } from '@/i18n/fr'
|
|
import { useLocaleStore } from '@/state/localeStore'
|
|
import {
|
|
baseText,
|
|
commitMove,
|
|
resetStore,
|
|
sb,
|
|
serverHas,
|
|
storedCopy,
|
|
store,
|
|
} from '../helpers/editorHarness'
|
|
import {
|
|
adminAnswer,
|
|
grant,
|
|
mountDraft,
|
|
round,
|
|
setWidth,
|
|
} from '../helpers/editorRoute'
|
|
|
|
vi.mock('@/lib/supabase', () => ({ getSupabaseClient: () => ({}) }))
|
|
vi.mock('@faunosteo/supabase', async (orig) => ({
|
|
...(await orig<typeof import('@faunosteo/supabase')>()),
|
|
getSheetVersion: vi.fn(),
|
|
downloadSheetDrawing: vi.fn(),
|
|
saveSheetDraft: vi.fn(),
|
|
getOfficialSheetAdmin: vi.fn(),
|
|
submitSheetReview: vi.fn(),
|
|
}))
|
|
|
|
beforeEach(() => serverHas(baseText(), 3))
|
|
afterEach(() => {
|
|
cleanup()
|
|
resetStore()
|
|
setWidth(1024)
|
|
})
|
|
|
|
const UNDO = 'Défaire la dernière modification'
|
|
const REDO = 'Refaire la dernière modification défaite'
|
|
const ready = () =>
|
|
screen.findByRole('heading', { level: 1, name: 'Brouillon, version 4' })
|
|
const undoButton = () => screen.getByRole('button', { name: UNDO })
|
|
const redoButton = () => screen.getByRole('button', { name: REDO })
|
|
const disabled = (button: HTMLElement) =>
|
|
button.getAttribute('aria-disabled') === 'true'
|
|
const geometry = () =>
|
|
store.getState().previewState?.document.annotations[0].geometry
|
|
const nameFr = () => store.getState().previewState?.document.name.fr
|
|
|
|
/**
|
|
* A committed field (it writes on its blur): the sheet's French name on Général. U2 Task 6
|
|
* took the annotation's committed fields out of the drawing (one dialog save).
|
|
*/
|
|
async function selectAnnotation(user: ReturnType<typeof userEvent.setup>) {
|
|
await user.click(screen.getByRole('tab', { name: 'Général' }))
|
|
return (await screen.findByLabelText('Nom (FR)')) as HTMLInputElement
|
|
}
|
|
|
|
describe('the buttons', () => {
|
|
it('have the T15 names, titles, shortcuts and a visible label', async () => {
|
|
mountDraft()
|
|
await ready()
|
|
const row = within(screen.getByTestId('history-buttons'))
|
|
expect(undoButton()).toHaveAttribute('title', `${UNDO} (Ctrl+Z ou ⌘Z)`)
|
|
expect(redoButton()).toHaveAttribute('title', `${REDO} (Ctrl+Maj+Z ou ⇧⌘Z)`)
|
|
expect(undoButton()).toHaveAttribute(
|
|
'aria-keyshortcuts',
|
|
'Control+Z Meta+Z',
|
|
)
|
|
expect(redoButton()).toHaveAttribute(
|
|
'aria-keyshortcuts',
|
|
'Control+Shift+Z Meta+Shift+Z',
|
|
)
|
|
expect(row.getAllByRole('button').map((b) => b.textContent)).toEqual([
|
|
'Défaire',
|
|
'Refaire',
|
|
])
|
|
expect(undoButton()).not.toHaveAttribute('disabled')
|
|
})
|
|
|
|
it('keep their English names and carry the English shortcut in the title', async () => {
|
|
mountDraft()
|
|
await ready()
|
|
act(() => useLocaleStore.setState({ locale: 'en' }))
|
|
const undo = screen.getByRole('button', {
|
|
name: en['editor.history.undo_title'],
|
|
})
|
|
const redo = screen.getByRole('button', {
|
|
name: en['editor.history.redo_title'],
|
|
})
|
|
expect(undo).toHaveAttribute('title', 'Undo the last change (Ctrl+Z or ⌘Z)')
|
|
expect(redo).toHaveAttribute(
|
|
'title',
|
|
'Redo the last undone change (Ctrl+Shift+Z or ⇧⌘Z)',
|
|
)
|
|
})
|
|
|
|
it('French prose says « Défaire » while the dialog cancel stays « Annuler »', () => {
|
|
expect(fr['editor.views.drawing.use_parent_body']).toContain('(Défaire)')
|
|
expect(fr['editor.views.repair.body_one']).toContain('un seul Défaire')
|
|
expect(fr['editor.views.repair.body_other']).toContain('un seul Défaire')
|
|
expect(fr['editor.views.drawing.use_parent_cancel']).toBe('Annuler')
|
|
})
|
|
|
|
it('are enabled exactly when the store can step, and step', async () => {
|
|
const user = userEvent.setup()
|
|
mountDraft()
|
|
await ready()
|
|
expect([disabled(undoButton()), disabled(redoButton())]).toEqual([
|
|
true,
|
|
true,
|
|
])
|
|
act(() => void commitMove(40))
|
|
expect([disabled(undoButton()), disabled(redoButton())]).toEqual([
|
|
false,
|
|
true,
|
|
])
|
|
await user.click(undoButton())
|
|
expect(geometry()).toMatchObject({ cx: 50 })
|
|
expect([disabled(undoButton()), disabled(redoButton())]).toEqual([
|
|
true,
|
|
false,
|
|
])
|
|
await user.click(redoButton())
|
|
expect(geometry()).toMatchObject({ cx: 40 })
|
|
})
|
|
|
|
it('stay focused when the last undo empties the stack', async () => {
|
|
const user = userEvent.setup()
|
|
mountDraft()
|
|
await ready()
|
|
act(() => void commitMove(40))
|
|
await user.click(undoButton())
|
|
expect(disabled(undoButton())).toBe(true)
|
|
expect(undoButton()).toHaveFocus()
|
|
})
|
|
|
|
it('are disabled in every mode that cannot edit', async () => {
|
|
const modes: Array<[string, Parameters<typeof mountDraft>[0]]> = [
|
|
['narrow', { width: 800 }],
|
|
['rights', { grants: [grant('sheet_reviewer')], roles: [] }],
|
|
['frozen', { answer: adminAnswer({ rounds: [round('open')] }) }],
|
|
['historical', { answer: adminAnswer({ historical: true }) }],
|
|
['inactive', { answer: adminAnswer({ status: 'archived' }) }],
|
|
]
|
|
for (const [, options] of modes) {
|
|
serverHas(baseText(), 3)
|
|
const view = mountDraft(options)
|
|
await ready()
|
|
store.setState({ undo: [{ text: baseText(), bytes: 1 }] })
|
|
expect(disabled(undoButton())).toBe(true)
|
|
await userEvent.setup().click(undoButton())
|
|
expect(store.getState().undo).toHaveLength(1)
|
|
view.unmount()
|
|
cleanup()
|
|
resetStore()
|
|
}
|
|
})
|
|
|
|
it('are disabled while a recovery decision is pending', async () => {
|
|
mountDraft()
|
|
await ready()
|
|
act(() => void commitMove(40))
|
|
act(() => store.setState({ recovery: 'pending' }))
|
|
expect(disabled(undoButton())).toBe(true)
|
|
})
|
|
|
|
it('stay enabled while saving, in step with Ctrl+Z', async () => {
|
|
const user = userEvent.setup()
|
|
sb.saveSheetDraft.mockReturnValue(new Promise(() => undefined) as never)
|
|
mountDraft()
|
|
await ready()
|
|
act(() => void commitMove(40))
|
|
await user.click(screen.getByRole('button', { name: 'Enregistrer' }))
|
|
await waitFor(() => expect(store.getState().saving).toBe(true))
|
|
expect(disabled(undoButton())).toBe(false)
|
|
fireEvent.keyDown(document.body, { key: 'z', ctrlKey: true })
|
|
expect(geometry()).toMatchObject({ cx: 50 })
|
|
expect(store.getState().redo).toHaveLength(1)
|
|
await user.click(redoButton())
|
|
expect(geometry()).toMatchObject({ cx: 40 })
|
|
})
|
|
|
|
it('undo from Général and from Constats reverts a canvas change', async () => {
|
|
const user = userEvent.setup()
|
|
mountDraft()
|
|
await ready()
|
|
act(() => void commitMove(40))
|
|
await user.click(screen.getByRole('tab', { name: 'Général' }))
|
|
await user.click(undoButton())
|
|
expect(geometry()).toMatchObject({ cx: 50 })
|
|
await user.click(redoButton())
|
|
await user.click(screen.getByRole('tab', { name: 'Constats' }))
|
|
await user.click(undoButton())
|
|
expect(geometry()).toMatchObject({ cx: 50 })
|
|
})
|
|
|
|
it('undo from Annotations reverts a Général change', async () => {
|
|
const user = userEvent.setup()
|
|
mountDraft()
|
|
await ready()
|
|
const original = store.getState().previewState?.document.name?.fr
|
|
await user.click(screen.getByRole('tab', { name: 'Général' }))
|
|
const place = document.querySelector(
|
|
'[data-place="general"]',
|
|
) as HTMLElement
|
|
const field = within(place).getByLabelText('Nom (FR)')
|
|
await user.clear(field)
|
|
await user.type(field, 'Renommée')
|
|
await user.click(screen.getByRole('tab', { name: 'Annotations' }))
|
|
expect(store.getState().previewState?.document.name?.fr).toBe('Renommée')
|
|
await user.click(undoButton())
|
|
expect(store.getState().previewState?.document.name?.fr).toBe(original)
|
|
})
|
|
|
|
it('leave no undo or redo pair in the tool column', async () => {
|
|
mountDraft()
|
|
await ready()
|
|
const tools = screen.getByRole('toolbar', {
|
|
name: fr['editor.annotations.tools'],
|
|
})
|
|
expect(
|
|
within(tools).queryByRole('button', { name: /Défaire|Refaire/ }),
|
|
).toBeNull()
|
|
})
|
|
})
|
|
|
|
describe('typed text and the press', () => {
|
|
it('undo reverts exactly the typed text, with and without earlier history', async () => {
|
|
const user = userEvent.setup()
|
|
mountDraft()
|
|
await ready()
|
|
const field = await selectAnnotation(user)
|
|
const original = nameFr()
|
|
await user.clear(field)
|
|
await user.type(field, 'Nouveau')
|
|
await user.pointer({ keys: '[MouseLeft]', target: undoButton() })
|
|
expect(nameFr()).toBe(original)
|
|
expect(store.getState().redo).toHaveLength(1)
|
|
act(() => void commitMove(40))
|
|
await user.clear(field)
|
|
await user.type(field, 'Encore')
|
|
await user.pointer({ keys: '[MouseLeft]', target: undoButton() })
|
|
expect(nameFr()).toBe(original)
|
|
expect(geometry()).toMatchObject({ cx: 40 })
|
|
})
|
|
|
|
it('the pointer press blurs the focused field', async () => {
|
|
const user = userEvent.setup()
|
|
mountDraft()
|
|
await ready()
|
|
const field = await selectAnnotation(user)
|
|
await user.clear(field)
|
|
await user.type(field, 'Saisie')
|
|
fireEvent.pointerDown(undoButton())
|
|
expect(field).not.toHaveFocus()
|
|
expect(nameFr()).toBe('Saisie')
|
|
})
|
|
|
|
it('a refused blur commit skips the undo and returns focus to the field', async () => {
|
|
const user = userEvent.setup()
|
|
mountDraft()
|
|
await ready()
|
|
act(() => void commitMove(40))
|
|
const field = await selectAnnotation(user)
|
|
await user.clear(field)
|
|
await user.pointer({ keys: '[MouseLeft]', target: undoButton() })
|
|
expect(field).toHaveAttribute('aria-invalid', 'true')
|
|
expect(field).toHaveFocus()
|
|
expect(geometry()).toMatchObject({ cx: 40 })
|
|
})
|
|
|
|
async function refusedField() {
|
|
const user = userEvent.setup()
|
|
mountDraft()
|
|
await ready()
|
|
act(() => void commitMove(40))
|
|
const field = await selectAnnotation(user)
|
|
await user.clear(field)
|
|
return field
|
|
}
|
|
|
|
/** A press as a touch sends it: down, up, the leave it fires, then the click. */
|
|
function touchPress() {
|
|
const init = { pointerType: 'touch' }
|
|
fireEvent.pointerDown(undoButton(), init)
|
|
fireEvent.pointerUp(undoButton(), init)
|
|
fireEvent.pointerLeave(undoButton(), init)
|
|
fireEvent.click(undoButton())
|
|
}
|
|
|
|
it('a touch press keeps the refused field across pointer leave and click', async () => {
|
|
const field = await refusedField()
|
|
touchPress()
|
|
expect(field).toHaveAttribute('aria-invalid', 'true')
|
|
expect(field).toHaveFocus()
|
|
expect(geometry()).toMatchObject({ cx: 40 })
|
|
expect(store.getState().undo).toHaveLength(1)
|
|
})
|
|
|
|
it('a touch press cancelled by the browser forgets the field', async () => {
|
|
const field = await refusedField()
|
|
fireEvent.pointerDown(undoButton(), { pointerType: 'touch' })
|
|
fireEvent.pointerCancel(undoButton(), { pointerType: 'touch' })
|
|
fireEvent.click(undoButton())
|
|
expect(field).not.toHaveFocus()
|
|
expect(geometry()).toMatchObject({ cx: 50 })
|
|
})
|
|
|
|
it('a mouse leaving the button forgets the field', async () => {
|
|
const field = await refusedField()
|
|
fireEvent.pointerDown(undoButton(), { pointerType: 'mouse' })
|
|
fireEvent.pointerLeave(undoButton(), { pointerType: 'mouse' })
|
|
fireEvent.click(undoButton())
|
|
expect(field).not.toHaveFocus()
|
|
expect(geometry()).toMatchObject({ cx: 50 })
|
|
})
|
|
|
|
it('a keyboard activation after a refused blur commit skips the undo too', async () => {
|
|
const user = userEvent.setup()
|
|
mountDraft()
|
|
await ready()
|
|
act(() => void commitMove(40))
|
|
const field = await selectAnnotation(user)
|
|
await user.clear(field)
|
|
field.blur()
|
|
act(() => undoButton().focus())
|
|
fireEvent.focus(undoButton(), { relatedTarget: field })
|
|
await user.keyboard('{Enter}')
|
|
expect(field).toHaveAttribute('aria-invalid', 'true')
|
|
expect(field).toHaveFocus()
|
|
expect(geometry()).toMatchObject({ cx: 40 })
|
|
expect(store.getState().undo).toHaveLength(1)
|
|
})
|
|
|
|
it('a field left through « Refaire » to « Défaire » still skips the undo', async () => {
|
|
const user = userEvent.setup()
|
|
mountDraft()
|
|
await ready()
|
|
act(() => void commitMove(40))
|
|
const field = await selectAnnotation(user)
|
|
await user.clear(field)
|
|
field.blur()
|
|
const redo = screen.getByRole('button', {
|
|
name: REDO,
|
|
})
|
|
act(() => redo.focus())
|
|
fireEvent.focus(redo, { relatedTarget: field })
|
|
act(() => undoButton().focus())
|
|
fireEvent.focus(undoButton(), { relatedTarget: redo })
|
|
await user.keyboard('{Enter}')
|
|
expect(field).toHaveFocus()
|
|
expect(store.getState().undo).toHaveLength(1)
|
|
})
|
|
|
|
it('Ctrl+Z is ignored while a DeleteDialog is open', async () => {
|
|
mountDraft()
|
|
await ready()
|
|
act(() => void commitMove(40))
|
|
render(
|
|
<DeleteDialog
|
|
target={{ key: { kind: 'annotation', id: 'anno-a' }, label: 'N' }}
|
|
onClose={vi.fn()}
|
|
/>,
|
|
)
|
|
await screen.findByRole('dialog')
|
|
fireEvent.keyDown(document.body, { key: 'z', ctrlKey: true })
|
|
expect(geometry()).toMatchObject({ cx: 40 })
|
|
})
|
|
|
|
it('Ctrl+Z inside a field leaves the store untouched', async () => {
|
|
mountDraft()
|
|
await ready()
|
|
act(() => void commitMove(40))
|
|
const before = store.getState().documentText
|
|
fireEvent.keyDown(document.querySelector('input') as Element, {
|
|
key: 'z',
|
|
ctrlKey: true,
|
|
})
|
|
expect(store.getState().documentText).toBe(before)
|
|
})
|
|
})
|
|
|
|
describe('the save status', () => {
|
|
it('announces state transitions, never each count', async () => {
|
|
const user = userEvent.setup()
|
|
sb.saveSheetDraft.mockResolvedValue({ revision: 4 } as never)
|
|
mountDraft()
|
|
await ready()
|
|
const status = screen.getByTestId('save-status')
|
|
expect(status).toHaveTextContent(/^$/)
|
|
act(() => void commitMove(40))
|
|
expect(status).toHaveTextContent(/^Modifications non enregistrées$/)
|
|
act(() => void commitMove(41))
|
|
expect(status).toHaveTextContent(/^Modifications non enregistrées$/)
|
|
expect(screen.getByTestId('save-line')).toHaveTextContent(
|
|
/^2 modifications non enregistrées$/,
|
|
)
|
|
await user.click(screen.getByRole('button', { name: 'Enregistrer' }))
|
|
await waitFor(() =>
|
|
expect(status).toHaveTextContent(/^Enregistré · révision 4$/),
|
|
)
|
|
})
|
|
|
|
it('shows the server time once read, « Enregistré · révision n » otherwise', async () => {
|
|
const user = userEvent.setup()
|
|
sb.saveSheetDraft.mockResolvedValue({ revision: 4 } as never)
|
|
mountDraft()
|
|
await ready()
|
|
act(() => void commitMove(40))
|
|
sb.getOfficialSheetAdmin.mockResolvedValue(
|
|
adminAnswer({
|
|
draft_version: { version_id: 'ver-1', version_number: 4, revision: 4 },
|
|
draft_last_save: {
|
|
revision: 4,
|
|
saved_at: '2026-11-04T13:32:00Z',
|
|
saved_by: null,
|
|
},
|
|
}) as never,
|
|
)
|
|
await user.click(screen.getByRole('button', { name: 'Enregistrer' }))
|
|
await waitFor(() =>
|
|
expect(screen.getByTestId('save-line')).toHaveTextContent(
|
|
/^Enregistré à 14:32 · révision 4$/,
|
|
),
|
|
)
|
|
})
|
|
|
|
it('shows « Enregistré · révision n » when the read fails, editor still mounted', async () => {
|
|
const user = userEvent.setup()
|
|
sb.saveSheetDraft.mockResolvedValue({ revision: 4 } as never)
|
|
mountDraft()
|
|
await ready()
|
|
act(() => void commitMove(40))
|
|
sb.getOfficialSheetAdmin.mockRejectedValue(new Error('offline'))
|
|
await user.click(screen.getByRole('button', { name: 'Enregistrer' }))
|
|
await waitFor(() =>
|
|
expect(screen.getByTestId('save-line')).toHaveTextContent(
|
|
/^Enregistré · révision 4$/,
|
|
),
|
|
)
|
|
expect(screen.getByRole('heading', { level: 1 })).toBeInTheDocument()
|
|
})
|
|
|
|
it('shows no saved line while the save is in flight', async () => {
|
|
const user = userEvent.setup()
|
|
sb.saveSheetDraft.mockReturnValue(new Promise(() => undefined) as never)
|
|
mountDraft()
|
|
await ready()
|
|
act(() => void commitMove(40))
|
|
await user.click(screen.getByRole('button', { name: 'Enregistrer' }))
|
|
expect(screen.getByTestId('save-line')).toHaveTextContent(
|
|
/^Enregistrement…$/,
|
|
)
|
|
})
|
|
|
|
it('reserves its widest form so the row does not move', async () => {
|
|
mountDraft()
|
|
await ready()
|
|
const sizers = screen
|
|
.getByTestId('save-line')
|
|
.parentElement!.querySelectorAll('[aria-hidden]')
|
|
expect([...sizers].map((el) => el.textContent)).toEqual([
|
|
'Enregistré à 00:00 · révision 999',
|
|
'999 modifications non enregistrées',
|
|
])
|
|
})
|
|
})
|
|
|
|
describe('« Abandonner les modifications »', () => {
|
|
const open = async (user: ReturnType<typeof userEvent.setup>) => {
|
|
await user.click(
|
|
screen.getByRole('button', { name: 'Abandonner les modifications' }),
|
|
)
|
|
return within(await screen.findByRole('dialog'))
|
|
}
|
|
|
|
it('names the stored copy, and keeps changes and copy on cancel', async () => {
|
|
const user = userEvent.setup()
|
|
mountDraft()
|
|
await ready()
|
|
act(() => void commitMove(40))
|
|
const dialog = await open(user)
|
|
expect(
|
|
dialog.getByText(new RegExp(fr['editor.draft.discard_copy'])),
|
|
).toBeInTheDocument()
|
|
await user.click(dialog.getByRole('button', { name: 'Annuler' }))
|
|
expect(store.getState().unsaved).toBe(true)
|
|
expect(storedCopy()).not.toBeNull()
|
|
})
|
|
|
|
it('names a copy left by an earlier write after a quota refusal', async () => {
|
|
const user = userEvent.setup()
|
|
mountDraft()
|
|
await ready()
|
|
act(() => void commitMove(40))
|
|
expect(storedCopy()).not.toBeNull()
|
|
vi.spyOn(console, 'warn').mockImplementation(() => {})
|
|
vi.spyOn(sessionStorage, 'setItem').mockImplementation(() => {
|
|
throw new DOMException('full', 'QuotaExceededError')
|
|
})
|
|
act(() => void commitMove(41))
|
|
await waitFor(() => expect(store.getState().copyIssue).toBe('quota'))
|
|
const dialog = await open(user)
|
|
expect(
|
|
dialog.getByText(new RegExp(fr['editor.draft.discard_copy'])),
|
|
).toBeInTheDocument()
|
|
})
|
|
|
|
it("keeps the session's save in the save line, and the save line says it", async () => {
|
|
const user = userEvent.setup()
|
|
sb.saveSheetDraft.mockResolvedValue({ revision: 4 } as never)
|
|
sb.getOfficialSheetAdmin.mockRejectedValue(new Error('offline'))
|
|
mountDraft()
|
|
await ready()
|
|
act(() => void commitMove(40))
|
|
await user.click(screen.getByRole('button', { name: 'Enregistrer' }))
|
|
const line = screen.getByTestId('save-line')
|
|
await waitFor(() =>
|
|
expect(line).toHaveTextContent(/^Enregistré · révision 4$/),
|
|
)
|
|
act(() => void commitMove(41))
|
|
expect(line).toHaveTextContent(/^1 modification non enregistrée$/)
|
|
const dialog = await open(user)
|
|
await user.click(
|
|
dialog.getByRole('button', { name: fr['editor.draft.discard_confirm'] }),
|
|
)
|
|
expect(store.getState().unsaved).toBe(false)
|
|
expect(geometry()).toMatchObject({ cx: 40 })
|
|
expect(line).toHaveTextContent(/^Enregistré · révision 4$/)
|
|
})
|
|
|
|
it('does not mention a copy when none is stored', async () => {
|
|
const user = userEvent.setup()
|
|
vi.spyOn(console, 'warn').mockImplementation(() => {})
|
|
vi.spyOn(sessionStorage, 'setItem').mockImplementation(() => {
|
|
throw new DOMException('full', 'QuotaExceededError')
|
|
})
|
|
mountDraft()
|
|
await ready()
|
|
act(() => void commitMove(40))
|
|
const dialog = await open(user)
|
|
expect(dialog.getByText(fr['editor.draft.discard_ask'])).toBeInTheDocument()
|
|
expect(
|
|
dialog.queryByText(new RegExp(fr['editor.draft.discard_copy'])),
|
|
).toBeNull()
|
|
})
|
|
})
|