Files
Jyotisha/frontend/tests/profile-state.test.ts
Jesse_Chen 1084dce770
Independent Staging Quality Gate / validate (push) Failing after 11m57s
Independent Staging Quality Gate / publish (push) Has been skipped
fix: avoid repeated daily starlanguage refresh
2026-08-15 23:28:49 +08:00

53 lines
1.6 KiB
TypeScript

import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import test from "node:test";
import { preserveShallowEqual } from "../src/lib/preserve-shallow-equal.ts";
const pageSource = readFileSync(new URL("../src/app/page.tsx", import.meta.url), "utf8");
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 updateSession", refreshAccountStart),
);
assert.match(
refreshAccountSource,
/setProfile\(\(current\) => preserveShallowEqual\(current, nextProfile\)\)/,
);
assert.doesNotMatch(refreshAccountSource, /setProfile\(nextProfile\)/);
});