import { describe, expect, it } from "vitest"; import { applyTemplate, builtInTemplates } from "."; const characterId = "a23ff62d-e74a-44fd-a8b1-c3aa62bedf13"; describe("built-in templates", () => { it("contains the six required reusable structures", () => { expect(builtInTemplates.map((template) => template.slug)).toEqual([ "classic-character-guide", "combo-rotation-guide", "combined-one-page-build", "multi-role-reaction-build", "categorized-team-database", "calculation-comparison-guide", ]); }); it("applies every template as hidden, independently validated content", () => { for (const template of builtInTemplates) { const applied = applyTemplate(template, characterId); expect(applied.pages.length).toBeGreaterThan(0); expect(applied.pages.every((page) => page.visible === false)).toBe(true); expect(applied.pages.every((page) => page.version === 1)).toBe(true); expect( applied.pages.flatMap((page) => page.blocks).every((block) => block.schemaVersion === 1), ).toBe(true); } }); it("clones pages, blocks, nested items, and data sources independently", () => { const template = builtInTemplates[0]; const first = applyTemplate(template, characterId); const second = applyTemplate(template, characterId); expect(first.pages[0].id).not.toBe(second.pages[0].id); expect(first.pages[0].blocks[0].id).not.toBe(second.pages[0].blocks[0].id); expect(first.dataSources[0].id).not.toBe(second.dataSources[0].id); expect( (first.pages[1].blocks[0].config as { dataSourceId: string }).dataSourceId, ).toBe(first.dataSources[0].id); expect( (second.pages[1].blocks[0].config as { dataSourceId: string }).dataSourceId, ).toBe(second.dataSources[0].id); first.pages[0].title = "แก้เฉพาะสำเนาแรก"; expect(second.pages[0].title).toBe("ข้อมูล"); expect(template.pages[0].title).toBe("ข้อมูล"); }); it("applies later template edits only to future applications", () => { const before = applyTemplate(builtInTemplates[1], characterId); const edited = structuredClone(builtInTemplates[1]); edited.pages[0].title = "โรเทชันฉบับใหม่"; const after = applyTemplate(edited, characterId); expect(before.pages[0].title).toBe("คอมโบ"); expect(after.pages[0].title).toBe("โรเทชันฉบับใหม่"); }); });