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 | |
| 3 | import { fakeTimers } from "../../../test/render"; |
| 4 | import { forwardWheelToTimeline } from "./timelineMinimapWheel"; |
| 5 | |
| 6 | function mountTimeline() { |
| 7 | const timeline = document.createElement("div"); |
| 8 | timeline.style.cssText = "height: 200px; overflow-y: auto;"; |
| 9 | const content = document.createElement("div"); |
| 10 | content.style.height = "2000px"; |
| 11 | timeline.append(content); |
| 12 | document.body.append(timeline); |
| 13 | return Object.assign(timeline, { [Symbol.dispose]: () => timeline.remove() }); |
| 14 | } |
| 15 | |
| 16 | function wheel(deltaY: number, wheelDeltaY: number): WheelEvent { |
| 17 | const init = { cancelable: true, deltaY, wheelDeltaY }; |
| 18 | return new WheelEvent("wheel", init); |
| 19 | } |
| 20 | |
| 21 | describe("forwardWheelToTimeline", () => { |
| 22 | it.each([ |
| 23 | ["macOS", -360], |
| 24 | ["Linux and Windows", -120], |
| 25 | ])("scrolls %s trackpad deltas immediately", (_platform, wheelDeltaY) => { |
| 26 | using timeline = mountTimeline(); |
| 27 | forwardWheelToTimeline(wheel(120, wheelDeltaY), timeline); |
| 28 | expect(timeline.scrollTop).toBe(120); |
| 29 | }); |
| 30 | |
| 31 | it("glides mouse wheel notches and accumulates them", () => { |
| 32 | using timeline = mountTimeline(); |
| 33 | using _timers = fakeTimers(); |
| 34 | forwardWheelToTimeline(wheel(100, -120), timeline); |
| 35 | forwardWheelToTimeline(wheel(100, -120), timeline); |
| 36 | expect(timeline.scrollTop).toBe(0); |
| 37 | vi.advanceTimersByTime(75); |
| 38 | expect(timeline.scrollTop).toBeGreaterThan(0); |
| 39 | expect(timeline.scrollTop).toBeLessThan(200); |
| 40 | vi.advanceTimersByTime(100); |
| 41 | expect(timeline.scrollTop).toBe(200); |
| 42 | }); |
| 43 | |
| 44 | it("stops gliding when the user clicks or navigates", () => { |
| 45 | using timeline = mountTimeline(); |
| 46 | using _timers = fakeTimers(); |
| 47 | forwardWheelToTimeline(wheel(100, -120), timeline); |
| 48 | vi.advanceTimersByTime(50); |
| 49 | timeline.scrollTop = 1000; |
| 50 | window.dispatchEvent(new PointerEvent("pointerdown")); |
| 51 | vi.advanceTimersByTime(200); |
| 52 | expect(timeline.scrollTop).toBe(1000); |
| 53 | }); |
| 54 | }); |