84 lines
7.0 KiB
JavaScript
84 lines
7.0 KiB
JavaScript
import assert from "node:assert/strict";
|
|
|
|
// The easy path for a club evening: the Dashboard's "Start practice" creates and starts an
|
|
// Open Practice on Race Day; Race Day's quick actions add a track layout (the running practice
|
|
// moves onto it) and switch sessions; Timing no longer has the run controls, only a link.
|
|
export async function runRaceDayQuickSmoke({ evaluate, navigate, savedState, waitFor, base, dialogs }) {
|
|
// The layout prompts are expected here; drop them afterwards so later "no unexpected dialog" checks stay meaningful.
|
|
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 seeded = await savedState();
|
|
// No Open Practice to continue, and nothing running: "Start practice" must create one.
|
|
await patchState({
|
|
sessions: seeded.sessions.map((session) => (session.type === "open_practice" || ["running", "paused"].includes(session.status) ? { ...session, status: "finished", endedAt: Date.now() } : session)),
|
|
events: [...seeded.events, { id: "rq_event", name: "RQ Race", mode: "race", raceConfig: {} }],
|
|
activeSessionId: "",
|
|
trackLayouts: [],
|
|
});
|
|
const before = new Set((await savedState()).sessions.map((session) => session.id));
|
|
let created = null;
|
|
try {
|
|
await navigate("dashboard", "dashboardQuickPractice");
|
|
await evaluate(`document.getElementById("dashboardQuickPractice").click()`);
|
|
await waitFor(async () => (await savedState()).sessions.some((session) => !before.has(session.id) && session.type === "open_practice" && session.status === "running"), "a new Open Practice is created and running");
|
|
created = (await savedState()).sessions.find((session) => !before.has(session.id) && session.type === "open_practice");
|
|
await waitFor(async () => (await savedState()).activeSessionId === created.id, "and selected");
|
|
await waitFor(async () => (await evaluate(`location.search`)).includes("race_day") && Boolean(await evaluate(`document.getElementById("raceDayQuickPractice")`)), "on Race Day");
|
|
await waitFor(async () => (await evaluate(`document.getElementById("raceDayQuickPractice").textContent`)).includes(created.name), "the quick button shows the running practice");
|
|
assert.equal(await evaluate(`Boolean(document.getElementById("raceDayNewPracticeDay"))`), true, "New practice day is on Race Day for a practice");
|
|
console.log("PASS Start practice on the Dashboard creates, starts and opens an Open Practice on Race Day");
|
|
|
|
await evaluate(`document.querySelector('.race-day-quick [data-track-layout-new]').click()`);
|
|
await waitFor(async () => ((await savedState()).trackLayouts || []).length === 1, "a layout is created from the quick actions");
|
|
const layoutId = (await savedState()).trackLayouts[0].id;
|
|
await waitFor(async () => (await savedState()).sessions.find((session) => session.id === created.id)?.trackLayoutId === layoutId, "the running practice moved onto it");
|
|
console.log("PASS New track layout from Race Day's quick actions moves the running practice onto it");
|
|
|
|
await patchState({ sessions: [...(await savedState()).sessions, { id: "rq_heat", eventId: "rq_event", name: "RQ Heat 1", type: "heat", status: "ready", durationMin: 5 }] });
|
|
await navigate("race_day", "raceDaySessionSelect");
|
|
await evaluate(`(() => { const select = document.getElementById("raceDaySessionSelect"); select.value = "rq_heat"; select.dispatchEvent(new Event("change")); })()`);
|
|
await waitFor(async () => (await savedState()).activeSessionId === "rq_heat", "the session picker switches session");
|
|
assert.equal(await evaluate(`Boolean(document.getElementById("raceDayNewPracticeDay"))`), false, "no New practice day for a heat");
|
|
await waitFor(async () => Boolean(await evaluate(`document.getElementById("raceDayResetSession")`)), "Reset data is on Race Day for a heat that is not running");
|
|
console.log("PASS Race Day's session picker switches the selected session");
|
|
|
|
// A finished heat can be picked again and reset to run again: clock back to zero, no laps.
|
|
const ranAt = Date.now() - 600000;
|
|
await patchState({
|
|
sessions: [...(await savedState()).sessions, { id: "rq_done", eventId: "rq_event", name: "RQ Heat 2", type: "qualification", status: "finished", durationMin: 5, startedAt: ranAt, endedAt: ranAt + 300000, finishedByTimer: true }],
|
|
resultsBySession: { ...(await savedState()).resultsBySession, rq_done: { passings: [{ id: "p1", timestamp: ranAt + 20000, lapMs: 20000 }], competitors: {}, adjustments: [] } },
|
|
});
|
|
await navigate("race_day", "raceDaySessionSelect");
|
|
assert.ok(await evaluate(`[...document.getElementById("raceDaySessionSelect").options].some((option) => option.value === "rq_done")`), "the finished heat is in the list");
|
|
await evaluate(`(() => { const select = document.getElementById("raceDaySessionSelect"); select.value = "rq_done"; select.dispatchEvent(new Event("change")); })()`);
|
|
await waitFor(async () => Boolean(await evaluate(`document.getElementById("raceDayResetSession")`)), "Reset data for the finished heat");
|
|
await evaluate(`document.getElementById("raceDayResetSession").click()`);
|
|
await waitFor(async () => (await savedState()).sessions.find((session) => session.id === "rq_done")?.status === "ready", "the heat is ready to run again");
|
|
const reset = (await savedState()).sessions.find((session) => session.id === "rq_done");
|
|
assert.deepEqual([reset.startedAt || null, reset.endedAt || null, reset.finishedByTimer], [null, null, false], "the clock is back at zero");
|
|
assert.equal((await savedState()).resultsBySession.rq_done?.passings?.length || 0, 0, "its laps are cleared");
|
|
await waitFor(async () => Boolean(await evaluate(`document.getElementById("raceDayStart")`)), "Start is offered again");
|
|
console.log("PASS a finished heat can be picked and reset: clock to zero, laps cleared, Start again");
|
|
|
|
await navigate("timing", "activeSessionSelect");
|
|
assert.equal(await evaluate(`Boolean(document.getElementById("startSession") || document.getElementById("resetSession") || document.getElementById("stopSession"))`), false, "no run controls on Timing");
|
|
await evaluate(`document.getElementById("timingOpenRaceDay").click()`);
|
|
await waitFor(async () => Boolean(await evaluate(`document.getElementById("raceDayQuickPractice")`)), "the link opens Race Day");
|
|
console.log("PASS Timing is for following: run controls moved to Race Day, with a link there");
|
|
} finally {
|
|
dialogs.splice(dialogsAtStart);
|
|
const current = await savedState();
|
|
await patchState({
|
|
sessions: current.sessions.filter((session) => session.id !== "rq_heat").map((session) => (created && session.id === created.id ? { ...session, status: "finished", endedAt: Date.now() } : session)),
|
|
events: current.events.filter((event) => event.id !== "rq_event"),
|
|
trackLayouts: [],
|
|
activeSessionId: "",
|
|
});
|
|
}
|
|
}
|