feat(race-day): offer Create finals once every qualifying heat has run (1.84.0)
This commit is contained in:
1 parent
ebdc6104e6
commit
0a4c017e44
9 files changed
+112
-7
No files matched your search
@@ -0,0 +1,45 @@
|
||||
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,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { runOverlaySmoke } from "./browser_overlays.js";
|
||||
import { runRaceSetupSmoke } from "./browser_race_setup.js";
|
||||
import { runRaceDaySmoke } from "./browser_race_day.js";
|
||||
import { runRaceDayFinalsSmoke } from "./browser_race_day_finals.js";
|
||||
import { runRaceDayStartSequencesSmoke } from "./browser_race_day_start_sequences.js";
|
||||
import { runTeamMembershipSmoke } from "./browser_team_membership.js";
|
||||
import { runEventManagerTabsSmoke } from "./browser_event_manager_tabs.js";
|
||||
@@ -189,6 +190,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 runRaceDayFinalsSmoke({ evaluate, navigate, savedState, waitFor, base });
|
||||
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 });
|
||||
|
||||
@@ -124,3 +124,24 @@ test("Race Day preflight warns when the decoder's clock is off, but never blocks
|
||||
state.decoder.clockSkewMs = 25; // network delay only
|
||||
assert.equal(buildRaceDayPreflight(state, state.sessions[0], { backendAvailable: true }).checks.some((item) => item.id === "decoder_clock"), false);
|
||||
});
|
||||
|
||||
test("Race Day offers Create finals once every heat the finals come from has run, and only once", async () => {
|
||||
const { shouldOfferFinals } = await import("../src/race_day_logic.js");
|
||||
const state = {
|
||||
events: [{ id: "e", raceConfig: {} }, { id: "p", raceConfig: { finalsSource: "practice" } }, { id: "s", mode: "track", sponsor: {}, raceConfig: {} }],
|
||||
sessions: [
|
||||
{ eventId: "e", type: "practice", status: "finished" },
|
||||
{ eventId: "e", type: "qualification", status: "finished" },
|
||||
{ eventId: "e", type: "qualification", status: "ready" },
|
||||
{ eventId: "p", type: "practice", status: "stopped" },
|
||||
{ eventId: "s", type: "qualification", status: "finished" },
|
||||
],
|
||||
};
|
||||
assert.equal(shouldOfferFinals(state, "e"), false, "a qualifying heat is still to run");
|
||||
state.sessions[2].status = "finished";
|
||||
assert.equal(shouldOfferFinals(state, "e"), true);
|
||||
assert.equal(shouldOfferFinals(state, "p"), true, "finals seeded from practice");
|
||||
assert.equal(shouldOfferFinals(state, "s"), false, "sponsor events have their own flow");
|
||||
state.sessions.push({ eventId: "e", type: "final", status: "ready" });
|
||||
assert.equal(shouldOfferFinals(state, "e"), false, "finals already made");
|
||||
});
|
||||
Reference in new issue
Block a user