fix(editor): plurals, trimmed names, default tab, parent drawing confirmation

This commit is contained in:
bchanot committed 2026-11-04 19:40:43 +01:00
1 parent b42c6ae844
commit be4f468790
35 files changed
+385 -63

No files matched your search

@@ -577,11 +577,11 @@ describe('tracing a zone or a link', () => {
)
await userEvent.setup().click(screen.getByRole('button', { name: 'Zone' }))
clickAt(20, 20)
expect(screen.getByText('1 sommet(s) posé(s).')).toBeInTheDocument()
expect(screen.getByText('1 sommet posé.')).toBeInTheDocument()
fireEvent.keyDown(screen.getByTestId('annotation-canvas'), {
key: 'Escape',
})
expect(screen.queryByText('1 sommet(s) posé(s).')).toBeNull()
expect(screen.queryByText('1 sommet posé.')).toBeNull()
expect(annotations()).toHaveLength(0)
})
@@ -47,6 +47,42 @@ describe('TextField', () => {
expect(onCommit).toHaveBeenCalledWith('Chevalz')
})
it('trim commits a padded name without its edge spaces', async () => {
const user = userEvent.setup()
const onCommit = vi.fn()
render(
<TextField id="f" label="Nom" value="Cheval" onCommit={onCommit} trim />,
)
await user.type(screen.getByLabelText('Nom'), ' {Enter}')
expect(onCommit).not.toHaveBeenCalled()
await user.type(screen.getByLabelText('Nom'), 'x ')
await user.tab()
expect(onCommit).toHaveBeenCalledWith('Chevalx')
})
it('trim: a blank value commits as empty; unmount trims too', async () => {
const user = userEvent.setup()
const onCommit = vi.fn()
const view = render(
<TextField id="f" label="Nom" value="" onCommit={onCommit} trim />,
)
await user.type(screen.getByLabelText('Nom'), ' ')
await user.tab()
expect(onCommit).not.toHaveBeenCalled()
await user.type(screen.getByLabelText('Nom'), ' a ')
view.unmount()
expect(onCommit).toHaveBeenCalledWith('a')
})
it('without trim a padded description commits unchanged', async () => {
const user = userEvent.setup()
const onCommit = vi.fn()
render(<TextField id="f" label="Texte" value="" onCommit={onCommit} />)
await user.type(screen.getByLabelText('Texte'), ' a ')
await user.tab()
expect(onCommit).toHaveBeenCalledWith(' a ')
})
it('a new committed value replaces what was typed; the refusal shows next to the control', () => {
const view = render(
<TextField
@@ -276,6 +276,37 @@ describe('Constats tab', () => {
expect(doc().finding_zones[0].categories[1].children).toHaveLength(1)
})
it('names the zone a category lands in and appends it at zone level, a node selected', async () => {
await openReady({ text: treeText() })
const user = userEvent.setup()
render(<FindingsTab {...props} />)
items()[0].focus()
await user.keyboard('{ArrowDown}{ArrowRight}{ArrowRight}')
expect(items()[2]).toHaveAttribute('aria-selected', 'true')
await user.click(
screen.getByRole('button', { name: 'Ajouter une catégorie' }),
)
expect(
screen.getByText('Nouvelle catégorie dans la zone « Zone A »'),
).toBeInTheDocument()
await user.type(
screen.getByLabelText('Nom (FR)', { selector: '#finding-new-name-fr' }),
'Nouv',
)
await user.type(
screen.getByLabelText('Nom (EN)', { selector: '#finding-new-name-en' }),
'New',
)
await user.selectOptions(
screen.getByLabelText('Type de catégorie'),
'anamnesis',
)
await user.click(screen.getByRole('button', { name: 'Créer' }))
const categories = doc().finding_zones[0].categories
expect(categories.map((c) => c.id)).toEqual(['fcat-a', expect.any(String)])
expect(categories[0].children[0].children).toHaveLength(1)
})
it('disables « Ajouter un constat » on a zone and at depth 8', async () => {
let text = treeText()
let path = ['fcat-a', 'node-a', 'node-b']
@@ -0,0 +1,41 @@
/** N1 (C40): the tab a version opens on. */
import { afterEach, describe, expect, it, vi } from 'vitest'
import { initialTab } from '@/editor/tabs'
import { emptyText } from '../helpers/editorFixtures'
import {
baseText,
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(),
}))
afterEach(resetStore)
async function stateOf(text: string) {
await openReady({ text })
return store.getState().previewState!
}
describe('initialTab', () => {
it('opens an empty new draft on Général', async () => {
expect(initialTab(await stateOf(emptyText()), 'wide')).toBe('general')
})
it('opens a draft with a measured view on Annotations', async () => {
expect(initialTab(await stateOf(baseText()), 'wide')).toBe('annotations')
})
it('keeps Annotations on a tier that does not list Général', async () => {
expect(initialTab(await stateOf(emptyText()), 'small')).toBe('annotations')
})
})
@@ -0,0 +1,16 @@
import { describe, expect, it } from 'vitest'
import { pluralKey } from '@/editor/plural'
describe('pluralKey', () => {
it('treats 0 and 1 as singular in French', () => {
expect(pluralKey('fr', 'k', 0)).toBe('k_one')
expect(pluralKey('fr', 'k', 1)).toBe('k_one')
expect(pluralKey('fr', 'k', 2)).toBe('k_other')
})
it('treats only 1 as singular in English', () => {
expect(pluralKey('en', 'k', 0)).toBe('k_other')
expect(pluralKey('en', 'k', 1)).toBe('k_one')
expect(pluralKey('en', 'k', 2)).toBe('k_other')
})
})
@@ -150,6 +150,36 @@ describe('Vues et illustrations: drawing states', () => {
expect(screen.queryByText(/introuvable/)).toBeNull()
})
it('use-parent asks first: cancel changes nothing, confirm commits once, undo restores', async () => {
const own = detail()
;(own.value as { svg_asset_id: string | null }).svg_asset_id = ASSET
await openReady({ text: insert(baseText(), own) })
const user = userEvent.setup()
render(<ViewsTab {...props} />)
const open = () =>
user.click(
screen.getByRole('button', {
name: "Utiliser l'illustration de la vue parente",
}),
)
await open()
const dialog = screen.getByRole('dialog')
expect(dialog).toHaveTextContent(/reste enregistré/)
await user.click(within(dialog).getByRole('button', { name: 'Annuler' }))
expect(doc().views[1]).toMatchObject({ svg_asset_id: ASSET })
expect(store.getState().undo).toHaveLength(0)
await open()
await user.click(
within(screen.getByRole('dialog')).getByRole('button', {
name: "Utiliser l'illustration parente",
}),
)
expect(doc().views[1]).toMatchObject({ svg_asset_id: null })
expect(store.getState().undo).toHaveLength(1)
store.getState().undoStep()
expect(doc().views[1]).toMatchObject({ svg_asset_id: ASSET })
})
it('read-only shows states as text and no action', async () => {
await openReady({ text: insert(baseText(), detail()) })
render(<ViewsTab {...props} readOnly />)
@@ -57,9 +57,9 @@ 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 erreurs bloquantes')).toBeTruthy()
expect(screen.getByText('1 avertissements')).toBeTruthy()
expect(screen.getByText('1 éléments à confirmer')).toBeTruthy()
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/),
@@ -75,7 +75,7 @@ describe('Vérification panel', () => {
await openReady({ text: textWithError() })
const user = userEvent.setup()
render(<VerificationTab {...props} />)
expect(screen.getByText('1 erreurs bloquantes')).toBeTruthy()
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(
@@ -96,7 +96,7 @@ describe('Vérification panel', () => {
}) as HTMLButtonElement
expect(button.disabled).toBe(true)
expect(
screen.getByText('Corrigez les 1 erreurs bloquantes pour soumettre.'),
screen.getByText("Corrigez l'erreur bloquante pour soumettre."),
).toBeTruthy()
})
@@ -104,7 +104,7 @@ describe('Vérification panel', () => {
useLocaleStore.setState({ locale: 'en' })
await openReady({ text: textWithError() })
render(<VerificationTab {...props} />)
expect(screen.getByText('1 blocking errors')).toBeTruthy()
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,
@@ -115,7 +115,7 @@ describe('Vérification panel', () => {
await openReady()
render(<VerificationTab {...props} readOnly />)
expect(screen.queryByRole('button', { name: SUBMIT })).toBeNull()
expect(screen.getByText('0 erreurs bloquantes')).toBeTruthy()
expect(screen.getByText('0 erreur bloquante')).toBeTruthy()
})
})