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:
1 parent
cade201d5a
commit
4def444202
8 files changed
+105
-3
No files matched your search
@@ -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: "" });
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import { runTrackLayoutsSmoke } from "./browser_track_layouts.js";
|
||||
import { runPrologueSmoke } from "./browser_prologue.js";
|
||||
import { runPracticeResetSmoke } from "./browser_practice_reset.js";
|
||||
import { runSuspectLapsSmoke } from "./browser_suspect_laps.js";
|
||||
import { runOverlayDriverLinkSmoke } from "./browser_overlay_driver_link.js";
|
||||
import { runCorrectionsScopeSmoke } from "./browser_corrections_scope.js";
|
||||
import { runDriversPageSmoke } from "./browser_drivers_page.js";
|
||||
import { runSeriesSmoke } from "./browser_series.js";
|
||||
@@ -163,6 +164,7 @@ try {
|
||||
await runPrologueSmoke({ evaluate, navigate, savedState, waitFor, base, dialogs });
|
||||
await runPracticeResetSmoke({ evaluate, navigate, savedState, waitFor, base, dialogs });
|
||||
await runSuspectLapsSmoke({ evaluate, navigate, savedState, waitFor, base, dialogs });
|
||||
await runOverlayDriverLinkSmoke({ evaluate, navigate, savedState, waitFor, base, send });
|
||||
await runCorrectionsScopeSmoke({ evaluate, navigate, savedState, waitFor, base });
|
||||
await runDriversPageSmoke({ evaluate, navigate, savedState, waitFor, base });
|
||||
await runSeriesSmoke({ evaluate, navigate, savedState, waitFor, base, dialogs });
|
||||
|
||||
Reference in new issue
Block a user