Files
Jyotisha/frontend/tests/chart-library-session.test.ts
T
Jesse_Chen 3198fb6b2b
Independent Staging Quality Gate / validate (push) Successful in 10m14s
Independent Staging Quality Gate / publish (push) Successful in 11m5s
perf(frontend): split chat streaming, load Inter, isolate admin CSS
Settled messages no longer rebuild on every token, Inter is actually
requested, and admin routes drop the 33 KB chat stylesheet. Root
force-dynamic is gone so public shells can prerender without changing
the no-store Cache-Control contract.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-29 03:39:43 +08:00

51 lines
1.9 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import {
chartLibraryFromCloudOthers,
chartLibrarySessionBranch,
keepLocalChartLibraryOnCloudFailure,
} from "../src/lib/chart-library-session.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];
}
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 leaves the local library in place", () => {
const local: RecordShape[] = [{ id: "self", role: "self" }, { id: "other-1", role: "other" }];
assert.equal(keepLocalChartLibraryOnCloudFailure(local), local);
});