Files
Jyotisha/frontend/tests/settings-url.test.ts
T
jesse-ux ab6c55f822 feat: keep up to five chart subjects on typed columns
Chart, ephemeris, reports, daily language, consult, and synastry read birth data only through resolveSubjectBirth. The current person is a request parameter outside Home(). /people replaces the settings chart pane, and deleting someone removes that person's chats and reports.
2026-09-25 04:19:05 +08:00

58 lines
2.3 KiB
TypeScript

import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import test from "node:test";
import { CHART_SETTINGS_HREF, parseSettingsQuery, stripSettingsQuery } from "../src/lib/settings-url.ts";
test("parses a billing settings query with source, plan and tab", () => {
const query = parseSettingsQuery("?settings=billing&source=legacy&plan=monthly&tab=orders");
assert.deepEqual(query, {
pane: "billing",
source: "legacy",
plan: "monthly",
tab: "orders",
});
});
test("returns null when the settings pane is absent or not billing", () => {
assert.equal(parseSettingsQuery(""), null);
assert.equal(parseSettingsQuery("?c=11111111-1111-4111-8111-111111111111"), null);
assert.equal(parseSettingsQuery("?settings=profile"), null);
});
test("ignores unknown plan and tab aliases", () => {
const query = parseSettingsQuery("?settings=billing&plan=weekly&tab=invoices&source=credits");
assert.deepEqual(query, {
pane: "billing",
source: "credits",
plan: null,
tab: null,
});
});
test("parses the chart settings deep link without changing billing", () => {
assert.deepEqual(parseSettingsQuery("?settings=chart"), {
pane: "chart",
source: null,
plan: null,
tab: null,
});
assert.equal(parseSettingsQuery("?settings=profile"), null);
// 原值: CHART_SETTINGS_HREF is /?settings=chart and the home effect opens the chart pane.
// 新值: the href is /people and the home effect assigns that path.
// 原因: D8 replaces the settings deep link with the archive page.
assert.equal(CHART_SETTINGS_HREF, "/people");
const page = readFileSync(new URL("../src/app/(app)/page.tsx", import.meta.url), "utf8");
assert.match(page, /query\.pane === "chart"\) \{\s*window\.location\.assign\("\/people"\);/);
assert.match(page, /openAccountDialog\("billing", \{ source: query\.source \?\? undefined, plan: query\.plan \?\? undefined, tab: query\.tab \?\? undefined \}\)/);
assert.equal(stripSettingsQuery("?settings=chart"), "/");
});
test("strips settings fields and keeps the session query", () => {
assert.equal(
stripSettingsQuery("?settings=billing&source=legacy&c=11111111-1111-4111-8111-111111111111"),
"/?c=11111111-1111-4111-8111-111111111111",
);
assert.equal(stripSettingsQuery("?settings=billing&source=legacy&plan=yearly&tab=redeem"), "/");
});