Files
loki/scripts/test/home-load-failure.ts
Cato 2dc59d1d83 fix(home): Home says why it is empty and how to get in, instead of loading forever (#1681)
QA's seat opened /control with a session that could not read Home: the
/api/control read answered 401, `data` stayed null, and Home showed its
skeleton cards for as long as the page was open.

A failed read now shows what happened: a 401 or 403 says the browser is
not signed in (or is the wrong account) with a Sign in link back to Home;
anything else names the error with Try again.

Test: scripts/test/home-load-failure.ts.
2026-11-12 12:57:56 +01:00

35 lines
1.3 KiB
TypeScript

/**
* Home says why it is empty instead of loading forever.
*
* QA's seat (2026-11-12) opened /control with a session that could not read
* Home: /api/control answered 401, `data` stayed null, and Home showed its
* skeleton cards for as long as the page was open.
*/
import assert from "node:assert/strict";
import fs from "node:fs";
import { homeLoadFailure } from "../../src/components/control/home-parts";
const unauth = homeLoadFailure("HTTP 401");
assert.equal(unauth.action, "sign-in");
assert.match(unauth.body, /not signed in/);
assert.equal(homeLoadFailure("HTTP 403").action, "sign-in");
const broken = homeLoadFailure("HTTP 500");
assert.equal(broken.action, "retry");
assert.match(broken.body, /HTTP 500/);
const offline = homeLoadFailure("Failed to fetch");
assert.equal(offline.action, "retry");
assert.match(offline.body, /could not be reached \(Failed to fetch\)/);
const panel = fs.readFileSync("src/components/control/ControlPanel.tsx", "utf8");
assert.match(
panel,
/if \(!data\)\s*return error \? \(\s*<HomeLoadFailed error=\{error\}/,
"a failed read shows the failure, not the skeleton",
);
assert.match(
fs.readFileSync("src/components/control/home-parts.tsx", "utf8"),
/href="\/sign-in\?callbackUrl=%2Fcontrol"/,
"sign-in comes back to Home",
);
console.log("home-load-failure ok");