Files
dbx/packages/app-tests/actionActivation.test.ts
T
t8y2 fabf2172e4 chore: migrate test runner from node:test/tsx to vitest
155 files, 1091 tests, 4.3s (2x faster than previous 9.1s).
2026-06-08 01:17:27 +08:00

36 lines
1.1 KiB
TypeScript

import { strict as assert } from "node:assert";
import { test } from "vitest";
import { shouldSuppressRepeatedActivation, tryStartExclusiveActivation } from "../../apps/desktop/src/lib/actionActivation.ts";
test("allows the first activation", () => {
const guard = {};
assert.equal(shouldSuppressRepeatedActivation(guard, 1000), false);
});
test("suppresses repeated activation inside the guard window", () => {
const guard = {};
assert.equal(shouldSuppressRepeatedActivation(guard, 1000, 500), false);
assert.equal(shouldSuppressRepeatedActivation(guard, 1200, 500), true);
});
test("allows activation after the guard window", () => {
const guard = {};
assert.equal(shouldSuppressRepeatedActivation(guard, 1000, 500), false);
assert.equal(shouldSuppressRepeatedActivation(guard, 1600, 500), false);
});
test("exclusive activation blocks concurrent starts until finished", () => {
const guard = {};
const finish = tryStartExclusiveActivation(guard);
assert.equal(typeof finish, "function");
assert.equal(tryStartExclusiveActivation(guard), null);
finish?.();
assert.equal(typeof tryStartExclusiveActivation(guard), "function");
});