Files
faunosteo/apps/app/tests/unit/editor-overview.test.tsx
T
bchanot 6131225288 feat(editor): board 01 annotation card, side column from 1 024 px
Annotations of the view move from under the drawing to the overview card
(grouped by category, name filter, all rows); side column from lg.
Properties panel gains « Toutes les annotations ».

E2E mapping (R-24): after a creation the card is hidden (the new annotation is
selected), so list(...).getByText(name) became selectionTag toContainText
(annotations, geometry, journey); row clicks go through pickAnnotation
(annotations, geometry, journey, structures); geometry's list count 0 while a
creation is pending became selectionTag count 0.
2026-11-06 21:40:25 +01:00

133 lines
4.8 KiB
TypeScript

/** V1-2.6 U1 Lot C: board 01's « Annotations de la vue » card, in edit and read-only. */
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { cleanup, render, screen, waitFor, within } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import type { Annotation } from '@faunosteo/core-wasm/types'
import AnnotationsTab from '@/components/editor/tabs/AnnotationsTab'
import { useLocaleStore } from '@/state/localeStore'
import { drawnText, insert, point } from '../helpers/editorFixtures'
import { openReady, resetStore } 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 props = {
readOnly: false,
navigate: vi.fn(),
reloadSheet: vi.fn(),
section: 'drawing' as const,
visited: ['drawing'] as const,
onOpenSection: vi.fn(),
onBack: vi.fn(),
}
const named = (id: string, fr: string, category: string, view = 'view-main') => {
const base = point(id, 50, 50, 5, view).value as Annotation
return {
kind: 'annotation',
value: { ...base, category_id: category, name: { fr, en: fr } },
} as const
}
/** Two categories (b declared after a); the first annotation sits in b. */
function sheet(): string {
let text = insert(drawnText(), {
kind: 'category',
value: { id: 'cat-b', name: { fr: 'Os', en: 'Bone' }, color: '#aa0000' },
})
text = insert(text, named('a1', 'Épaule', 'cat-b'))
text = insert(text, named('a2', 'Genou', 'cat-a'))
return insert(text, {
kind: 'view',
value: {
kind: 'detail',
id: 'view-det',
name: { fr: 'Tête', en: 'Head' },
svg_asset_id: null,
view_box: { min_x: 10, min_y: 10, width: 80, height: 80 },
parent_view_id: 'view-main',
},
})
}
beforeEach(() => useLocaleStore.setState({ locale: 'fr' }))
afterEach(() => {
cleanup()
resetStore()
})
async function mount(readOnly = false) {
await openReady({ text: sheet() })
render(<AnnotationsTab {...props} readOnly={readOnly} />)
await screen.findByRole('list', { name: 'Annotations de la vue' })
}
const card = () => screen.getByRole('list', { name: 'Annotations de la vue' })
const rows = () => within(card()).getAllByRole('button')
describe.each([
['edit', false],
['read-only', true],
])('the annotation card (%s)', (_mode, readOnly) => {
it('groups the rows by category in document order, with a count per group', async () => {
await mount(readOnly)
const titles = within(card())
.getAllByRole('listitem')
.filter((item) => item.querySelector('ul'))
.map((item) => item.querySelector('p')?.textContent)
expect(titles).toEqual(['N1', 'Os1'])
expect(rows().map((b) => b.textContent)).toEqual([
expect.stringContaining('Genou'),
expect.stringContaining('Épaule'),
])
})
it('filters on the displayed name, ignoring case and accents', async () => {
await mount(readOnly)
const user = userEvent.setup()
await user.type(screen.getByRole('searchbox', { name: 'Filtrer par nom' }), 'EPAULE')
expect(rows()).toHaveLength(1)
expect(rows()[0]).toHaveTextContent('Épaule')
await user.type(screen.getByRole('searchbox'), 'zzz')
expect(screen.getByText('Aucune annotation ne correspond.')).toBeInTheDocument()
})
it('a row selects the annotation; « Toutes les annotations » returns with focus on its row', async () => {
await mount(readOnly)
const user = userEvent.setup()
await user.click(rows()[1])
expect(await screen.findByTestId('annotation-properties')).toBeVisible()
await user.click(screen.getByRole('button', { name: 'Toutes les annotations' }))
expect(screen.getByTestId('annotation-overview')).toBeVisible()
await waitFor(() => expect(document.activeElement).toBe(rows()[1]))
})
it('a view row switches the canvas view', async () => {
await mount(readOnly)
const user = userEvent.setup()
const views = screen.getByRole('region', { name: 'Aperçu de la fiche' })
await user.click(within(views).getByRole('button', { name: /^Tête/ }))
expect(within(views).getByRole('button', { name: /^Tête/ })).toHaveAttribute(
'aria-current',
'true',
)
expect(screen.getByText('Aucune annotation dans cette vue.')).toBeInTheDocument()
})
})
describe('the side column', () => {
it('sits beside the canvas from lg (1 024 px), not xl', async () => {
await mount()
const grid = screen.getByTestId('annotation-overview').closest('.grid')
expect(grid?.className).toContain('lg:grid-cols-[minmax(0,1fr)_22rem]')
expect(grid?.className).not.toContain('xl:')
})
})