feat(day): several fixed breaks a day (lunch, prize-giving ...) in Race Day's schedule (1.89.26)

This commit is contained in:
larssand committed 2026-11-14 15:31:10 +01:00
1 parent 239cac8033
commit 5241cced77
11 files changed
+147 -47

No files matched your search

+21
View File
@@ -50,6 +50,27 @@ export async function runDayScheduleSmoke({ evaluate, navigate, savedState, wait
}
console.log("PASS the day gets a first start time and gap, and every heat its planned time");
// Several fixed breaks: fill the empty row, + Add break for a second, save; ✕ removes one.
// Early-morning times so they never move the heats the rest of this test plans.
const savedBreaks = async () => ((await savedState()).raceDays || []).find((day) => day.date === today)?.fixedBreaks || [];
await evaluate(`(() => {
const form = document.getElementById("dayPlanForm");
const fill = (row, label, from, to) => { row.querySelector('[name="breakLabel"]').value = label; row.querySelector('[name="breakFrom"]').value = from; row.querySelector('[name="breakTo"]').value = to; };
fill(form.querySelector("[data-fixed-break]"), "Prisutdelning", "04:00", "04:10");
form.querySelector("[data-fixed-break-add]").click();
const rows = form.querySelectorAll("[data-fixed-break]");
fill(rows[rows.length - 1], "Lunch", "03:00", "03:10");
form.requestSubmit();
})()`);
await waitFor(async () => (await savedBreaks()).length === 2, "two breaks saved");
assert.deepEqual((await savedBreaks()).map((item) => item.label), ["Lunch", "Prisutdelning"], "saved in time order");
await waitFor(async () => (await evaluate(`document.querySelectorAll("#dayPlanForm [data-fixed-break]").length`)) === 3, "two breaks and an empty row after saving");
await evaluate(`(() => { const form = document.getElementById("dayPlanForm"); form.querySelector("[data-fixed-break] [data-fixed-break-remove]").click(); form.requestSubmit(); })()`);
await waitFor(async () => (await savedBreaks()).map((item) => item.label).join() === "Prisutdelning", "✕ removed the lunch");
await evaluate(`(() => { const form = document.getElementById("dayPlanForm"); form.querySelector("[data-fixed-break] [data-fixed-break-remove]").click(); form.requestSubmit(); })()`);
await waitFor(async () => (await savedBreaks()).length === 0, "no breaks left");
console.log("PASS several fixed breaks a day: add, save in time order, remove");
await evaluate(`document.getElementById("dayAutopilotOn").click()`);
await waitFor(async () => ((await savedState()).raceDays || []).find((day) => day.date === today)?.autopilot === true, "autopilot on");
await waitFor(async () => (await evaluate(`document.querySelector("[data-autopilot-status]").textContent`)).startsWith("Next: 4WD") || (await evaluate(`document.querySelector("[data-autopilot-status]").textContent`)).includes("DS"), "the autopilot says what is next");
+18
View File
@@ -145,6 +145,24 @@ test("a break at fixed clock times (lunch 12-13): no heat starts or runs inside
assert.equal(fixedBreakWindow(day).label, "Lunch");
});
test("several fixed breaks a day: each moves the heat that would hit it, the old single break carries over", () => {
const at = (hhmm) => new Date(`2026-11-08T${hhmm}:00`).getTime();
const list = ["a", "b", "c", "d"].map((id, i) => s(id, "e2", "qualification", `Q1 H${i + 1}`));
const day = { date: "2026-11-08", startAt: at("11:50"), gapMin: 2, fixedBreaks: [{ from: "15:00", to: "15:20", label: "Prisutdelning" }, { from: "12:00", to: "13:00", label: "Lunch" }, { from: "13:05", to: "13:15", label: "Banunderhåll" }] };
const plan = buildDaySchedule(list, day, at("08:00"));
// a 11:50-11:55; b 11:57 runs into lunch -> 13:00, but 13:00-13:05 ends as the track break starts: ok;
// c 13:07 runs into the track break -> 13:15; d 13:22.
assert.deepEqual(plan.map((row) => new Date(row.start).toTimeString().slice(0, 5)), ["11:50", "13:00", "13:15", "13:22"]);
assert.deepEqual(plan.map((row) => row.afterBreak?.label || ""), ["", "Lunch", "Banunderhåll", ""]);
// Sorted, and an overlapping or backwards break is dropped.
const normalized = normalizeRaceDays([{ date: "2026-11-08", fixedBreaks: [{ from: "13:00", to: "14:00" }, { from: "12:00", to: "13:30" }, { from: "16:00", to: "15:00" }] }])[0];
assert.deepEqual(normalized.fixedBreaks.map((item) => item.from), ["12:00"]);
// A day saved with the single break keeps it as the first entry.
const old = normalizeRaceDays([{ date: "2026-11-08", breakFrom: "12:00", breakTo: "12:45", breakLabel: "Lunch" }])[0];
assert.deepEqual(old.fixedBreaks, [{ from: "12:00", to: "12:45", label: "Lunch" }]);
assert.equal(normalizeRaceDays([{ date: "2026-11-08", breakFrom: "12:00", breakTo: "12:45", fixedBreaks: [] }])[0].breakFrom, null, "an emptied list wins over the old fields");
});
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();