Files
Jyotisha/frontend/tests/profile-state.test.ts
T
Jesse_Chen bf6989eccf refactor(chat): extract profile onboarding and rectification surface hooks
Close the home-page split by moving account/onboarding and rectification glue out of page.tsx without relocating React state, keeping the route static and hook order intact.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-02 05:56:58 +08:00

51 lines
1.6 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import { preserveShallowEqual } from "../src/lib/preserve-shallow-equal.ts";
import { homeSurface as pageSource } from "./home-surface.ts";
test("preserves the current profile reference when refreshed values are unchanged", () => {
const current = {
name: "测试用户",
date: "2000-01-01",
time: "",
birthTimeSource: "period_only",
birthTimePeriod: "evening",
timezoneId: "Asia/Shanghai",
latitude: 31.23,
longitude: 121.47,
timezoneOffset: null,
};
const refreshed = { ...current };
assert.notEqual(refreshed, current);
assert.equal(preserveShallowEqual(current, refreshed), current);
});
test("uses the refreshed profile reference when a value changed", () => {
const current = {
name: "测试用户",
birthTimePeriod: "evening",
timezoneId: "Asia/Shanghai",
};
const refreshed = {
...current,
birthTimePeriod: "morning",
};
assert.equal(preserveShallowEqual(current, refreshed), refreshed);
});
test("account refresh preserves an equivalent normalized profile instead of replacing it", () => {
const refreshAccountStart = pageSource.indexOf("async function refreshAccount()");
const refreshAccountSource = pageSource.slice(
refreshAccountStart,
pageSource.indexOf("function openAccountDialog", refreshAccountStart),
);
assert.match(
refreshAccountSource,
/setProfile\(\(current\) => preserveShallowEqual\(current, nextProfile\)\)/,
);
assert.doesNotMatch(refreshAccountSource, /setProfile\(nextProfile\)/);
});