35 lines
3.1 KiB
JavaScript
35 lines
3.1 KiB
JavaScript
import assert from "node:assert/strict";
|
|
|
|
// Results archive: "View" on a race shows the race overview, "View" on a final heat shows the
|
|
// heat - both with each driver's qualifying place and TQ for the top qualifier.
|
|
export async function runArchiveQualifyingSmoke({ evaluate, navigate, savedState, waitFor, base }) {
|
|
const seeded = await savedState();
|
|
const startedAt = Date.now() - 30 * 86400000;
|
|
const event = { id: "aq_event", name: "AQ Cup", mode: "race", date: new Date(startedAt).toISOString().slice(0, 10), raceConfig: {} };
|
|
const heat = (id, name, type, offset) => ({ id, eventId: event.id, name, type, mode: "race", status: "finished", durationMin: 5, startedAt: startedAt + offset, endedAt: startedAt + offset + 300000, driverIds: ["AQ Pole", "AQ Winner"] });
|
|
const competitor = (id, laps, offset) => ({ key: id, driverId: id, driverName: id, displayName: id, transponder: id, laps, bestLapMs: 18000, lastLapMs: 18000, startTimestamp: startedAt + offset, lastTimestamp: startedAt + offset + 300000 });
|
|
const sessions = [heat("aq_q1", "Q1 H1", "qualification", 0), heat("aq_f1", "A Final", "final", 1200000)];
|
|
await fetch(base + "/api/state", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({
|
|
...seeded,
|
|
drivers: [...seeded.drivers, { id: "AQ Pole", name: "AQ Pole", transponder: "8560001" }, { id: "AQ Winner", name: "AQ Winner", transponder: "8560002" }],
|
|
events: [...seeded.events, event],
|
|
sessions: [...seeded.sessions.map((session) => (["running", "paused"].includes(session.status) ? { ...session, status: "finished", endedAt: Date.now() } : session)), ...sessions],
|
|
resultsBySession: {
|
|
...seeded.resultsBySession,
|
|
aq_q1: { passings: [], adjustments: [], competitors: { "AQ Pole": competitor("AQ Pole", 17, 0), "AQ Winner": competitor("AQ Winner", 16, 0) } },
|
|
aq_f1: { passings: [], adjustments: [], competitors: { "AQ Winner": competitor("AQ Winner", 17, 1200000), "AQ Pole": competitor("AQ Pole", 16, 1200000) } },
|
|
},
|
|
activeSessionId: null,
|
|
}) });
|
|
|
|
await navigate("archive", "archiveDriverFilter");
|
|
await waitFor(async () => evaluate(`Boolean(document.querySelector('[data-archive-event="aq_event"]'))`), "the race is in the archive");
|
|
await evaluate(`document.querySelector('[data-archive-event="aq_event"]').click()`);
|
|
await waitFor(async () => evaluate(`Boolean(document.querySelector('[data-archive-open="aq_f1"]'))`), "the final heat is listed");
|
|
await evaluate(`document.querySelector('[data-archive-open="aq_f1"]').click()`);
|
|
await waitFor(async () => evaluate(`Boolean(document.querySelector(".archive-detail .tq-badge"))`), "the final heat shows TQ");
|
|
const rows = await evaluate(`[...document.querySelectorAll(".archive-detail tbody tr")].slice(0, 2).map((row) => [...row.children].slice(0, 3).map((cell) => cell.textContent.trim()))`);
|
|
assert.deepEqual(rows, [["1", "2", "AQ Winner"], ["2", "TQ", "AQ Pole"]], "winner qualified 2nd, the pole sitter finished 2nd");
|
|
console.log("PASS results archive: a final heat shows each driver's qualifying place with TQ for the top qualifier");
|
|
}
|