test(editor): scoped overview card queries, group names
This commit is contained in:
1 parent
6131225288
commit
7cca88592f
4 files changed
+92
-43
No files matched your search
@@ -502,8 +502,11 @@ export async function pickAnnotation(
|
||||
name: dict['editor.annotations.show_all'],
|
||||
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()
|
||||
await annotationList(page, dict).getByRole('button', { name }).click()
|
||||
await list.getByRole('button', { name }).click()
|
||||
}
|
||||
|
||||
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. */
|
||||
function GroupTitle({ group }: { group: AnnotationGroup }) {
|
||||
function GroupTitle({ group, id }: { group: AnnotationGroup; id: string }) {
|
||||
const t = useT()
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
const { category } = group
|
||||
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
|
||||
aria-hidden="true"
|
||||
className="size-3 rounded-full border border-[var(--color-border)]"
|
||||
@@ -86,30 +86,36 @@ function GroupTitle({ group }: { group: AnnotationGroup }) {
|
||||
export default function AnnotationList({
|
||||
groups,
|
||||
views,
|
||||
idPrefix = '',
|
||||
onSelect,
|
||||
}: {
|
||||
groups: readonly AnnotationGroup[]
|
||||
views: readonly SheetView[]
|
||||
/** Put before every id (the read-only twin beside the kept edit panel). */
|
||||
idPrefix?: string
|
||||
onSelect: (id: string) => void
|
||||
}) {
|
||||
const t = useT()
|
||||
return (
|
||||
<ul aria-label={t('editor.annotations.list')} className={LIST}>
|
||||
{groups.map((group) => (
|
||||
<li key={group.category?.id ?? 'none'}>
|
||||
<GroupTitle group={group} />
|
||||
<ul>
|
||||
{group.annotations.map((annotation) => (
|
||||
<Row
|
||||
key={annotation.id}
|
||||
annotation={annotation}
|
||||
views={views}
|
||||
onSelect={onSelect}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
</li>
|
||||
))}
|
||||
{groups.map((group) => {
|
||||
const id = `${idPrefix}overview-group-${group.category?.id ?? 'none'}`
|
||||
return (
|
||||
<li key={id}>
|
||||
<GroupTitle group={group} id={id} />
|
||||
<ul aria-labelledby={id}>
|
||||
{group.annotations.map((annotation) => (
|
||||
<Row
|
||||
key={annotation.id}
|
||||
annotation={annotation}
|
||||
views={views}
|
||||
onSelect={onSelect}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
@@ -227,6 +227,7 @@ function AnnotationsCard(props: OverviewPanelProps) {
|
||||
<AnnotationList
|
||||
groups={groups}
|
||||
views={doc.views}
|
||||
idPrefix={prefix}
|
||||
onSelect={onSelectAnnotation}
|
||||
/>
|
||||
) : (
|
||||
|
||||
@@ -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:')
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user