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>
31 lines
2.5 KiB
JavaScript
31 lines
2.5 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { getPositionChange } from "../src/overlays.js";
|
|
|
|
test("places gained or lost since the start - only for heats and finals started together", () => {
|
|
const order = ["a", "b", "c", "d", "e"];
|
|
const final = { type: "final", startMode: "position", status: "running" };
|
|
assert.equal(getPositionChange(final, order, "e", 2), 3, "started 5th, now 2nd: +3");
|
|
assert.equal(getPositionChange(final, order, "a", 3), -2, "started 1st, now 3rd: -2");
|
|
assert.equal(getPositionChange(final, order, "c", 3), 0);
|
|
assert.equal(getPositionChange(final, order, "late_entry", 1), null, "not in the start order");
|
|
assert.equal(getPositionChange({ ...final, startMode: "mass", type: "heat" }, order, "e", 1), 4);
|
|
assert.equal(getPositionChange({ ...final, status: "ready" }, order, "e", 2), null, "not before the start");
|
|
assert.equal(getPositionChange({ ...final, type: "open_practice" }, order, "e", 2), null, "practice ranks on best lap");
|
|
assert.equal(getPositionChange({ ...final, type: "qualification" }, order, "e", 2), null, "qualifying has individual clocks");
|
|
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);
|
|
});
|