From 00b037cf97004fed1d9d793191f3d234847ee470 Mon Sep 17 00:00:00 2001 From: plebeius Date: Mon, 19 Jan 2026 16:08:13 +0100 Subject: [PATCH] not needed --- src/hooks/use-scroll-to-reply.test.tsx | 132 ------------------------- 1 file changed, 132 deletions(-) delete mode 100644 src/hooks/use-scroll-to-reply.test.tsx diff --git a/src/hooks/use-scroll-to-reply.test.tsx b/src/hooks/use-scroll-to-reply.test.tsx deleted file mode 100644 index 2ae78df0..00000000 --- a/src/hooks/use-scroll-to-reply.test.tsx +++ /dev/null @@ -1,132 +0,0 @@ -/* @vitest-environment jsdom */ -import { act, useMemo } from 'react'; -import { describe, it, vi, beforeEach, afterEach, expect } from 'vitest'; -import { createRoot, Root } from 'react-dom/client'; -import { VirtuosoHandle } from 'react-virtuoso'; -import useScrollToReply from './use-scroll-to-reply'; - -const TestHarness = ({ - targetReplyCid, - replies, - hasMore, - loadMore, - virtuosoRef, - renderTargetElement = false, -}: { - targetReplyCid?: string; - replies: Array<{ cid?: string | null }>; - hasMore: boolean; - loadMore: () => void; - virtuosoRef: React.RefObject; - renderTargetElement?: boolean; -}) => { - const memoizedReplies = useMemo(() => replies, [replies]); - useScrollToReply({ - targetReplyCid, - replies: memoizedReplies, - hasMore, - loadMore, - virtuosoRef, - enabled: true, - }); - - return renderTargetElement ?
: null; -}; - -describe('useScrollToReply', () => { - const originalScrollIntoView = Element.prototype.scrollIntoView; - let root: Root; - let container: HTMLDivElement; - - beforeEach(() => { - Element.prototype.scrollIntoView = vi.fn(); - container = document.createElement('div'); - document.body.appendChild(container); - root = createRoot(container); - vi.useFakeTimers(); - }); - - afterEach(() => { - act(() => { - root.unmount(); - }); - container.remove(); - Element.prototype.scrollIntoView = originalScrollIntoView; - vi.useRealTimers(); - vi.restoreAllMocks(); - }); - - it('scrolls to target reply index when present', async () => { - const scrollToIndex = vi.fn(); - const virtuosoRef = { current: { scrollToIndex } as unknown as VirtuosoHandle }; - const replies = [{ cid: 'a' }, { cid: 'b' }, { cid: 'c' }]; - - await act(() => { - root.render(); - }); - - await act(() => Promise.resolve()); - - act(() => { - vi.advanceTimersByTime(400); - }); - - expect(scrollToIndex).toHaveBeenCalledWith({ - index: 1, - align: 'center', - behavior: 'smooth', - }); - }); - - it('loads more when target reply is not yet present', async () => { - const loadMore = vi.fn(); - const virtuosoRef = { current: { scrollToIndex: vi.fn() } as unknown as VirtuosoHandle }; - let intervalCallback: (() => void) | null = null; - let timeoutCallback: (() => void) | null = null; - - vi.spyOn(window, 'setInterval').mockImplementation((callback) => { - intervalCallback = callback as () => void; - return 1; - }); - - vi.spyOn(window, 'setTimeout').mockImplementation((callback) => { - timeoutCallback = callback as () => void; - return 1; - }); - - await act(() => { - root.render(); - }); - - await act(() => Promise.resolve()); - - act(() => { - intervalCallback?.(); - }); - - act(() => { - timeoutCallback?.(); - }); - - expect(loadMore).toHaveBeenCalled(); - }); - - it('scrolls into view when virtualization is not active', async () => { - const loadMore = vi.fn(); - const virtuosoRef = { current: { scrollToIndex: vi.fn() } as unknown as VirtuosoHandle }; - - await act(() => { - root.render( - , - ); - }); - - await act(() => Promise.resolve()); - - act(() => { - vi.advanceTimersByTime(400); - }); - - expect(Element.prototype.scrollIntoView).toHaveBeenCalled(); - }); -});