354 lines
6.1 KiB
TypeScript
354 lines
6.1 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import fs from "fs";
|
|
import parseAbsence from "../scrape/utils/parseAbsence.js";
|
|
|
|
const teachermap: Record<string, string> = JSON.parse(
|
|
fs.readFileSync("./tests/content/teachermap.json", "utf8"),
|
|
);
|
|
|
|
const cases: [string, any[]][] = [
|
|
[
|
|
"Me",
|
|
[
|
|
{
|
|
teacher: "Michaela Meitnerová",
|
|
teacherCode: "me",
|
|
type: "wholeDay",
|
|
hours: null,
|
|
},
|
|
],
|
|
],
|
|
[
|
|
"ad",
|
|
[
|
|
{
|
|
teacher: "Bc. Daniel Adámek",
|
|
teacherCode: "ad",
|
|
type: "wholeDay",
|
|
hours: null,
|
|
},
|
|
],
|
|
],
|
|
[
|
|
"me ad",
|
|
[
|
|
{
|
|
teacher: "Michaela Meitnerová",
|
|
teacherCode: "me",
|
|
type: "wholeDay",
|
|
hours: null,
|
|
},
|
|
{
|
|
teacher: "Bc. Daniel Adámek",
|
|
teacherCode: "ad",
|
|
type: "wholeDay",
|
|
hours: null,
|
|
},
|
|
],
|
|
],
|
|
[
|
|
"me 3",
|
|
[
|
|
{
|
|
teacher: "Michaela Meitnerová",
|
|
teacherCode: "me",
|
|
type: "single",
|
|
hours: 3,
|
|
},
|
|
],
|
|
],
|
|
[
|
|
"ad 1",
|
|
[
|
|
{
|
|
teacher: "Bc. Daniel Adámek",
|
|
teacherCode: "ad",
|
|
type: "single",
|
|
hours: 1,
|
|
},
|
|
],
|
|
],
|
|
[
|
|
"me 2-4",
|
|
[
|
|
{
|
|
teacher: "Michaela Meitnerová",
|
|
teacherCode: "me",
|
|
type: "range",
|
|
hours: { from: 2, to: 4 },
|
|
},
|
|
],
|
|
],
|
|
[
|
|
"ad 5,6",
|
|
[
|
|
{
|
|
teacher: "Bc. Daniel Adámek",
|
|
teacherCode: "ad",
|
|
type: "range",
|
|
hours: { from: 5, to: 6 },
|
|
},
|
|
],
|
|
],
|
|
[
|
|
"me 7+",
|
|
[
|
|
{
|
|
teacher: "Michaela Meitnerová",
|
|
teacherCode: "me",
|
|
type: "range",
|
|
hours: { from: 7, to: 10 },
|
|
},
|
|
],
|
|
],
|
|
[
|
|
"me,ad 3-5",
|
|
[
|
|
{
|
|
teacher: "Michaela Meitnerová",
|
|
teacherCode: "me",
|
|
type: "range",
|
|
hours: { from: 3, to: 5 },
|
|
},
|
|
{
|
|
teacher: "Bc. Daniel Adámek",
|
|
teacherCode: "ad",
|
|
type: "range",
|
|
hours: { from: 3, to: 5 },
|
|
},
|
|
],
|
|
],
|
|
[
|
|
"me;ad 4",
|
|
[
|
|
{
|
|
teacher: "Michaela Meitnerová",
|
|
teacherCode: "me",
|
|
type: "wholeDay",
|
|
hours: null,
|
|
},
|
|
{
|
|
teacher: "Bc. Daniel Adámek",
|
|
teacherCode: "ad",
|
|
type: "single",
|
|
hours: 4,
|
|
},
|
|
],
|
|
],
|
|
[
|
|
"me;ad;bo 2-3",
|
|
[
|
|
{
|
|
teacher: "Michaela Meitnerová",
|
|
teacherCode: "me",
|
|
type: "wholeDay",
|
|
hours: null,
|
|
},
|
|
{
|
|
teacher: "Bc. Daniel Adámek",
|
|
teacherCode: "ad",
|
|
type: "wholeDay",
|
|
hours: null,
|
|
},
|
|
{
|
|
teacher: "Ing. Anna Bodnárová",
|
|
teacherCode: "bo",
|
|
type: "range",
|
|
hours: { from: 2, to: 3 },
|
|
},
|
|
],
|
|
],
|
|
[
|
|
"me 2 ad 4-5",
|
|
[
|
|
{
|
|
teacher: "Michaela Meitnerová",
|
|
teacherCode: "me",
|
|
type: "single",
|
|
hours: 2,
|
|
},
|
|
{
|
|
teacher: "Bc. Daniel Adámek",
|
|
teacherCode: "ad",
|
|
type: "range",
|
|
hours: { from: 4, to: 5 },
|
|
},
|
|
],
|
|
],
|
|
[
|
|
"3",
|
|
[
|
|
{
|
|
type: "invalid",
|
|
teacher: null,
|
|
teacherCode: null,
|
|
hours: null,
|
|
original: "3",
|
|
},
|
|
],
|
|
],
|
|
[
|
|
"2-4",
|
|
[
|
|
{
|
|
type: "invalid",
|
|
teacher: null,
|
|
teacherCode: null,
|
|
hours: null,
|
|
original: "2-4",
|
|
},
|
|
],
|
|
],
|
|
[
|
|
"me Xx 3",
|
|
[
|
|
{
|
|
teacher: "Michaela Meitnerová",
|
|
teacherCode: "me",
|
|
type: "wholeDay",
|
|
hours: null,
|
|
},
|
|
{
|
|
teacher: null,
|
|
teacherCode: "xx",
|
|
type: "single",
|
|
hours: 3,
|
|
},
|
|
],
|
|
],
|
|
[
|
|
"me,ad;bo 1-2 ad 5+",
|
|
[
|
|
{
|
|
teacher: "Michaela Meitnerová",
|
|
teacherCode: "me",
|
|
type: "wholeDay",
|
|
hours: null,
|
|
},
|
|
{
|
|
teacher: "Bc. Daniel Adámek",
|
|
teacherCode: "ad",
|
|
type: "wholeDay",
|
|
hours: null,
|
|
},
|
|
{
|
|
teacher: "Ing. Anna Bodnárová",
|
|
teacherCode: "bo",
|
|
type: "range",
|
|
hours: { from: 1, to: 2 },
|
|
},
|
|
{
|
|
teacher: "Bc. Daniel Adámek",
|
|
teacherCode: "ad",
|
|
type: "range",
|
|
hours: { from: 5, to: 10 },
|
|
},
|
|
],
|
|
],
|
|
[
|
|
"Me-exk",
|
|
[
|
|
{
|
|
teacher: "Michaela Meitnerová",
|
|
teacherCode: "me",
|
|
type: "exkurze",
|
|
hours: null,
|
|
},
|
|
],
|
|
],
|
|
[
|
|
"za Vn zastupuje Jk",
|
|
[
|
|
{
|
|
teacher: "Ing. Zdeněk Vondra",
|
|
teacherCode: "vn",
|
|
type: "zastoupen",
|
|
hours: null,
|
|
zastupuje: {
|
|
teacher: "David Janoušek",
|
|
teacherCode: "jk",
|
|
},
|
|
},
|
|
],
|
|
],
|
|
[
|
|
"Vc 1. h",
|
|
[
|
|
{
|
|
teacher: "Ing. Antonín Vobecký",
|
|
teacherCode: "vc",
|
|
type: "single",
|
|
hours: 1,
|
|
},
|
|
],
|
|
],
|
|
[
|
|
"Sv-5-exk",
|
|
[
|
|
{
|
|
teacher: "Ing. Jan Šváb",
|
|
teacherCode: "sv",
|
|
type: "exkurze",
|
|
hours: { from: 5, to: 10 },
|
|
},
|
|
],
|
|
],
|
|
[
|
|
"Ex-exk. 3+",
|
|
[
|
|
{
|
|
teacher: "Ing. Jana Exnerová",
|
|
teacherCode: "ex",
|
|
type: "exkurze",
|
|
hours: { from: 3, to: 10 },
|
|
},
|
|
],
|
|
],
|
|
[
|
|
"Ex-exk.3+",
|
|
[
|
|
{
|
|
teacher: "Ing. Jana Exnerová",
|
|
teacherCode: "ex",
|
|
type: "exkurze",
|
|
hours: { from: 3, to: 10 },
|
|
},
|
|
],
|
|
],
|
|
[
|
|
"Ex-exk. 3",
|
|
[
|
|
{
|
|
teacher: "Ing. Jana Exnerová",
|
|
teacherCode: "ex",
|
|
type: "exkurze",
|
|
hours: 3,
|
|
},
|
|
],
|
|
],
|
|
[
|
|
"Su 4 - 6",
|
|
[
|
|
{
|
|
teacher: "MUDr. Kristina Studénková",
|
|
teacherCode: "su",
|
|
type: "range",
|
|
hours: { from: 4, to: 6 },
|
|
},
|
|
],
|
|
],
|
|
];
|
|
|
|
function expectSameItems(actual: any[], expected: any[]) {
|
|
expect(actual).toHaveLength(expected.length);
|
|
for (const item of expected) {
|
|
expect(actual).toContainEqual(item);
|
|
}
|
|
}
|
|
|
|
describe("parseAbsence", () => {
|
|
it.each(cases)("parseAbsence(%s) → %j", (input, expected) => {
|
|
expectSameItems(parseAbsence(input, teachermap), expected);
|
|
});
|
|
});
|