/** The LAN spec's revision reading, run on the strings the save line really shows. */ import { describe, expect, it } from 'vitest' import { fr } from '@/i18n/fr' import { shownRevision } from '../../e2e/support/saveLineText' const line = (key: keyof typeof fr, values: Record = {}) => Object.entries(values).reduce( (text, [name, value]) => text.replace(`{${name}}`, value), fr[key], ) describe('shownRevision', () => { it('reads the revision of the « Révision n » line', () => { expect( shownRevision(line('editor.draft.status.revision', { revision: '7' })), ).toBe(7) }) it('reads it from both saved forms', () => { const saved = line('editor.draft.status.saved', { revision: '8' }) const savedAt = line('editor.draft.status.saved_at', { revision: '12', time: '14:02', }) expect([shownRevision(saved), shownRevision(savedAt)]).toEqual([8, 12]) }) it('throws on the forms that carry none, never answers NaN', () => { const texts = [ fr['editor.draft.status.unsaved'], line('editor.draft.status.unsaved_count_one', { count: '1' }), fr['editor.draft.status.saving'], '', ] for (const text of texts) { expect(() => shownRevision(text)).toThrow('shows no revision') } }) })