Files
CatoandClaude d88cab3923 feat(notifications): turn this phone's push on, prove it, turn it off (#1212)
Production held ZERO subscribed push devices (the messaging doctor,
2026-10-15): the server could send a push, the VAPID keys and the service
worker were in place, and no screen anywhere offered a phone the choice —
usePushSubscription was imported by nothing. A new report on a site
reached no device, and said so only in a log line.

- Settings → Notifications gets an "On this phone" card: Turn on, Send a
  test, Turn off, with a plain sentence for every state (not asked,
  working, on, blocked by the browser, unsupported — with the iPhone
  Add-to-Home-Screen fix — error with retry, server has no key).
  Pure view logic (lib/push-card.ts) is pinned by scripts/test/push-card.ts;
  copy is SSOT in config/comms.ts.
- GET /api/push/public-key hands out the server's own VAPID_PUBLIC_KEY, so
  a phone no longer subscribes against a key inlined at build time that a
  build can lose or leave stale; POST /api/push/test sends one test push
  and names the failed precondition instead of a bare zero.
- The page-render harness is now a shared core (render-harness.mjs) with a
  thin script per page; the push card has one, and rendering it is how a
  filled button 8px shorter than its neighbour, and under 44px, was caught
  and fixed.


Claude-Session: https://claude.ai/code/session_01NJJp6XiUkeEVzjDaBmWjL3

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-15 05:21:22 -07:00

56 lines
2.3 KiB
TypeScript

// The "notifications on this phone" card: every state the browser can be in
// says what is true and offers a way forward — a state with neither is the dead
// end this card exists to remove (production held zero subscribed devices
// because no screen ever offered the choice).
import assert from "node:assert/strict";
import { pushCardView, type PushStatus } from "../../src/lib/push-card";
const STATUSES: PushStatus[] = [
"unsupported",
"denied",
"default",
"granted",
"subscribed",
"registering",
"error",
];
const base = { keyMissing: false, isIos: false, error: null };
// Every state has words; every state a person can act in has a button.
for (const status of STATUSES) {
const v = pushCardView({ ...base, status });
assert.ok(v.headline.length > 0 && v.body.length > 0, `${status}: says something`);
if (status === "default" || status === "granted" || status === "error") {
assert.equal(v.primary?.action, "subscribe", `${status}: the way forward is Turn on`);
}
}
// Subscribed: proof and an exit, and it reads as working.
const on = pushCardView({ ...base, status: "subscribed" });
assert.equal(on.tone, "on");
assert.equal(on.primary?.action, "test", "a working channel can be tested");
assert.equal(on.secondary?.action, "unsubscribe", "and turned off");
// Blocked and unsupported cannot be fixed by a button here — they say what to do instead.
const denied = pushCardView({ ...base, status: "denied" });
assert.equal(denied.primary, null);
assert.match(denied.body, /site settings/i, "denied names where to change it");
// iPhone Safari: the one fix is Add to Home Screen, and the card says so.
const ios = pushCardView({ ...base, status: "unsupported", isIos: true });
assert.match(ios.body, /Home Screen/);
const other = pushCardView({ ...base, status: "unsupported", isIos: false });
assert.doesNotMatch(other.body, /Home Screen/, "no iPhone advice for other browsers");
// A server with no key cannot subscribe anyone, whatever the browser says.
const noKey = pushCardView({ ...base, status: "default", keyMissing: true });
assert.equal(noKey.primary, null);
assert.match(noKey.headline, /aren't set up/i);
// An error names itself but still offers a retry.
const err = pushCardView({ ...base, status: "error", error: "boom" });
assert.match(err.body, /boom/);
assert.equal(err.primary?.action, "subscribe");
console.log("push-card: ok");