fix(timing): keep timing the running session when another one is selected
Passings and the session clock followed only the selected session, so selecting another practice or the next heat while one was running dropped every lap. They now go to the running session, and Timing and Race Day show where laps are being recorded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cdde070c1c
commit
3a6789f42f
13 files changed
+137
-13
No files matched your search
@@ -0,0 +1,48 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import { runDriversPageSmoke } from "./browser_drivers_page.js";
|
||||
import { runSeriesSmoke } from "./browser_series.js";
|
||||
import { runTrainingSourceSmoke } from "./browser_training_source.js";
|
||||
import { runDecoderUrlSmoke } from "./browser_decoder_url.js";
|
||||
import { runLiveSessionSmoke } from "./browser_live_session.js";
|
||||
import { runObsPopupSmoke } from "./browser_obs_popup.js";
|
||||
import { runDecoderReconnectSmoke } from "./browser_decoder_reconnect.js";
|
||||
import assert from "node:assert/strict";
|
||||
@@ -166,6 +167,7 @@ try {
|
||||
await runSeriesSmoke({ evaluate, navigate, savedState, waitFor, base, dialogs });
|
||||
await runTrainingSourceSmoke({ evaluate, navigate, savedState, waitFor, base });
|
||||
await runDecoderUrlSmoke({ evaluate, navigate, savedState, waitFor, base });
|
||||
await runLiveSessionSmoke({ evaluate, navigate, savedState, waitFor, base });
|
||||
await runRaceDaySmoke({ evaluate, navigate, fill, savedState, waitFor, pause, base, dialogs });
|
||||
await runRaceDayStartSequencesSmoke({ evaluate, navigate, waitFor, pause, base, dialogs });
|
||||
await runObsPopupSmoke({ evaluate, navigate, fill, savedState, waitFor, pause, base, debugPort, dialogs, realClick });
|
||||
|
||||
@@ -16,3 +16,15 @@ test("places gained or lost since the start - only for heats and finals started
|
||||
assert.equal(getPositionChange({ ...final, startMode: "flying" }, order, "e", 2), null, "no common start order");
|
||||
assert.equal(getPositionChange(null, order, "e", 2), null);
|
||||
});
|
||||
|
||||
test("laps go to the session actually running when another one is selected", async () => {
|
||||
const { getLiveSession } = await import("../src/timing_logic.js");
|
||||
const session = (id, status, startedAt = 0) => ({ id, status, startedAt });
|
||||
const state = (activeSessionId, sessions) => ({ activeSessionId, sessions });
|
||||
assert.equal(getLiveSession({ state: state("b", [session("a", "running", 1), session("b", "running", 2)]) }).id, "b", "the selected session when it runs");
|
||||
assert.equal(getLiveSession({ state: state("next", [session("heat", "running", 5), session("next", "ready")]) }).id, "heat", "next heat picked while the current one runs");
|
||||
assert.equal(getLiveSession({ state: state("op2", [session("op1", "running", 5), session("op2", "ready"), session("old", "running", 1)]) }).id, "op1", "the most recently started running session");
|
||||
assert.equal(getLiveSession({ state: state("b", [session("a", "paused", 3), session("b", "finished")]) }).id, "a", "a paused session still counts as live");
|
||||
assert.equal(getLiveSession({ state: state("b", [session("a", "finished"), session("b", "ready")]) }).id, "b", "nothing running: the selected one");
|
||||
assert.equal(getLiveSession({ state: state("", []) }), null);
|
||||
});
|
||||
Reference in new issue
Block a user