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

25 lines
1.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("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");
});
});
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);
}