aboutsummaryrefslogtreecommitdiff
path: root/src/i18n/coverage.test.ts
blob: f12178d2fa08e1e7684a88a1c3a926b6d0c73599 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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');
  });
});