Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @vitest-environment happy-dom
import { act } from "react";
import { afterEach, expect, it, vi } from "vitest";
import { afterEach, describe, expect, it, vi } from "vitest";
import { PARITY_MODES as MODES } from "../../../tests/parityModes";
import { usePlayerStore } from "../store/playerStore";
import {
detachedFakeIframe,
Expand Down Expand Up @@ -37,21 +38,21 @@ const RELOADED = {
clips: [clip("a", "p", 0), clip("dropped", "video", 1)],
};

/** A reloaded film whose runtime holds RELOADED: on its window, and over its editing port once sealed. */
function reloadedFilm() {
/** A reloaded film whose runtime holds `manifest`: on its window, and over its editing port once sealed. */
function reloadedFilm(film = FILM, manifest: typeof RELOADED = RELOADED) {
const { win } = makeAdapterWindow({ duration: 2 });
const frame = win as unknown as Record<string, unknown>;
const iframe = detachedFakeIframe(frame);
Object.defineProperty(iframe, "isConnected", { value: true });
iframe.contentDocument!.body.innerHTML = FILM;
frame.__clipManifest = RELOADED;
iframe.contentDocument!.body.innerHTML = film;
frame.__clipManifest = manifest;
const markup = {
html: `<!doctype html><html><body>${FILM}</body></html>`,
html: `<!doctype html><html><body>${film}</body></html>`,
baseURI: "http://localhost/",
};
closers.push(
serveEditingRequests(frame, (kind) =>
kind === "runtime-snapshot" ? { clipManifest: RELOADED, clipParents: [] } : markup,
kind === "runtime-snapshot" ? { clipManifest: manifest, clipParents: [] } : markup,
),
);
// A cross-origin window: reading its document or globals throws.
Expand Down Expand Up @@ -108,3 +109,58 @@ it.each(["scriptable", "sealed"] as const)(
act(() => root.unmount());
},
);

const ONE_CLIP = `<div data-composition-id="main"><p id="a"></p></div>`;
// Clip "a" as either mode derives it from ONE_CLIP, less the fields that name it on its page.
const A_BY_POSITION = {
id: "a",
label: "a",
kind: "element",
tag: "p",
start: 0,
duration: 2,
track: 0,
authoredTrack: 0,
stackingContextId: null,
compositionScope: "main",
zIndex: 0,
};

describe.each(MODES)("a %s preview", (mode) => {
// fails without the fix: a clip list read again that changed only a clip's ids counted as unchanged and was dropped.
it("gives a clip its ids when its list is read again with the same clips", async () => {
const { getApi, root } = renderTimelinePlayerHarness();
const live = makeFakeIframe(makeAdapterWindow({ duration: 2 }).win);
act(() => {
getApi().iframeRef.current = live;
getApi().onIframeLoad();
});
// As a film read before its page loaded leaves it: the clip, by position only.
act(() => usePlayerStore.getState().setElements([A_BY_POSITION]));
act(() => getApi().refreshPlayer());
const gen = getApi().previewSlots.find((slot) => slot.role === "shadow")!.gen;
const shadow = reloadedFilm(ONE_CLIP, { ...RELOADED, clips: [clip("a", "p", 0)] });
act(() => {
getApi().setShadowIframeNode(shadow.iframe);
getApi().onShadowIframeLoad(gen);
});
if (mode === "sealed") shadow.seal();
act(() => getApi().onShadowReadyChange(gen, true));
act(() => {
window.dispatchEvent(
new MessageEvent("message", {
source: shadow.frame as unknown as Window,
origin: window.location.origin,
data: { source: "hf-preview", type: "state", isPlaying: false },
}),
);
});

await vi.waitFor(() =>
expect(usePlayerStore.getState().elements).toEqual([
{ ...A_BY_POSITION, key: "index.html#a", domId: "a", selector: "#a" },
]),
);
act(() => root.unmount());
});
});
18 changes: 17 additions & 1 deletion packages/studio/tests/sealed-parity/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,18 @@
}
]
},
{
"id": "clip-ids-on-reread",
"behaviour": "A clip list read again with the same clips gives them their ids on the timeline",
"tests": [
{
"kind": "vitest",
"package": "studio",
"file": "src/player/hooks/useTimelinePlayer.reloadedTimeline.test.ts",
"name": "a %s preview gives a clip its ids when its list is read again with the same clips"
}
]
},
{
"id": "gsap-route",
"behaviour": "A GSAP-animated layer is edited through its animation",
Expand Down Expand Up @@ -506,7 +518,11 @@
{
"id": "edit-accuracy",
"behaviour": "Edit accuracy bench",
"tests": [{ "kind": "edit-accuracy" }]
"tests": [
{
"kind": "edit-accuracy"
}
]
},
{
"id": "caption-editing",
Expand Down
Loading