test: replacement coverage for the deleted legacy suites (v3 schema rejections, appointment kinds, i18n keys and placeholders, pickLocaleLabel, region mapping, new report route); importer comment
This commit is contained in:
1 parent
09d8b01a54
commit
06a2e86f3c
5 files changed
+242
-1
No files matched your search
@@ -0,0 +1,61 @@
|
||||
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')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,40 @@
|
||||
/** The new-report form on the bundled sheet: species select, submit gate. */
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
||||
import { cleanup, render, screen, waitFor } from '@testing-library/react'
|
||||
import { MemoryRouter } from 'react-router-dom'
|
||||
import NewReportRoute from '@/app/routes/NewReportRoute'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { fr } from '@/i18n/fr'
|
||||
|
||||
beforeEach(() => {
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
localStorage.clear()
|
||||
})
|
||||
afterEach(cleanup)
|
||||
|
||||
function mount() {
|
||||
return render(
|
||||
<MemoryRouter initialEntries={['/new']}>
|
||||
<NewReportRoute />
|
||||
</MemoryRouter>,
|
||||
)
|
||||
}
|
||||
|
||||
describe('NewReportRoute', () => {
|
||||
it('selects equine and names it once the sheet is loaded', async () => {
|
||||
mount()
|
||||
const select = screen.getByLabelText(
|
||||
fr['form.animal.species'],
|
||||
) as HTMLSelectElement
|
||||
await waitFor(() => {
|
||||
expect(select.value).toBe('equine')
|
||||
expect(select.selectedOptions[0]?.textContent).toBe('Cheval')
|
||||
})
|
||||
})
|
||||
|
||||
it('disables submit while the names are empty', async () => {
|
||||
mount()
|
||||
const button = screen.getByRole('button', { name: fr['new_report.submit'] })
|
||||
await waitFor(() => expect(button).toBeDisabled())
|
||||
})
|
||||
})
|
||||
@@ -77,6 +77,27 @@ describe('sheet index', () => {
|
||||
expect(sheet.isSpine('head-trigger')).toBe(false)
|
||||
})
|
||||
|
||||
it('maps spine annotations to their region codes on the main view', () => {
|
||||
const codes = ['C', 'T', 'L', 'S', 'Cd']
|
||||
for (const code of codes) {
|
||||
const a = sheet.spineAnnotation(code, 'main')
|
||||
expect(a, code).toBeDefined()
|
||||
expect(a!.vertebral_region_code).toBe(code)
|
||||
expect(sheet.isSpine(a!.id)).toBe(true)
|
||||
}
|
||||
const spineIds = sheet.sheet.document.annotations
|
||||
.filter((a) => sheet.isSpine(a.id))
|
||||
.map((a) => a.id)
|
||||
expect(spineIds).toHaveLength(5)
|
||||
const carried = sheet.sheet.document.annotations
|
||||
.filter(isObservable)
|
||||
.map((a) => a.vertebral_region_code)
|
||||
.filter((c) => c !== null)
|
||||
expect(sheet.regions().map((r) => r.code).sort()).toEqual(
|
||||
[...carried].sort(),
|
||||
)
|
||||
})
|
||||
|
||||
it('resolves finding paths and reports absent ones', () => {
|
||||
expect(
|
||||
sheet.nodeAt('hip', [
|
||||
|
||||
Reference in new issue
Block a user