fix(race-day): keep local state while starting or timing a heat, keep count-down voice on time (1.46.1)

This commit is contained in:
larssand committed 2026-11-01 16:16:46 +01:00
1 parent 8d27072567
commit c4163441fc
8 files changed
+119 -10

No files matched your search

+30
View File
@@ -261,3 +261,33 @@ test("fastest lap, track record and leader events use mapped effects and dynamic
assert.deepEqual(played, ["/race-sounds/sounds/effects/fastest.wav", "/race-sounds/sounds/effects/record.wav"]);
assert.deepEqual(spoken, ["Snabbast Kim 16.200", "Rekord Kim 16.200", "Ledare Kim"]);
});
test("count-down calls replace each other instead of queueing, and late ones are dropped", async () => {
const spoken = [];
const resolvers = [];
let clock = 1000;
const engine = createRaceAudioEngine({
fetchImpl: async () => ({ ok: true, json: async () => manifest }),
audioFactory: () => ({ play: () => Promise.resolve(), volume: 1 }),
speak: (text) => new Promise((resolve) => { spoken.push(text); resolvers.push(resolve); }),
now: () => clock,
getSettings: () => normalizeRaceAudioSettings(),
});
const tick = async () => { for (let i = 0; i < 20; i += 1) await new Promise((resolve) => setImmediate(resolve)); };
const count = (seconds) => engine.trigger("prologue_count", { interrupt: true, force: true, group: "prologue", maxDelayMs: 1200, voiceText: String(seconds) });
// A slow voice: "9" is still being said when "8" and "7" are due.
count(9); await tick();
count(8); await tick();
count(7); await tick();
assert.deepEqual(spoken, ["9", "8", "7"], "each new call cuts the previous one");
// A call that waited longer than its limit is never said.
// Another call holds the voice past the limit: the waiting "6" is skipped.
engine.trigger("prologue_hold", { interrupt: true, force: true, priority: "critical", voiceText: "Håll" });
await tick();
const late = count(6);
await tick();
clock += 5000;
resolvers.forEach((resolve) => resolve(true));
assert.equal(await late.voiceDone, false);
assert.ok(!spoken.includes("6"));
});