fix(studio): refine preset surfaces and repair gallery interactions
This commit is contained in:
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);
|
||||
});
|
||||
Reference in new issue
Block a user