import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import test from "node:test"; import { CHAT_CHART_OPEN_STORAGE_KEY, CHAT_CHART_WIDTH_DEFAULT, CHAT_CHART_WIDTH_MAX, CHAT_CHART_WIDTH_MIN, CHAT_CHART_WIDTH_STORAGE_KEY, clampChatChartWidth, readStoredChatChartOpen, readStoredChatChartWidth, writeStoredChatChartOpen, writeStoredChatChartWidth, type ChatChartStorage, } from "../src/lib/chat-chart-panel-state.ts"; function memoryStorage(seed: Record = {}): ChatChartStorage & { values: Map } { const values = new Map(Object.entries(seed)); return { values, getItem: (key) => values.get(key) ?? null, setItem: (key, value) => { values.set(key, String(value)); }, }; } test("chat natal panel remembers open and width on this machine", () => { const storage = memoryStorage(); assert.equal(readStoredChatChartOpen(storage), false); assert.equal(readStoredChatChartWidth(storage), CHAT_CHART_WIDTH_DEFAULT); writeStoredChatChartOpen(true, storage); writeStoredChatChartWidth(480, storage); assert.equal(storage.values.get(CHAT_CHART_OPEN_STORAGE_KEY), "1"); assert.equal(readStoredChatChartOpen(storage), true); assert.equal(readStoredChatChartWidth(storage), 480); writeStoredChatChartOpen(false, storage); assert.equal(readStoredChatChartOpen(storage), false); assert.equal(readStoredChatChartWidth(storage), 480); }); test("chat natal panel width stays between 280 and 560", () => { assert.equal(clampChatChartWidth(10), CHAT_CHART_WIDTH_MIN); assert.equal(clampChatChartWidth(900), CHAT_CHART_WIDTH_MAX); assert.equal(clampChatChartWidth(Number.NaN), CHAT_CHART_WIDTH_DEFAULT); const storage = memoryStorage(); writeStoredChatChartWidth(12, storage); assert.equal(storage.values.get(CHAT_CHART_WIDTH_STORAGE_KEY), String(CHAT_CHART_WIDTH_MIN)); assert.equal(readStoredChatChartWidth(memoryStorage({ [CHAT_CHART_WIDTH_STORAGE_KEY]: "nope" })), CHAT_CHART_WIDTH_DEFAULT); }); test("the chat page loads the natal split only when the panel opens, and phones have no entry", () => { const page = readFileSync(new URL("../src/app/(app)/page.tsx", import.meta.url), "utf8"); const frame = readFileSync(new URL("../src/components/chat-chart-frame.tsx", import.meta.url), "utf8"); const split = readFileSync(new URL("../src/components/chat-chart-split.tsx", import.meta.url), "utf8"); assert.match(page, //); assert.match(page, //); assert.doesNotMatch(page, /react-resizable-panels|vedic-chart-svg|chat-chart-split/); assert.match(frame, /打开本命盘/); assert.match(frame, /收起本命盘/); assert.match(frame, /if \(!ready \|\| isMobile\) return null/); assert.match(frame, /import\("@\/components\/chat-chart-split"\)/); assert.match(split, /ResizablePanelGroup/); assert.match(split, /collapsible/); assert.doesNotMatch(split, /data-onboarding-draw/); });