| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { BUSY_LIMIT, stillBusy } from "./busy.ts"; |
| 5 | |
| 6 | test("a pressed button is busy until the status changes", () => { |
| 7 | const press = { status: "starting", at: 1_000 }; |
| 8 | assert.equal(stillBusy(press, "starting", 1_500), true); |
| 9 | assert.equal(stillBusy(press, "running", 1_500), false); |
| 10 | }); |
| 11 | |
| 12 | test("a pressed button is given back when nothing changes for a while", () => { |
| 13 | const press = { status: "starting", at: 1_000 }; |
| 14 | assert.equal(stillBusy(press, "starting", 1_000 + BUSY_LIMIT - 1), true); |
| 15 | assert.equal(stillBusy(press, "starting", 1_000 + BUSY_LIMIT), false); |
| 16 | assert.equal(BUSY_LIMIT, 20_000); |
| 17 | }); |
| 18 | |
| 19 | test("a button nobody pressed is not busy", () => { |
| 20 | assert.equal(stillBusy(null, "starting", 0), false); |
| 21 | }); |