feat(race-day): day schedule for all classes, autopilot, pause the day, printed running order and drivers' board (1.50.0)
This commit is contained in:
1 parent
0ba858d638
commit
fdc6c179dc
18 files changed
+735
-20
No files matched your search
@@ -0,0 +1,85 @@
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
// The race day schedule: every class on one date in one running order with times, ▲▼, a
|
||||
// start time and gap, pause/resume of the day, the autopilot telling what it waits for, and
|
||||
// the drivers' board with the next heats and a heads-up.
|
||||
export async function runDayScheduleSmoke({ evaluate, navigate, savedState, waitFor, base, send, dialogs }) {
|
||||
const dialogsAtStart = dialogs.length;
|
||||
const patchState = async (patch) => {
|
||||
const current = await savedState();
|
||||
Object.assign(current, patch);
|
||||
const response = await fetch(base + "/api/state", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(current) });
|
||||
assert.equal(response.ok, true);
|
||||
};
|
||||
const d = new Date();
|
||||
const today = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
||||
const seeded = await savedState();
|
||||
const heat = (id, eventId, name) => ({ id, eventId, name, type: "qualification", mode: "race", status: "ready", durationMin: 5, startMode: "staggered" });
|
||||
await patchState({
|
||||
sessions: [
|
||||
...seeded.sessions.map((session) => (["running", "paused"].includes(session.status) ? { ...session, status: "finished", endedAt: Date.now() } : session)),
|
||||
heat("ds_2wd_q1", "ds_2wd", "Q1 H1"), heat("ds_4wd_q1", "ds_4wd", "Q1 H1"), heat("ds_2wd_q2", "ds_2wd", "Q2 H1"),
|
||||
],
|
||||
events: [...seeded.events, { id: "ds_2wd", name: "DS Cup 2WD", date: today, mode: "race", raceConfig: {} }, { id: "ds_4wd", name: "DS Cup 4WD", date: today, mode: "race", raceConfig: {} }],
|
||||
activeSessionId: "ds_2wd_q1",
|
||||
raceDays: [],
|
||||
});
|
||||
const rowIds = () => evaluate(`[...document.querySelectorAll("[data-day-row]")].map((row) => row.dataset.dayRow)`);
|
||||
try {
|
||||
await navigate("race_day", "daySchedule");
|
||||
await waitFor(async () => (await rowIds()).join() === "ds_2wd_q1,ds_4wd_q1,ds_2wd_q2", "both classes in one running order, round by round");
|
||||
await evaluate(`document.querySelector('[data-day-move="ds_4wd_q1"][data-step="-1"]').click()`);
|
||||
await waitFor(async () => (await rowIds()).join() === "ds_4wd_q1,ds_2wd_q1,ds_2wd_q2", "▲ moves the 4WD heat first");
|
||||
await waitFor(async () => ((await savedState()).raceDays || []).find((day) => day.date === today)?.sessionOrder?.[0] === "ds_4wd_q1", "the day order is saved");
|
||||
console.log("PASS Race Day shows today's schedule for every class in running order and ▲▼ change it");
|
||||
|
||||
// First start in an hour, 2 min between heats: the second heat is 5 + 2 min later.
|
||||
const inAnHour = new Date(Date.now() + 3600000);
|
||||
const hhmm = (date) => `${String(date.getHours()).padStart(2, "0")}:${String(date.getMinutes()).padStart(2, "0")}`;
|
||||
await evaluate(`(() => { const form = document.getElementById("dayPlanForm"); form.elements.startTime.value = ${JSON.stringify(hhmm(inAnHour))}; form.elements.gapMin.value = "2"; form.requestSubmit(); })()`);
|
||||
await waitFor(async () => Boolean(((await savedState()).raceDays || []).find((day) => day.date === today)?.startAt), "start time saved");
|
||||
const times = await evaluate(`[...document.querySelectorAll("[data-day-row] td:first-child strong")].map((cell) => cell.textContent)`);
|
||||
assert.equal(times[0], hhmm(inAnHour));
|
||||
assert.equal(times[1], hhmm(new Date(inAnHour.getTime() + 7 * 60000)));
|
||||
console.log("PASS the day gets a first start time and gap, and every heat its planned time");
|
||||
|
||||
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");
|
||||
assert.match(await evaluate(`document.querySelector("[data-autopilot-status]").textContent`), /^Next: .*Q1 H1 at /);
|
||||
// Time is up but no decoder: it waits and says why instead of starting.
|
||||
await evaluate(`(() => { const form = document.getElementById("dayPlanForm"); form.elements.startTime.value = ${JSON.stringify(hhmm(new Date(Date.now() - 60000)))}; form.requestSubmit(); })()`);
|
||||
await waitFor(async () => (await evaluate(`document.querySelector("[data-autopilot-status]").textContent`)).includes("decoder is not connected"), "waits for the decoder");
|
||||
assert.equal((await savedState()).sessions.find((session) => session.id === "ds_4wd_q1").status, "ready", "nothing started without a decoder");
|
||||
await evaluate(`document.getElementById("dayPause").click()`);
|
||||
await waitFor(async () => Boolean(((await savedState()).raceDays || []).find((day) => day.date === today)?.pausedAt), "the day is paused");
|
||||
await waitFor(async () => (await evaluate(`document.querySelector("[data-autopilot-status]").textContent`)) === "The day is paused", "the autopilot says the day is paused");
|
||||
await evaluate(`document.getElementById("dayResume").click()`);
|
||||
await waitFor(async () => !((await savedState()).raceDays || []).find((day) => day.date === today)?.pausedAt, "the day is resumed");
|
||||
await evaluate(`document.getElementById("dayAutopilotOff").click()`);
|
||||
await waitFor(async () => ((await savedState()).raceDays || []).find((day) => day.date === today)?.autopilot === false, "autopilot off");
|
||||
console.log("PASS the autopilot says what comes next, waits for the decoder, and the day can be paused and resumed");
|
||||
|
||||
const printHtml = await evaluate(`(async () => {
|
||||
const { buildDaySchedulePrintHtml } = await import("/src/day_schedule_view.js");
|
||||
return buildDaySchedulePrintHtml({ t: (key, vars = {}) => key + JSON.stringify(vars), escapeHtml: (value) => String(value), date: "D", rows: [{ start: Date.now(), session: { name: "Q1 H1" } }], getClassLabel: () => "2WD", getSessionGridEntries: () => [{ name: "Roy" }, { name: "Eddie" }] });
|
||||
})()`);
|
||||
assert.ok(printHtml.includes("2WD · Q1 H1") && printHtml.includes("<li>Roy</li><li>Eddie</li>"), "the printed running order lists each heat's drivers");
|
||||
|
||||
// The drivers' board: the next heats with a heads-up (the first is due now) and the rest.
|
||||
await send("Page.navigate", { url: base + "/public-overlay/schedule" });
|
||||
await waitFor(async () => (await evaluate(`document.querySelectorAll(".board-next").length`)) === 3, "the board shows the next three heats");
|
||||
const board = await evaluate(`document.querySelector(".driver-board").innerText`);
|
||||
assert.ok(board.includes("Get ready"), "a heat due within 10 minutes gets a heads-up");
|
||||
assert.equal(await evaluate(`document.querySelector(".board-next").dataset.boardSession`), "ds_4wd_q1", "in the day's order");
|
||||
console.log("PASS the drivers' board shows the next heats with their drivers and a heads-up");
|
||||
} finally {
|
||||
const current = await savedState();
|
||||
await patchState({
|
||||
sessions: current.sessions.filter((session) => !session.id.startsWith("ds_")),
|
||||
events: current.events.filter((event) => !event.id.startsWith("ds_")),
|
||||
raceDays: [],
|
||||
});
|
||||
dialogs.splice(dialogsAtStart);
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import { runTrainingSourceSmoke } from "./browser_training_source.js";
|
||||
import { runDecoderUrlSmoke } from "./browser_decoder_url.js";
|
||||
import { runLiveSessionSmoke } from "./browser_live_session.js";
|
||||
import { runRaceDayQuickSmoke } from "./browser_race_day_quick.js";
|
||||
import { runDayScheduleSmoke } from "./browser_day_schedule.js";
|
||||
import { runObsPopupSmoke } from "./browser_obs_popup.js";
|
||||
import { runDecoderReconnectSmoke } from "./browser_decoder_reconnect.js";
|
||||
import assert from "node:assert/strict";
|
||||
@@ -175,6 +176,7 @@ try {
|
||||
await runDecoderUrlSmoke({ evaluate, navigate, savedState, waitFor, base });
|
||||
await runLiveSessionSmoke({ evaluate, navigate, savedState, waitFor, base });
|
||||
await runRaceDayQuickSmoke({ evaluate, navigate, savedState, waitFor, base, dialogs });
|
||||
await runDayScheduleSmoke({ evaluate, navigate, savedState, waitFor, base, send, dialogs });
|
||||
await runRaceDaySmoke({ evaluate, navigate, fill, savedState, waitFor, pause, base, dialogs });
|
||||
await runRaceDayStartSequencesSmoke({ evaluate, navigate, waitFor, pause, base, dialogs });
|
||||
await runObsPopupSmoke({ evaluate, navigate, fill, savedState, waitFor, pause, base, debugPort, dialogs, realClick });
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { orderDaySessions, buildDaySchedule, getAutopilotAction, normalizeRaceDays, moveInDayOrder, pickBoardDate } from "../src/day_schedule_logic.js";
|
||||
|
||||
const events = [
|
||||
{ id: "e4", name: "Cup #1 4WD", date: "2026-11-08", mode: "race" },
|
||||
{ id: "e2", name: "Cup #1 2WD", date: "2026-11-08", mode: "race" },
|
||||
{ id: "other", name: "Other day", date: "2026-11-09", mode: "race" },
|
||||
];
|
||||
const s = (id, eventId, type, name, extra = {}) => ({ id, eventId, type, name, mode: "race", status: "ready", durationMin: 5, ...extra });
|
||||
const sessions = [
|
||||
s("a4", "e4", "final", "A Final 1"), s("q4", "e4", "qualification", "Q1 H1"), s("q4b", "e4", "qualification", "Q2 H1"),
|
||||
s("b2", "e2", "final", "B Final 1"), s("a2", "e2", "final", "A Final 1"), s("q2b", "e2", "qualification", "Q2 H1"),
|
||||
s("q2", "e2", "qualification", "Q1 H1"), s("q2h2", "e2", "qualification", "Q1 H2"), s("p2", "e2", "practice", "Seeding"),
|
||||
s("x", "other", "qualification", "Q1 H1"),
|
||||
];
|
||||
|
||||
test("the day runs every class step by step: practice, each qualifying round, finals lowest first", () => {
|
||||
const ids = orderDaySessions({ events, sessions, date: "2026-11-08" }).map((item) => item.id);
|
||||
assert.deepEqual(ids, ["p2", "q2", "q2h2", "q4", "q2b", "q4b", "b2", "a2", "a4"]);
|
||||
});
|
||||
|
||||
test("a manual day order and a class's own order are kept", () => {
|
||||
const ordered = orderDaySessions({ events, sessions, date: "2026-11-08" });
|
||||
const manual = moveInDayOrder(ordered, "q4", -1);
|
||||
assert.deepEqual(orderDaySessions({ events, sessions, date: "2026-11-08", manualOrder: manual }).slice(0, 4).map((item) => item.id), ["p2", "q2", "q4", "q2h2"]);
|
||||
const swapped = events.map((event) => (event.id === "e2" ? { ...event, sessionOrder: ["q2h2", "q2"] } : event));
|
||||
assert.deepEqual(orderDaySessions({ events: swapped, sessions, date: "2026-11-08" }).slice(1, 3).map((item) => item.id), ["q2h2", "q2"]);
|
||||
});
|
||||
|
||||
test("the schedule cascades from the start time and a late or paused day pushes the rest", () => {
|
||||
const start = Date.UTC(2026, 10, 8, 10, 0);
|
||||
const list = [s("one", "e2", "qualification", "Q1 H1"), s("two", "e2", "qualification", "Q1 H2")];
|
||||
const day = { startAt: start, gapMin: 3 };
|
||||
const plan = buildDaySchedule(list, day, start - 3600000);
|
||||
assert.deepEqual(plan.map((row) => row.start), [start, start + 8 * 60000]);
|
||||
assert.equal(plan[1].upcomingIndex, 1);
|
||||
// Nothing started 4 minutes after the planned time: expected now, everything after moves.
|
||||
const late = buildDaySchedule(list, day, start + 4 * 60000);
|
||||
assert.equal(late[0].start, start + 4 * 60000);
|
||||
assert.equal(late[0].delayed, true);
|
||||
assert.equal(late[1].start, start + 12 * 60000);
|
||||
// A heat running with a 2 minute pause ends 2 minutes later.
|
||||
const running = [{ ...list[0], status: "running", startedAt: start + 60000, totalPausedMs: 120000 }, list[1]];
|
||||
const live = buildDaySchedule(running, day, start + 2 * 60000);
|
||||
assert.equal(live[0].state, "live");
|
||||
assert.equal(live[0].end, start + 8 * 60000);
|
||||
assert.equal(live[1].start, start + 11 * 60000);
|
||||
});
|
||||
|
||||
test("the autopilot waits for the planned time minus the count-down, never while something runs or the day is paused", () => {
|
||||
const start = Date.UTC(2026, 10, 8, 10, 0);
|
||||
const rows = buildDaySchedule([s("one", "e2", "qualification", "Q1 H1")], { startAt: start }, start - 600000);
|
||||
const prologueMs = () => 120000;
|
||||
assert.deepEqual(getAutopilotAction(rows, { day: {}, now: start - 300000, prologueMs }).reason, "until");
|
||||
assert.equal(getAutopilotAction(rows, { day: {}, now: start - 120000, prologueMs }).type, "start");
|
||||
assert.equal(getAutopilotAction(rows, { day: {}, now: start, busy: true, prologueMs }).reason, "running");
|
||||
assert.equal(getAutopilotAction(rows, { day: { pausedAt: start }, now: start, prologueMs }).reason, "paused");
|
||||
assert.equal(getAutopilotAction([], { day: {}, now: start }).reason, "done");
|
||||
});
|
||||
|
||||
test("race days are stored one per date, and the board shows today or the next day still to race", () => {
|
||||
const days = normalizeRaceDays([{ date: "2026-11-08", gapMin: 0 }, { date: "bad" }, { date: "2026-11-08", gapMin: 5, autopilot: true }]);
|
||||
assert.equal(days.length, 1);
|
||||
assert.equal(days[0].gapMin, 5);
|
||||
assert.equal(normalizeRaceDays([{ date: "2026-11-08", gapMin: 0 }])[0].gapMin, 0);
|
||||
assert.equal(pickBoardDate({ events, sessions, today: "2026-11-08" }), "2026-11-08");
|
||||
assert.equal(pickBoardDate({ events, sessions, today: "2026-11-01" }), "2026-11-08");
|
||||
assert.equal(pickBoardDate({ events, sessions, today: "2026-12-01" }), "2026-12-01");
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import "./auth.test.js";
|
||||
import "./day_schedule.test.js";
|
||||
import "./race_day_live.test.js";
|
||||
import "./series_next_step.test.js";
|
||||
import "./race_day_sessions.test.js";
|
||||
|
||||
Reference in new issue
Block a user