import assert from "node:assert/strict"; import { startFakeDecoder } from "./browser_fake_decoder.js"; // The user's case: an Open Practice is running, another session gets selected (another // practice, or the next heat on Race Day). Passings used to be dropped as "no running // session"; they must keep going to the running one, and the page must say so. export async function runLiveSessionSmoke({ 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 decoder = await startFakeDecoder(); const seeded = await savedState(); const startedAt = Date.now() - 60000; const running = { id: "ls_running", eventId: "ls_event", name: "LS Practice A", type: "open_practice", status: "running", startedAt, durationMin: 600 }; const selected = { id: "ls_selected", eventId: "ls_event", name: "LS Practice B", type: "open_practice", status: "ready", durationMin: 600 }; await patchState({ events: [...seeded.events, { id: "ls_event", name: "LS Club", mode: "race", raceConfig: { practiceOnly: true } }], drivers: [...seeded.drivers, { id: "ls_driver", name: "LS Driver", transponder: "8880001" }], sessions: [...seeded.sessions.map((session) => (["running", "paused"].includes(session.status) ? { ...session, status: "finished", endedAt: Date.now() } : session)), running, selected], activeSessionId: selected.id, settings: { ...seeded.settings, autoReconnect: true, wsUrl: `ws://127.0.0.1:${decoder.port}` }, }); try { await navigate("timing", "resetSession"); await waitFor(async () => evaluate('document.getElementById("connectionBadge")?.classList.contains("badge-online")'), "decoder connected"); await waitFor(async () => (await evaluate(`document.getElementById("liveElsewhereBanner")?.textContent || ""`)).includes("LS Practice A"), "the page says laps go to the running practice"); decoder.sendPassing("8880001", startedAt + 20000); await waitFor(async () => ((await savedState()).resultsBySession?.ls_running?.passings || []).length === 1, "the passing is counted on the running practice, not dropped"); assert.equal(((await savedState()).resultsBySession?.ls_selected?.passings || []).length, 0, "nothing on the selected, not-started one"); await evaluate(`document.querySelector("[data-show-live]").click()`); await waitFor(async () => (await savedState()).activeSessionId === running.id, "Show it selects the running session"); await waitFor(async () => !(await evaluate(`Boolean(document.getElementById("liveElsewhereBanner"))`)), "notice gone once it is selected"); console.log("PASS passings keep going to the running session when another one is selected, and the page says so"); } finally { const current = await savedState(); await patchState({ settings: { ...current.settings, autoReconnect: false }, sessions: current.sessions.filter((session) => !session.id.startsWith("ls_")), events: current.events.filter((event) => event.id !== "ls_event"), drivers: current.drivers.filter((driver) => driver.id !== "ls_driver"), activeSessionId: "", }); await decoder.close(); } }