feat(app): search, sort, count and date on the official sheet list
Boards 28 and 29 A: name search with clear button and Escape, « Trier par » (last modification by default, or name), a polite count line, « Modifiée le … » on each row in a <time>, and the search no-result block. The detail line moves to labels.ts as sheetDetails. R-24: no existing assertion removed or rewritten; six tests added.
This commit is contained in:
1 parent
a950e403c2
commit
423125c18f
6 files changed
+534
-133
No files matched your search
@@ -642,6 +642,159 @@ describe('Official sheets list (H1)', () => {
|
||||
await screen.findByRole('list', { name: 'Liste des fiches officielles' })
|
||||
expect(screen.queryByRole('link', { name: 'Nouvelle fiche' })).toBeNull()
|
||||
})
|
||||
// R3 (boards 28, 29 A): search, sort, count line and date over three sheets.
|
||||
const HORSE = 'Cheval, squelette et rachis'
|
||||
const DOG = 'Chien, squelette et rachis'
|
||||
const DONKEY = 'Âne, squelette et rachis'
|
||||
const threeSheets = () => [
|
||||
summary({ last_modified_at: '2026-11-09T11:06:00.123456+00:00' }),
|
||||
summary({
|
||||
sheet_id: '55555555-5555-4555-8555-555555555555',
|
||||
slug: 'chien-squelette',
|
||||
name: { fr: DOG, en: 'Dog, skeleton and spine' },
|
||||
last_modified_at: '2026-11-08T16:41:00+00:00',
|
||||
}),
|
||||
summary({
|
||||
sheet_id: '66666666-6666-4666-8666-666666666666',
|
||||
slug: 'ane-squelette',
|
||||
name: { fr: DONKEY, en: 'Donkey, skeleton and spine' },
|
||||
last_modified_at: '2026-11-03T10:02:00+00:00',
|
||||
}),
|
||||
]
|
||||
const ALL_NAMES = [HORSE, DOG, DONKEY]
|
||||
async function mountThree() {
|
||||
fake.rpcResults.list_official_sheets_admin = { data: threeSheets() }
|
||||
mount('/app/admin/sheets', [grant('sheet_editor')])
|
||||
return within(
|
||||
await screen.findByRole('list', { name: 'Liste des fiches officielles' }),
|
||||
)
|
||||
}
|
||||
const rowNames = (list: ReturnType<typeof within>) =>
|
||||
list
|
||||
.getAllByRole('link')
|
||||
.map((row: HTMLElement) => ALL_NAMES.find((n) => row.textContent?.startsWith(n)))
|
||||
const searchField = () =>
|
||||
screen.getByRole('searchbox', { name: 'Rechercher une fiche par son nom' })
|
||||
|
||||
it('orders by last modification, newest first, and dates each row', async () => {
|
||||
const list = await mountThree()
|
||||
expect(rowNames(list)).toEqual([HORSE, DOG, DONKEY])
|
||||
const date = list.getByText('Modifiée le 9 nov. 2026, 12:06')
|
||||
expect(date.tagName).toBe('TIME')
|
||||
expect(date).toHaveAttribute('datetime', '2026-11-09T11:06:00.123Z')
|
||||
expect(screen.getByText('3 fiches')).toHaveAttribute('aria-live', 'polite')
|
||||
expect(screen.getByLabelText('Trier par')).toHaveValue('modified')
|
||||
})
|
||||
|
||||
it('narrows the list by name as the user types and counts « 1 fiche sur 3 »', async () => {
|
||||
const user = userEvent.setup()
|
||||
const list = await mountThree()
|
||||
expect(searchField()).toHaveAttribute('maxlength', '100')
|
||||
expect(searchField()).toHaveAttribute('autocomplete', 'off')
|
||||
await user.type(searchField(), 'chev')
|
||||
expect(rowNames(list)).toEqual([HORSE])
|
||||
expect(screen.getByText('1 fiche sur 3')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('clears the search by « × » or Escape and gives the focus back to the field', async () => {
|
||||
const user = userEvent.setup()
|
||||
await mountThree()
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'Effacer la recherche' }),
|
||||
).toBeNull()
|
||||
await user.type(searchField(), 'chev')
|
||||
await user.click(screen.getByRole('button', { name: 'Effacer la recherche' }))
|
||||
expect(searchField()).toHaveValue('')
|
||||
expect(screen.getByText('3 fiches')).toBeInTheDocument()
|
||||
expect(searchField()).toHaveFocus()
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'Effacer la recherche' }),
|
||||
).toBeNull()
|
||||
|
||||
const reached: string[] = []
|
||||
const listen = (event: KeyboardEvent) => reached.push(event.key)
|
||||
window.addEventListener('keydown', listen)
|
||||
try {
|
||||
await user.type(searchField(), 'chien')
|
||||
expect(screen.getByText('1 fiche sur 3')).toBeInTheDocument()
|
||||
reached.length = 0
|
||||
await user.keyboard('{Escape}')
|
||||
expect(searchField()).toHaveValue('')
|
||||
expect(screen.getByText('3 fiches')).toBeInTheDocument()
|
||||
expect(searchField()).toHaveFocus()
|
||||
expect(reached).toEqual([])
|
||||
await user.keyboard('{Escape}')
|
||||
expect(searchField()).toHaveValue('')
|
||||
expect(screen.getByText('3 fiches')).toBeInTheDocument()
|
||||
expect(reached).toEqual(['Escape'])
|
||||
} finally {
|
||||
window.removeEventListener('keydown', listen)
|
||||
}
|
||||
})
|
||||
|
||||
it('reorders the rows by name with « Nom »', async () => {
|
||||
const user = userEvent.setup()
|
||||
const list = await mountThree()
|
||||
await user.selectOptions(screen.getByLabelText('Trier par'), 'name')
|
||||
expect(rowNames(list)).toEqual([DONKEY, HORSE, DOG])
|
||||
})
|
||||
|
||||
it('tells the three empty states apart; the search text is shown as typed', async () => {
|
||||
const user = userEvent.setup()
|
||||
fake.rpcResults.list_official_sheets_admin = { data: [] }
|
||||
const view = mount('/app/admin/sheets', [grant('sheet_editor')])
|
||||
expect(
|
||||
await screen.findByText('Aucune fiche officielle pour le moment.'),
|
||||
).toBeInTheDocument()
|
||||
expect(screen.queryByText(/^0 fiche/)).toBeNull()
|
||||
view.unmount()
|
||||
|
||||
await mountThree()
|
||||
await user.type(searchField(), ' mulet ')
|
||||
expect(screen.getByText('0 fiche sur 3')).toBeInTheDocument()
|
||||
expect(
|
||||
screen.getByText('Aucune fiche ne contient « mulet » dans son nom.'),
|
||||
).toBeInTheDocument()
|
||||
const clears = screen.getAllByRole('button', {
|
||||
name: 'Effacer la recherche',
|
||||
})
|
||||
expect(clears).toHaveLength(2)
|
||||
await user.click(clears[1])
|
||||
expect(searchField()).toHaveValue('')
|
||||
expect(searchField()).toHaveFocus()
|
||||
expect(screen.getByText('3 fiches')).toBeInTheDocument()
|
||||
|
||||
await user.type(searchField(), '$&')
|
||||
expect(
|
||||
screen.getByText('Aucune fiche ne contient « $& » dans son nom.'),
|
||||
).toBeInTheDocument()
|
||||
|
||||
await user.selectOptions(
|
||||
screen.getByLabelText('Statut de version'),
|
||||
'published',
|
||||
)
|
||||
expect(
|
||||
screen.getByText('Aucune fiche ne correspond à ces filtres.'),
|
||||
).toBeInTheDocument()
|
||||
expect(screen.queryByText(/Aucune fiche ne contient/)).toBeNull()
|
||||
})
|
||||
|
||||
it('reads in English: count, date and sort label', async () => {
|
||||
useLocaleStore.setState({ locale: 'en' })
|
||||
const user = userEvent.setup()
|
||||
fake.rpcResults.list_official_sheets_admin = { data: threeSheets() }
|
||||
mount('/app/admin/sheets', [grant('sheet_editor')])
|
||||
const list = within(
|
||||
await screen.findByRole('list', { name: 'Official sheet list' }),
|
||||
)
|
||||
expect(list.getByText('Modified on 9 Nov 2026, 12:06')).toBeInTheDocument()
|
||||
expect(screen.getByLabelText('Sort by')).toBeInTheDocument()
|
||||
await user.type(
|
||||
screen.getByRole('searchbox', { name: 'Search a sheet by name' }),
|
||||
'horse',
|
||||
)
|
||||
expect(screen.getByText('1 sheet of 3')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Sheet creation (A1)', () => {
|
||||
|
||||
Reference in new issue
Block a user