test(editor): scoped overview card queries, group names

This commit is contained in:
bchanot committed 2026-11-07 03:03:39 +01:00
1 parent 6131225288
commit 7cca88592f
4 files changed
+92 -43

No files matched your search

+64 -25
View File
@@ -1,6 +1,12 @@
/** 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 {
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'
@@ -28,7 +34,12 @@ const props = {
onBack: vi.fn(),
}
const named = (id: string, fr: string, category: string, view = 'view-main') => {
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',
@@ -69,8 +80,15 @@ async function mount(readOnly = false) {
await screen.findByRole('list', { name: 'Annotations de la vue' })
}
const card = () => screen.getByRole('list', { name: 'Annotations de la vue' })
const overview = () =>
screen.getByRole('region', { name: 'Aperçu de la fiche' })
const card = () =>
within(overview()).getByRole('list', { name: 'Annotations de la vue' })
const rows = () => within(card()).getAllByRole('button')
const chip = (name: string) =>
within(screen.getByRole('group', { name: 'Vues' })).getByRole('button', {
name,
})
describe.each([
['edit', false],
@@ -78,25 +96,28 @@ describe.each([
])('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'),
])
const groups = within(card()).getAllByRole('list')
expect(groups).toHaveLength(2)
const [first, second] = groups
expect(first).toHaveAccessibleName('N 1')
expect(second).toHaveAccessibleName('Os 1')
expect(within(first).getByRole('button')).toHaveTextContent('Genou')
expect(within(second).getByRole('button')).toHaveTextContent('É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')
const field = within(overview()).getByRole('searchbox', {
name: 'Filtrer par nom',
})
await user.type(field, '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()
await user.type(field, 'zzz')
expect(
within(overview()).getByText('Aucune annotation ne correspond.'),
).toBeInTheDocument()
})
it('a row selects the annotation; « Toutes les annotations » returns with focus on its row', async () => {
@@ -104,28 +125,46 @@ describe.each([
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 user.click(
screen.getByRole('button', { name: 'Toutes les annotations' }),
)
expect(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()
expect(chip('Tête')).toHaveAttribute('aria-pressed', 'false')
await user.click(within(overview()).getByRole('button', { name: /^Tête/ }))
expect(
within(overview()).getByRole('button', { name: /^Tête/ }),
).toHaveAttribute('aria-current', 'true')
expect(chip('Tête')).toHaveAttribute('aria-pressed', 'true')
expect(
within(overview()).getByText('Aucune annotation dans cette vue.'),
).toBeInTheDocument()
})
})
describe('« Sans catégorie »', () => {
it('a group appears only for an annotation whose category is not in the document', async () => {
let text = insert(drawnText(), named('stray', 'Perdue', 'ghost'))
text = insert(text, named('a2', 'Genou', 'cat-a'))
await openReady({ text })
render(<AnnotationsTab {...props} />)
await screen.findByRole('list', { name: 'Annotations de la vue' })
const groups = within(card()).getAllByRole('list')
expect(groups).toHaveLength(2)
expect(groups[1]).toHaveAccessibleName('Sans catégorie 1')
expect(within(groups[1]).getByRole('button')).toHaveTextContent('Perdue')
})
})
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')
const grid = overview().closest('.grid')
expect(grid?.className).toContain('lg:grid-cols-[minmax(0,1fr)_22rem]')
expect(grid?.className).not.toContain('xl:')
})