feat(app): collapsible sheet filters on phone, one empty announcement

This commit is contained in:
bchanot committed 2026-11-16 20:30:27 +01:00
1 parent 5014a45053
commit 9efc7b7647
4 files changed
+220 -5

No files matched your search

+107
View File
@@ -920,6 +920,113 @@ describe('Official sheets list (H1)', () => {
)
expect(screen.getByText('1 sheet of 3')).toBeInTheDocument()
})
it('announces an empty filtered result once: the count line, not a status', async () => {
const user = userEvent.setup()
await mountThree()
await user.selectOptions(
screen.getByLabelText('Statut de version'),
'published',
)
const note = screen.getByText('Aucune fiche ne correspond à ces filtres.')
expect(note.closest('[role="status"]')).toBeNull()
expect(screen.getByText('0 fiche sur 3')).toHaveAttribute(
'aria-live',
'polite',
)
})
describe('collapsible filters on a phone', () => {
const toggle = (name: RegExp | string = /^Filtres/) =>
screen.getByRole('button', { name })
const panel = () => document.getElementById('admin-sheets-filters')!
const reset = () =>
screen.queryByRole('button', { name: 'Réinitialiser les filtres' })
it('is closed by default: aria-expanded false, controls the panel, hidden on a phone only', async () => {
await mountThree()
expect(toggle()).toHaveTextContent('Filtres')
expect(toggle()).toHaveAttribute('aria-expanded', 'false')
expect(toggle()).toHaveAttribute('aria-controls', 'admin-sheets-filters')
expect(toggle()).toHaveClass('sm:hidden')
expect(panel()).toHaveAttribute('data-open', 'false')
expect(panel().className).toContain('max-sm:invisible')
expect(panel().className).toContain('motion-reduce:transition-none')
expect(panel().className).not.toMatch(/(^|\s)invisible/)
})
it('opens and closes on the button, with the four filters inside', async () => {
const user = userEvent.setup()
await mountThree()
await user.click(toggle())
expect(toggle()).toHaveAttribute('aria-expanded', 'true')
expect(panel()).toHaveAttribute('data-open', 'true')
expect(panel().className).not.toContain('max-sm:invisible')
for (const label of [
'Espèce',
'État de la fiche',
'Statut de version',
'État de la dernière revue',
])
expect(within(panel()).getByLabelText(label)).toBeInTheDocument()
await user.click(toggle())
expect(toggle()).toHaveAttribute('aria-expanded', 'false')
expect(panel().className).toContain('max-sm:invisible')
})
it('counts the active filters on the button; closing keeps them', async () => {
const user = userEvent.setup()
const list = await mountThree()
await user.click(toggle())
await user.selectOptions(screen.getByLabelText('Espèce'), 'equine')
await user.selectOptions(
screen.getByLabelText('État de la fiche'),
'active',
)
expect(toggle()).toHaveTextContent('Filtres (2)')
await user.click(toggle(/^Filtres \(2\)/))
expect(toggle()).toHaveTextContent('Filtres (2)')
await user.click(toggle())
expect(screen.getByLabelText('Espèce')).toHaveValue('equine')
expect(screen.getByLabelText('État de la fiche')).toHaveValue('active')
expect(list.getAllByRole('link').length).toBeGreaterThan(0)
})
it('resets every filter, keeps the search, and hands the focus to the button', async () => {
const user = userEvent.setup()
await mountThree()
expect(reset()).toBeNull()
await user.click(toggle())
await user.type(searchField(), 'chev')
await user.selectOptions(
screen.getByLabelText('Statut de version'),
'published',
)
expect(toggle()).toHaveTextContent('Filtres (1)')
await user.click(reset()!)
expect(screen.getByLabelText('Statut de version')).toHaveValue('')
expect(toggle()).toHaveTextContent(/^Filtres$/)
expect(searchField()).toHaveValue('chev')
expect(reset()).toBeNull()
expect(toggle()).toHaveFocus()
})
it('reads in English', async () => {
useLocaleStore.setState({ locale: 'en' })
const user = userEvent.setup()
fake.rpcResults.list_official_sheets_admin = { data: threeSheets() }
mount('/app/admin/sheets', [grant('sheet_editor')])
await screen.findByRole('list', { name: 'Official sheet list' })
await user.click(screen.getByRole('button', { name: 'Filters' }))
await user.selectOptions(screen.getByLabelText('Version status'), 'draft')
expect(
screen.getByRole('button', { name: 'Filters (1)' }),
).toBeInTheDocument()
expect(
screen.getByRole('button', { name: 'Reset filters' }),
).toBeInTheDocument()
})
})
})
describe('Sheet creation (A1)', () => {