Files
NianAIGC/tests/create-studio-template-interaction.test.ts
2026-09-11 15:33:18 +08:00

44 lines
2.1 KiB
TypeScript

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("offers the shared 3:4 portrait preset in creation and template settings", async () => {
const source = await readFile(createStudioUrl, "utf8");
const presets = await readFile(new URL("../lib/image-size-presets.ts", import.meta.url), "utf8");
expect(presets).toContain('{ label: "3:4", width: 1728, height: 2304 }');
expect(source).toContain('from "@/lib/image-size-presets"');
expect(source.match(/imageSizePresets\.map/g)?.length || 0).toBeGreaterThanOrEqual(2);
});
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);
}