|
| 1 | +import { parseHTML } from "linkedom"; |
1 | 2 | import { describe, expect, it } from "vitest"; |
2 | 3 | import { extractStandaloneEntryFromIndex } from "./standaloneEntry"; |
3 | 4 |
|
@@ -112,4 +113,77 @@ describe("extractStandaloneEntryFromIndex", () => { |
112 | 113 | expect(extracted).toContain('data-duration="2"'); |
113 | 114 | expect(extracted).not.toContain('data-duration="12"'); |
114 | 115 | }); |
| 116 | + describe("master bus chain", () => { |
| 117 | + const hostIndexHtml = `<!DOCTYPE html> |
| 118 | +<html> |
| 119 | +<body> |
| 120 | + <div id="scene1" data-composition-id="scene1" data-composition-src="compositions/scene1.html" data-width="640" data-height="360" data-fx-chain="{"version":1,"nodes":[{"type":"truepeak","id":"index"}]}"></div> |
| 121 | +</body> |
| 122 | +</html>`; |
| 123 | + const indexHtml = `<!DOCTYPE html> |
| 124 | +<html> |
| 125 | +<body> |
| 126 | + <div data-composition-id="master" data-width="640" data-height="360" data-fx-chain="{"version":1,"nodes":[{"type":"truepeak","id":"index"}]}"> |
| 127 | + <div id="scene1" data-composition-id="scene1" data-composition-src="compositions/scene1.html" data-start="0"></div> |
| 128 | + </div> |
| 129 | +</body> |
| 130 | +</html>`; |
| 131 | + const chainOf = (html: string): string | null => { |
| 132 | + const { document } = parseHTML(html); |
| 133 | + const roots = Array.from(document.querySelectorAll("[data-composition-id]")) as Element[]; |
| 134 | + const top = roots.find((el) => !el.parentElement?.closest("[data-composition-id]")); |
| 135 | + return top?.getAttribute("data-fx-chain") ?? null; |
| 136 | + }; |
| 137 | + |
| 138 | + it("carries the scene's own chain, not the index's", () => { |
| 139 | + const chain = '{"version":1,"nodes":[{"type":"truepeak","id":"scene"}]}'; |
| 140 | + const sceneHtml = `<template id="t"><div data-composition-id="scene1" data-width="640" data-height="360" data-fx-chain='${chain}'></div></template>`; |
| 141 | + |
| 142 | + const extracted = extractStandaloneEntryFromIndex( |
| 143 | + indexHtml, |
| 144 | + "compositions/scene1.html", |
| 145 | + sceneHtml, |
| 146 | + ); |
| 147 | + |
| 148 | + expect(chainOf(extracted ?? "")).toBe(chain); |
| 149 | + }); |
| 150 | + |
| 151 | + it("drops the index's chain when the scene declares none", () => { |
| 152 | + const sceneHtml = `<template id="t"><div data-composition-id="scene1" data-width="640" data-height="360"></div></template>`; |
| 153 | + |
| 154 | + const extracted = extractStandaloneEntryFromIndex( |
| 155 | + indexHtml, |
| 156 | + "compositions/scene1.html", |
| 157 | + sceneHtml, |
| 158 | + ); |
| 159 | + |
| 160 | + expect(chainOf(extracted ?? "")).toBeNull(); |
| 161 | + }); |
| 162 | + |
| 163 | + it("carries the scene's chain when the index's top-level root is the mount itself", () => { |
| 164 | + const chain = '{"version":1,"nodes":[{"type":"truepeak","id":"scene"}]}'; |
| 165 | + const sceneHtml = `<template id="t"><div data-composition-id="scene1" data-width="640" data-height="360" data-fx-chain='${chain}'></div></template>`; |
| 166 | + |
| 167 | + const extracted = extractStandaloneEntryFromIndex( |
| 168 | + hostIndexHtml, |
| 169 | + "compositions/scene1.html", |
| 170 | + sceneHtml, |
| 171 | + ); |
| 172 | + |
| 173 | + expect(chainOf(extracted ?? "")).toBe(chain); |
| 174 | + }); |
| 175 | + |
| 176 | + it("drops the index's chain from a top-level mount when the scene declares none", () => { |
| 177 | + const sceneHtml = `<template id="t"><div data-composition-id="scene1" data-width="640" data-height="360"></div></template>`; |
| 178 | + |
| 179 | + const extracted = extractStandaloneEntryFromIndex( |
| 180 | + hostIndexHtml, |
| 181 | + "compositions/scene1.html", |
| 182 | + sceneHtml, |
| 183 | + ); |
| 184 | + |
| 185 | + expect(extracted).not.toBeNull(); |
| 186 | + expect(chainOf(extracted ?? "")).toBeNull(); |
| 187 | + }); |
| 188 | + }); |
115 | 189 | }); |
0 commit comments