Файли
openidea/src/ui/useFrozenWhileWindowResizes.test.tsx
T
l0ng-ai f4a7a7bafb perf(ui): smoother editor scrolling, tab switching and first file open (#4633)
Removes selectors that restyled whole subtrees on every inserted editor line or focus change (CodeMirror via a pnpm patch; selectorCost.test.ts guards them), measures space width once per font, shares one tooltip host, builds tab menus lazily, caches parsed SVG icons, prewarms an off-screen editor at idle, stats project-tree entries in parallel, and keeps the Git tool window at its size during a live window resize. Verified with full vitest, typecheck, ide-vfs cargo test and clippy, gitLog e2e, and a window resize in the app.
2026-11-20 09:13:29 +08:00

53 рядки
1.9 KiB
TypeScript

import { act, render } from "@testing-library/react";
import { useRef } from "react";
import { afterEach, beforeEach, expect, it, vi } from "vitest";
import { WINDOW_RESIZE_SETTLE_MS, useFrozenWhileWindowResizes } from "./useFrozenWhileWindowResizes";
function Frozen() {
const ref = useRef<HTMLDivElement>(null);
useFrozenWhileWindowResizes(ref);
return (
<div data-testid="parent">
<div ref={ref} data-testid="view" />
</div>
);
}
beforeEach(() => vi.useFakeTimers());
afterEach(() => vi.useRealTimers());
it("keeps the view at its size while the window resizes and releases it once the drag pauses", () => {
const { getByTestId } = render(<Frozen />);
const view = getByTestId("view");
const parent = getByTestId("parent");
view.getBoundingClientRect = () => ({ width: 300, height: 120 }) as DOMRect;
act(() => void window.dispatchEvent(new Event("resize")));
expect(view.style.width).toBe("300px");
expect(view.style.height).toBe("120px");
expect(view.style.flexGrow).toBe("0");
expect(parent.style.overflow).toBe("hidden");
// Still dragging: the size taken at the start stays.
view.getBoundingClientRect = () => ({ width: 200, height: 80 }) as DOMRect;
act(() => vi.advanceTimersByTime(WINDOW_RESIZE_SETTLE_MS - 1));
act(() => void window.dispatchEvent(new Event("resize")));
act(() => vi.advanceTimersByTime(WINDOW_RESIZE_SETTLE_MS - 1));
expect(view.style.width).toBe("300px");
act(() => vi.advanceTimersByTime(1));
expect(view.style.width).toBe("");
expect(view.style.height).toBe("");
expect(view.style.flex).toBe("");
expect(parent.style.overflow).toBe("");
});
it("releases the view when it unmounts mid-drag", () => {
const { getByTestId, unmount } = render(<Frozen />);
const parent = getByTestId("parent");
act(() => void window.dispatchEvent(new Event("resize")));
expect(parent.style.overflow).toBe("hidden");
unmount();
expect(parent.style.overflow).toBe("");
});