/** * @vitest-environment jsdom */ import { describe, it, expect } from "vitest"; import { generateHyperframesHtml, generateGsapTimelineScript, generateHyperframesStyles, } from "./hyperframes.js"; import { GSAP_CDN } from "../templates/constants.js"; import type { TimelineTextElement, TimelineMediaElement } from "../core.types"; function makeTextElement(overrides: Partial = {}): TimelineTextElement { return { id: "text-1", type: "text", name: "Title", content: "Hello World", startTime: 0, duration: 5, zIndex: 1, ...overrides, }; } function makeVideoElement(overrides: Partial = {}): TimelineMediaElement { return { id: "vid-1", type: "video", name: "Background", src: "video.mp4", startTime: 0, duration: 10, zIndex: 0, ...overrides, }; } describe("generateHyperframesHtml", () => { it("generates valid HTML with proper data attributes", () => { const elements = [makeTextElement()]; const html = generateHyperframesHtml(elements, 5); expect(html).toContain(""); expect(html).toContain("data-composition-id="); expect(html).toContain("data-composition-duration="); expect(html).toContain('id="stage"'); expect(html).toContain('id="stage-zoom-container"'); }); it("includes element data attributes", () => { const elements = [makeTextElement({ id: "my-text", startTime: 2, duration: 3 })]; const html = generateHyperframesHtml(elements, 5); expect(html).toContain('id="my-text"'); expect(html).toContain('data-start="2"'); expect(html).toContain('data-end="5"'); expect(html).toContain('data-layer="1"'); }); it("includes GSAP CDN script tag when includeScripts is true", () => { const elements = [makeTextElement()]; const html = generateHyperframesHtml(elements, 5, { includeScripts: true }); expect(html).toContain(``); }); it("does NOT include GSAP CDN by default", () => { const elements = [makeTextElement()]; const html = generateHyperframesHtml(elements, 5); expect(html).not.toContain(GSAP_CDN); }); it("includes timeline script when includeScripts is true", () => { const elements = [makeTextElement()]; const html = generateHyperframesHtml(elements, 5, { includeScripts: true }); expect(html).toContain("gsap.timeline({ paused: true })"); }); it("generates GSAP timeline with visibility animations when includeScripts is true", () => { const elements = [makeTextElement({ id: "el-1", startTime: 1, duration: 3 })]; const html = generateHyperframesHtml(elements, 5, { includeScripts: true }); // Default animations include visibility bookends expect(html).toContain('tl.set("#el-1"'); expect(html).toContain('visibility: "hidden"'); expect(html).toContain('visibility: "visible"'); }); it("sets resolution data attribute", () => { const elements = [makeTextElement()]; const landscapeHtml = generateHyperframesHtml(elements, 5, { resolution: "landscape" }); expect(landscapeHtml).toContain('data-resolution="landscape"'); const portraitHtml = generateHyperframesHtml(elements, 5, { resolution: "portrait" }); expect(portraitHtml).toContain('data-resolution="portrait"'); }); it("generates video elements with proper tags", () => { const elements = [makeVideoElement()]; const html = generateHyperframesHtml(elements, 10); expect(html).toContain(" { const elements = [makeTextElement({ content: "My Content" })]; const html = generateHyperframesHtml(elements, 5); expect(html).toContain("
My Content
"); }); it("includes custom compositionId", () => { const elements = [makeTextElement()]; const html = generateHyperframesHtml(elements, 5, { compositionId: "test-comp-123" }); expect(html).toContain('data-composition-id="test-comp-123"'); }); it("calculates total duration from elements if they exceed provided duration", () => { const elements = [makeTextElement({ startTime: 0, duration: 15 })]; const html = generateHyperframesHtml(elements, 5); expect(html).toContain('data-composition-duration="15"'); }); it("includes style tags when includeStyles is true", () => { const elements = [makeTextElement()]; const html = generateHyperframesHtml(elements, 5, { includeStyles: true }); expect(html).toContain('