46 lines
3.2 KiB
JavaScript
46 lines
3.2 KiB
JavaScript
import assert from "node:assert/strict";
|
|
|
|
// Race Day: once every qualifying heat has run, "Create finals" is offered right there
|
|
// (not only under Manage → Format) and takes you to the first final.
|
|
export async function runRaceDayFinalsSmoke({ evaluate, navigate, savedState, waitFor, base }) {
|
|
const post = (state) => fetch(base + "/api/state", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(state) });
|
|
const before = await savedState();
|
|
const eventId = "finals_smoke_event";
|
|
const driver = { id: "finals_smoke_driver", name: "Finals Smoke Driver", classId: "test_class", transponder: "4455661" };
|
|
const qual = (id, status) => ({ id, eventId, name: id === "finals_smoke_q1" ? "Q1 H1" : "Q2 H1", type: "qualification", mode: "race", status, durationMin: 5, driverIds: [driver.id], generated: true, startedAt: status === "finished" ? Date.now() - 600000 : 0, endedAt: status === "finished" ? Date.now() - 300000 : 0 });
|
|
try {
|
|
await post({
|
|
...before,
|
|
drivers: [...before.drivers, driver],
|
|
events: [...before.events, { id: eventId, name: "Finals Smoke Race", date: new Date().toISOString().slice(0, 10), classId: "test_class", raceConfig: { driverIds: [driver.id], participantsConfigured: true, carsPerFinal: 8, finalLegs: 1, countedFinalLegs: 1 } }],
|
|
sessions: [...before.sessions, qual("finals_smoke_q1", "finished"), qual("finals_smoke_q2", "ready")],
|
|
activeSessionId: "finals_smoke_q1",
|
|
});
|
|
await navigate("race_day", "raceDaySessionSelect");
|
|
assert.equal(await evaluate(`Boolean(document.getElementById("raceDayCreateFinals"))`), false, "a qualifying heat is still to run");
|
|
|
|
const current = await savedState();
|
|
current.sessions.find((session) => session.id === "finals_smoke_q2").status = "finished";
|
|
await post(current);
|
|
await navigate("race_day", "raceDaySessionSelect");
|
|
await waitFor(async () => evaluate(`Boolean(document.getElementById("raceDayCreateFinals"))`), "Create finals offered after the last qualifying heat");
|
|
await evaluate(`document.getElementById("raceDayCreateFinals").click()`);
|
|
await waitFor(async () => (await savedState()).sessions.some((session) => session.eventId === eventId && session.type === "final"), "finals created");
|
|
const saved = await savedState();
|
|
const final = saved.sessions.find((session) => session.eventId === eventId && session.type === "final");
|
|
assert.deepEqual(final.driverIds, [driver.id]);
|
|
await waitFor(async () => (await savedState()).activeSessionId === final.id, "Race Day moves on to the first final");
|
|
assert.equal(await evaluate(`Boolean(document.getElementById("raceDayCreateFinals"))`), false, "offered only once");
|
|
console.log("PASS Race Day offers Create finals once every qualifying heat has run and goes to the first final");
|
|
} finally {
|
|
const current = await savedState();
|
|
await post({
|
|
...current,
|
|
drivers: current.drivers.filter((item) => item.id !== driver.id),
|
|
events: current.events.filter((item) => item.id !== eventId),
|
|
sessions: current.sessions.filter((session) => session.eventId !== eventId),
|
|
activeSessionId: before.activeSessionId || null,
|
|
});
|
|
}
|
|
}
|