Files
Jyotisha/frontend/tests/chart-library-session.test.ts
ClaudeandClaude Opus 5.5 8ae116d303
Independent Staging Quality Gate / validate-frontend (push) Failing after 3m16s
Independent Staging Quality Gate / validate-python (push) Successful in 5m54s
Independent Staging Quality Gate / publish (push) Skipped
feat(ux): novice walkthrough pass — onboarding, settings flash, type scale B (BUG-1662, BUG-1663, BUG-1664, BUG-1670)
Walked sign-up → profile → chart → question → answer as a first-time user
and fixed what got in the way:

- 星盘档案 showed 「出生时间待补全」 for a reported time the chart already
  draws at; period profiles showed the raw key (BUG-1662).
- Phone header: title, person chip and guide pill overlapped at 360–390px
  (BUG-1663).
- Birth time: a recorded time no longer demands an earliest/latest range;
  design B folds the six sources into one row with 更改 (BUG-1664). Intake
  hints trimmed with the owner's approval.
- Page switch rendered the new page twice; the copy in the leaving slot took
  /?account=… and its dialog vanished with it (BUG-1670). The leaving page now
  keeps its own router context.
- 新手指引 design C: 「下一步:…」 pill plus count, no prices, no 去做 buttons;
  short labels on narrow phones. 「这次提问免费」 removed.
- Login: consent box above the button, 「登录或注册」, plain two-step copy.
- Place: no false 「搜索」 claim, 北纬/东经 first, UTC offset with 夏令时 note,
  Chinese country names in pinyin order.
- One name 「生时纠正」 on user-facing copy; middle dots off the main path;
  calmer delete and error styles; no frosted glass or in-page card shadows.
- Type scale B: every page uses 13 / 16 / 20 / 28 px (chart drawings excepted).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXozbkyFNqbu8pVEtZ7W
2026-11-06 20:53:42 +08:00

122 lines
5.0 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import {
chartLibraryFromCloudOthers,
chartLibraryOnCloudFailure,
chartLibrarySessionBranch,
} from "../src/lib/chart-library-session.ts";
import { sessionSidebarSubtitle, sessionSidebarTitle, toSidebarSessionRow } from "../src/lib/session-sidebar-row.ts";
import { emptyProfile, type ChartLibraryRecord, type ChatSession } from "../src/lib/home-types.ts";
type RecordShape = { id: string; role: "self" | "other" };
function upsertSelf(library: RecordShape[], profile: unknown): RecordShape[] {
const others = library.filter((record) => record.role !== "self");
if (!profile) return others;
return [{ id: "self", role: "self" }, ...others];
}
// 2026-11-06 主路径去掉中间点:日期、时间、地点用空格隔开;「资料已删除 · 名字」→「名字(资料已删除)」;「名字 · 本命盘」→「名字的本命盘」;地点按「浙江省杭州市西湖区」连写
test("clearing the account empties the chart library session", () => {
assert.equal(chartLibrarySessionBranch(null, "acct-1"), "clear");
assert.equal(chartLibrarySessionBranch("", "acct-1"), "clear");
});
test("switching accounts hydrates local then cloud instead of writing the previous library", () => {
assert.equal(chartLibrarySessionBranch("acct-2", "acct-1"), "hydrate-then-persist");
});
test("a later profile change on the same account still upserts self", () => {
assert.equal(chartLibrarySessionBranch("acct-1", "acct-1"), "persist-self");
const current: RecordShape[] = [{ id: "other-1", role: "other" }];
assert.deepEqual(upsertSelf(current, { name: "self" }), [
{ id: "self", role: "self" },
{ id: "other-1", role: "other" },
]);
});
test("a successful cloud read keeps only non-self records before upserting self", () => {
const cloud: RecordShape[] = [
{ id: "stale-self", role: "self" },
{ id: "other-1", role: "other" },
];
assert.deepEqual(chartLibraryFromCloudOthers(cloud, { name: "self" }, upsertSelf), [
{ id: "self", role: "self" },
{ id: "other-1", role: "other" },
]);
});
test("a failed cloud read keeps only the profile-derived self chart", () => {
// Former value: keepLocalChartLibraryOnCloudFailure(local) === local.
// Local other-charts are no longer a fallback when the cloud read fails.
const local: RecordShape[] = [{ id: "self", role: "self" }, { id: "other-1", role: "other" }];
assert.notDeepEqual(chartLibraryOnCloudFailure({ name: "self" }, upsertSelf), local);
assert.deepEqual(chartLibraryOnCloudFailure({ name: "self" }, upsertSelf), [
{ id: "self", role: "self" },
]);
});
test("sidebar titles drop the chart-name prefix and only subtitle others", () => {
// 原值:本人盘副标题 null;他人盘只有资料名
// 新值:一律「M月D日 HH:MM」,他人盘再加「 · 盘主」
// 原因:任务书 T4 副标题规则
const createdAt = Date.parse("2026-09-14T04:14:00.000Z");
const selfRecord: ChartLibraryRecord = {
id: "self",
role: "self",
relationship: "self",
updatedAt: 1,
profile: { ...emptyProfile, name: "本人" },
};
const library: ChartLibraryRecord[] = [selfRecord];
const base: ChatSession = {
id: "11111111-1111-4111-8111-111111111111",
title: "半年内换工作时机",
theme: "career",
modelId: "m",
messages: [],
createdAt,
updatedAt: createdAt,
sessionType: "consultation",
rectificationCaseId: null,
chartProfileId: "self",
chartProfileName: "本人",
chartProfileRole: "self",
pinned: false,
archivedAt: null,
messagesHydrated: true,
};
// 原值: sessionSidebarTitle(base, library)
// 新值: sessionSidebarTitle(base)
// 原因: sessionSidebarTitle 只吃 session;第二参是 e4e73f56 的 TS 错,挡住 tsc / next build
assert.equal(sessionSidebarTitle(base), "半年内换工作时机");
assert.equal(sessionSidebarSubtitle(base, library), "9月14日 12:14");
const other = { ...base, chartProfileId: "other-1", chartProfileName: "对方", chartProfileRole: "other" as const };
assert.equal(sessionSidebarSubtitle(other, library), "9月14日 12:14 · 对方(资料已删除)");
const liveOtherLibrary: ChartLibraryRecord[] = [{
...selfRecord,
id: "other-1",
role: "other",
relationship: "partner",
profile: { ...emptyProfile, name: "对方" },
}];
assert.equal(sessionSidebarSubtitle(other, liveOtherLibrary), "9月14日 12:14 · 对方");
const renamedLibrary: ChartLibraryRecord[] = [{
...selfRecord,
id: "other-1",
role: "other",
relationship: "partner",
profile: { ...emptyProfile, name: "新名字" },
}];
assert.equal(sessionSidebarSubtitle(other, renamedLibrary), "9月14日 12:14 · 新名字");
assert.equal(other.chartProfileName, "对方");
assert.deepEqual(toSidebarSessionRow(other, liveOtherLibrary), {
id: other.id,
title: "半年内换工作时机",
subtitle: "9月14日 12:14 · 对方",
pinned: false,
updatedAt: createdAt,
});
});