import { readFile } from "node:fs/promises"; import { describe, expect, it } from "vitest"; const createStudioUrl = new URL("../components/create-studio.tsx", import.meta.url); describe("create studio template interaction", () => { it("applies and clears templates without changing the selected creation mode", async () => { const source = await readFile(createStudioUrl, "utf8"); const clearSelection = functionSource(source, "clearImageTemplateSelection", "applyTemplateToConsole"); const applyTemplate = functionSource(source, "applyTemplateToConsole", "resetTemplateForm"); expect(clearSelection).not.toMatch(/\bsetMode\s*\(/); expect(applyTemplate).not.toMatch(/\bsetMode\s*\(/); expect(applyTemplate).toContain("[generateMode]: template.prompt"); }); it("keeps the effect preview display-only instead of adding it to generation materials", async () => { const source = await readFile(createStudioUrl, "utf8"); const applyTemplate = functionSource(source, "applyTemplateToConsole", "resetTemplateForm"); const buildBody = functionSource(source, "buildGenerationBody", "submit"); expect(applyTemplate).not.toMatch(/\bsetMaterials\s*\(/); expect(applyTemplate).not.toContain("previewImageUrl"); expect(buildBody).not.toContain("previewImageUrl"); }); }); function functionSource(source: string, name: string, nextName: string) { const start = source.indexOf(`function ${name}`); const end = source.indexOf(`function ${nextName}`, start + 1); expect(start, `${name} should exist`).toBeGreaterThanOrEqual(0); expect(end, `${nextName} should follow ${name}`).toBeGreaterThan(start); return source.slice(start, end); }