// The guard a page holding unsaved work puts in front of in-app navigation. // Run by `npm test`. import assert from "node:assert/strict"; import { test } from "node:test"; import { mayNavigate, setNavGuard } from "../src/shell/navGuard.ts"; test("with no guard every move goes ahead", () => { setNavGuard(null); assert.equal(mayNavigate("/alerts"), true); }); test("a guard that says no stops the move and is told where it was headed", () => { const asked = []; setNavGuard((to) => { asked.push(to); return false; }); assert.equal(mayNavigate("/alerts"), false); assert.deepEqual(asked, ["/alerts"]); setNavGuard(null); assert.equal(mayNavigate("/alerts"), true, "removing it lets moves through"); }); test("a guard that says yes lets the move through", () => { setNavGuard(() => true); assert.equal(mayNavigate("/jobs"), true); setNavGuard(null); });