diff options
| author | LalleSX | 2026-10-24 14:58:21 +0200 |
|---|---|---|
| committer | LalleSX | 2026-10-24 14:58:21 +0200 |
| commit | 73b09270c54acab810c10a80bed1d77c1a7bb2ab (patch) | |
| tree | e5bae1180c9a76345cc7779a24988875542d2dd9 /src/i18n/coverage.test.ts | |
| parent | Add tests for math rendering and interactive scenes; update navigation and viewport handling (diff) | |
| download | 3D-Electrophysics-73b09270c54acab810c10a80bed1d77c1a7bb2ab.tar.gz 3D-Electrophysics-73b09270c54acab810c10a80bed1d77c1a7bb2ab.zip | |
Diffstat (limited to 'src/i18n/coverage.test.ts')
| -rw-r--r-- | src/i18n/coverage.test.ts | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/i18n/coverage.test.ts b/src/i18n/coverage.test.ts new file mode 100644 index 0000000..f12178d --- /dev/null +++ b/src/i18n/coverage.test.ts @@ -0,0 +1,61 @@ +import { describe, expect, it, afterEach } from 'vitest'; +import { defaults, experiments, type Experiment } from '../experiments'; +import { daMeasurementLabels, daWords, setLanguage } from '../i18n'; +import { testLessons, type TestLesson } from '../test4'; +import { danishLessons } from './da'; +import { presentLesson } from './present'; + +const lessons: Experiment[] = [...testLessons, ...experiments]; + +afterEach(() => setLanguage('en')); + +describe('Danish catalog', () => { + it('translates every lesson, control and answer while keeping the mathematics', () => { + setLanguage('da'); + for (const lesson of lessons) { + const copy = danishLessons[lesson.id]; + const view = presentLesson(lesson); + expect(view.title).toBe(copy.title); + expect(view.title).not.toBe(lesson.title); + expect(view.shortTitle).toBe(copy.shortTitle); + expect(view.legend.map(([, text]) => text)).toEqual(copy.legend); + expect(view.controls.map(control => control.id)).toEqual(lesson.controls.map(control => control.id)); + for (const control of view.controls) { + const source = lesson.controls.find(item => item.id === control.id)!; + expect(control.label).toBe(copy.controls[control.id].label); + expect(control.label).not.toBe(source.label); + if (control.kind === 'select' && source.kind === 'select') { + expect(control.options.map(option => option.value)).toEqual(source.options.map(option => option.value)); + expect(control.options.map(option => option.label)).toEqual(source.options.map(option => copy.controls[control.id].options?.[option.value])); + } + } + if (!('questions' in lesson) || !('questions' in view)) continue; + const source = lesson as TestLesson; + const translated = view as TestLesson; + expect(translated.questions).toHaveLength(source.questions.length); + expect(translated.answers).toHaveLength(source.answers.length); + translated.answers.forEach((part, index) => { + expect(part.steps).toHaveLength(source.answers[index].steps.length); + part.steps.forEach((step, stepIndex) => { + expect(step.math).toBe(source.answers[index].steps[stepIndex].math); + expect(step.why).not.toBe(source.answers[index].steps[stepIndex].why); + }); + }); + expect(translated.observe(defaults(lesson))).not.toBe(source.observe(defaults(lesson))); + } + }); + + it('has a Danish label for every live measurement and status word', () => { + const labels = lessons.flatMap(lesson => lesson.measure(defaults(lesson)).map(measurement => measurement.label)); + for (const label of labels) expect(daMeasurementLabels[label], label).toBeTruthy(); + for (const status of ['Repulsive', 'Attractive', 'Inside', 'Outside', 'On surface', 'Undefined', 'pairs']) { + expect(daWords[status], status).toBeTruthy(); + } + setLanguage('da'); + const field = presentLesson(experiments[0]); + expect(field.measure({ ...defaults(field), configuration: 'like' }).map(measurement => measurement.value)).toContain('Frastødende'); + expect(presentLesson(lessons[0]).title).toBe('Arbejde langs en bane'); + setLanguage('en'); + expect(presentLesson(lessons[0]).title).toBe('Work along a path'); + }); +}); |