The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { describe, expect, it, vi } from "vite-plus/test"; |
| 2 | import { measuredEndOffset, settleListScroll } from "./useTimelinePositionRestore"; |
| 3 | |
| 4 | describe("settleListScroll", () => { |
| 5 | it("hands off when a streaming reply keeps moving the end", async () => { |
| 6 | vi.useFakeTimers(); |
| 7 | // The node test environment has no animation frames; fake ones run on the fake clock. |
| 8 | vi.stubGlobal("requestAnimationFrame", (callback: FrameRequestCallback) => |
| 9 | setTimeout(() => callback(0), 16), |
| 10 | ); |
| 11 | // Every correction lands, then the reply grows before the next frame. |
| 12 | const element = { scrollTop: 0, scrollHeight: 5_000, clientHeight: 800 }; |
| 13 | const list = { |
| 14 | getScrollableNode: () => element as unknown as HTMLElement, |
| 15 | scrollToOffset: async ({ offset }: { offset: number }) => { |
| 16 | element.scrollTop = offset; |
| 17 | element.scrollHeight += 40; |
| 18 | }, |
| 19 | }; |
| 20 | |
| 21 | let settled = false; |
| 22 | void settleListScroll(list, measuredEndOffset, () => false).then(() => { |
| 23 | settled = true; |
| 24 | }); |
| 25 | await vi.advanceTimersByTimeAsync(5_000); |
| 26 | vi.useRealTimers(); |
| 27 | vi.unstubAllGlobals(); |
| 28 | |
| 29 | expect(settled).toBe(true); |
| 30 | }); |
| 31 | }); |