Files
magistr/frontend/tests/schedule-view-semesters.test.mjs

65 lines
2.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import assert from 'node:assert/strict';
import test from 'node:test';
import {
findDefaultSemester,
findSemesterForDate,
formatLessonWeeksText,
scheduleRangeForSemester,
semesterOptionLabel
} from '../admin/js/views/schedule-view.js';
const autumnSemester = {
id: 11,
academicYearTitle: '2025/2026',
semesterType: 'autumn',
startDate: '2025-09-01',
endDate: '2026-01-31'
};
const springSemester = {
id: 12,
academicYearTitle: '2025/2026',
semesterType: 'spring',
startDate: '2026-02-09',
endDate: '2026-06-30'
};
test('семестр определяется по выбранной дате включительно с границами', () => {
const semesters = [autumnSemester, springSemester];
assert.equal(findSemesterForDate(semesters, '2025-09-01')?.id, 11);
assert.equal(findSemesterForDate(semesters, '2026-06-30')?.id, 12);
assert.equal(findSemesterForDate(semesters, '2026-07-01'), null);
});
test('вне учебного периода по умолчанию выбирается последний доступный семестр', () => {
assert.equal(findDefaultSemester([springSemester, autumnSemester], '2026-08-14')?.id, 12);
});
test('при выборе семестра диапазон охватывает его целиком', () => {
assert.deepEqual(scheduleRangeForSemester('2026-07-21', autumnSemester), {
startDate: '2025-09-01',
endDate: '2026-01-31'
});
});
test('дата внутри выбранного семестра не сужает его до двух недель', () => {
assert.deepEqual(scheduleRangeForSemester('2026-03-18', springSemester), {
startDate: '2026-02-09',
endDate: '2026-06-30'
});
});
test('диапазон недель занятия всегда показывается явно', () => {
assert.equal(formatLessonWeeksText(1, 18), '(с 1 по 18 нед.)');
assert.equal(formatLessonWeeksText(7, 7), '(7 нед.)');
});
test('название семестра содержит учебный год, тип и границы', () => {
assert.equal(
semesterOptionLabel(springSemester),
'2025/2026 · Весенний семестр · 09.02.2026 — 30.06.2026'
);
});