import { describe, it, expect, beforeEach } from "vitest"; import { MEDIA_RENDER_ID_ATTR } from "../compiler/mediaRenderIds"; import { readMediaRenderId, renderFrameElementId, findInjectedRenderFrame, } from "./renderFrameSibling"; function videoWith(attrs: Record): HTMLVideoElement { const el = document.createElement("video"); for (const [name, value] of Object.entries(attrs)) el.setAttribute(name, value); return el; } describe("readMediaRenderId", () => { it("prefers the stamped render id over the author id", () => { expect(readMediaRenderId(videoWith({ id: "clip", [MEDIA_RENDER_ID_ATTR]: "clip__hf2" }))).toBe( "clip__hf2", ); }); it("falls back to the author id in an uncompiled document", () => { expect(readMediaRenderId(videoWith({ id: "clip" }))).toBe("clip"); }); it("returns null when the element has neither", () => { expect(readMediaRenderId(videoWith({}))).toBeNull(); }); }); describe("renderFrameElementId", () => { // Pins the id format the engine's in-page bridge mirrors when it CREATES the // sibling (screenshotService.ensureRenderFrameSiblings). If this format // changes on one side only, the readers stop finding the frame. it("wraps the render id in the injector's sibling id format", () => { expect(renderFrameElementId(videoWith({ id: "hero" }))).toBe("__render_frame_hero__"); expect(renderFrameElementId(videoWith({ id: "c", [MEDIA_RENDER_ID_ATTR]: "c__hf2" }))).toBe( "__render_frame_c__hf2__", ); }); }); describe("findInjectedRenderFrame", () => { beforeEach(() => { document.body.innerHTML = ""; }); it("resolves each colliding video to its own frame, not the first one's", () => { // Two scenes sharing `