test(spec): cover whenRoute matching, gating, and array routes

This commit is contained in:
pj committed 2026-04-27 00:05:34 +07:00
1 parent 97d7269ba5
commit cd6bc0e86f
1 file changed
+36
+36
View File
@@ -20,6 +20,7 @@ import {
taps, taps,
waitOnce, waitOnce,
weighted, weighted,
whenRoute,
} from "../src/index.ts"; } from "../src/index.ts";
import type { import type {
AccessibilityElement, AccessibilityElement,
@@ -323,6 +324,41 @@ test("keyedBy substitutes empty strings for missing children", () => {
); );
}); });
test("whenRoute returns [] when current route does not match", () => {
installFakeRuntime();
const route = { current: "home" as string | null };
let bodyCalled = false;
const generator = whenRoute(route, "ledger", () => {
bodyCalled = true;
return [Tap({ on: "id:x" })];
});
assert.deepEqual(generator.generate(), []);
assert.equal(bodyCalled, false);
});
test("whenRoute calls body when current route matches", () => {
installFakeRuntime();
const route = { current: "ledger" as string | null };
const generator = whenRoute(route, "ledger", () => [Tap({ on: "id:x" })]);
const result = generator.generate();
assert.equal(result.length, 1);
assert.equal(result[0]?.kind, "Tap");
});
test("whenRoute accepts an array of allowed routes", () => {
installFakeRuntime();
const route = { current: "add-account" as string | null };
const generator = whenRoute(route, ["home", "add-account"], () => [Tap({ on: "id:x" })]);
assert.equal(generator.generate().length, 1);
});
test("whenRoute returns [] for null route", () => {
installFakeRuntime();
const route = { current: null as string | null };
const generator = whenRoute(route, ["home"], () => [Tap({ on: "id:x" })]);
assert.deepEqual(generator.generate(), []);
});
test("default generators proxy through to the runtime", () => { test("default generators proxy through to the runtime", () => {
installFakeRuntime(); installFakeRuntime();
assert.equal(taps.__sanderlingActionGenerator, true); assert.equal(taps.__sanderlingActionGenerator, true);