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:
1 parent
8d27072567
commit
c4163441fc
8 files changed
+119
-10
No files matched your search
@@ -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"));
|
||||
});
|
||||
@@ -183,6 +183,28 @@ test("successful backend hydration applies state without scheduling a write-back
|
||||
assert.equal(backend.lastSyncAt, "2026-08-24T10:00:00.000Z");
|
||||
});
|
||||
|
||||
test("hydration never replaces a newer local state: a lap or start made while the request was out, or a race run here", async () => {
|
||||
const run = async ({ keepLocal = () => false, bumpDuringFetch = false }) => {
|
||||
let version = 1;
|
||||
const applied = [];
|
||||
await withMockFetch(
|
||||
async () => {
|
||||
if (bumpDuringFetch) version += 1; // e.g. a passing saved while the request was out
|
||||
return { ok: true, json: async () => ({ state: { sessions: [{ id: "q1", status: "ready" }] } }) };
|
||||
},
|
||||
() => hydrateFromBackendHelper({
|
||||
backend: { available: true }, t: (key) => key, getBackendUrl: () => "http://race:8081",
|
||||
applyPersistedState: (state) => applied.push(state), saveState: () => {},
|
||||
getLocalStateVersion: () => version, keepLocal,
|
||||
})
|
||||
);
|
||||
return applied.length;
|
||||
};
|
||||
assert.equal(await run({}), 1, "an idle browser is refreshed");
|
||||
assert.equal(await run({ bumpDuringFetch: true }), 0, "a change made during the request wins");
|
||||
assert.equal(await run({ keepLocal: () => true }), 0, "a browser starting or timing a heat keeps its own state");
|
||||
});
|
||||
|
||||
test("failed hydration preserves local state and reports backend offline", async () => {
|
||||
const backend = { available: true, lastError: "" };
|
||||
let applied = false;
|
||||
|
||||
Reference in new issue
Block a user