feat(overlay): click a driver to open their training stats

In RaceCore's own overlay a driver row opens Training stats for that
driver and class; the stand-alone overlay window opens them in a new tab.
The public overlay gets no links: the mobile profile link is personal
and can write.
This commit is contained in:
larssand committed 2026-10-22 10:05:24 +02:00
1 parent cade201d5a
commit 4def444202
8 files changed
+105 -3

No files matched your search

+58
View File
@@ -0,0 +1,58 @@
import assert from "node:assert/strict";
// Overlay -> a driver's own training stats in one click. In the menu's Overlay it switches to
// Training stats with that driver; the stand-alone overlay window opens them in a new tab; the
// public overlay has no links (the mobile profile link is personal and can write).
export async function runOverlayDriverLinkSmoke({ evaluate, navigate, savedState, waitFor, base, send }) {
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() - 120000;
const passings = [21000, 20500].map((lapMs, index) => ({ driverId: "ol_driver", driverName: "OL Driver", competitorKey: "driver_ol_driver", transponder: "8550001", lapMs, timestamp: startedAt + (index + 1) * 21000, validLap: true }));
await patchState({
classes: [...seeded.classes, { id: "ol_class", name: "OL Class" }],
drivers: [...seeded.drivers, { id: "ol_driver", name: "OL Driver", classId: "ol_class", transponder: "8550001" }],
events: [...seeded.events, { id: "ol_event", name: "OL Practice", classId: "ol_class", mode: "race", raceConfig: { practiceOnly: true } }],
sessions: [...seeded.sessions.map((session) => (["running", "paused"].includes(session.status) ? { ...session, status: "finished", endedAt: Date.now() } : session)), { id: "ol_practice", eventId: "ol_event", name: "OL Open Practice", type: "open_practice", durationMin: 600, status: "running", startedAt }],
resultsBySession: { ...seeded.resultsBySession, ol_practice: { passings, competitors: { driver_ol_driver: { key: "driver_ol_driver", driverId: "ol_driver", driverName: "OL Driver", displayName: "OL Driver", transponder: "8550001", laps: 2, lastLapMs: 20500, bestLapMs: 20500, startTimestamp: startedAt, lastTimestamp: startedAt + 42000 } } } },
activeSessionId: "ol_practice",
});
const row = `document.querySelector('[data-training-driver="ol_driver"]')`;
try {
// The menu's Overlay: switches view in place.
await navigate("dashboard", "view");
await evaluate(`[...document.querySelectorAll(".nav-item")].find((button) => /^Overlay$/.test(button.textContent.trim())).click()`);
await waitFor(async () => evaluate(`Boolean(${row})`), "the driver row is a link in the menu's Overlay");
await evaluate(`${row}.querySelector("strong").click()`);
await waitFor(async () => (await evaluate(`location.search`)).includes("view=training"), "Training stats opened");
const search = await evaluate(`location.search`);
// Training stats group a person's driver records (one per class) into one profile.
assert.equal(new URLSearchParams(search).get("driver"), "legacy:ol driver", "OL Driver's profile is selected");
assert.match(search, /class=ol_class/);
assert.match(await evaluate(`document.getElementById("view").innerText`), /OL Driver/, "the driver's own stats are shown");
console.log("PASS a click on a driver in the Overlay opens that driver's training stats");
// The stand-alone overlay window stays up and opens a new tab.
await navigate("overlay", "view");
await waitFor(async () => evaluate(`Boolean(${row})`), "the driver row is a link in the overlay window");
await evaluate(`window.__opened = []; window.open = (url, target) => { window.__opened.push([url, target]); return null; }; ${row}.click()`);
const [openedUrl, target] = (await evaluate(`window.__opened`))[0];
assert.equal(target, "_blank");
assert.match(openedUrl, /view=training&driver=ol_driver&class=ol_class/);
assert.equal(await evaluate(`new URLSearchParams(location.search).get("view")`), "overlay", "the overlay window stays on the overlay");
console.log("PASS the stand-alone overlay window opens the driver's stats in a new tab");
// The public overlay: no links.
await send("Page.navigate", { url: base + "/public-overlay/leaderboard" });
await waitFor(async () => evaluate(`Boolean(document.querySelector('[data-overlay-competitor="driver_ol_driver"]'))`), "public overlay shows the driver");
assert.equal(await evaluate(`Boolean(document.querySelector("[data-training-driver]"))`), false, "no training links on the public overlay");
console.log("PASS the public overlay has no links to drivers' stats");
} finally {
const current = await savedState();
await patchState({ sessions: current.sessions.map((session) => (session.id === "ol_practice" ? { ...session, status: "finished", endedAt: Date.now() } : session)), activeSessionId: "" });
}
}