Skip to content

Commit 247f121

Browse files
committed
test(studio): a same-scale pan must render its scroll before paint
Reads the render window outside act, so unwrapping the flush fails it, and records each published scroll at call time instead of reading the live element afterwards.
1 parent 487a281 commit 247f121

2 files changed

Lines changed: 34 additions & 14 deletions

File tree

‎packages/studio/src/player/components/timelineZoomInput.test.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,14 @@ describe("zoomTimelineToRange", () => {
269269
timelinePps: 100,
270270
});
271271
const { scroll } = viewport(0);
272-
publishScroll.mockClear();
272+
const published: number[] = [];
273+
publishScroll.mockImplementation((el: HTMLDivElement) => published.push(el.scrollLeft));
273274
void zoomTimelineToRange(60, 70);
274275
for (let i = 0; i < 40; i++) vi.advanceTimersToNextFrame();
276+
publishScroll.mockReset();
275277
expect(usePlayerStore.getState().timelinePps).toBe(100);
276278
expect(scroll.scrollLeft).toBeGreaterThan(5000);
277-
expect(publishScroll.mock.lastCall?.[0].scrollLeft).toBe(scroll.scrollLeft);
279+
expect(published.at(-1)).toBe(scroll.scrollLeft);
278280
});
279281

280282
it("fills the width with the range and puts its start at the left margin", () => {

‎packages/studio/src/player/components/useTimelinePlayhead.test.tsx‎

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ describe("useTimelinePlayhead follow while paused", () => {
250250
});
251251

252252
describe("useTimelinePlayhead committed viewport", () => {
253-
it("keeps the visible 59-second clip mounted when a pointer zoom commits", () => {
253+
function mountViewport(scrollLeft: number) {
254254
vi.stubGlobal(
255255
"ResizeObserver",
256256
class {
@@ -264,7 +264,7 @@ describe("useTimelinePlayhead committed viewport", () => {
264264
timelineFitPps: 10,
265265
timelinePps: 100,
266266
});
267-
const scroll = scrollBox(5000, 1080);
267+
const scroll = scrollBox(scrollLeft, 1080);
268268
const container = document.createElement("div");
269269
function Probe() {
270270
const pps = usePlayerStore((s) => s.timelinePps);
@@ -290,18 +290,36 @@ describe("useTimelinePlayhead committed viewport", () => {
290290
}
291291
const root = createRoot(container);
292292
roots.push(root);
293+
act(() => root.render(<Probe />));
294+
return { scroll, container };
295+
}
296+
297+
afterEach(() => vi.unstubAllGlobals());
298+
299+
it("keeps the visible 59-second clip mounted when a pointer zoom commits", () => {
300+
const { scroll, container } = mountViewport(5000);
301+
expect(container.querySelector('[data-clip="59"]')).not.toBeNull();
302+
act(() => {
303+
requestTimelineZoom(1090, { time: 55.24, x: 556 });
304+
settleTimelineZoom();
305+
});
306+
expect(scroll.scrollLeft).toBeCloseTo(5497.16);
307+
expect(container.querySelector('[data-clip="59"]')).not.toBeNull();
308+
expect(Number(container.querySelector("output")?.textContent)).toBeCloseTo(5497.16);
309+
});
310+
311+
it("renders a pan at the laid-out scale before the browser paints", () => {
312+
const { scroll, container } = mountViewport(0);
313+
const actEnvironment = globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean };
314+
const wasActEnvironment = actEnvironment.IS_REACT_ACT_ENVIRONMENT;
315+
actEnvironment.IS_REACT_ACT_ENVIRONMENT = false;
293316
try {
294-
act(() => root.render(<Probe />));
295-
expect(container.querySelector('[data-clip="59"]')).not.toBeNull();
296-
act(() => {
297-
requestTimelineZoom(1090, { time: 55.24, x: 556 });
298-
settleTimelineZoom();
299-
});
300-
expect(scroll.scrollLeft).toBeCloseTo(5497.16);
301-
expect(container.querySelector('[data-clip="59"]')).not.toBeNull();
302-
expect(Number(container.querySelector("output")?.textContent)).toBeCloseTo(5497.16);
317+
requestTimelineZoom(1000, { time: 60, x: ORIGIN });
318+
settleTimelineZoom();
319+
expect(scroll.scrollLeft).toBe(6000);
320+
expect(container.querySelector("output")?.textContent).toBe("6000");
303321
} finally {
304-
vi.unstubAllGlobals();
322+
actEnvironment.IS_REACT_ACT_ENVIRONMENT = wasActEnvironment;
305323
}
306324
});
307325
});

0 commit comments

Comments
 (0)