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
20 changes: 19 additions & 1 deletion src/components/chunks-panel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import { ChunksPanel } from "./chunks-panel";
import { sourceOriginalPreviewRequest } from "./source-original-preview-request";

const C = ChunksPanel as React.FC<Record<string, unknown>>;
const virtualizerScrollResetDelayMs = 150;

let shouldFlushVirtualizerTimers: boolean = false;

vi.mock("react-pdf", () => ({
pdfjs: {
Expand All @@ -28,14 +31,19 @@ vi.mock("react-pdf", () => ({

describe("ChunksPanel", () => {
beforeEach(() => {
shouldFlushVirtualizerTimers = false;
globalThis.ResizeObserver = class ResizeObserver {
observe() {}
unobserve() {}
disconnect() {}
};
});

afterEach(() => {
afterEach(async () => {
if (shouldFlushVirtualizerTimers) {
await flushVirtualizerTimers();
}

cleanup();
sourceOriginalPreviewRequest.clearCacheForTests();
vi.unstubAllGlobals();
Expand Down Expand Up @@ -1427,6 +1435,8 @@ function createFileDropEvent(file: File): Event {
function mockVirtualViewportWithChunkHeights(
heightsByChunkId: Readonly<Record<string, number>>,
): 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;
Expand All @@ -1438,3 +1448,11 @@ function mockVirtualViewportWithChunkHeights(
vi.spyOn(window.HTMLElement.prototype, "offsetWidth", "get")
.mockImplementation((): number => 720);
}

async function flushVirtualizerTimers(): Promise<void> {
await act(async () => {
await new Promise<void>((resolve) => {
window.setTimeout(resolve, virtualizerScrollResetDelayMs + 25);
});
});
}
2 changes: 1 addition & 1 deletion src/domains/sources/route-upload.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Loading