Skip to content

Commit a3af143

Browse files
committed
test(sdk): cover attachSync mirroring for setVariableValue and setTiming
setVariableValue is the headline case the sync spec was built for and had no coverage; setTiming (data-start/data-end mirroring) was also untested. Both regression-checked by temporarily breaking the underlying mutate/apply-patches code paths and confirming the new assertions fail.
1 parent 145f05e commit a3af143

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

‎packages/sdk/src/adapters/iframe.sync.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,41 @@ window.__timelines = { t: tl };</script>
196196
) as HTMLElement;
197197
expect(liveTitle.style.getPropertyValue("color")).not.toBe("#f00");
198198
});
199+
200+
it("mirrors setVariableValue onto the live root's CSS custom property", async () => {
201+
const html = `<!DOCTYPE html>
202+
<html data-composition-variables='[{"id":"accent","default":"#fff"}]'>
203+
<body>
204+
<div data-hf-id="hf-stage" data-hf-root style="--accent: #fff; width: 1280px; height: 720px" data-duration="5">
205+
<h1 data-hf-id="hf-title" style="color: var(--accent)">Hello World</h1>
206+
</div>
207+
</body>
208+
</html>`;
209+
const iframe = mountIframe(html);
210+
const comp = await openComposition(html);
211+
const adapter = createIframePreviewAdapter(iframe);
212+
adapter.attachSync(comp);
213+
214+
comp.setVariableValue("accent", "#0f0");
215+
216+
const liveRoot = iframe.contentDocument!.querySelector(
217+
'[data-hf-id="hf-stage"]',
218+
) as HTMLElement;
219+
expect(liveRoot.style.getPropertyValue("--accent")).toBe("#0f0");
220+
});
221+
222+
it("mirrors setTiming onto the live element's data-start/data-end attributes", async () => {
223+
const iframe = mountIframe(BASE_HTML);
224+
const comp = await openComposition(BASE_HTML);
225+
const adapter = createIframePreviewAdapter(iframe);
226+
adapter.attachSync(comp);
227+
228+
comp.setTiming("hf-title", { start: 1, duration: 2 });
229+
230+
const liveTitle = iframe.contentDocument!.querySelector(
231+
'[data-hf-id="hf-title"]',
232+
) as HTMLElement;
233+
expect(liveTitle.getAttribute("data-start")).toBe("1");
234+
expect(liveTitle.getAttribute("data-end")).toBe("3");
235+
});
199236
});

0 commit comments

Comments
 (0)