feat(editor): four tabs, Annotations sections, references from the header
U1 Lot B1. Four tabs (Général, Annotations, Constats, Vérification); views,
categories and regions become full-width Annotations sections opened from the
overview panel; references move to a header-toggled panel (minimal, Lot D
completes it); « Aller à » goes through EditorTarget and the navigation hook.
EditorWorkspace owns the navigation; DraftHeader split in HeaderActions and
SaveLine; EditorTabs split in TabList and MoreTabs.
R-24, assertions removed or rewritten (file: old -> new):
unit
- editor-route.test: seven tab names -> four; « Plus » at 800 px with
Références clicked -> no « Plus »; below 640 px five others -> Général,
Constats, and Constats opens the findings tab; + references panel cases
- editor-route-recovery.test: tab Références + editor-tab-references label ->
header button + editor-references-panel labelled by its heading
- editor-mode.test: small tier `more` of five -> [general, findings]
- editor-focus-request.test: {key,serial} -> {target,serial}; ReferencesTab and
VertebraeTab -> ReferencesPanel and RegionsSection; issueTarget tab/key ->
target place/section/key (vertebrae tab -> annotations/regions); consumed
context (serial) -> (serial, outcome); annotation case adds heading focus
- editor-verification.test: onGoTo('annotations', key) -> navigate(targetOfKey
(key), opener); props onSelectTab/onGoTo -> navigate
- editor-annotations-tab.test: props onSelectTab -> navigate + section props;
no_category text « (onglet Général) » -> « (Annotations, section
Catégories) »
- editor-tabs-general.test: categories cases render GeneralTab ->
CategoriesSection(doc); + Général holds no categories editor
- editor-tabs-lists.test: tab imports -> panel and section; read-only
references « no button » -> only « Fermer les références »
- editor-tabs-views, editor-drawing-upload, editor-repair.test: ViewsTab ->
ViewsSection import, assertions kept; editor-findings.test: navigate prop
e2e
- support/editor selectTab: exact name -> pattern (error badge in the name);
+ place, openSection, showDrawing, backToDrawing, openReferences, TABS
- support/warm-up: seven tabs -> four + sections + references panel
- editor-access: seven-tab axe loops -> four tabs + three sections + panel
(edit and read-only); narrow widths add panel overflow and axe
- editor-drawings: tab Vues -> openSection views; tab Annotations ->
showDrawing
- editor-structures: tab Général (categories) -> openSection categories, axe
label « general tab » -> « categories section »; tab Références ->
openReferences/closeReferences; tab Vertèbres -> openSection regions; tab
Annotations -> showDrawing
- editor-geometry: three tab Vues -> openSection views
- editor-equine: tab Général (categories add) -> openSection categories; five
tabs loop -> two tabs + sections + panel; tab Annotations -> showDrawing
- editor-journey: tab Vues, tab Général (category), tab Annotations ->
openSection views/categories, showDrawing; frozen axe scrolls to the header
- lan/trial-lan (not run): tab Vues -> Annotations tab + views entry
Verified: typecheck, lint, vitest 107 files / 1125 tests, whole shell suite on
the sandbox 151 passed, 49 skipped, 0 failed.
This commit is contained in:
1 parent
95b1b7e461
commit
bc2dba7c14
56 files changed
+2419
-699
No files matched your search
@@ -1,17 +1,25 @@
|
||||
/** Lot J fix: « Aller à … » seeds each tab's own selection once. */
|
||||
/** « 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 { useState } from 'react'
|
||||
import { cleanup, render, screen } from '@testing-library/react'
|
||||
import { cleanup, render, screen, waitFor } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type {
|
||||
AnatomicalSheetDocument,
|
||||
ElementKey,
|
||||
} from '@faunosteo/core-wasm/types'
|
||||
import FindingsTab from '@/components/editor/tabs/FindingsTab'
|
||||
import ReferencesTab from '@/components/editor/tabs/ReferencesTab'
|
||||
import VertebraeTab from '@/components/editor/tabs/VertebraeTab'
|
||||
import RegionsSection from '@/components/editor/annotations/sections/RegionsSection'
|
||||
import EditorTabBody from '@/components/editor/EditorTabBody'
|
||||
import EditorTabs from '@/components/editor/EditorTabs'
|
||||
import ReferencesPanel from '@/components/editor/references/ReferencesPanel'
|
||||
import AnnotationsTab from '@/components/editor/tabs/AnnotationsTab'
|
||||
import { FocusConsumedContext, type FocusRequest } from '@/editor/focusRequest'
|
||||
import {
|
||||
FocusConsumedContext,
|
||||
ownedBy,
|
||||
type FocusRequest,
|
||||
} from '@/editor/focusRequest'
|
||||
import { targetOfKey, type EditorTarget } from '@/editor/navigation'
|
||||
import { useEditorNavigation } from '@/editor/useEditorNavigation'
|
||||
import { issueTarget } from '@/editor/verification'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { edit, insert, point } from '../helpers/editorFixtures'
|
||||
@@ -32,7 +40,17 @@ vi.mock('@faunosteo/supabase', async (orig) => ({
|
||||
submitSheetReview: vi.fn(),
|
||||
}))
|
||||
|
||||
const base = { readOnly: false, onSelectTab: vi.fn(), reloadSheet: vi.fn() }
|
||||
const base = { readOnly: false, navigate: vi.fn(), reloadSheet: vi.fn() }
|
||||
const section = {
|
||||
section: 'drawing' as const,
|
||||
onOpenSection: vi.fn(),
|
||||
onBack: vi.fn(),
|
||||
}
|
||||
const panel = { open: true, onClose: vi.fn() }
|
||||
const request = (key: ElementKey, serial = 1): FocusRequest => ({
|
||||
target: targetOfKey(key),
|
||||
serial,
|
||||
})
|
||||
const doc = (): AnatomicalSheetDocument =>
|
||||
JSON.parse(store.getState().documentText)
|
||||
const name = (n: string) => ({ fr: n, en: n })
|
||||
@@ -90,24 +108,29 @@ describe('focus requests', () => {
|
||||
zone_id: 'zone-a',
|
||||
path: ['fcat-a', 'node-a'],
|
||||
}
|
||||
render(<FindingsTab {...base} focus={{ key, serial: 1 }} />)
|
||||
render(<FindingsTab {...base} focus={request(key)} />)
|
||||
const item = await screen.findByRole('treeitem', { name: /Nœud A/ })
|
||||
expect(item.getAttribute('aria-selected')).toBe('true')
|
||||
await waitFor(() => expect(document.activeElement).toBe(item))
|
||||
})
|
||||
|
||||
it('Annotations: selects the annotation of the request', async () => {
|
||||
it('Annotations: selects the annotation and focuses the properties heading', async () => {
|
||||
const text = insert(baseText(), point('anno-b', 20, 20, 3))
|
||||
await openReady({ text })
|
||||
render(
|
||||
<AnnotationsTab
|
||||
{...base}
|
||||
focus={{ key: { kind: 'annotation', id: 'anno-b' }, serial: 1 }}
|
||||
{...section}
|
||||
focus={request({ kind: 'annotation', id: 'anno-b' })}
|
||||
/>,
|
||||
)
|
||||
expect(await screen.findAllByText(/anno-b|Sélection/)).not.toHaveLength(0)
|
||||
await waitFor(() =>
|
||||
expect(document.activeElement).toHaveAttribute('data-properties-heading'),
|
||||
)
|
||||
})
|
||||
|
||||
it('Références and Vertèbres: focus the named row', async () => {
|
||||
it('Références and Régions: focus the named row', async () => {
|
||||
let text = insert(baseText(), {
|
||||
kind: 'reference',
|
||||
value: {
|
||||
@@ -129,9 +152,10 @@ describe('focus requests', () => {
|
||||
})
|
||||
await openReady({ text })
|
||||
render(
|
||||
<ReferencesTab
|
||||
<ReferencesPanel
|
||||
{...base}
|
||||
focus={{ key: { kind: 'reference', id: 'ref-a' }, serial: 1 }}
|
||||
{...panel}
|
||||
focus={request({ kind: 'reference', id: 'ref-a' })}
|
||||
/>,
|
||||
)
|
||||
expect(document.activeElement?.getAttribute('data-focus-key')).toContain(
|
||||
@@ -139,9 +163,9 @@ describe('focus requests', () => {
|
||||
)
|
||||
cleanup()
|
||||
render(
|
||||
<VertebraeTab
|
||||
<RegionsSection
|
||||
{...base}
|
||||
focus={{ key: { kind: 'region', code: 'C' }, serial: 1 }}
|
||||
focus={request({ kind: 'region', code: 'C' })}
|
||||
/>,
|
||||
)
|
||||
expect(document.activeElement?.getAttribute('data-focus-key')).toContain(
|
||||
@@ -161,15 +185,37 @@ describe('focus requests', () => {
|
||||
},
|
||||
})
|
||||
await openReady({ text })
|
||||
const focus = {
|
||||
key: { kind: 'reference', id: 'ref-a' } as ElementKey,
|
||||
serial: 1,
|
||||
}
|
||||
const view = render(<ReferencesTab {...base} focus={focus} />)
|
||||
const focus = request({ kind: 'reference', id: 'ref-a' })
|
||||
const view = render(<ReferencesPanel {...base} {...panel} focus={focus} />)
|
||||
;(document.activeElement as HTMLElement).blur()
|
||||
view.rerender(<ReferencesTab {...base} focus={focus} />)
|
||||
view.rerender(<ReferencesPanel {...base} {...panel} focus={focus} />)
|
||||
expect(document.activeElement?.getAttribute('data-focus-key')).toBeNull()
|
||||
})
|
||||
|
||||
it('reports found, or none when the place holds no such element', async () => {
|
||||
await openReady({ text: findingsText() })
|
||||
const consumed = vi.fn()
|
||||
const gone: ElementKey = { kind: 'zone', id: 'zone-gone' }
|
||||
render(
|
||||
<FocusConsumedContext value={consumed}>
|
||||
<FindingsTab {...base} focus={request(gone, 4)} />
|
||||
</FocusConsumedContext>,
|
||||
)
|
||||
await waitFor(() => expect(consumed).toHaveBeenCalledWith(4, 'none'))
|
||||
})
|
||||
})
|
||||
|
||||
describe('ownedBy', () => {
|
||||
it('passes a request only to the place its target names', () => {
|
||||
const view = request({ kind: 'view', id: 'view-main' })
|
||||
expect(ownedBy(view, 'annotations.views')).toBe(view)
|
||||
expect(ownedBy(view, 'annotations.drawing')).toBeUndefined()
|
||||
expect(ownedBy(view, 'general')).toBeUndefined()
|
||||
const ref = request({ kind: 'reference', id: 'ref-a' })
|
||||
expect(ownedBy(ref, 'references')).toBe(ref)
|
||||
expect(ownedBy(ref, 'findings')).toBeUndefined()
|
||||
expect(ownedBy(undefined, 'general')).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('issueTarget', () => {
|
||||
@@ -178,50 +224,122 @@ describe('issueTarget', () => {
|
||||
const d = doc()
|
||||
const path = 'finding_zones[0].categories[0].children[0].reference_ids[1]'
|
||||
expect(issueTarget(d, path, 'fr')).toMatchObject({
|
||||
tab: 'findings',
|
||||
key: { kind: 'finding', zone_id: 'zone-a', path: ['fcat-a', 'node-a'] },
|
||||
target: {
|
||||
place: 'tab',
|
||||
tab: 'findings',
|
||||
key: { kind: 'finding', zone_id: 'zone-a', path: ['fcat-a', 'node-a'] },
|
||||
},
|
||||
name: 'Nœud A',
|
||||
})
|
||||
expect(issueTarget(d, 'finding_zones[0]', 'fr')?.key).toEqual({
|
||||
kind: 'zone',
|
||||
id: 'zone-a',
|
||||
expect(issueTarget(d, 'finding_zones[0]', 'fr')?.target).toMatchObject({
|
||||
key: { kind: 'zone', id: 'zone-a' },
|
||||
})
|
||||
expect(
|
||||
issueTarget(d, 'vertebral_config.regions[3].count_range', 'fr'),
|
||||
).toMatchObject({
|
||||
tab: 'vertebrae',
|
||||
key: null,
|
||||
target: { tab: 'annotations', section: 'regions', key: null },
|
||||
})
|
||||
expect(issueTarget(d, 'nothing', 'fr')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
/** The route's contract: one tab mounted at a time, the request cleared once consumed. */
|
||||
function Harness() {
|
||||
const [tab, setTab] = useState<'references' | 'vertebrae'>('references')
|
||||
const [focus, setFocus] = useState<FocusRequest | undefined>({
|
||||
key: { kind: 'reference', id: 'ref-a' },
|
||||
serial: 1,
|
||||
/** The workspace's wiring in miniature: the hook, the tab row, the shown body. */
|
||||
function Probe({ go, tier }: { go: EditorTarget; tier: 'wide' | 'small' }) {
|
||||
const nav = useEditorNavigation('verification')
|
||||
const { state } = nav
|
||||
return (
|
||||
<FocusConsumedContext value={nav.consumed}>
|
||||
<EditorTabs active={state.tab} tier={tier} onSelect={nav.selectTab} />
|
||||
<button onClick={() => nav.navigate(go)}>go</button>
|
||||
<EditorTabBody
|
||||
tab={state.tab}
|
||||
{...base}
|
||||
navigate={nav.navigate}
|
||||
focus={ownedBy(state.focus, state.tab)}
|
||||
annotations={{
|
||||
section: state.section,
|
||||
onOpenSection: nav.openSection,
|
||||
onBack: nav.backToDrawing,
|
||||
}}
|
||||
/>
|
||||
</FocusConsumedContext>
|
||||
)
|
||||
}
|
||||
|
||||
describe('a request that finds nothing', () => {
|
||||
const missing: EditorTarget = {
|
||||
place: 'tab',
|
||||
tab: 'findings',
|
||||
section: null,
|
||||
key: { kind: 'zone', id: 'zone-gone' },
|
||||
}
|
||||
|
||||
it('lands on the tab button, never on body', async () => {
|
||||
await openReady({ text: findingsText() })
|
||||
const user = userEvent.setup()
|
||||
render(<Probe go={missing} tier="wide" />)
|
||||
await user.click(screen.getByText('go'))
|
||||
await waitFor(() =>
|
||||
expect(document.activeElement).toBe(
|
||||
screen.getByRole('tab', { name: 'Constats' }),
|
||||
),
|
||||
)
|
||||
})
|
||||
|
||||
it('below 640 px lands on « Plus » while the tab sits in its closed list', async () => {
|
||||
await openReady({ text: findingsText() })
|
||||
const user = userEvent.setup()
|
||||
render(<Probe go={missing} tier="small" />)
|
||||
await user.click(screen.getByText('go'))
|
||||
await waitFor(() =>
|
||||
expect(document.activeElement).toBe(
|
||||
screen.getByRole('button', { name: 'Plus' }),
|
||||
),
|
||||
)
|
||||
})
|
||||
|
||||
it('a found element keeps the focus it took', async () => {
|
||||
await openReady({ text: findingsText() })
|
||||
const user = userEvent.setup()
|
||||
const key: ElementKey = { kind: 'zone', id: 'zone-a' }
|
||||
render(<Probe go={targetOfKey(key)} tier="wide" />)
|
||||
await user.click(screen.getByText('go'))
|
||||
await waitFor(() =>
|
||||
expect(document.activeElement).toBe(
|
||||
screen.getByRole('treeitem', { name: /Zone A/ }),
|
||||
),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
/** The route's contract: one place mounted at a time, the request cleared once consumed. */
|
||||
function Harness() {
|
||||
const [shown, setShown] = useState<'references' | 'regions'>('references')
|
||||
const [focus, setFocus] = useState<FocusRequest | undefined>(
|
||||
request({ kind: 'reference', id: 'ref-a' }),
|
||||
)
|
||||
const clear = (serial: number) =>
|
||||
setFocus((prev) => (prev?.serial === serial ? undefined : prev))
|
||||
const Body = tab === 'references' ? ReferencesTab : VertebraeTab
|
||||
return (
|
||||
<FocusConsumedContext value={clear}>
|
||||
<button
|
||||
onClick={() =>
|
||||
setTab(tab === 'references' ? 'vertebrae' : 'references')
|
||||
setShown(shown === 'references' ? 'regions' : 'references')
|
||||
}
|
||||
>
|
||||
switch
|
||||
</button>
|
||||
<Body {...base} focus={focus} />
|
||||
{shown === 'references' ? (
|
||||
<ReferencesPanel {...base} {...panel} focus={focus} />
|
||||
) : (
|
||||
<RegionsSection {...base} focus={focus} />
|
||||
)}
|
||||
</FocusConsumedContext>
|
||||
)
|
||||
}
|
||||
|
||||
describe('a consumed request', () => {
|
||||
it('is not replayed when the tab is left and reopened', async () => {
|
||||
it('is not replayed when the place is left and reopened', async () => {
|
||||
const text = insert(baseText(), {
|
||||
kind: 'reference',
|
||||
value: {
|
||||
|
||||
Reference in new issue
Block a user