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

+4 -1
View File
@@ -502,8 +502,11 @@ export async function pickAnnotation(
name: dict['editor.annotations.show_all'], name: dict['editor.annotations.show_all'],
exact: true, exact: true,
}) })
const list = annotationList(page, dict)
// Either the card (nothing selected) or the properties panel has settled.
await expect(all.or(list)).toBeVisible()
if (await all.isVisible()) await all.click() if (await all.isVisible()) await all.click()
await annotationList(page, dict).getByRole('button', { name }).click() await list.getByRole('button', { name }).click()
} }
export const toolButton = (page: Page, dict: Dict, id: string) => export const toolButton = (page: Page, dict: Dict, id: string) =>
@@ -58,12 +58,12 @@ function Row({
} }
/** « Sans catégorie » or the category: swatch, name and the count of rows shown. */ /** « Sans catégorie » or the category: swatch, name and the count of rows shown. */
function GroupTitle({ group }: { group: AnnotationGroup }) { function GroupTitle({ group, id }: { group: AnnotationGroup; id: string }) {
const t = useT() const t = useT()
const locale = useLocaleStore((s) => s.locale) const locale = useLocaleStore((s) => s.locale)
const { category } = group const { category } = group
return ( return (
<p className="flex items-center gap-2 px-3 text-sm font-semibold"> <p id={id} className="flex items-center gap-2 px-3 text-sm font-semibold">
<span <span
aria-hidden="true" aria-hidden="true"
className="size-3 rounded-full border border-[var(--color-border)]" className="size-3 rounded-full border border-[var(--color-border)]"
@@ -86,30 +86,36 @@ function GroupTitle({ group }: { group: AnnotationGroup }) {
export default function AnnotationList({ export default function AnnotationList({
groups, groups,
views, views,
idPrefix = '',
onSelect, onSelect,
}: { }: {
groups: readonly AnnotationGroup[] groups: readonly AnnotationGroup[]
views: readonly SheetView[] views: readonly SheetView[]
/** Put before every id (the read-only twin beside the kept edit panel). */
idPrefix?: string
onSelect: (id: string) => void onSelect: (id: string) => void
}) { }) {
const t = useT() const t = useT()
return ( return (
<ul aria-label={t('editor.annotations.list')} className={LIST}> <ul aria-label={t('editor.annotations.list')} className={LIST}>
{groups.map((group) => ( {groups.map((group) => {
<li key={group.category?.id ?? 'none'}> const id = `${idPrefix}overview-group-${group.category?.id ?? 'none'}`
<GroupTitle group={group} /> return (
<ul> <li key={id}>
{group.annotations.map((annotation) => ( <GroupTitle group={group} id={id} />
<Row <ul aria-labelledby={id}>
key={annotation.id} {group.annotations.map((annotation) => (
annotation={annotation} <Row
views={views} key={annotation.id}
onSelect={onSelect} annotation={annotation}
/> views={views}
))} onSelect={onSelect}
</ul> />
</li> ))}
))} </ul>
</li>
)
})}
</ul> </ul>
) )
} }
@@ -227,6 +227,7 @@ function AnnotationsCard(props: OverviewPanelProps) {
<AnnotationList <AnnotationList
groups={groups} groups={groups}
views={doc.views} views={doc.views}
idPrefix={prefix}
onSelect={onSelectAnnotation} onSelect={onSelectAnnotation}
/> />
) : ( ) : (
+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. */ /** 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 { 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 userEvent from '@testing-library/user-event'
import type { Annotation } from '@faunosteo/core-wasm/types' import type { Annotation } from '@faunosteo/core-wasm/types'
import AnnotationsTab from '@/components/editor/tabs/AnnotationsTab' import AnnotationsTab from '@/components/editor/tabs/AnnotationsTab'
@@ -28,7 +34,12 @@ const props = {
onBack: vi.fn(), 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 const base = point(id, 50, 50, 5, view).value as Annotation
return { return {
kind: 'annotation', kind: 'annotation',
@@ -69,8 +80,15 @@ async function mount(readOnly = false) {
await screen.findByRole('list', { name: 'Annotations de la vue' }) 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 rows = () => within(card()).getAllByRole('button')
const chip = (name: string) =>
within(screen.getByRole('group', { name: 'Vues' })).getByRole('button', {
name,
})
describe.each([ describe.each([
['edit', false], ['edit', false],
@@ -78,25 +96,28 @@ describe.each([
])('the annotation card (%s)', (_mode, readOnly) => { ])('the annotation card (%s)', (_mode, readOnly) => {
it('groups the rows by category in document order, with a count per group', async () => { it('groups the rows by category in document order, with a count per group', async () => {
await mount(readOnly) await mount(readOnly)
const titles = within(card()) const groups = within(card()).getAllByRole('list')
.getAllByRole('listitem') expect(groups).toHaveLength(2)
.filter((item) => item.querySelector('ul')) const [first, second] = groups
.map((item) => item.querySelector('p')?.textContent) expect(first).toHaveAccessibleName('N 1')
expect(titles).toEqual(['N1', 'Os1']) expect(second).toHaveAccessibleName('Os 1')
expect(rows().map((b) => b.textContent)).toEqual([ expect(within(first).getByRole('button')).toHaveTextContent('Genou')
expect.stringContaining('Genou'), expect(within(second).getByRole('button')).toHaveTextContent('Épaule')
expect.stringContaining('Épaule'),
])
}) })
it('filters on the displayed name, ignoring case and accents', async () => { it('filters on the displayed name, ignoring case and accents', async () => {
await mount(readOnly) await mount(readOnly)
const user = userEvent.setup() 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()).toHaveLength(1)
expect(rows()[0]).toHaveTextContent('Épaule') expect(rows()[0]).toHaveTextContent('Épaule')
await user.type(screen.getByRole('searchbox'), 'zzz') await user.type(field, 'zzz')
expect(screen.getByText('Aucune annotation ne correspond.')).toBeInTheDocument() 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 () => { 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() const user = userEvent.setup()
await user.click(rows()[1]) await user.click(rows()[1])
expect(await screen.findByTestId('annotation-properties')).toBeVisible() expect(await screen.findByTestId('annotation-properties')).toBeVisible()
await user.click(screen.getByRole('button', { name: 'Toutes les annotations' })) await user.click(
expect(screen.getByTestId('annotation-overview')).toBeVisible() screen.getByRole('button', { name: 'Toutes les annotations' }),
)
expect(overview()).toBeVisible()
await waitFor(() => expect(document.activeElement).toBe(rows()[1])) await waitFor(() => expect(document.activeElement).toBe(rows()[1]))
}) })
it('a view row switches the canvas view', async () => { it('a view row switches the canvas view', async () => {
await mount(readOnly) await mount(readOnly)
const user = userEvent.setup() const user = userEvent.setup()
const views = screen.getByRole('region', { name: 'Aperçu de la fiche' }) expect(chip('Tête')).toHaveAttribute('aria-pressed', 'false')
await user.click(within(views).getByRole('button', { name: /^Tête/ })) await user.click(within(overview()).getByRole('button', { name: /^Tête/ }))
expect(within(views).getByRole('button', { name: /^Tête/ })).toHaveAttribute( expect(
'aria-current', within(overview()).getByRole('button', { name: /^Tête/ }),
'true', ).toHaveAttribute('aria-current', 'true')
) expect(chip('Tête')).toHaveAttribute('aria-pressed', 'true')
expect(screen.getByText('Aucune annotation dans cette vue.')).toBeInTheDocument() 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', () => { describe('the side column', () => {
it('sits beside the canvas from lg (1 024 px), not xl', async () => { it('sits beside the canvas from lg (1 024 px), not xl', async () => {
await mount() 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).toContain('lg:grid-cols-[minmax(0,1fr)_22rem]')
expect(grid?.className).not.toContain('xl:') expect(grid?.className).not.toContain('xl:')
}) })