feat(app): search, sort and date format of the admin sheet list
This commit is contained in:
1 parent
d5852f5f8e
commit
f3b58abe70
5 files changed
+121
-5
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { failureMessage } from '@/admin/labels'
|
||||
import { failureMessage, formatShortParisDateTime } from '@/admin/labels'
|
||||
import { en } from '@/i18n/en'
|
||||
import { fr } from '@/i18n/fr'
|
||||
|
||||
@@ -16,3 +16,13 @@ describe('failure messages of the submission', () => {
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
describe('formatShortParisDateTime (A8)', () => {
|
||||
it('reads « 9 nov. 2026, 12:06 » in French and « 9 Nov 2026, 12:06 » in English, in Paris time', () => {
|
||||
expect(formatShortParisDateTime('2026-11-09T11:06:00.123456+00:00', 'fr')).toBe('9 nov. 2026, 12:06')
|
||||
expect(formatShortParisDateTime('2026-11-09T11:06:00.123456+00:00', 'en')).toBe('9 Nov 2026, 12:06')
|
||||
})
|
||||
it('follows the Paris summer offset', () => {
|
||||
expect(formatShortParisDateTime('2026-07-01T22:30:00+00:00', 'fr')).toBe('2 juil. 2026, 00:30')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,44 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { OfficialSheetAdminSummary } from '@faunosteo/supabase'
|
||||
import { searchSheets, sortSheets } from '@/admin/sheetList'
|
||||
|
||||
const sheet = (id: string, fr: string, en: string, at: string) =>
|
||||
({ sheet_id: id, name: { fr, en }, last_modified_at: at }) as OfficialSheetAdminSummary
|
||||
const A = sheet('a', 'Âne, squelette', 'Donkey, skeleton', '2026-11-03T10:02:00+00:00')
|
||||
const C = sheet('c', 'Cheval (tête)', 'Horse (head)', '2026-11-09T11:06:00.123456+00:00')
|
||||
const E = sheet('e', 'Émeu', 'Emu', '2026-11-05T15:20:00+00:00')
|
||||
const Z = sheet('z', 'Zèbre', 'Zebra', '2026-11-05T15:20:00+00:00')
|
||||
const ids = (list: OfficialSheetAdminSummary[]) => list.map((s) => s.sheet_id).join('')
|
||||
|
||||
describe('searchSheets', () => {
|
||||
it('matches the French or the English name, accents and case ignored', () => {
|
||||
expect(ids(searchSheets([A, C, E, Z], 'ane'))).toBe('a')
|
||||
expect(ids(searchSheets([A, C, E, Z], 'HORSE'))).toBe('c')
|
||||
expect(ids(searchSheets([A, C, E, Z], 'émeu'))).toBe('e')
|
||||
})
|
||||
it('ignores surrounding spaces; an empty search keeps every sheet; brackets are plain text', () => {
|
||||
expect(ids(searchSheets([A, C], ' cheval '))).toBe('c')
|
||||
expect(ids(searchSheets([A, C], ' '))).toBe('ac')
|
||||
expect(ids(searchSheets([A, C], '(tête)'))).toBe('c')
|
||||
})
|
||||
})
|
||||
|
||||
describe('sortSheets', () => {
|
||||
it('modified: newest first, equal dates by name', () => {
|
||||
expect(ids(sortSheets([A, Z, E, C], 'modified', 'fr'))).toBe('ceza')
|
||||
})
|
||||
it('name: the collation of the interface language, not code points', () => {
|
||||
expect(ids(sortSheets([Z, E, C, A], 'name', 'fr'))).toBe('acez')
|
||||
expect(ids(sortSheets([Z, E, C, A], 'name', 'en'))).toBe('aecz')
|
||||
})
|
||||
it('equal names fall back to the id, whatever the input order', () => {
|
||||
const twin = { ...A, sheet_id: 'b' }
|
||||
expect(ids(sortSheets([twin, A], 'name', 'fr'))).toBe('ab')
|
||||
expect(ids(sortSheets([A, twin], 'modified', 'fr'))).toBe('ab')
|
||||
})
|
||||
it('returns a new array and leaves its input alone', () => {
|
||||
const input = [Z, A]
|
||||
expect(sortSheets(input, 'name', 'fr')).not.toBe(input)
|
||||
expect(ids(input)).toBe('za')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user