Skip to content

Commit 05b34df

Browse files
test(studio): the sealed parity gate counts a clip list read again giving its clips their ids (#9091)
* test(studio): the sealed parity gate counts a clip list read again giving its clips their ids * test(studio): the clip-ids parity case differs only in the fields that name the clip
1 parent a7d1496 commit 05b34df

2 files changed

Lines changed: 80 additions & 8 deletions

File tree

‎packages/studio/src/player/hooks/useTimelinePlayer.reloadedTimeline.test.ts‎

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @vitest-environment happy-dom
22
import { act } from "react";
3-
import { afterEach, expect, it, vi } from "vitest";
3+
import { afterEach, describe, expect, it, vi } from "vitest";
4+
import { PARITY_MODES as MODES } from "../../../tests/parityModes";
45
import { usePlayerStore } from "../store/playerStore";
56
import {
67
detachedFakeIframe,
@@ -37,21 +38,21 @@ const RELOADED = {
3738
clips: [clip("a", "p", 0), clip("dropped", "video", 1)],
3839
};
3940

40-
/** A reloaded film whose runtime holds RELOADED: on its window, and over its editing port once sealed. */
41-
function reloadedFilm() {
41+
/** A reloaded film whose runtime holds `manifest`: on its window, and over its editing port once sealed. */
42+
function reloadedFilm(film = FILM, manifest: typeof RELOADED = RELOADED) {
4243
const { win } = makeAdapterWindow({ duration: 2 });
4344
const frame = win as unknown as Record<string, unknown>;
4445
const iframe = detachedFakeIframe(frame);
4546
Object.defineProperty(iframe, "isConnected", { value: true });
46-
iframe.contentDocument!.body.innerHTML = FILM;
47-
frame.__clipManifest = RELOADED;
47+
iframe.contentDocument!.body.innerHTML = film;
48+
frame.__clipManifest = manifest;
4849
const markup = {
49-
html: `<!doctype html><html><body>${FILM}</body></html>`,
50+
html: `<!doctype html><html><body>${film}</body></html>`,
5051
baseURI: "http://localhost/",
5152
};
5253
closers.push(
5354
serveEditingRequests(frame, (kind) =>
54-
kind === "runtime-snapshot" ? { clipManifest: RELOADED, clipParents: [] } : markup,
55+
kind === "runtime-snapshot" ? { clipManifest: manifest, clipParents: [] } : markup,
5556
),
5657
);
5758
// A cross-origin window: reading its document or globals throws.
@@ -108,3 +109,58 @@ it.each(["scriptable", "sealed"] as const)(
108109
act(() => root.unmount());
109110
},
110111
);
112+
113+
const ONE_CLIP = `<div data-composition-id="main"><p id="a"></p></div>`;
114+
// Clip "a" as either mode derives it from ONE_CLIP, less the fields that name it on its page.
115+
const A_BY_POSITION = {
116+
id: "a",
117+
label: "a",
118+
kind: "element",
119+
tag: "p",
120+
start: 0,
121+
duration: 2,
122+
track: 0,
123+
authoredTrack: 0,
124+
stackingContextId: null,
125+
compositionScope: "main",
126+
zIndex: 0,
127+
};
128+
129+
describe.each(MODES)("a %s preview", (mode) => {
130+
// fails without the fix: a clip list read again that changed only a clip's ids counted as unchanged and was dropped.
131+
it("gives a clip its ids when its list is read again with the same clips", async () => {
132+
const { getApi, root } = renderTimelinePlayerHarness();
133+
const live = makeFakeIframe(makeAdapterWindow({ duration: 2 }).win);
134+
act(() => {
135+
getApi().iframeRef.current = live;
136+
getApi().onIframeLoad();
137+
});
138+
// As a film read before its page loaded leaves it: the clip, by position only.
139+
act(() => usePlayerStore.getState().setElements([A_BY_POSITION]));
140+
act(() => getApi().refreshPlayer());
141+
const gen = getApi().previewSlots.find((slot) => slot.role === "shadow")!.gen;
142+
const shadow = reloadedFilm(ONE_CLIP, { ...RELOADED, clips: [clip("a", "p", 0)] });
143+
act(() => {
144+
getApi().setShadowIframeNode(shadow.iframe);
145+
getApi().onShadowIframeLoad(gen);
146+
});
147+
if (mode === "sealed") shadow.seal();
148+
act(() => getApi().onShadowReadyChange(gen, true));
149+
act(() => {
150+
window.dispatchEvent(
151+
new MessageEvent("message", {
152+
source: shadow.frame as unknown as Window,
153+
origin: window.location.origin,
154+
data: { source: "hf-preview", type: "state", isPlaying: false },
155+
}),
156+
);
157+
});
158+
159+
await vi.waitFor(() =>
160+
expect(usePlayerStore.getState().elements).toEqual([
161+
{ ...A_BY_POSITION, key: "index.html#a", domId: "a", selector: "#a" },
162+
]),
163+
);
164+
act(() => root.unmount());
165+
});
166+
});

‎packages/studio/tests/sealed-parity/manifest.json‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,18 @@
432432
}
433433
]
434434
},
435+
{
436+
"id": "clip-ids-on-reread",
437+
"behaviour": "A clip list read again with the same clips gives them their ids on the timeline",
438+
"tests": [
439+
{
440+
"kind": "vitest",
441+
"package": "studio",
442+
"file": "src/player/hooks/useTimelinePlayer.reloadedTimeline.test.ts",
443+
"name": "a %s preview gives a clip its ids when its list is read again with the same clips"
444+
}
445+
]
446+
},
435447
{
436448
"id": "gsap-route",
437449
"behaviour": "A GSAP-animated layer is edited through its animation",
@@ -525,7 +537,11 @@
525537
{
526538
"id": "edit-accuracy",
527539
"behaviour": "Edit accuracy bench",
528-
"tests": [{ "kind": "edit-accuracy" }]
540+
"tests": [
541+
{
542+
"kind": "edit-accuracy"
543+
}
544+
]
529545
},
530546
{
531547
"id": "caption-editing",

0 commit comments

Comments
 (0)