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.
304 lines
10 KiB
TypeScript
304 lines
10 KiB
TypeScript
/** Lot J: the Vérification tab and the submission. */
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { act, cleanup, render, screen, waitFor } from '@testing-library/react'
|
|
import userEvent from '@testing-library/user-event'
|
|
import { SheetFailure } from '@faunosteo/supabase'
|
|
import VerificationTab from '@/components/editor/tabs/VerificationTab'
|
|
import {
|
|
ISSUE_CODES,
|
|
issueMessageKey,
|
|
issueTarget,
|
|
placeKey,
|
|
} from '@/editor/verification'
|
|
import { getDict } from '@/i18n'
|
|
import { useLocaleStore } from '@/state/localeStore'
|
|
import { insert, point } from '../helpers/editorFixtures'
|
|
import {
|
|
baseText,
|
|
commitMove,
|
|
openReady,
|
|
resetStore,
|
|
sb,
|
|
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(),
|
|
}))
|
|
|
|
const navigate = vi.fn()
|
|
const reloadSheet = vi.fn()
|
|
const props = { readOnly: false, navigate, reloadSheet }
|
|
const SUBMIT = 'Soumettre à la revue'
|
|
|
|
/** An annotation without geometry: a blocking error of the core. */
|
|
function textWithError(): string {
|
|
const bare = point('anno-bare', 10, 10, 2)
|
|
const value = {
|
|
...bare.value,
|
|
geometry: null,
|
|
name: { fr: 'Sans tracé', en: 'Bare' },
|
|
}
|
|
return insert(baseText(), { kind: 'annotation', value } as typeof bare)
|
|
}
|
|
|
|
beforeEach(() => useLocaleStore.setState({ locale: 'fr' }))
|
|
afterEach(() => {
|
|
cleanup()
|
|
resetStore()
|
|
navigate.mockReset()
|
|
reloadSheet.mockReset()
|
|
})
|
|
|
|
describe('Vérification panel', () => {
|
|
it('shows the counts, the warning apart, the size and the groups', async () => {
|
|
await openReady()
|
|
render(<VerificationTab {...props} />)
|
|
expect(screen.getByText('0 erreur bloquante')).toBeTruthy()
|
|
expect(screen.getByText('1 avertissement')).toBeTruthy()
|
|
expect(screen.getByText('1 élément à confirmer')).toBeTruthy()
|
|
expect(screen.getByRole('heading', { name: 'Avertissements' })).toBeTruthy()
|
|
expect(
|
|
screen.getByText(/lié(e)? à aucune zone|liée à aucune zone/),
|
|
).toBeTruthy()
|
|
expect(screen.getByText(/sur 2 097 152 o$/)).toBeTruthy()
|
|
expect(
|
|
screen.getByRole('heading', { name: 'Statuts par groupe' }),
|
|
).toBeTruthy()
|
|
expect(screen.getByText(/n'empêche pas la soumission/)).toBeTruthy()
|
|
})
|
|
|
|
it('names an error with its message and goes to the tab of the element', async () => {
|
|
await openReady({ text: textWithError() })
|
|
const user = userEvent.setup()
|
|
render(<VerificationTab {...props} />)
|
|
expect(screen.getByText('1 erreur bloquante')).toBeTruthy()
|
|
expect(screen.getAllByText('Sans tracé')).toHaveLength(2)
|
|
expect(screen.getByText(/n'a pas de géométrie/)).toBeTruthy()
|
|
await user.click(
|
|
screen.getAllByRole('button', { name: 'Aller à Sans tracé' })[0],
|
|
)
|
|
expect(navigate).toHaveBeenCalledWith(
|
|
{
|
|
place: 'tab',
|
|
tab: 'annotations',
|
|
section: 'drawing',
|
|
key: { kind: 'annotation', id: 'anno-bare' },
|
|
},
|
|
expect.any(HTMLElement),
|
|
)
|
|
expect(screen.queryByText('Aucun problème détecté')).toBeNull()
|
|
})
|
|
|
|
it('disables the submission with the hint while errors exist', async () => {
|
|
await openReady({ text: textWithError() })
|
|
render(<VerificationTab {...props} />)
|
|
const button = screen.getByRole('button', {
|
|
name: SUBMIT,
|
|
}) as HTMLButtonElement
|
|
expect(button.disabled).toBe(true)
|
|
expect(
|
|
screen.getByText("Corrigez l'erreur bloquante pour soumettre."),
|
|
).toBeTruthy()
|
|
})
|
|
|
|
it('phrases the issues in English', async () => {
|
|
useLocaleStore.setState({ locale: 'en' })
|
|
await openReady({ text: textWithError() })
|
|
render(<VerificationTab {...props} />)
|
|
expect(screen.getByText('1 blocking error')).toBeTruthy()
|
|
expect(screen.getByText(/This annotation has no geometry/)).toBeTruthy()
|
|
expect(screen.getAllByRole('button', { name: 'Go to Bare' })).toHaveLength(
|
|
2,
|
|
)
|
|
})
|
|
|
|
it('hides the submission when read-only', async () => {
|
|
await openReady()
|
|
render(<VerificationTab {...props} readOnly />)
|
|
expect(screen.queryByRole('button', { name: SUBMIT })).toBeNull()
|
|
expect(screen.getByText('0 erreur bloquante')).toBeTruthy()
|
|
})
|
|
})
|
|
|
|
describe('Submission', () => {
|
|
it('needs a note and the saved draft', async () => {
|
|
await openReady()
|
|
const user = userEvent.setup()
|
|
render(<VerificationTab {...props} />)
|
|
const button = screen.getByRole('button', {
|
|
name: SUBMIT,
|
|
}) as HTMLButtonElement
|
|
expect(button.disabled).toBe(true)
|
|
expect(screen.getByText(/Saisissez la note/)).toBeTruthy()
|
|
await user.type(
|
|
screen.getByLabelText('Note de soumission (obligatoire)'),
|
|
' ',
|
|
)
|
|
expect(button.disabled).toBe(true)
|
|
act(() => void commitMove(60))
|
|
await user.type(
|
|
screen.getByLabelText('Note de soumission (obligatoire)'),
|
|
'Prête',
|
|
)
|
|
expect(button.disabled).toBe(true)
|
|
expect(
|
|
screen.getByText('Enregistrez le brouillon avant de le soumettre.'),
|
|
).toBeTruthy()
|
|
})
|
|
|
|
it('submits the note as typed on the saved revision and reloads the sheet', async () => {
|
|
await openReady()
|
|
sb.submitSheetReview.mockResolvedValue('review-1' as never)
|
|
const user = userEvent.setup()
|
|
render(<VerificationTab {...props} />)
|
|
await user.type(
|
|
screen.getByLabelText('Note de soumission (obligatoire)'),
|
|
' Prête ',
|
|
)
|
|
await user.click(screen.getByRole('button', { name: SUBMIT }))
|
|
await waitFor(() => expect(reloadSheet).toHaveBeenCalled())
|
|
expect(sb.submitSheetReview).toHaveBeenCalledWith(expect.anything(), {
|
|
version_id: 'ver-1',
|
|
expected_revision: 3,
|
|
note: ' Prête ',
|
|
})
|
|
})
|
|
|
|
it('shows a server refusal and keeps the note', async () => {
|
|
await openReady()
|
|
sb.submitSheetReview.mockRejectedValue(new SheetFailure('draft.frozen'))
|
|
const user = userEvent.setup()
|
|
render(<VerificationTab {...props} />)
|
|
await user.type(
|
|
screen.getByLabelText('Note de soumission (obligatoire)'),
|
|
'Prête',
|
|
)
|
|
await user.click(screen.getByRole('button', { name: SUBMIT }))
|
|
expect(await screen.findByRole('alert')).toBeTruthy()
|
|
expect(reloadSheet).not.toHaveBeenCalled()
|
|
expect(
|
|
(
|
|
screen.getByLabelText(
|
|
'Note de soumission (obligatoire)',
|
|
) as HTMLTextAreaElement
|
|
).value,
|
|
).toBe('Prête')
|
|
})
|
|
|
|
it('opens the conflict read on a draft conflict and shows no message', async () => {
|
|
await openReady()
|
|
sb.submitSheetReview.mockRejectedValue(new SheetFailure('draft_conflict'))
|
|
sb.getOfficialSheetAdmin.mockRejectedValue(new Error('x'))
|
|
const user = userEvent.setup()
|
|
render(<VerificationTab {...props} />)
|
|
await user.type(
|
|
screen.getByLabelText('Note de soumission (obligatoire)'),
|
|
'Prête',
|
|
)
|
|
await user.click(screen.getByRole('button', { name: SUBMIT }))
|
|
await waitFor(() =>
|
|
expect(store.getState().conflict).toEqual({ status: 'unknown' }),
|
|
)
|
|
expect(screen.queryByRole('alert')).toBeNull()
|
|
expect(reloadSheet).not.toHaveBeenCalled()
|
|
expect(sb.submitSheetReview).toHaveBeenCalledTimes(1)
|
|
})
|
|
})
|
|
|
|
describe('issueTarget', () => {
|
|
const at = (path: string) => issueTarget(doc(), path, 'fr')?.target
|
|
const doc = () => JSON.parse(store.getState().documentText)
|
|
|
|
it('each issue root names its place and the element it resolves to', async () => {
|
|
await openReady({ text: textWithError() })
|
|
expect(at('views[0].frame')).toMatchObject({
|
|
place: 'tab',
|
|
tab: 'annotations',
|
|
section: 'views',
|
|
key: { kind: 'view', id: 'view-main' },
|
|
})
|
|
expect(at('categories[0].name')).toMatchObject({
|
|
place: 'tab',
|
|
tab: 'annotations',
|
|
section: 'categories',
|
|
key: { kind: 'category', id: 'cat-a' },
|
|
})
|
|
expect(at('vertebral_config.regions[0].count')).toMatchObject({
|
|
place: 'tab',
|
|
tab: 'annotations',
|
|
section: 'regions',
|
|
})
|
|
expect(at('references[0].citation')).toMatchObject({
|
|
place: 'references',
|
|
citedBy: null,
|
|
})
|
|
expect(at('finding_zones[0].name')).toMatchObject({
|
|
place: 'tab',
|
|
tab: 'findings',
|
|
})
|
|
expect(at('annotations[0].geometry')).toMatchObject({
|
|
tab: 'annotations',
|
|
section: 'drawing',
|
|
})
|
|
})
|
|
|
|
it('a path whose element is gone names the place alone, and the label names it', async () => {
|
|
await openReady({ text: textWithError() })
|
|
const gone = at('views[9].frame')
|
|
expect(gone).toEqual({
|
|
place: 'tab',
|
|
tab: 'annotations',
|
|
section: 'views',
|
|
key: null,
|
|
})
|
|
expect(placeKey(gone!)).toBe('editor.place.views')
|
|
expect(placeKey(at('references[9].citation')!)).toBe(
|
|
'editor.place.references',
|
|
)
|
|
expect(placeKey(at('annotations[9].geometry')!)).toBe(
|
|
'editor.tab.annotations',
|
|
)
|
|
})
|
|
})
|
|
|
|
describe('Issue messages', () => {
|
|
it('has an FR and an EN message for every known code', () => {
|
|
for (const code of ISSUE_CODES) {
|
|
const key = issueMessageKey(code)
|
|
expect(getDict('fr')[key], key).toBeTruthy()
|
|
expect(getDict('en')[key], key).toBeTruthy()
|
|
}
|
|
})
|
|
|
|
it('falls back to a neutral message for an unknown code', () => {
|
|
const key = issueMessageKey('something.new')
|
|
expect(key).toBe('editor.verification.issue.unknown')
|
|
expect(getDict('fr')[key]).toBeTruthy()
|
|
})
|
|
})
|
|
|
|
describe('Submission after the tab is gone', () => {
|
|
it('still reloads the sheet when the tab unmounted during the await', async () => {
|
|
await openReady()
|
|
let resolve: (id: never) => void = () => undefined
|
|
sb.submitSheetReview.mockReturnValue(new Promise((r) => (resolve = r)))
|
|
const user = userEvent.setup()
|
|
const view = render(<VerificationTab {...props} />)
|
|
await user.type(
|
|
screen.getByLabelText('Note de soumission (obligatoire)'),
|
|
'Prête',
|
|
)
|
|
await user.click(screen.getByRole('button', { name: SUBMIT }))
|
|
view.unmount()
|
|
await act(async () => resolve('review-1' as never))
|
|
await waitFor(() => expect(reloadSheet).toHaveBeenCalled())
|
|
})
|
|
})
|