|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { lintHyperframeHtml } from "../hyperframeLinter.js"; |
| 3 | +import { audioAttributeShapeError } from "./audioAttributes.js"; |
| 4 | + |
| 5 | +function composition(body: string, rootAttrs = ""): string { |
| 6 | + return ` |
| 7 | +<html><body> |
| 8 | + <div id="root" data-composition-id="c1" data-width="1920" data-height="1080"${rootAttrs}> |
| 9 | + ${body} |
| 10 | + </div> |
| 11 | + <script>window.__timelines = {};</script> |
| 12 | +</body></html>`; |
| 13 | +} |
| 14 | + |
| 15 | +async function findings(body: string, rootAttrs = "") { |
| 16 | + const result = await lintHyperframeHtml(composition(body, rootAttrs)); |
| 17 | + return result.findings.filter((f) => f.code === "audio_attribute_unreadable"); |
| 18 | +} |
| 19 | + |
| 20 | +const LANE = `{"target": "volume", "points": [{"t": 0, "v": 0}, {"t": 1, "v": 0.3}]}`; |
| 21 | +const CUE = `id="bed" src="bed.mp3" data-start="0" data-duration="4" data-track-index="2"`; |
| 22 | + |
| 23 | +describe("audio_attribute_unreadable", () => { |
| 24 | + it("flags a volume lane written without a version, which the render refuses", async () => { |
| 25 | + const found = await findings(`<audio ${CUE} data-automation='{"lanes": [${LANE}]}'></audio>`); |
| 26 | + expect(found).toHaveLength(1); |
| 27 | + expect(found[0]).toMatchObject({ severity: "error", elementId: "bed" }); |
| 28 | + expect(found[0]!.message).toContain("unsupported automation version: undefined"); |
| 29 | + expect(found[0]!.fixHint).toContain('{"version": 1, "lanes": [...]}'); |
| 30 | + }); |
| 31 | + |
| 32 | + it("ignores an empty or valueless attribute, as the mixer does, but not a blank one it would parse", async () => { |
| 33 | + for (const attr of ["data-automation", "data-fx-chain"]) { |
| 34 | + expect(await findings(`<audio ${CUE} ${attr}=""></audio>`)).toEqual([]); |
| 35 | + expect(await findings(`<audio ${CUE} ${attr}></audio>`)).toEqual([]); |
| 36 | + expect(await findings(`<audio ${CUE} ${attr}=" "></audio>`)).toHaveLength(1); |
| 37 | + } |
| 38 | + }); |
| 39 | + |
| 40 | + it("passes a well-formed lane and chain", async () => { |
| 41 | + const chain = `{"version": 1, "nodes": [{"type": "highpass", "id": "n1", "params": {"frequency": 70}}]}`; |
| 42 | + const body = `<audio ${CUE} data-automation='{"version": 1, "lanes": [${LANE}]}' data-fx-chain='${chain}'></audio>`; |
| 43 | + expect(await findings(body)).toEqual([]); |
| 44 | + }); |
| 45 | + |
| 46 | + it("reads an entity-encoded chain and names the master bus when the root carries it", async () => { |
| 47 | + const found = await findings( |
| 48 | + "", |
| 49 | + ' data-fx-chain="{"version": 2, "nodes": []}"', |
| 50 | + ); |
| 51 | + expect(found).toHaveLength(1); |
| 52 | + expect(found[0]!.message).toBe( |
| 53 | + "#root has a `data-fx-chain` the render cannot read: unsupported chain version: 2. The render fails on it, locally and in the cloud.", |
| 54 | + ); |
| 55 | + }); |
| 56 | + |
| 57 | + it.each([ |
| 58 | + ["data-automation", "{version: 1}", /^it is not valid JSON/], |
| 59 | + ["data-automation", "[]", /^it is not a JSON object$/], |
| 60 | + ["data-automation", '{"version": 1}', /^it is missing a `lanes` array$/], |
| 61 | + [ |
| 62 | + "data-automation", |
| 63 | + '{"version": 1, "lanes": [{"target": "volume"}]}', |
| 64 | + /^Lane 0 is missing a `points` array$/, |
| 65 | + ], |
| 66 | + ["data-automation", '{"version": 1, "lanes": [{"points": []}]}', /^Lane 0 has no `target`$/], |
| 67 | + ["data-fx-chain", '{"version": 1, "nodes": [7]}', /^Node 0 is not an object$/], |
| 68 | + ["data-fx-chain", '{"version": 1, "nodes": [{"id": "n1"}]}', /^Node 0 has no effect `type`$/], |
| 69 | + ] as const)("%s %s is refused", (attr, json, reason) => { |
| 70 | + expect(audioAttributeShapeError(attr, json)).toMatch(reason); |
| 71 | + }); |
| 72 | +}); |
0 commit comments