gram/packages/scheduler/tests/days.test.ts
abiwab c653893ab0
All checks were successful
CI / Build, Test & Publish (push) Successful in 4m11s
feat: replace the Gantt chart with the work plan (#88)
Introduce @gram-lang/scheduler, work plan views, mise en place modes, comments option, and CLI/editor integrations.
2026-11-05 09:49:00 +01:00

89 lines
2.6 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import { groupsFromDays, dayOverflows, daysOf } from "../src/days";
import type { ScheduleBlock } from "../src/types";
describe("groupsFromDays", () => {
it("orders groups from the furthest day, sections in source order", () => {
expect(groupsFromDays([2, 2, 1, 0, 0])).toEqual([[0, 1], [2], [3, 4]]);
});
});
describe("daysOf", () => {
it("bounds a working day by its active blocks and ignores passive ones", () => {
const blocks: ScheduleBlock[] = [
{ kind: "prep", task: "s0.prep", section: 0, start: 0, end: 5 },
{ kind: "step", task: "s0.0", section: 0, step: 0, start: 5, end: 15 },
{
kind: "passive",
task: "s0.0.t0",
section: 0,
step: 0,
start: 15,
end: 900,
},
{ kind: "step", task: "s1.0", section: 1, step: 0, start: 900, end: 920 },
];
expect(daysOf(blocks, [[0], [1]], [1, 0])).toEqual([
{ day: 1, start: 0, end: 15, sections: [0] },
{ day: 0, start: 900, end: 920, sections: [1] },
]);
});
it("skips a group without active work", () => {
expect(daysOf([], [[0]], [0])).toEqual([]);
});
});
describe("dayOverflows", () => {
const step = (
section: number,
start: number,
end: number,
): ScheduleBlock => ({
kind: "step",
task: `s${section}.0`,
section,
step: 0,
start,
end,
});
it("flags a working day whose active work starts before its 24 h window", () => {
// Day 1 must start after 3000 - 2 x 1440 = 120; it starts at 100.
const blocks = [step(0, 100, 110), step(1, 2990, 3000)];
const days = daysOf(blocks, [[0], [1]], [1, 0]);
expect(dayOverflows(days, blocks, 3000)).toEqual([
{ code: "DAY_OVERFLOW", section: 0, day: 1, overflowMinutes: 20 },
]);
});
it("accepts a working day that starts exactly when its window opens", () => {
const blocks = [step(0, 120, 130), step(1, 2990, 3000)];
const days = daysOf(blocks, [[0], [1]], [1, 0]);
expect(dayOverflows(days, blocks, 3000)).toEqual([]);
});
it("holds the day itself to a single 24 h window", () => {
const blocks = [step(0, 0, 10), step(0, 1990, 2000)];
const days = daysOf(blocks, [[0]], [0]);
expect(dayOverflows(days, blocks, 2000)).toEqual([
{ code: "DAY_OVERFLOW", section: 0, day: 0, overflowMinutes: 560 },
]);
});
it("ignores a passive rest running through the night", () => {
const blocks: ScheduleBlock[] = [
step(0, 1500, 1510),
{
kind: "passive",
task: "s0.0.t0",
section: 0,
step: 0,
start: 0,
end: 1500,
},
];
const days = daysOf(blocks, [[0]], [0]);
expect(dayOverflows(days, blocks, 1510)).toEqual([]);
});
});