Files
psu-schedule/test/timetable.test.js
Zakhar Timoshenko d900e038b6 feat: add Next Lesson widget and enhance existing widgets
- Implemented a new Next Lesson widget to display the upcoming lesson details on the home screen.
- Updated Today widget to dynamically adjust the number of lessons displayed based on available space.
- Enhanced the Settings screen to allow users to manage hidden lessons more effectively.
- Introduced harmonized color palettes for better visual consistency across themes.
- Updated the timetable API to support a new range parameter for semester-based queries.
- Added tests to ensure the new semester range functionality works as expected.
- Refactored widget styling for improved appearance on devices with different Android versions.
2026-10-18 00:39:32 +03:00

61 lines
3.0 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 test from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { parseDocx } from "../server/parser.js";
import { parseWeeksDocx, parseBellsDocx } from "../server/calendar.js";
import { mergeWeekTables } from "../server/source.js";
import { timetable } from "../server/timetable.js";
const fixture = (name) =>
readFileSync(new URL(`./fixtures/${name}.docx`, import.meta.url));
const calendar = {
...mergeWeekTables([parseWeeksDocx(fixture("weeks"))]),
bells: parseBellsDocx(fixture("bells")),
source: {},
};
const schedule = parseDocx(fixture("fef-23-ba"), { name: "23-ЛГ_23-БА.docx" });
const file = { id: "fef", name: "23-ЛГ_23-БА.docx", faculty: "ФЭФ", course: "4 курс" };
test("Расписание группы по датам: недели, пары, подгруппы, пустые выходные", () => {
const t = timetable({ file, schedule, calendar, group: "23-БА", from: "2026-10-16", days: 3 });
assert.equal(t.semester.label, "Осенний семестр 2026/27");
assert.deepEqual(t.days.map((d) => [d.date, d.weekday, d.week.n, d.week.color]), [
["2026-10-16", 5, 7, "white"],
["2026-10-17", 6, 7, "white"],
["2026-10-18", 7, 7, "white"],
]);
// Friday of week 7: "12-15н." and "16н." lessons are not on this date.
assert.deepEqual(
t.days[0].lessons.map((l) => [l.start, l.pair, l.subject]),
[
["08:30", 1, "Инновационный менеджмент"],
["10:05", 2, "PR-менеджмент"],
["11:45", 3, "Бизнес-анализ"],
],
);
assert.equal(t.days[1].lessons.length, 0);
assert.ok(t.weekly.length >= 5, "строки Word по дням недели доступны всегда");
const lg = timetable({ file, schedule, calendar, group: "23-ЛГ", from: "2026-10-12", days: 7 });
assert.deepEqual(lg.subgroups, ["Подгруппа 1", "Подгруппа 2"]);
assert.ok(lg.days.flatMap((d) => d.lessons).some((l) => l.subgroup === "Подгруппа 2"));
});
test("Без семестра в таблице недель даты не угадываются", () => {
const spring = { ...schedule, period: "Весенний семестр" };
const t = timetable({ file, schedule: spring, calendar, group: "23-БА", from: "2027-03-01", days: 7 });
assert.equal(t.semester, null);
assert.ok(t.note);
assert.ok(t.days.every((d) => d.lessons.length === 0 && d.week === null));
assert.throws(
() => timetable({ file, schedule, calendar, group: "99-ХХ", from: "2026-10-16", days: 1 }),
/нет группы/,
);
});
test("range=semester: все дни текущего семестра от первого до последнего", () => {
const t = timetable({ file, schedule, calendar, group: "23-БА", from: "2026-10-16", range: "semester", today: "2026-10-16" });
assert.equal(t.days[0].date, t.semester.start);
assert.equal(t.days.at(-1).date, t.semester.end);
assert.ok(t.days.length > 62, "больше обычного предела в 62 дня");
});