From 99cb1ca395d1ea0f57d7eef7eadd15bfce12ec65 Mon Sep 17 00:00:00 2001 From: suguanYang Date: Wed, 17 Jun 2026 00:28:39 +0800 Subject: [PATCH] Fix chunks panel test teardown --- src/components/chunks-panel.test.ts | 20 +++++++++++++++++++- src/domains/sources/route-upload.ts | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/components/chunks-panel.test.ts b/src/components/chunks-panel.test.ts index e97763c..61ecf7f 100644 --- a/src/components/chunks-panel.test.ts +++ b/src/components/chunks-panel.test.ts @@ -15,6 +15,9 @@ import { ChunksPanel } from "./chunks-panel"; import { sourceOriginalPreviewRequest } from "./source-original-preview-request"; const C = ChunksPanel as React.FC>; +const virtualizerScrollResetDelayMs = 150; + +let shouldFlushVirtualizerTimers: boolean = false; vi.mock("react-pdf", () => ({ pdfjs: { @@ -28,6 +31,7 @@ vi.mock("react-pdf", () => ({ describe("ChunksPanel", () => { beforeEach(() => { + shouldFlushVirtualizerTimers = false; globalThis.ResizeObserver = class ResizeObserver { observe() {} unobserve() {} @@ -35,7 +39,11 @@ describe("ChunksPanel", () => { }; }); - afterEach(() => { + afterEach(async () => { + if (shouldFlushVirtualizerTimers) { + await flushVirtualizerTimers(); + } + cleanup(); sourceOriginalPreviewRequest.clearCacheForTests(); vi.unstubAllGlobals(); @@ -1427,6 +1435,8 @@ function createFileDropEvent(file: File): Event { function mockVirtualViewportWithChunkHeights( heightsByChunkId: Readonly>, ): void { + shouldFlushVirtualizerTimers = true; + vi.spyOn(window.HTMLElement.prototype, "offsetHeight", "get") .mockImplementation(function getOffsetHeight(this: HTMLElement): number { if (this.hasAttribute("data-radix-scroll-area-viewport")) return 720; @@ -1438,3 +1448,11 @@ function mockVirtualViewportWithChunkHeights( vi.spyOn(window.HTMLElement.prototype, "offsetWidth", "get") .mockImplementation((): number => 720); } + +async function flushVirtualizerTimers(): Promise { + await act(async () => { + await new Promise((resolve) => { + window.setTimeout(resolve, virtualizerScrollResetDelayMs + 25); + }); + }); +} diff --git a/src/domains/sources/route-upload.ts b/src/domains/sources/route-upload.ts index 2f6f7f4..4c3fc7d 100644 --- a/src/domains/sources/route-upload.ts +++ b/src/domains/sources/route-upload.ts @@ -1,6 +1,6 @@ import { Effect } from "effect" -import type { Source, Workspace } from "@/infrastructure/db/schema" +import type { Workspace } from "@/infrastructure/db/schema" import { routeResult } from "@/lib/route-result" import { startBackgroundReconciliation } from "./background-reconcile" import { validateSourceBlobUploadInput } from "./blob-upload"