Files
faunosteo/apps/app/tests/unit/editor-mode.test.ts
T
bchanot bc2dba7c14 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.
2026-11-06 20:25:35 +01:00

112 lines
3.6 KiB
TypeScript

/** Lot E: the display rules of the draft's mode (the server decides every write). */
import { describe, expect, it } from 'vitest'
import {
draftEditable,
editorMode,
freezingRound,
hasEditRight,
modeAfterSave,
storeCanEdit,
} from '@/editor/mode'
import { tabsFor } from '@/editor/tabs'
const sheet = (patch: Record<string, unknown> = {}) =>
({
status: 'active',
historical: false,
draft_version: { version_id: 'v1', version_number: 1, revision: 1 },
rounds: [],
...patch,
}) as never
const round = (status: string, version_id = 'v1') =>
({ version_id, status }) as never
describe('editorMode', () => {
const base = { hasRight: true, sheet: sheet(), wide: true }
it('edit, narrow and the reasons that read only, strongest first', () => {
expect(editorMode(base)).toBe('edit')
expect(editorMode({ ...base, wide: false })).toBe('narrow')
expect(editorMode({ ...base, hasRight: false, wide: false })).toBe('rights')
expect(
editorMode({
...base,
sheet: sheet({ status: 'archived' }),
wide: false,
}),
).toBe('inactive')
expect(editorMode({ ...base, sheet: sheet({ historical: true }) })).toBe(
'historical',
)
expect(
editorMode({ ...base, sheet: sheet({ rounds: [round('open')] }) }),
).toBe('frozen')
})
it('only verifying, open and approved rounds of the edited draft freeze it', () => {
for (const status of ['verifying', 'open', 'approved']) {
expect(freezingRound(sheet({ rounds: [round(status)] }))).not.toBeNull()
}
for (const status of [
'changes_requested',
'withdrawn',
'verification_failed',
]) {
expect(freezingRound(sheet({ rounds: [round(status)] }))).toBeNull()
}
expect(
freezingRound(sheet({ rounds: [round('open', 'other')] })),
).toBeNull()
})
it('the right needs the capability and the admin or owner role', () => {
expect(hasEditRight(true, ['admin'])).toBe(true)
expect(hasEditRight(true, ['owner'])).toBe(true)
expect(hasEditRight(true, ['support'])).toBe(false)
expect(hasEditRight(false, ['admin'])).toBe(false)
})
it('the overview offers « Ouvrir » only when the draft can be edited', () => {
expect(draftEditable(true, sheet())).toBe(true)
expect(draftEditable(true, sheet({ rounds: [round('verifying')] }))).toBe(
false,
)
expect(draftEditable(false, sheet())).toBe(false)
})
it('the store may use a recovery copy where the account could save', () => {
expect(['edit', 'narrow'].every((m) => storeCanEdit(m as never))).toBe(true)
expect(
['rights', 'frozen', 'historical', 'inactive'].some((m) =>
storeCanEdit(m as never),
),
).toBe(false)
})
})
describe('modeAfterSave', () => {
it('a refused save names the state the page missed', () => {
expect(modeAfterSave('edit', 'draft.frozen')).toBe('frozen')
expect(modeAfterSave('edit', 'sheet.inactive')).toBe('inactive')
expect(modeAfterSave('edit', 'rights.mfa')).toBe('rights')
expect(modeAfterSave('edit', 'network')).toBe('edit')
expect(modeAfterSave('edit', null)).toBe('edit')
expect(modeAfterSave('narrow', 'draft.frozen')).toBe('narrow')
})
})
describe('tabsFor', () => {
it('the static lists of board 05, four tabs', () => {
expect(tabsFor('wide').more).toEqual([])
expect(tabsFor('medium').shown).toEqual([
'general',
'annotations',
'findings',
'verification',
])
expect(tabsFor('small').shown).toEqual(['annotations', 'verification'])
expect(tabsFor('small').more).toEqual(['general', 'findings'])
})
})