feat(app): Administration home lists the latest modified sheets

Board 29 B: five latest sheets with badges, detail line and date; footer
link shows the total from two sheets. R-24: no existing assertion removed
or rewritten; seven cases added.
This commit is contained in:
bchanot committed 2026-11-16 17:17:27 +01:00
1 parent 856667d070
commit de2424f519
4 files changed
+210 -22

No files matched your search

+125
View File
@@ -310,6 +310,131 @@ describe('Administration page (board 10)', () => {
})
})
/** Seven sheets named « Fiche n », modified on n Nov 2026 (Paris 11:00), unsorted. */
function sevenSheets() {
return [3, 7, 1, 5, 2, 6, 4].map((n) =>
summary({
sheet_id: `00000000-0000-4000-8000-00000000000${n}`,
slug: `fiche-${n}`,
name: { fr: `Fiche ${n}`, en: `Sheet ${n}` },
last_modified_at: `2026-11-0${n}T10:00:00.000000+00:00`,
}),
)
}
describe('Administration home card: latest modified sheets (board 29 B)', () => {
const cardItems = async () =>
within(await screen.findByRole('list')).getAllByRole('listitem')
const historicalAt = (day: string) => ({
...historical(),
last_modified_at: `2026-${day}T10:00:00.000000+00:00`,
})
const COPY = { name: 'Créer une copie de travail' }
it('seven sheets: five items, newest first, then « Voir les 7 fiches »', async () => {
fake.rpcResults.list_official_sheets_admin = { data: sevenSheets() }
mount('/app/admin', [grant('sheet_editor')])
const items = await cardItems()
expect(items).toHaveLength(5)
expect(
items.map((li) => within(li).getAllByRole('link')[0].textContent),
).toEqual(['Fiche 7', 'Fiche 6', 'Fiche 5', 'Fiche 4', 'Fiche 3'])
expect(
screen.getByRole('heading', { name: 'Dernières modifications' }),
).toBeInTheDocument()
expect(
screen.getByRole('link', { name: 'Voir les 7 fiches' }),
).toHaveAttribute('href', '/app/admin/sheets')
expect(screen.queryByText('Toutes les fiches officielles')).toBeNull()
})
it('one sheet: the sub-heading, the item and « Toutes les fiches officielles »', async () => {
fake.rpcResults.list_official_sheets_admin = { data: [summary()] }
mount('/app/admin', [grant('sheet_editor')])
expect(await cardItems()).toHaveLength(1)
expect(
screen.getByRole('heading', { name: 'Dernières modifications' }),
).toBeInTheDocument()
expect(
screen.getByRole('link', { name: 'Toutes les fiches officielles' }),
).toHaveAttribute('href', '/app/admin/sheets')
})
it('no sheet: the empty sentence, no sub-heading, the same link', async () => {
fake.rpcResults.list_official_sheets_admin = { data: [] }
mount('/app/admin', [grant('sheet_editor')])
expect(await screen.findByText(fr['admin.sheets.empty'])).toBeInTheDocument()
expect(
screen.queryByRole('heading', { name: 'Dernières modifications' }),
).toBeNull()
expect(screen.queryByRole('list')).toBeNull()
expect(
screen.getByRole('link', { name: 'Toutes les fiches officielles' }),
).toBeInTheDocument()
})
it('the historical sheet keeps its action inside the five, for an editor only', async () => {
// Newest of all: inside the five.
fake.rpcResults.list_official_sheets_admin = {
data: [historicalAt('11-09'), ...sevenSheets()],
}
mount('/app/admin', [grant('sheet_editor')])
await cardItems()
expect(screen.getByRole('button', COPY)).toBeInTheDocument()
cleanup()
// Inside the five, but the account is a reviewer.
mount('/app/admin', [grant('sheet_reviewer')])
await cardItems()
expect(screen.queryByRole('button', COPY)).toBeNull()
cleanup()
// Oldest of all: outside the five.
fake.rpcResults.list_official_sheets_admin = {
data: [historicalAt('10-01'), ...sevenSheets()],
}
mount('/app/admin', [grant('sheet_editor')])
await cardItems()
expect(screen.queryByRole('link', { name: 'Cheval' })).toBeNull()
expect(screen.queryByRole('button', COPY)).toBeNull()
})
it('the detail line and the date are those of the list', async () => {
mount('/app/admin', [grant('sheet_editor')])
const [item] = await cardItems()
const detail = within(item).getByText(/^Cheval · /).textContent ?? ''
const date = within(item).getByText(/^Modifiée le /).textContent ?? ''
expect(date).toBe('Modifiée le 1 nov. 2026, 11:00')
cleanup()
mount('/app/admin/sheets', [grant('sheet_editor')])
const row = (await screen.findAllByRole('listitem'))[0]
expect(within(row).getByText(detail)).toBeInTheDocument()
expect(within(row).getByText(date)).toBeInTheDocument()
})
it('a refused species read: the card still shows, the id in the detail line', async () => {
fake.rpcResults.list_catalog_species = refusal('rights.capability')
mount('/app/admin', [grant('sheet_editor')])
const [item] = await cardItems()
expect(within(item).getByText(/^equine · /)).toBeInTheDocument()
expect(screen.queryByRole('alert')).toBeNull()
})
it('English texts', async () => {
useLocaleStore.setState({ locale: 'en' })
fake.rpcResults.list_official_sheets_admin = { data: sevenSheets() }
mount('/app/admin', [grant('sheet_editor')])
await cardItems()
expect(
screen.getByRole('heading', { name: 'Latest changes' }),
).toBeInTheDocument()
expect(
screen.getByRole('link', { name: 'See the 7 sheets' }),
).toBeInTheDocument()
expect(
screen.getByText('Modified on 7 Nov 2026, 11:00'),
).toBeInTheDocument()
})
})
describe('Species (S1, matrix §5.4)', () => {
const rows = () => within(screen.getByRole('list', { name: 'Espèces' }))