Files
Live_RC/tests/browser_judging_after.js
T

45 lines
3.8 KiB
JavaScript

import assert from "node:assert/strict";
// Judging after the race: a finished qualifier can be picked under Judging (a protest, a car
// found illegal) - a time penalty with a reason and a DSQ change the result straight away.
export async function runJudgingAfterRaceSmoke({ evaluate, navigate, savedState, waitFor, base, dialogs }) {
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();
const startedAt = Date.now() - 900000;
const event = { id: "ja_event", name: "JA Cup", mode: "race", raceConfig: {} };
const heat = { id: "ja_q1", eventId: event.id, name: "Q1 H1", type: "qualification", mode: "race", status: "finished", durationMin: 5, startedAt, endedAt: startedAt + 300000 };
const competitor = (id, laps, lastTs) => ({ key: id, driverId: id, driverName: id, displayName: id, transponder: id, laps, bestLapMs: 18000, lastLapMs: 18000, startTimestamp: startedAt, lastTimestamp: lastTs });
await patchState({
drivers: [...seeded.drivers, { id: "JA Winner", name: "JA Winner", transponder: "8550001" }, { id: "JA Second", name: "JA Second", transponder: "8550002" }],
events: [...seeded.events, event],
sessions: [...seeded.sessions.map((session) => (["running", "paused"].includes(session.status) ? { ...session, status: "finished", endedAt: Date.now() } : session)), heat],
resultsBySession: { ...seeded.resultsBySession, [heat.id]: { passings: [], adjustments: [], competitors: { "JA Winner": competitor("JA Winner", 17, startedAt + 300000), "JA Second": competitor("JA Second", 16, startedAt + 301000) } } },
activeSessionId: null,
});
const competitors = async () => (await savedState()).resultsBySession.ja_q1.competitors;
await navigate("judging", "speakerPanel");
await waitFor(async () => evaluate(`Boolean(document.querySelector('#judgingSessionSelect option[value="ja_q1"]'))`), "the finished heat can be picked");
await evaluate(`(() => { const select = document.getElementById("judgingSessionSelect"); select.value = "ja_q1"; select.dispatchEvent(new Event("change")); })()`);
await waitFor(async () => evaluate(`Boolean(document.getElementById("judgeDsq"))`), "the winner is selected with the penalty buttons");
assert.match(await evaluate(`document.querySelector(".judge-selected-row")?.textContent || ""`), /JA Winner/);
assert.equal(await evaluate(`Boolean(document.querySelector("[data-judge-call]"))`), false, "no calls to the driver after the race");
await evaluate(`(() => { document.getElementById("judgeReason").value = "Unfair overtake"; document.getElementById("judgeCustomSec").value = "10"; document.getElementById("judgeCustomApply").click(); })()`);
await waitFor(async () => (await competitors())["JA Winner"].manualTimeAdjustmentMs === 10000, "+10 s saved");
assert.ok((await savedState()).resultsBySession.ja_q1.adjustments.some((entry) => entry.reason === "Unfair overtake"), "the reason is logged");
await evaluate(`document.getElementById("judgeDsq").click()`);
await waitFor(async () => (await competitors())["JA Winner"].raceStatus === "dsq", "DSQ saved");
await waitFor(async () => /JA Second/.test(await evaluate(`document.querySelector("#judgingCompetitorFilter")?.closest(".panel")?.querySelector("tbody tr")?.textContent || ""`)), "the disqualified winner drops to last");
assert.ok(dialogs.slice(dialogsAtStart).some((dialog) => dialog.type === "confirm" && /JA Winner/.test(dialog.message)), "DSQ asks first");
dialogs.splice(dialogsAtStart);
console.log("PASS judging after the race: pick a finished heat, +10 s with a reason, DSQ puts the driver last");
}