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

+22
View File
@@ -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;