feat(practice): open practice settings with ranking by best N in a row or best X minutes (1.68.0)
This commit is contained in:
1 parent
8a8b2417fd
commit
a7d2d0b9ae
11 files changed
+243
-7
No files matched your search
@@ -0,0 +1,54 @@
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
// Open practice settings (Events → Settings on an Open Practice row): the ranking chosen there
|
||||
// re-sorts the list everywhere - here the overlay - and the setting is saved on the session.
|
||||
export async function runPracticeRankingSmoke({ evaluate, navigate, savedState, waitFor, base }) {
|
||||
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();
|
||||
const event = { id: "rk_event", name: "RK Practice", classId: "", mode: "race", raceConfig: { practiceOnly: true } };
|
||||
const startedAt = Date.now() - 600000;
|
||||
const practice = { id: "rk_practice", eventId: event.id, name: "RK Open Practice", type: "open_practice", durationMin: 600, status: "running", startedAt };
|
||||
// Fast: one quick lap, then slow. Steady: three even laps - better over 2 laps in a row.
|
||||
const laps = (id, tp, lapTimes) => {
|
||||
let ts = startedAt + 5000;
|
||||
return [{ driverId: id, driverName: id, competitorKey: id, transponder: tp, lapMs: 0, timestamp: ts, validLap: true },
|
||||
...lapTimes.map((lapMs) => { ts += lapMs; return { driverId: id, driverName: id, competitorKey: id, transponder: tp, lapMs, timestamp: ts, validLap: true }; })];
|
||||
};
|
||||
const competitor = (id, tp, lapTimes) => ({ key: id, driverId: id, driverName: id, transponder: tp, laps: lapTimes.length, bestLapMs: Math.min(...lapTimes), lastLapMs: lapTimes.at(-1), startTimestamp: startedAt });
|
||||
await patchState({
|
||||
drivers: [...seeded.drivers, { id: "RK Fast", name: "RK Fast", classId: "", transponder: "8440001" }, { id: "RK Steady", name: "RK Steady", classId: "", transponder: "8440002" }],
|
||||
events: [...seeded.events, event],
|
||||
sessions: [...seeded.sessions.map((session) => (["running", "paused"].includes(session.status) ? { ...session, status: "finished", endedAt: Date.now() } : session)), practice],
|
||||
resultsBySession: {
|
||||
...seeded.resultsBySession,
|
||||
[practice.id]: {
|
||||
passings: [...laps("RK Fast", "8440001", [17000, 25000, 25000]), ...laps("RK Steady", "8440002", [18000, 18000, 18000])].sort((a, b) => a.timestamp - b.timestamp),
|
||||
competitors: { "RK Fast": competitor("RK Fast", "8440001", [17000, 25000, 25000]), "RK Steady": competitor("RK Steady", "8440002", [18000, 18000, 18000]) },
|
||||
},
|
||||
},
|
||||
activeSessionId: practice.id,
|
||||
});
|
||||
const firstOnOverlay = () => evaluate(`document.querySelector("[data-overlay-competitor]")?.textContent || ""`);
|
||||
|
||||
await navigate("overlay", "overlayFullscreen");
|
||||
await waitFor(async () => /RK Fast/.test(await firstOnOverlay()), "best lap ranks the one quick lap first");
|
||||
|
||||
await navigate("race_setup", "raceWizardStepForm");
|
||||
await evaluate(`document.getElementById("event-edit-rk_event").click()`);
|
||||
await waitFor(async () => evaluate(`Boolean(document.querySelector('#eventEditForm [name="practiceRanking"]'))`), "settings window with ranking");
|
||||
await evaluate(`(() => { const form = document.getElementById("eventEditForm"); form.elements.date.value = "2026-01-01"; form.elements.practiceRanking.value = "consecutive"; form.elements.practiceRankLaps.value = "2"; form.elements.minLapSec.value = "10"; form.elements.maxLapSec.value = "40"; form.requestSubmit(); })()`);
|
||||
await waitFor(async () => (await savedState()).sessions.some((session) => session.id === practice.id && session.practiceRanking === "consecutive" && session.practiceRankLaps === 2), "ranking saved on the practice");
|
||||
const saved = (await savedState()).events.find((item) => item.id === event.id);
|
||||
assert.equal(saved.raceConfig.minLapMs, 10000);
|
||||
assert.equal(saved.raceConfig.maxLapMs, 40000);
|
||||
|
||||
await navigate("overlay", "overlayFullscreen");
|
||||
await waitFor(async () => /RK Steady/.test(await firstOnOverlay()), "best 2 in a row ranks the steady driver first");
|
||||
assert.match(await firstOnOverlay(), /2 (laps|varv)/);
|
||||
console.log("PASS open practice settings: ranking by best N laps in a row re-sorts the overlay");
|
||||
}
|
||||
Reference in new issue
Block a user