bf6989eccf
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>
51 lines
1.6 KiB
TypeScript
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\)/);
|
|
});
|