feat(race): practice split into heats by cars per heat; format change rebuilds heats not run yet (1.89.46)
This commit is contained in:
1 parent
ce86f771c3
commit
74a2e9ba47
11 files changed
+159
-17
No files matched your search
@@ -83,7 +83,8 @@ export async function runRaceSetupSmoke({ evaluate, navigate, fill, savedState,
|
||||
const club = await findEvent("Browser Club Race");
|
||||
const clubSessions = (await savedState()).sessions.filter((session) => session.eventId === club.id);
|
||||
const quals = clubSessions.filter((session) => session.type === "qualification");
|
||||
assert.equal(clubSessions.filter((session) => session.type === "practice").length, 1, "one practice");
|
||||
const practices = clubSessions.filter((session) => session.type === "practice");
|
||||
assert.ok(practices.length >= 1 && practices.every((session) => session.driverIds.length <= club.raceConfig.carsPerHeat), `practice split by cars per heat: ${practices.map((session) => session.name + ":" + session.driverIds.length)}`);
|
||||
assert.ok(quals.length >= 2 && quals.every((session) => /^Q[12] H\d+$/.test(session.name) && session.generated), `qualifying heats per round: ${quals.map((session) => session.name)}`);
|
||||
assert.equal(club.raceConfig.qualifyingRounds, 2);
|
||||
console.log("PASS wizard builds qualifying as Q<round> H<heat> heats");
|
||||
@@ -97,6 +98,17 @@ export async function runRaceSetupSmoke({ evaluate, navigate, fill, savedState,
|
||||
await evaluate(`document.querySelector('.race-participant[value="${first}"]').click()`);
|
||||
await waitFor(async () => (await savedState()).sessions.some((session) => session.eventId === club.id && session.type === "qualification" && session.driverIds.includes(first)), "ticked again: back in a heat");
|
||||
console.log("PASS race participants can be changed after creation and the heats follow");
|
||||
// Format: changing cars per heat / rounds rebuilds the qualifying heats that have not run.
|
||||
const qualCount = async () => (await savedState()).sessions.filter((session) => session.eventId === club.id && session.type === "qualification").length;
|
||||
const before = await qualCount();
|
||||
await fill("raceFormatForm", { qualifyingRounds: "3", carsPerHeat: "2" });
|
||||
await submit("raceFormatForm");
|
||||
await waitFor(async () => (await savedState()).sessions.some((session) => session.eventId === club.id && session.name === "Q3 H1"), "a third round after the format change");
|
||||
const heats = (await savedState()).sessions.filter((session) => session.eventId === club.id && session.type === "qualification");
|
||||
assert.ok(heats.length > before && heats.every((session) => session.driverIds.length <= 2), `heats rebuilt with max 2 cars: ${heats.map((session) => session.name + ":" + session.driverIds.length)}`);
|
||||
const practiceHeats = (await savedState()).sessions.filter((session) => session.eventId === club.id && session.type === "practice");
|
||||
assert.ok(practiceHeats.every((session) => session.driverIds.length <= 2), `practice heats rebuilt with max 2 cars: ${practiceHeats.map((session) => session.name + ":" + session.driverIds.length)}`);
|
||||
console.log("PASS format change rebuilds the practice and qualifying heats (cars per heat, rounds)");
|
||||
}
|
||||
await navigate("race_setup", "raceWizardStepForm");
|
||||
await editEvent(race, "race_setup", "raceWizardStepForm");
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { buildPracticeHeats, rebuildPracticeHeats, parsePracticeHeatName, syncParticipantsToSessions } from "../src/event_race_logic.js";
|
||||
|
||||
let n = 0;
|
||||
const t = (key) => ({ "session.practice": "träning" }[key] || key);
|
||||
const buildRaceSession = (eventId, name, type, durationMin, overrides = {}) => ({ id: `s${++n}`, eventId, name, type, durationMin, status: "ready", startedAt: null, driverIds: overrides.driverIds || [] });
|
||||
const drivers = (count) => Array.from({ length: count }, (_, i) => `d${i + 1}`);
|
||||
const event = (count, carsPerHeat, extra = {}) => ({ id: "e1", raceConfig: { driverIds: drivers(count), carsPerHeat, qualDurationMin: 5, ...extra } });
|
||||
|
||||
test("practice heats: each round is split into balanced heats of at most cars per heat", () => {
|
||||
const sessions = buildPracticeHeats(event(12, 5), 2, { t, buildRaceSession });
|
||||
assert.deepEqual(sessions.map((s) => s.name), ["träning 1 H1", "träning 1 H2", "träning 1 H3", "träning 2 H1", "träning 2 H2", "träning 2 H3"]);
|
||||
assert.deepEqual(sessions.slice(0, 3).map((s) => s.driverIds.length), [4, 4, 4]);
|
||||
assert.ok(sessions.every((s) => s.generated && s.type === "practice"));
|
||||
});
|
||||
|
||||
test("practice heats: everyone in one heat keeps the plain name", () => {
|
||||
assert.deepEqual(buildPracticeHeats(event(6, 10), 1, { t, buildRaceSession }).map((s) => s.name), ["träning 1"]);
|
||||
});
|
||||
|
||||
test("practice heats: rebuilt for a new heat size, also from an older race without heats", () => {
|
||||
const ev = event(10, 5);
|
||||
const state = { sessions: [
|
||||
{ id: "old1", eventId: "e1", name: "träning 1", type: "practice", status: "ready", driverIds: drivers(10) },
|
||||
{ id: "old2", eventId: "e1", name: "träning 2", type: "practice", status: "ready", driverIds: drivers(10) },
|
||||
{ id: "q", eventId: "e1", name: "Q1 H1", type: "qualification", status: "ready", driverIds: [] },
|
||||
], resultsBySession: {} };
|
||||
assert.equal(rebuildPracticeHeats(ev, { state, t, buildRaceSession }), 4);
|
||||
assert.deepEqual(state.sessions.filter((s) => s.type === "practice").map((s) => `${s.name}:${s.driverIds.length}`), ["träning 1 H1:5", "träning 1 H2:5", "träning 2 H1:5", "träning 2 H2:5"]);
|
||||
assert.ok(state.sessions.some((s) => s.id === "q"), "qualifying untouched");
|
||||
});
|
||||
|
||||
test("practice heats: never rebuilt once one has run", () => {
|
||||
const state = { sessions: [{ id: "p", eventId: "e1", name: "träning 1", type: "practice", status: "finished", startedAt: 1, driverIds: [] }], resultsBySession: {} };
|
||||
assert.equal(rebuildPracticeHeats(event(10, 5), { state, t, buildRaceSession }), -1);
|
||||
assert.equal(state.sessions[0].id, "p");
|
||||
});
|
||||
|
||||
test("practice heats: a new participant joins the smallest heat of every round", () => {
|
||||
const sessions = buildPracticeHeats(event(9, 5), 2, { t, buildRaceSession });
|
||||
syncParticipantsToSessions(sessions, drivers(9), [...drivers(9), "new"]);
|
||||
const withNew = sessions.filter((s) => s.driverIds.includes("new")).map((s) => s.name);
|
||||
assert.deepEqual(withNew, ["träning 1 H2", "träning 2 H2"]);
|
||||
assert.deepEqual(parsePracticeHeatName("practice 3 H2"), { round: 3, heat: 2 });
|
||||
});
|
||||
@@ -39,6 +39,7 @@ import "./race_timing_logic.test.js";
|
||||
import "./track_layouts_logic.test.js";
|
||||
import "./race_day_logic.test.js";
|
||||
import "./schedule_drift.test.js";
|
||||
import "./practice_heats.test.js";
|
||||
import "./race_day_export.test.js";
|
||||
import "./backup_service.test.js";
|
||||
import "./judging_logic.test.js";
|
||||
|
||||
Reference in new issue
Block a user