feat: Enhance group selection logic to exclude duplicates for main schedules and past documents

This commit is contained in:
2026-10-19 19:53:03 +03:00
parent 5f7bffd6e4
commit db9a3f8243
3 changed files with 56 additions and 6 deletions

View File

@@ -166,3 +166,32 @@ test("Поиск группы: любое написание, без учёта
assert.equal(findGroups(idx, {}).results.length, 0);
assert.equal(findGroups(idx, {}).total, 4);
});
test("Выбор группы: зачёты не дублируют группу с основным расписанием", async () => {
const { findGroups } = await import("../server/directory.js");
const credits = parseDocx(fixture("isf-credits-26-arh"), { name: "26-АРХ.docx" });
const main = { ...credits, period: "Осенний семестр" };
const doc = (id, schedule) => ({ id, file: { id, name: "26-АРХ.docx", faculty: "ИСФ", course: "1 курс" }, schedule });
// With a semester timetable the credits stay in the session countdown, not in the picker.
const both = findGroups({ docs: [doc("main", main), doc("credits", credits)] }, { q: "26-АРХ" });
assert.deepEqual(both.results.map((r) => [r.group, r.fileId]), [["26-АРХ", "main"]]);
assert.equal(both.total, 1);
// A group with only a credit schedule can still open it.
const only = findGroups({ docs: [doc("credits", credits)] }, { q: "26-АРХ" });
assert.deepEqual(only.results.map((r) => [r.group, r.fileId, r.period]), [["26-АРХ", "credits", "Зачёты"]]);
});
test("Выбор группы: прошедший документ с датами не дублирует основное расписание", async () => {
const { findGroups } = await import("../server/directory.js");
// A document dated 8–27 June 2026, like an orientation week, beside the group's semester timetable.
const dated = parseDocx(fixture("itzs-summer-2026"), { name: "23-ИТзс.docx" });
const main = { ...dated, period: "Осенний семестр", lessons: dated.lessons.map(({ date, ...l }) => l) };
const doc = (id, schedule) => ({ id, file: { id, name: `${id}.docx` }, schedule });
const idx = { docs: [doc("main", main), doc("dated", dated)] };
const ids = (today) => findGroups(idx, { q: "23-ИТзс", today }).results.map((r) => r.fileId);
assert.deepEqual(ids("2026-10-19"), ["main"]);
// Before it is over, both are offered.
assert.deepEqual(ids("2026-06-20").sort(), ["dated", "main"]);
// Alone, even a finished one stays: it is all the group has.
assert.deepEqual(findGroups({ docs: [doc("dated", dated)] }, { q: "23-ИТзс", today: "2026-10-19" }).results.length, 1);
});