feat(canvas): 画布主题 - 与工作台外观隔离并提高连线对比

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
ddCat
2026-09-16 22:59:34 +08:00
parent 9868f5e8b8
commit f394cd7385
54 changed files with 207 additions and 134 deletions

View File

@@ -0,0 +1,36 @@
import { afterEach, describe, expect, test } from "bun:test";
import { useThemeStore } from "../src/stores/use-theme-store";
import { useCanvasThemeStore } from "../src/stores/canvas/use-canvas-theme-store";
const workspaceBefore = useThemeStore.getState().theme;
const canvasBefore = useCanvasThemeStore.getState().theme;
afterEach(() => {
useThemeStore.setState({ theme: workspaceBefore });
useCanvasThemeStore.setState({ theme: canvasBefore, active: false });
});
describe("canvas theme ownership", () => {
test("editing the canvas theme never mutates the workspace preference", () => {
useThemeStore.setState({ theme: "light" });
useCanvasThemeStore.setState({ active: true });
useCanvasThemeStore.getState().setTheme("dark");
expect(useThemeStore.getState().theme).toBe("light");
expect(useCanvasThemeStore.getState().theme).toBe("dark");
useCanvasThemeStore.setState({ active: false });
expect(useThemeStore.getState().theme).toBe("light");
});
test("workspace switches cannot change canvas preference", () => {
useCanvasThemeStore.setState({ theme: "light" });
useThemeStore.getState().setTheme("dark");
expect(useCanvasThemeStore.getState().theme).toBe("light");
});
test("rejects malformed canvas themes", () => {
useCanvasThemeStore.setState({ theme: "light", active: true });
useCanvasThemeStore.getState().setTheme("invalid" as "light");
expect(useCanvasThemeStore.getState().theme).toBe("light");
});
test("persistence source contract excludes transient route state", async () => {
const source = await Bun.file(new URL("../src/stores/canvas/use-canvas-theme-store.ts", import.meta.url)).text();
expect(source).toContain('partialize: ({ theme }) => ({ theme })');
});
});