mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
* feat(studio): a host can make the preview read-only Gates the shared geometry commit funnel (offset/size/rotation), so the inspector's manual X/Y/W/H/rotation fields refuse the same as canvas drag/resize/rotate. The flat inspector's fields render disabled with a host-supplied reason. Fixes a hooks-order crash on deselect found in review. * refactor(studio): derive the read-only preview flag from context, not a synced store EditorShell synced its readOnlyPreview prop into a zustand store via a raw useEffect behind an eslint-disable of no-restricted-syntax. Replace it with a PreviewReadOnlyProvider context computed fresh from the prop every render: Tier-1 consumers (genuine EditorShell descendants) read it via useContext; Tier-2 consumers (useAppHotkeys, useGestureCommit, the useDomEditSession/useDomEditCommits/useDomGeometryCommits chain), which run in App.tsx above EditorShell, take it as an explicit parameter threaded from StudioApp's own prop instead. Adds a host-mount test proving EditorShell gates its descendants from its own prop with no StudioApp/App.tsx involved. * fix(studio): keep preview hotkeys context explicit * fix(studio): close read-only interaction escapes * fix(studio): preserve timeline ownership in read-only preview * fix(studio): rollback read-only preview work * fix(studio): keep hotkey ownership on the active surface * fix(studio): format preview overlay and strengthen split test * fix(studio): clear preview gate findings * refactor(studio): share preview test fixtures
109 lines
3.4 KiB
TypeScript
109 lines
3.4 KiB
TypeScript
// @vitest-environment happy-dom
|
|
|
|
import React, { act } from "react";
|
|
import { createRoot } from "react-dom/client";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import "./EditorShellTestMocks";
|
|
import { EditorShell } from "./EditorShell";
|
|
import { usePreviewReadOnly } from "./editor/previewReadOnlyContext";
|
|
|
|
const hookMocks = vi.hoisted(() => ({
|
|
useTimelineSelectionPreviewSync: vi.fn(),
|
|
}));
|
|
const previewOverlaysProbe = vi.hoisted(() => ({ readOnly: null as boolean | null }));
|
|
|
|
vi.mock("../hooks/useTimelineSelectionPreviewSync", () => hookMocks);
|
|
vi.mock("./nle/PreviewPane", () => ({
|
|
// Renders its previewOverlay prop for real, so the mocked PreviewOverlays
|
|
// below (which reads the read-only context) actually mounts.
|
|
PreviewPane: (props: { previewOverlay?: React.ReactNode }) => props.previewOverlay ?? null,
|
|
}));
|
|
vi.mock("./nle/PreviewOverlays", () => ({
|
|
PreviewOverlays: () => {
|
|
previewOverlaysProbe.readOnly = usePreviewReadOnly();
|
|
return null;
|
|
},
|
|
}));
|
|
|
|
Object.assign(globalThis, {
|
|
IS_REACT_ACT_ENVIRONMENT: true,
|
|
ResizeObserver: class {
|
|
observe() {}
|
|
unobserve() {}
|
|
disconnect() {}
|
|
},
|
|
});
|
|
|
|
afterEach(() => {
|
|
document.body.innerHTML = "";
|
|
hookMocks.useTimelineSelectionPreviewSync.mockClear();
|
|
});
|
|
|
|
const shell = (readOnlyPreview?: boolean) => (
|
|
<EditorShell
|
|
panels={null}
|
|
timelineToolbar={null}
|
|
renderClipContent={() => null}
|
|
handleTimelineElementDelete={vi.fn()}
|
|
handleTimelineAssetDrop={vi.fn()}
|
|
handleTimelineFileDrop={vi.fn()}
|
|
handleTimelineElementMove={vi.fn()}
|
|
handleTimelineElementsMove={vi.fn()}
|
|
handleTimelineElementResize={vi.fn()}
|
|
handleTimelineGroupResize={vi.fn()}
|
|
handleToggleTrackHidden={vi.fn()}
|
|
setAudioGroupAttribute={{ setLive: vi.fn(), setQuiet: vi.fn() }}
|
|
handleBlockedTimelineEdit={vi.fn()}
|
|
handleTimelineElementSplit={vi.fn()}
|
|
handleRazorSplit={vi.fn()}
|
|
handleRazorSplitAll={vi.fn()}
|
|
onCopyClip={vi.fn(() => false)}
|
|
onPasteClip={vi.fn(async () => {})}
|
|
onDuplicateClip={vi.fn(async () => false)}
|
|
canPasteClip={vi.fn(() => false)}
|
|
setCompIdToSrc={vi.fn()}
|
|
setCompositionLoading={vi.fn()}
|
|
shouldShowMotionPath={false}
|
|
shouldShowSelectedDomBounds={false}
|
|
readOnlyPreview={readOnlyPreview}
|
|
/>
|
|
);
|
|
|
|
describe("EditorShell timeline selection sync", () => {
|
|
it("keeps the timeline store mirrored into the preview selection", () => {
|
|
const host = document.createElement("div");
|
|
document.body.append(host);
|
|
const root = createRoot(host);
|
|
|
|
act(() => {
|
|
root.render(shell());
|
|
});
|
|
|
|
expect(hookMocks.useTimelineSelectionPreviewSync).toHaveBeenCalledOnce();
|
|
expect(hookMocks.useTimelineSelectionPreviewSync).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
activeCompPath: "index.html",
|
|
timelineElements: [],
|
|
domEditSelection: null,
|
|
domEditGroupSelections: [],
|
|
}),
|
|
);
|
|
|
|
act(() => root.unmount());
|
|
});
|
|
|
|
it("threads the read-only prop into descendants via context, and follows it across renders", () => {
|
|
const host = document.createElement("div");
|
|
document.body.append(host);
|
|
const root = createRoot(host);
|
|
|
|
act(() => root.render(shell(true)));
|
|
expect(previewOverlaysProbe.readOnly).toBe(true);
|
|
act(() => root.render(shell(false)));
|
|
expect(previewOverlaysProbe.readOnly).toBe(false);
|
|
act(() => root.render(shell(true)));
|
|
expect(previewOverlaysProbe.readOnly).toBe(true);
|
|
act(() => root.unmount());
|
|
});
|
|
});
|