62 lines
1.6 KiB
TypeScript
62 lines
1.6 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { fr } from '@/i18n/fr'
|
|
import { en } from '@/i18n/en'
|
|
import { pickLocaleLabel } from '@/i18n/pickLocaleLabel'
|
|
|
|
const REQUIRED = [
|
|
'severity.mild',
|
|
'severity.moderate',
|
|
'severity.severe',
|
|
'severity.aria',
|
|
'home.import.error_invalid_pdf',
|
|
'home.import.error_no_attachment',
|
|
'home.import.error_generic',
|
|
'pdf.section.zones',
|
|
'pdf.section.findings_prefix',
|
|
'pdf.section.free_findings',
|
|
'pdf.section.severity',
|
|
'pdf.section.comment',
|
|
'pdf.view.general',
|
|
'pdf.view.detail_prefix',
|
|
'pdf.empty',
|
|
'sheet.status.draft',
|
|
'sheet.loading',
|
|
'vertebra.range_note',
|
|
]
|
|
|
|
const PLACEHOLDERS: Record<string, string> = {
|
|
'home.import.error_incompatible_version': '{version}',
|
|
'home.import.migrated': '{count}',
|
|
'vertebra.extend_to': '{max}',
|
|
}
|
|
|
|
describe.each([
|
|
['fr', fr],
|
|
['en', en],
|
|
])('i18n keys (%s)', (_name, dict) => {
|
|
it.each(REQUIRED)('has %s', (key) => {
|
|
expect(dict[key]).toBeTruthy()
|
|
})
|
|
|
|
it.each(Object.entries(PLACEHOLDERS))('%s carries %s', (key, ph) => {
|
|
expect(dict[key]).toContain(ph)
|
|
})
|
|
})
|
|
|
|
describe('pickLocaleLabel', () => {
|
|
it('returns the active locale label', () => {
|
|
expect(pickLocaleLabel('f', 'e', 'fr')).toBe('f')
|
|
expect(pickLocaleLabel('f', 'e', 'en')).toBe('e')
|
|
})
|
|
|
|
it('falls back to the other language when empty', () => {
|
|
expect(pickLocaleLabel('', 'e', 'fr')).toBe('e')
|
|
expect(pickLocaleLabel('f', '', 'en')).toBe('f')
|
|
})
|
|
|
|
it('returns the fallback when both are empty', () => {
|
|
expect(pickLocaleLabel('', '', 'fr', 'x')).toBe('x')
|
|
expect(pickLocaleLabel(undefined, undefined, 'en', 'x')).toBe('x')
|
|
})
|
|
})
|