fix(studio): refine preset surfaces and repair gallery interactions
Quality / quality (ubuntu-latest) (push) Failing after 11m2s
Quality / quality (windows-latest) (push) Canceled after 0s

This commit is contained in:
Clintchiz committed 2026-10-19 19:10:44 +05:30
1 parent f642a84c58
commit bb40dffee8
20 files changed
+345 -72

No files matched your search

@@ -0,0 +1,62 @@
import { expect, test } from "bun:test";
import { handlePreviewClipboard } from "../src/preview-clipboard.ts";
test("clipboard broker accepts only current preview frames and bounded user-initiated text", async () => {
const results: unknown[] = [];
const source = { postMessage: (value: unknown) => results.push(value) } as unknown as Window;
const frames = [{ contentWindow: source, src: "https://example.test/preview/current" }];
const event = {
source,
data: {
type: "wrn-studio-copy",
id: "copy-1",
path: "/preview/current",
text: "npm install @wrnexus/ui",
},
};
const copied: string[] = [];
const write = async (text: string) => {
copied.push(text);
};
expect(await handlePreviewClipboard(event, frames, write)).toBe(true);
expect(copied).toEqual(["npm install @wrnexus/ui"]);
expect(results).toEqual([{ type: "wrn-studio-copy-result", id: "copy-1", ok: true }]);
expect(await handlePreviewClipboard({ ...event, source: null }, frames, write)).toBe(false);
expect(
await handlePreviewClipboard(
{ ...event, data: { ...event.data, path: "/preview/old" } },
frames,
write,
),
).toBe(false);
expect(
await handlePreviewClipboard(
{ ...event, data: { ...event.data, text: "x".repeat(16385) } },
frames,
write,
),
).toBe(false);
expect(await handlePreviewClipboard(event, frames, write, false)).toBe(true);
expect(copied).toHaveLength(1);
expect(results.at(-1)).toEqual({ type: "wrn-studio-copy-result", id: "copy-1", ok: false });
});
test("clipboard denial reports failure rather than claiming a copy succeeded", async () => {
let result: any;
const source = {
postMessage: (value: unknown) => {
result = value;
},
} as unknown as Window;
await handlePreviewClipboard(
{
source,
data: { type: "wrn-studio-copy", id: "copy-2", path: "/preview/current", text: "test" },
},
[{ contentWindow: source, src: "https://example.test/preview/current" }],
async () => {
throw Error("denied");
},
);
expect(result.ok).toBe(false);
});
@@ -33,3 +33,18 @@ test("choosing a new preset stays undoable and never mutates the catalog", () =>
session.undo();
expect(session.valid.id).toBe("square");
});
test("revised directions stay distinct and Editorial status tokens remain monochrome", () => {
const organic = ["soft", "forest", "ember"].map((id) => STUDIO_PRESETS[id]!);
expect(new Set(organic.map((s) => s.modes!.light!["color.bg"]!.value)).size).toBe(3);
expect(new Set(organic.map((s) => s.tokens["shape.control"]!.value)).size).toBe(3);
for (const tokens of [
STUDIO_PRESETS.editorial!.tokens,
...Object.values(STUDIO_PRESETS.editorial!.modes!),
]) {
for (const name of ["success", "warning", "danger", "info"]) {
const color = String(tokens[`color.${name}`]!.value);
expect(color).toMatch(/^#([0-9a-f]{2})\1\1$/i);
}
}
});