feat(day): fixed-time break such as lunch 12-13 in the day schedule (1.89.15)
This commit is contained in:
1 parent
10a0dd49bd
commit
5b34317bcb
10 files changed
+113
-19
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { orderDaySessions, buildDaySchedule, getAutopilotAction, normalizeRaceDays, moveInDayOrder, pickBoardDate } from "../src/day_schedule_logic.js";
|
||||
import { orderDaySessions, buildDaySchedule, getAutopilotAction, normalizeRaceDays, moveInDayOrder, pickBoardDate, fixedBreakWindow } from "../src/day_schedule_logic.js";
|
||||
|
||||
const events = [
|
||||
{ id: "e4", name: "Cup #1 4WD", date: "2026-11-08", mode: "race" },
|
||||
@@ -122,3 +122,38 @@ test("race day plan keeps the round and finals gaps and drops empty breaks", ()
|
||||
assert.equal(day.finalsGapMin, null);
|
||||
assert.deepEqual(day.breaks, { q3: 15 });
|
||||
});
|
||||
|
||||
test("a break at fixed clock times (lunch 12-13): no heat starts or runs inside it", () => {
|
||||
const at = (hhmm) => new Date(`2026-11-08T${hhmm}:00`).getTime();
|
||||
const list = [s("q1", "e2", "qualification", "Q1 H1"), s("q2", "e2", "qualification", "Q1 H2"), s("q3", "e2", "qualification", "Q1 H3")];
|
||||
const day = { date: "2026-11-08", startAt: at("11:46"), gapMin: 2, breakFrom: "12:00", breakTo: "13:00", breakLabel: "Lunch" };
|
||||
const plan = buildDaySchedule(list, day, at("08:00"));
|
||||
// q1 11:46-11:51, q2 11:53-11:58 (ends before lunch), q3 would start 12:00 -> 13:00.
|
||||
assert.deepEqual(plan.map((row) => new Date(row.start).toTimeString().slice(0, 5)), ["11:46", "11:53", "13:00"]);
|
||||
assert.deepEqual(plan.map((row) => row.afterFixedBreak), [false, false, true]);
|
||||
assert.equal(plan[2].delayed, false, "moved for lunch is not late");
|
||||
// A heat that would start before lunch but run into it waits too.
|
||||
const into = buildDaySchedule(list, { ...day, startAt: at("11:50") }, at("08:00"));
|
||||
assert.equal(new Date(into[1].start).toTimeString().slice(0, 5), "13:00", "11:57-12:02 would run into lunch");
|
||||
// During lunch, the next heat still waits for 13:00 (the autopilot doesn't start it).
|
||||
const lunch = buildDaySchedule([{ ...list[0], status: "finished", startedAt: at("11:46"), endedAt: at("11:51") }, list[1]], day, at("12:20"));
|
||||
assert.equal(lunch[1].start, at("13:00"));
|
||||
assert.equal(getAutopilotAction(lunch, { day, now: at("12:20") }).reason, "until");
|
||||
// Invalid or backwards times mean no break.
|
||||
assert.equal(fixedBreakWindow({ ...day, breakTo: "11:00" }), null);
|
||||
assert.equal(normalizeRaceDays([{ ...day, breakFrom: "25:00" }])[0].breakFrom, null);
|
||||
assert.equal(fixedBreakWindow(day).label, "Lunch");
|
||||
});
|
||||
|
||||
test("the drivers' board shows the lunch while it is on, and before the heat after it", async () => {
|
||||
const { renderDriverBoard } = await import("../src/day_schedule_view.js");
|
||||
const at = (hhmm) => new Date(`2026-11-08T${hhmm}:00`).getTime();
|
||||
const day = { date: "2026-11-08", startAt: at("11:55"), gapMin: 2, breakFrom: "12:00", breakTo: "13:00", breakLabel: "Lunch" };
|
||||
const list = [s("q1", "e2", "qualification", "Q1 H1", { status: "finished", startedAt: at("11:46"), endedAt: at("11:51") }), s("q2", "e2", "qualification", "Q1 H2")];
|
||||
const rows = buildDaySchedule(list, day, at("12:20"));
|
||||
const html = renderDriverBoard({ t: (k) => k, escapeHtml: String, date: "2026-11-08", rows, getClassLabel: () => "2WD", getSessionGridEntries: () => [], getRemainingLabel: () => "", day, now: at("12:20") });
|
||||
assert.match(html, /board-break">🍽 Lunch 12:00–13:00/);
|
||||
assert.match(html, /board-break-note">🍽 Lunch 12:00–13:00/);
|
||||
const before = renderDriverBoard({ t: (k) => k, escapeHtml: String, date: "2026-11-08", rows, getClassLabel: () => "2WD", getSessionGridEntries: () => [], getRemainingLabel: () => "", day, now: at("11:58") });
|
||||
assert.doesNotMatch(before, /class="board-live board-break"/, "no lunch banner before lunch");
|
||||
});
|
||||
Reference in new issue
Block a user