37 lines
2.5 KiB
JavaScript
37 lines
2.5 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { decoderAlarm, silentLimitMs } from "../src/decoder_watch.js";
|
|
|
|
const t0 = 1_000_000;
|
|
const running = { status: "running", startedAt: t0 };
|
|
|
|
test("no alarm outside a running heat or its count-down", () => {
|
|
assert.equal(decoderAlarm({ connected: false, disconnectedAt: t0 }, { status: "finished" }, { now: t0 + 60000 }).kind, "ok");
|
|
assert.equal(decoderAlarm({ connected: false, disconnectedAt: t0 }, { status: "paused", startedAt: t0 }, { now: t0 + 60000 }).kind, "ok");
|
|
assert.equal(decoderAlarm({ connected: false }, null, { now: t0 }).kind, "ok");
|
|
});
|
|
|
|
test("lost: the decoder link drops during the heat or the count-down, after 3 s", () => {
|
|
assert.equal(decoderAlarm({ connected: false, disconnectedAt: t0 + 60000 }, running, { now: t0 + 61000 }).kind, "ok", "quick reconnect window");
|
|
assert.deepEqual(decoderAlarm({ connected: false, disconnectedAt: t0 + 60000 }, running, { now: t0 + 65000 }), { kind: "lost", sinceMs: 5000 });
|
|
assert.equal(decoderAlarm({ connected: false }, { status: "ready" }, { startPending: true, now: t0 }).kind, "lost", "never connected during the count-down");
|
|
});
|
|
|
|
test("silent: connected but no passing for 30 s, or 3 best laps", () => {
|
|
assert.equal(silentLimitMs(0), 30000);
|
|
assert.equal(silentLimitMs(18000), 54000);
|
|
const decoder = { connected: true, lastPassingAt: t0 + 40000 };
|
|
assert.equal(decoderAlarm(decoder, running, { now: t0 + 65000 }).kind, "ok");
|
|
assert.deepEqual(decoderAlarm(decoder, running, { now: t0 + 71000 }), { kind: "silent", sinceMs: 31000 });
|
|
assert.equal(decoderAlarm(decoder, running, { bestLapMs: 18000, now: t0 + 71000 }).kind, "ok", "slow track: 3 laps of 18 s");
|
|
assert.equal(decoderAlarm({ connected: true }, running, { now: t0 + 20000 }).kind, "ok", "first 30 s after the start");
|
|
assert.equal(decoderAlarm({ connected: true, lastPassingAt: t0 - 99999 }, running, { now: t0 + 45000 }).kind, "silent", "a passing before the start doesn't count");
|
|
assert.equal(decoderAlarm({ connected: true }, { status: "ready" }, { startPending: true, now: t0 + 99999 }).kind, "ok", "no silence alarm before the start");
|
|
});
|
|
|
|
test("practice: no silence alarm (nobody may be driving), but a dropped link still alarms", () => {
|
|
const practice = { status: "running", startedAt: t0, type: "open_practice" };
|
|
assert.equal(decoderAlarm({ connected: true }, practice, { now: t0 + 600000 }).kind, "ok");
|
|
assert.equal(decoderAlarm({ connected: false, disconnectedAt: t0 + 1000 }, practice, { now: t0 + 9000 }).kind, "lost");
|
|
});
|