fix(editor): final review fixes (touch undo guard, focus, save line)
Important 1: a touch press fires pointer leave between up and click; only a mouse leave (or a pointer cancel) forgets the refused field, so Annuler no longer undoes an unrelated change. Important 2: the LAN spec reads the revision before the attach, through shownRevision, which throws instead of NaN (spec stays not run). Minor 1: refocusIfHidden refocuses a still shown element the commit blurred (references search on a 1 024 px crossing). Minor 2: discardChanges keeps lastSave (reload path still drops it). Minor 3: the overview filter term lives in UiState / the read-only twin, not the card. Minor 4: categories section drops its inner h3 and the unused editor.general.categories keys. AC8: badge test. Assertions rewritten or added (R-24): - editor-tabs-general « Général no longer holds the categories editor »: queryByText of the deleted heading (now vacuous) -> queryByLabelText of the category name fields. - editor-focus-request « Annotations: selects the annotation »: findAllByText /anno-b|Sélection/ -> the properties panel holds Centre x = 20 (anno-b) and owns the focused heading. - editor-shell-layout panel walk: added after.at(-1) === 'side'. - editor-recovery title « Annuler les modifications » -> « Abandonner ». - new: touch/cancel/mouse press, references search crossing, discard keeps lastSave, filter kept, one categories heading, badge 1/2/0, shownRevision.
This commit is contained in:
1 parent
942d52a835
commit
0467885527
22 files changed
+327
-38
No files matched your search
@@ -3,6 +3,7 @@ import { fr } from '@/i18n/fr'
|
|||||||
import type { Page } from '@playwright/test'
|
import type { Page } from '@playwright/test'
|
||||||
import { totpCode } from '../../../../packages/supabase/tests/sandbox/totp'
|
import { totpCode } from '../../../../packages/supabase/tests/sandbox/totp'
|
||||||
import { expect, test } from '../support/browser'
|
import { expect, test } from '../support/browser'
|
||||||
|
import { shownRevision } from '../support/saveLineText'
|
||||||
|
|
||||||
// Owner trial through its LAN origin (C47): sign-in, TOTP enrolment and challenge, the
|
// Owner trial through its LAN origin (C47): sign-in, TOTP enrolment and challenge, the
|
||||||
// catalogue, a non-equine sheet, an SVG import, save and reload. The request guard of
|
// catalogue, a non-equine sheet, an SVG import, save and reload. The request guard of
|
||||||
@@ -23,11 +24,9 @@ const SVG =
|
|||||||
|
|
||||||
const saveLine = (page: Page) => page.getByTestId('save-line')
|
const saveLine = (page: Page) => page.getByTestId('save-line')
|
||||||
|
|
||||||
|
// Read while the line says « Révision n »: a pending change shows no revision.
|
||||||
async function revisionShown(page: Page): Promise<number> {
|
async function revisionShown(page: Page): Promise<number> {
|
||||||
const text = (await saveLine(page).textContent()) ?? ''
|
return shownRevision((await saveLine(page).textContent()) ?? '')
|
||||||
return Number(
|
|
||||||
/révision (\d+)|Révision (\d+)/.exec(text)?.slice(1).find(Boolean),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function nextCode(secret: string): Promise<string> {
|
async function nextCode(secret: string): Promise<string> {
|
||||||
@@ -131,6 +130,8 @@ test('trial through the LAN origin: MFA, new sheet, SVG import, save, reload', a
|
|||||||
await challenge(page, secret)
|
await challenge(page, secret)
|
||||||
await createNonEquineSheet(page, tag)
|
await createNonEquineSheet(page, tag)
|
||||||
await openViews(page)
|
await openViews(page)
|
||||||
|
await expect(saveLine(page)).toHaveText(/^Révision \d+$/)
|
||||||
|
const before = await revisionShown(page)
|
||||||
await page
|
await page
|
||||||
.locator('[data-testid$="-file"]')
|
.locator('[data-testid$="-file"]')
|
||||||
.first()
|
.first()
|
||||||
@@ -147,7 +148,6 @@ test('trial through the LAN origin: MFA, new sheet, SVG import, save, reload', a
|
|||||||
.getByRole('button', { name: dict['editor.cleaning.confirm'] })
|
.getByRole('button', { name: dict['editor.cleaning.confirm'] })
|
||||||
.click()
|
.click()
|
||||||
await expect(page.getByText(dict['editor.upload.done'])).toBeVisible()
|
await expect(page.getByText(dict['editor.upload.done'])).toBeVisible()
|
||||||
const before = await revisionShown(page)
|
|
||||||
await page.getByRole('button', { name: dict['common.save'] }).click()
|
await page.getByRole('button', { name: dict['common.save'] }).click()
|
||||||
await expect(saveLine(page)).toHaveText(
|
await expect(saveLine(page)).toHaveText(
|
||||||
new RegExp(`^Enregistré( à \\d\\d:\\d\\d)? · révision ${before + 1}$`),
|
new RegExp(`^Enregistré( à \\d\\d:\\d\\d)? · révision ${before + 1}$`),
|
||||||
|
|||||||
@@ -308,5 +308,6 @@ test.describe('editor shell keyboard order (H)', () => {
|
|||||||
const after = await walk(page, 'side')
|
const after = await walk(page, 'side')
|
||||||
expect(after.slice(0, 4)).toEqual(['header', 'tab', 'undo', 'redo'])
|
expect(after.slice(0, 4)).toEqual(['header', 'tab', 'undo', 'redo'])
|
||||||
expect(after).not.toContain('panel')
|
expect(after).not.toContain('panel')
|
||||||
|
expect(after.at(-1)).toBe('side')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* The revision a save line text names: « Révision n » or « Enregistré · révision n ». The
|
||||||
|
* unsaved forms name none, so a reading taken while changes are pending throws instead of
|
||||||
|
* answering NaN.
|
||||||
|
*/
|
||||||
|
export function shownRevision(text: string): number {
|
||||||
|
const found = /révision (\d+)/i.exec(text)
|
||||||
|
if (!found) throw new Error(`The save line shows no revision: « ${text} »`)
|
||||||
|
return Number(found[1])
|
||||||
|
}
|
||||||
@@ -1,4 +1,9 @@
|
|||||||
import { useRef, type FocusEvent, type RefObject } from 'react'
|
import {
|
||||||
|
useRef,
|
||||||
|
type FocusEvent,
|
||||||
|
type PointerEvent,
|
||||||
|
type RefObject,
|
||||||
|
} from 'react'
|
||||||
import { useEditorReadOnly } from '@/editor/editingContext'
|
import { useEditorReadOnly } from '@/editor/editingContext'
|
||||||
import { commitFocusedField } from '@/editor/focusRequest'
|
import { commitFocusedField } from '@/editor/focusRequest'
|
||||||
import { canRedo, canUndo, useEditorStore } from '@/editor/state/editorStore'
|
import { canRedo, canUndo, useEditorStore } from '@/editor/state/editorStore'
|
||||||
@@ -33,7 +38,9 @@ function asField(element: Element | EventTarget | null): HTMLElement | null {
|
|||||||
* pointer-down, natural when Tab reaches the button), the click or key then reads the
|
* pointer-down, natural when Tab reaches the button), the click or key then reads the
|
||||||
* store, so the typed text is the last change the undo reverts. A field whose commit was
|
* store, so the typed text is the last change the undo reverts. A field whose commit was
|
||||||
* refused keeps its error: the step is skipped and focus goes back to it. The field is
|
* refused keeps its error: the step is skipped and focus goes back to it. The field is
|
||||||
* remembered across the pair: from a field, « Annuler » is two Shift+Tab away.
|
* remembered across the pair: from a field, « Annuler » is two Shift+Tab away. A touch
|
||||||
|
* press fires pointer leave between its up and its click, so only a mouse leaving the
|
||||||
|
* button forgets the field (a hovering pointer that left meant no press), or a cancel.
|
||||||
*/
|
*/
|
||||||
function usePress(
|
function usePress(
|
||||||
direction: Direction,
|
direction: Direction,
|
||||||
@@ -48,6 +55,9 @@ function usePress(
|
|||||||
const pair = event.currentTarget.parentElement
|
const pair = event.currentTarget.parentElement
|
||||||
if (!pair?.contains(event.relatedTarget as Node | null)) forget()
|
if (!pair?.contains(event.relatedTarget as Node | null)) forget()
|
||||||
}
|
}
|
||||||
|
const onPointerLeave = (event: PointerEvent<HTMLElement>) => {
|
||||||
|
if (event.pointerType === 'mouse') forget()
|
||||||
|
}
|
||||||
const onPointerDown = () => {
|
const onPointerDown = () => {
|
||||||
left.current = asField(document.activeElement) ?? left.current
|
left.current = asField(document.activeElement) ?? left.current
|
||||||
commitFocusedField()
|
commitFocusedField()
|
||||||
@@ -72,7 +82,8 @@ function usePress(
|
|||||||
onPointerDown,
|
onPointerDown,
|
||||||
onFocus,
|
onFocus,
|
||||||
onBlur,
|
onBlur,
|
||||||
onPointerLeave: forget,
|
onPointerLeave,
|
||||||
|
onPointerCancel: forget,
|
||||||
onClick,
|
onClick,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -274,6 +274,8 @@ function SidePanel({
|
|||||||
doc={doc}
|
doc={doc}
|
||||||
viewId={scene.viewId}
|
viewId={scene.viewId}
|
||||||
readOnly={false}
|
readOnly={false}
|
||||||
|
filter={ui.filter}
|
||||||
|
onFilter={(term) => dispatch({ type: 'filter', term })}
|
||||||
onSelectView={(id) => dispatch({ type: 'view', viewId: id })}
|
onSelectView={(id) => dispatch({ type: 'view', viewId: id })}
|
||||||
onSelectAnnotation={(id) => dispatch({ type: 'select', id })}
|
onSelectAnnotation={(id) => dispatch({ type: 'select', id })}
|
||||||
onOpenSection={scene.onOpenSection}
|
onOpenSection={scene.onOpenSection}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useMemo, useState } from 'react'
|
import { useMemo } from 'react'
|
||||||
import type {
|
import type {
|
||||||
AnatomicalSheetDocument,
|
AnatomicalSheetDocument,
|
||||||
SheetView,
|
SheetView,
|
||||||
@@ -29,6 +29,9 @@ export interface OverviewPanelProps {
|
|||||||
readOnly: boolean
|
readOnly: boolean
|
||||||
/** Put before every id (the read-only twin beside the kept edit panel). */
|
/** Put before every id (the read-only twin beside the kept edit panel). */
|
||||||
idPrefix?: string
|
idPrefix?: string
|
||||||
|
/** The « Filtrer par nom » term, held by the parent so a selection does not lose it. */
|
||||||
|
filter: string
|
||||||
|
onFilter: (term: string) => void
|
||||||
onSelectView: (viewId: string) => void
|
onSelectView: (viewId: string) => void
|
||||||
onSelectAnnotation: (annotationId: string) => void
|
onSelectAnnotation: (annotationId: string) => void
|
||||||
onOpenSection: (section: AnnotationSection, opener: HTMLElement) => void
|
onOpenSection: (section: AnnotationSection, opener: HTMLElement) => void
|
||||||
@@ -193,8 +196,7 @@ function CategoriesCard(props: OverviewPanelProps) {
|
|||||||
function AnnotationsCard(props: OverviewPanelProps) {
|
function AnnotationsCard(props: OverviewPanelProps) {
|
||||||
const t = useT()
|
const t = useT()
|
||||||
const locale = useLocaleStore((s) => s.locale)
|
const locale = useLocaleStore((s) => s.locale)
|
||||||
const { doc, viewId, onSelectAnnotation } = props
|
const { doc, viewId, filter: term, onFilter, onSelectAnnotation } = props
|
||||||
const [term, setTerm] = useState('')
|
|
||||||
const prefix = props.idPrefix ?? ''
|
const prefix = props.idPrefix ?? ''
|
||||||
const total = useOverviewCounts(doc).annotationsByView.get(viewId) ?? 0
|
const total = useOverviewCounts(doc).annotationsByView.get(viewId) ?? 0
|
||||||
const groups = useMemo(
|
const groups = useMemo(
|
||||||
@@ -221,7 +223,7 @@ function AnnotationsCard(props: OverviewPanelProps) {
|
|||||||
aria-label={t('editor.overview.filter')}
|
aria-label={t('editor.overview.filter')}
|
||||||
placeholder={t('editor.overview.filter')}
|
placeholder={t('editor.overview.filter')}
|
||||||
value={term}
|
value={term}
|
||||||
onChange={(event) => setTerm(event.target.value)}
|
onChange={(event) => onFilter(event.target.value)}
|
||||||
/>
|
/>
|
||||||
{groups.length > 0 ? (
|
{groups.length > 0 ? (
|
||||||
<AnnotationList
|
<AnnotationList
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import { useLocaleStore } from '@/state/localeStore'
|
|||||||
|
|
||||||
const CARD = 'rounded-lg border border-[var(--color-border)] p-3'
|
const CARD = 'rounded-lg border border-[var(--color-border)] p-3'
|
||||||
|
|
||||||
/** Annotation categories: list, rename, colour, add, delete with dependents. */
|
/** Annotation categories: list, rename, colour, add, delete; the frame names the section. */
|
||||||
export default function CategoriesSection({
|
export default function CategoriesSection({
|
||||||
doc,
|
doc,
|
||||||
readOnly,
|
readOnly,
|
||||||
@@ -30,15 +30,11 @@ export default function CategoriesSection({
|
|||||||
readOnly: boolean
|
readOnly: boolean
|
||||||
focus?: FocusRequest
|
focus?: FocusRequest
|
||||||
}) {
|
}) {
|
||||||
const t = useT()
|
|
||||||
useRowFocus(focus)
|
useRowFocus(focus)
|
||||||
const locale = useLocaleStore((s) => s.locale)
|
const locale = useLocaleStore((s) => s.locale)
|
||||||
const [deleting, setDeleting] = useState<DeleteTarget | null>(null)
|
const [deleting, setDeleting] = useState<DeleteTarget | null>(null)
|
||||||
return (
|
return (
|
||||||
<section aria-labelledby="general-categories" className="space-y-3">
|
<div data-testid="editor-section-categories" className="space-y-3">
|
||||||
<h3 id="general-categories" className="text-base font-semibold">
|
|
||||||
{t('editor.general.categories')}
|
|
||||||
</h3>
|
|
||||||
<ul className="space-y-3">
|
<ul className="space-y-3">
|
||||||
{doc.categories.map((category) => (
|
{doc.categories.map((category) => (
|
||||||
<CategoryRow
|
<CategoryRow
|
||||||
@@ -58,7 +54,7 @@ export default function CategoriesSection({
|
|||||||
<CategoryForm />
|
<CategoryForm />
|
||||||
</EditOnly>
|
</EditOnly>
|
||||||
<DeleteDialog target={deleting} onClose={() => setDeleting(null)} />
|
<DeleteDialog target={deleting} onClose={() => setDeleting(null)} />
|
||||||
</section>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -149,6 +149,7 @@ function ReadOnlyAnnotations({
|
|||||||
const handleVersion = useEditorStore((s) => s.handleVersion)
|
const handleVersion = useEditorStore((s) => s.handleVersion)
|
||||||
const [viewId, setViewId] = useState(mainViewId(doc))
|
const [viewId, setViewId] = useState(mainViewId(doc))
|
||||||
const [selectedId, setSelectedId] = useState<string | null>(null)
|
const [selectedId, setSelectedId] = useState<string | null>(null)
|
||||||
|
const [filter, setFilter] = useState('')
|
||||||
useViewFallback(doc, viewId, setViewId, setSelectedId)
|
useViewFallback(doc, viewId, setViewId, setSelectedId)
|
||||||
useAnnotationRequest(focus, doc, {
|
useAnnotationRequest(focus, doc, {
|
||||||
viewId,
|
viewId,
|
||||||
@@ -162,6 +163,12 @@ function ReadOnlyAnnotations({
|
|||||||
const model = useViewModel(doc, viewId)
|
const model = useViewModel(doc, viewId)
|
||||||
const view = doc.views.find((v) => v.id === viewId)
|
const view = doc.views.find((v) => v.id === viewId)
|
||||||
const selected = model.annotations.find((a) => a.id === selectedId)
|
const selected = model.annotations.find((a) => a.id === selectedId)
|
||||||
|
// A view of its own has its own list: the filter and the selection start over.
|
||||||
|
const showView = (id: string) => {
|
||||||
|
setViewId(id)
|
||||||
|
setSelectedId(null)
|
||||||
|
setFilter('')
|
||||||
|
}
|
||||||
if (!preview || !view) return null
|
if (!preview || !view) return null
|
||||||
return (
|
return (
|
||||||
<div className="grid gap-4 lg:grid-cols-[minmax(0,1fr)_22rem]">
|
<div className="grid gap-4 lg:grid-cols-[minmax(0,1fr)_22rem]">
|
||||||
@@ -169,10 +176,7 @@ function ReadOnlyAnnotations({
|
|||||||
<ViewSwitcher
|
<ViewSwitcher
|
||||||
views={doc.views}
|
views={doc.views}
|
||||||
current={viewId}
|
current={viewId}
|
||||||
onSelect={(id) => {
|
onSelect={showView}
|
||||||
setViewId(id)
|
|
||||||
setSelectedId(null)
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
{selected && (
|
{selected && (
|
||||||
<SelectionTag
|
<SelectionTag
|
||||||
@@ -208,10 +212,9 @@ function ReadOnlyAnnotations({
|
|||||||
viewId={viewId}
|
viewId={viewId}
|
||||||
idPrefix={READ_ONLY_IDS}
|
idPrefix={READ_ONLY_IDS}
|
||||||
readOnly
|
readOnly
|
||||||
onSelectView={(id) => {
|
filter={filter}
|
||||||
setViewId(id)
|
onFilter={setFilter}
|
||||||
setSelectedId(null)
|
onSelectView={showView}
|
||||||
}}
|
|
||||||
onSelectAnnotation={setSelectedId}
|
onSelectAnnotation={setSelectedId}
|
||||||
onOpenSection={onOpenSection}
|
onOpenSection={onOpenSection}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ export interface UiState {
|
|||||||
serial: number
|
serial: number
|
||||||
tracing: Tracing | null
|
tracing: Tracing | null
|
||||||
hint: string | null
|
hint: string | null
|
||||||
|
/** The overview's « Filtrer par nom » term: it outlives a selection, not a view. */
|
||||||
|
filter: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type UiAction =
|
export type UiAction =
|
||||||
@@ -33,6 +35,7 @@ export type UiAction =
|
|||||||
| { type: 'trace_add'; point: Point }
|
| { type: 'trace_add'; point: Point }
|
||||||
| { type: 'trace_cancel' }
|
| { type: 'trace_cancel' }
|
||||||
| { type: 'hint'; hint: string | null }
|
| { type: 'hint'; hint: string | null }
|
||||||
|
| { type: 'filter'; term: string }
|
||||||
|
|
||||||
export const initialUi: UiState = {
|
export const initialUi: UiState = {
|
||||||
viewId: null,
|
viewId: null,
|
||||||
@@ -42,6 +45,7 @@ export const initialUi: UiState = {
|
|||||||
serial: 0,
|
serial: 0,
|
||||||
tracing: null,
|
tracing: null,
|
||||||
hint: null,
|
hint: null,
|
||||||
|
filter: '',
|
||||||
}
|
}
|
||||||
|
|
||||||
const TOOL_OF: Record<Tracing['target'], ToolId> = {
|
const TOOL_OF: Record<Tracing['target'], ToolId> = {
|
||||||
@@ -108,5 +112,7 @@ export function uiReducer(state: UiState, action: UiAction): UiState {
|
|||||||
return { ...state, tracing: null, hint: null }
|
return { ...state, tracing: null, hint: null }
|
||||||
case 'hint':
|
case 'hint':
|
||||||
return { ...state, hint: action.hint }
|
return { ...state, hint: action.hint }
|
||||||
|
case 'filter':
|
||||||
|
return { ...state, filter: action.term }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -140,10 +140,14 @@ export function heldElement(): HTMLElement | null {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* After the render that hides parts: `held` (taken before) that left the page or sits in a
|
* After the render that hides parts: `held` (taken before) that left the page or sits in a
|
||||||
* hidden part hands its focus to the shown tab. An element still visible keeps its place.
|
* hidden part hands its focus to the shown tab; one still shown gets its focus back when
|
||||||
|
* the commit blurred it (never `body`), and the tab takes it if the element refuses.
|
||||||
*/
|
*/
|
||||||
export function refocusIfHidden(held: HTMLElement | null): void {
|
export function refocusIfHidden(held: HTMLElement | null): void {
|
||||||
if (held && (!held.isConnected || held.closest('[hidden]'))) focusActiveTab()
|
if (!held) return
|
||||||
|
const gone = !held.isConnected || held.closest('[hidden]')
|
||||||
|
if (!gone && document.activeElement !== held) held.focus()
|
||||||
|
if (gone || document.activeElement !== held) focusActiveTab()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -208,8 +208,9 @@ function applyReload(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* « Annuler les modifications » (confirmed): back to the saved text; with `staleBase` the
|
* « Abandonner les modifications » (confirmed): back to the saved text, which is the save
|
||||||
* server draft is reloaded instead (the saved text is an older revision's).
|
* `lastSave` describes, so the save line keeps it; with `staleBase` the server draft is
|
||||||
|
* reloaded instead (the saved text is an older revision's).
|
||||||
*/
|
*/
|
||||||
export async function discardChanges(
|
export async function discardChanges(
|
||||||
api: StoreApi,
|
api: StoreApi,
|
||||||
@@ -228,6 +229,9 @@ export async function discardChanges(
|
|||||||
: { ok: false, reason: 'blocked', kind: 'not_ready' }
|
: { ok: false, reason: 'blocked', kind: 'not_ready' }
|
||||||
}
|
}
|
||||||
removeCopy(state.userId ?? '', state.versionId ?? '')
|
removeCopy(state.userId ?? '', state.versionId ?? '')
|
||||||
api.set(reloadPatch(state, state.savedText, replaced.state, state.savedRevision))
|
api.set({
|
||||||
|
...reloadPatch(state, state.savedText, replaced.state, state.savedRevision),
|
||||||
|
lastSave: state.lastSave,
|
||||||
|
})
|
||||||
return { ok: true }
|
return { ok: true }
|
||||||
}
|
}
|
||||||
@@ -1356,7 +1356,6 @@ export const en: Dict = {
|
|||||||
'editor.general.author_remove': 'Remove {name}',
|
'editor.general.author_remove': 'Remove {name}',
|
||||||
'editor.general.license': 'Licence',
|
'editor.general.license': 'Licence',
|
||||||
'editor.general.notes': 'Notes',
|
'editor.general.notes': 'Notes',
|
||||||
'editor.general.categories': 'Annotation categories',
|
|
||||||
'editor.general.category_name_fr': 'Category name (FR)',
|
'editor.general.category_name_fr': 'Category name (FR)',
|
||||||
'editor.general.category_name_en': 'Category name (EN)',
|
'editor.general.category_name_en': 'Category name (EN)',
|
||||||
'editor.general.category_color': 'Colour',
|
'editor.general.category_color': 'Colour',
|
||||||
|
|||||||
@@ -1387,7 +1387,6 @@ export const fr: Dict = {
|
|||||||
'editor.general.author_remove': 'Retirer {name}',
|
'editor.general.author_remove': 'Retirer {name}',
|
||||||
'editor.general.license': 'Licence',
|
'editor.general.license': 'Licence',
|
||||||
'editor.general.notes': 'Notes',
|
'editor.general.notes': 'Notes',
|
||||||
'editor.general.categories': 'Catégories d\'annotation',
|
|
||||||
'editor.general.category_name_fr': 'Nom de la catégorie (FR)',
|
'editor.general.category_name_fr': 'Nom de la catégorie (FR)',
|
||||||
'editor.general.category_name_en': 'Nom de la catégorie (EN)',
|
'editor.general.category_name_en': 'Nom de la catégorie (EN)',
|
||||||
'editor.general.category_color': 'Couleur',
|
'editor.general.category_color': 'Couleur',
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/** The LAN spec's revision reading, run on the strings the save line really shows. */
|
||||||
|
import { describe, expect, it } from 'vitest'
|
||||||
|
import { fr } from '@/i18n/fr'
|
||||||
|
import { shownRevision } from '../../e2e/support/saveLineText'
|
||||||
|
|
||||||
|
const line = (key: keyof typeof fr, values: Record<string, string> = {}) =>
|
||||||
|
Object.entries(values).reduce(
|
||||||
|
(text, [name, value]) => text.replace(`{${name}}`, value),
|
||||||
|
fr[key],
|
||||||
|
)
|
||||||
|
|
||||||
|
describe('shownRevision', () => {
|
||||||
|
it('reads the revision of the « Révision n » line', () => {
|
||||||
|
expect(
|
||||||
|
shownRevision(line('editor.draft.status.revision', { revision: '7' })),
|
||||||
|
).toBe(7)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('reads it from both saved forms', () => {
|
||||||
|
const saved = line('editor.draft.status.saved', { revision: '8' })
|
||||||
|
const savedAt = line('editor.draft.status.saved_at', {
|
||||||
|
revision: '12',
|
||||||
|
time: '14:02',
|
||||||
|
})
|
||||||
|
expect([shownRevision(saved), shownRevision(savedAt)]).toEqual([8, 12])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('throws on the forms that carry none, never answers NaN', () => {
|
||||||
|
const texts = [
|
||||||
|
fr['editor.draft.status.unsaved'],
|
||||||
|
line('editor.draft.status.unsaved_count_one', { count: '1' }),
|
||||||
|
fr['editor.draft.status.saving'],
|
||||||
|
'',
|
||||||
|
]
|
||||||
|
for (const text of texts) {
|
||||||
|
expect(() => shownRevision(text)).toThrow('shows no revision')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -1,7 +1,13 @@
|
|||||||
/** « Aller à … »: each request reaches the place its target names, once, and never lands on body. */
|
/** « Aller à … »: each request reaches the place its target names, once, and never lands on body. */
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { cleanup, render, screen, waitFor } from '@testing-library/react'
|
import {
|
||||||
|
cleanup,
|
||||||
|
render,
|
||||||
|
screen,
|
||||||
|
waitFor,
|
||||||
|
within,
|
||||||
|
} from '@testing-library/react'
|
||||||
import userEvent from '@testing-library/user-event'
|
import userEvent from '@testing-library/user-event'
|
||||||
import type {
|
import type {
|
||||||
AnatomicalSheetDocument,
|
AnatomicalSheetDocument,
|
||||||
@@ -125,10 +131,13 @@ describe('focus requests', () => {
|
|||||||
focus={request({ kind: 'annotation', id: 'anno-b' })}
|
focus={request({ kind: 'annotation', id: 'anno-b' })}
|
||||||
/>,
|
/>,
|
||||||
)
|
)
|
||||||
expect(await screen.findAllByText(/anno-b|Sélection/)).not.toHaveLength(0)
|
// anno-b and anno-a share a name: the circle's centre tells which one is selected.
|
||||||
|
const properties = await screen.findByTestId('annotation-properties')
|
||||||
|
expect(within(properties).getByLabelText('Centre x')).toHaveValue('20')
|
||||||
await waitFor(() =>
|
await waitFor(() =>
|
||||||
expect(document.activeElement).toHaveAttribute('data-properties-heading'),
|
expect(document.activeElement).toHaveAttribute('data-properties-heading'),
|
||||||
)
|
)
|
||||||
|
expect(properties).toContainElement(document.activeElement as HTMLElement)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Références and Régions: focus the named row', async () => {
|
it('Références and Régions: focus the named row', async () => {
|
||||||
|
|||||||
@@ -252,6 +252,52 @@ describe('typed text and the press', () => {
|
|||||||
expect(geometry()).toMatchObject({ cx: 40 })
|
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 () => {
|
it('a keyboard activation after a refused blur commit skips the undo too', async () => {
|
||||||
const user = userEvent.setup()
|
const user = userEvent.setup()
|
||||||
mountDraft()
|
mountDraft()
|
||||||
@@ -443,6 +489,29 @@ describe('« Abandonner les modifications »', () => {
|
|||||||
).toBeInTheDocument()
|
).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 () => {
|
it('does not mention a copy when none is stored', async () => {
|
||||||
const user = userEvent.setup()
|
const user = userEvent.setup()
|
||||||
vi.spyOn(console, 'warn').mockImplementation(() => {})
|
vi.spyOn(console, 'warn').mockImplementation(() => {})
|
||||||
|
|||||||
@@ -290,6 +290,22 @@ describe('the guards of a width change', () => {
|
|||||||
expect(document.activeElement).toBe(refs)
|
expect(document.activeElement).toBe(refs)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('the references search, shown in both modes, keeps its focus and its text', async () => {
|
||||||
|
const user = await mount()
|
||||||
|
await user.click(button('Références'))
|
||||||
|
const panel = screen.getByTestId('editor-references-panel')
|
||||||
|
const search = within(panel).getByRole('searchbox', {
|
||||||
|
name: 'Rechercher une référence',
|
||||||
|
})
|
||||||
|
await user.type(search, 'code')
|
||||||
|
expect(document.activeElement).toBe(search)
|
||||||
|
cross(800)
|
||||||
|
expect(document.activeElement).toBe(search)
|
||||||
|
expect(search).toHaveValue('code')
|
||||||
|
cross(1280)
|
||||||
|
expect(document.activeElement).toBe(search)
|
||||||
|
})
|
||||||
|
|
||||||
it('a crossing with the focus on no field leaves the focus alone', async () => {
|
it('a crossing with the focus on no field leaves the focus alone', async () => {
|
||||||
const user = await mount()
|
const user = await mount()
|
||||||
await user.click(tab('Général'))
|
await user.click(tab('Général'))
|
||||||
|
|||||||
@@ -143,6 +143,21 @@ describe.each([
|
|||||||
await waitFor(() => expect(document.activeElement).toBe(rows()[1]))
|
await waitFor(() => expect(document.activeElement).toBe(rows()[1]))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('keeps the « Filtrer par nom » term across a selection and back', async () => {
|
||||||
|
await mount(readOnly)
|
||||||
|
const user = userEvent.setup()
|
||||||
|
const field = () =>
|
||||||
|
within(overview()).getByRole('searchbox', { name: 'Filtrer par nom' })
|
||||||
|
await user.type(field(), 'epaule')
|
||||||
|
await user.click(rows()[0])
|
||||||
|
await user.click(
|
||||||
|
screen.getByRole('button', { name: 'Toutes les annotations' }),
|
||||||
|
)
|
||||||
|
expect(field()).toHaveValue('epaule')
|
||||||
|
expect(rows()).toHaveLength(1)
|
||||||
|
expect(rows()[0]).toHaveTextContent('Épaule')
|
||||||
|
})
|
||||||
|
|
||||||
it('a view row switches the canvas view', async () => {
|
it('a view row switches the canvas view', async () => {
|
||||||
await mount(readOnly)
|
await mount(readOnly)
|
||||||
const user = userEvent.setup()
|
const user = userEvent.setup()
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ describe('restore', () => {
|
|||||||
expect(node).toMatchObject({ reference_ids: [], children: [], review_status: 'inherited' })
|
expect(node).toMatchObject({ reference_ids: [], children: [], review_status: 'inherited' })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('takes the reload path for « Annuler les modifications » under staleBase', async () => {
|
it('takes the reload path for « Abandonner les modifications » under staleBase', async () => {
|
||||||
seed(movedText(10), 2)
|
seed(movedText(10), 2)
|
||||||
await openReady({ revision: 5 })
|
await openReady({ revision: 5 })
|
||||||
await store.getState().restoreCopy()
|
await store.getState().restoreCopy()
|
||||||
@@ -182,6 +182,19 @@ describe('restore', () => {
|
|||||||
expect(storedCopy()).toBeNull()
|
expect(storedCopy()).toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('keeps `lastSave` on a plain discard, drops it on the reload path', async () => {
|
||||||
|
await openReady({ revision: 3 })
|
||||||
|
const saved = { revision: 3, savedAt: '2026-11-04T13:32:00Z' }
|
||||||
|
store.setState({ lastSave: saved })
|
||||||
|
commitMove(40)
|
||||||
|
expect(await store.getState().discardChanges({ confirmed: true })).toEqual({ ok: true })
|
||||||
|
expect(store.getState().lastSave).toBe(saved)
|
||||||
|
store.setState({ staleBase: true })
|
||||||
|
serverHas(baseText(), 6)
|
||||||
|
await store.getState().discardChanges({ confirmed: true })
|
||||||
|
expect(store.getState().lastSave).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
it('reports a copy the core refuses, keeps it, blocks editing until ignored', async () => {
|
it('reports a copy the core refuses, keeps it, blocks editing until ignored', async () => {
|
||||||
sessionStorage.setItem(
|
sessionStorage.setItem(
|
||||||
copyKeyOf(),
|
copyKeyOf(),
|
||||||
|
|||||||
@@ -91,6 +91,19 @@ describe('the overview entries', () => {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
it('the categories section shows its own heading once, as the other sections', async () => {
|
||||||
|
const user = userEvent.setup()
|
||||||
|
mountDraft()
|
||||||
|
await ready()
|
||||||
|
await user.click(entry('Modifier les catégories'))
|
||||||
|
const headings = within(place('annotations.categories')!).getAllByRole(
|
||||||
|
'heading',
|
||||||
|
)
|
||||||
|
expect(headings.map((h) => [h.tagName, h.textContent])).toEqual([
|
||||||
|
['H2', 'Catégories'],
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
it('the Catégories card header shows the number of categories', async () => {
|
it('the Catégories card header shows the number of categories', async () => {
|
||||||
mountDraft()
|
mountDraft()
|
||||||
await ready()
|
await ready()
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
/** AC8: the Vérification tab carries the blocking-error count as text, and nothing at zero. */
|
||||||
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
|
import { act, cleanup, render, screen } from '@testing-library/react'
|
||||||
|
import type { SheetIssue } from '@faunosteo/core-wasm/types'
|
||||||
|
import EditorTabs from '@/components/editor/EditorTabs'
|
||||||
|
import { useLocaleStore } from '@/state/localeStore'
|
||||||
|
import { openReady, resetStore, store } from '../helpers/editorHarness'
|
||||||
|
|
||||||
|
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(() => useLocaleStore.setState({ locale: 'fr' }))
|
||||||
|
afterEach(() => {
|
||||||
|
cleanup()
|
||||||
|
resetStore()
|
||||||
|
})
|
||||||
|
|
||||||
|
const issue = (severity: SheetIssue['severity'], at: number): SheetIssue => ({
|
||||||
|
code: 'x.y',
|
||||||
|
severity,
|
||||||
|
path: `annotations[${at}]`,
|
||||||
|
message: 'm',
|
||||||
|
})
|
||||||
|
|
||||||
|
function reportIssues(issues: SheetIssue[]) {
|
||||||
|
const previewState = store.getState().previewState
|
||||||
|
if (!previewState) throw new Error('the editor is not ready')
|
||||||
|
act(() =>
|
||||||
|
store.setState({
|
||||||
|
previewState: {
|
||||||
|
...previewState,
|
||||||
|
report: { ...previewState.report, issues },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const verificationTab = () => screen.getByRole('tab', { name: /^Vérification/ })
|
||||||
|
|
||||||
|
describe('the Vérification tab badge', () => {
|
||||||
|
it.each([
|
||||||
|
[1, 'Vérification 1 erreur'],
|
||||||
|
[2, 'Vérification 2 erreurs'],
|
||||||
|
])('says « n erreur(s) » for %i blocking error(s)', async (count, name) => {
|
||||||
|
await openReady()
|
||||||
|
render(<EditorTabs active="general" tier="wide" onSelect={vi.fn()} />)
|
||||||
|
reportIssues(
|
||||||
|
Array.from({ length: count }, (_, at) => issue('error', at)),
|
||||||
|
)
|
||||||
|
expect(verificationTab()).toHaveTextContent(new RegExp(`^${name}$`))
|
||||||
|
})
|
||||||
|
|
||||||
|
it('shows nothing at zero, and warnings do not count', async () => {
|
||||||
|
await openReady()
|
||||||
|
render(<EditorTabs active="general" tier="wide" onSelect={vi.fn()} />)
|
||||||
|
reportIssues([])
|
||||||
|
expect(verificationTab()).toHaveTextContent(/^Vérification$/)
|
||||||
|
reportIssues([issue('warning', 0), issue('warning', 1)])
|
||||||
|
expect(verificationTab()).toHaveTextContent(/^Vérification$/)
|
||||||
|
expect(screen.queryByText(/erreur/)).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('the other tabs never carry the count', async () => {
|
||||||
|
await openReady()
|
||||||
|
render(<EditorTabs active="general" tier="wide" onSelect={vi.fn()} />)
|
||||||
|
reportIssues([issue('error', 0)])
|
||||||
|
expect(screen.getByRole('tab', { name: 'Général' })).toHaveTextContent(
|
||||||
|
/^Général$/,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -107,7 +107,7 @@ describe('Annotations, section Catégories', () => {
|
|||||||
it('Général no longer holds the categories editor', async () => {
|
it('Général no longer holds the categories editor', async () => {
|
||||||
await openReady()
|
await openReady()
|
||||||
render(<GeneralTab {...props} />)
|
render(<GeneralTab {...props} />)
|
||||||
expect(screen.queryByText("Catégories d'annotation")).toBeNull()
|
expect(screen.queryByLabelText(/Nom de la catégorie/)).toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('renames, recolours and adds a category', async () => {
|
it('renames, recolours and adds a category', async () => {
|
||||||
|
|||||||
Reference in new issue
Block a user