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'); }); });