The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { describe, expect, test } from "vite-plus/test"; |
| 2 | |
| 3 | import { getTimelinePageScrollKey } from "./pageScrollController"; |
| 4 | |
| 5 | describe("page scroll helpers", () => { |
| 6 | const composerPageScrollEvent = ( |
| 7 | overrides: Partial<Parameters<typeof getTimelinePageScrollKey>[0]> = {}, |
| 8 | ) => ({ |
| 9 | altKey: false, |
| 10 | clientHeight: 200, |
| 11 | ctrlKey: false, |
| 12 | defaultPrevented: false, |
| 13 | isComposing: false, |
| 14 | key: "PageDown", |
| 15 | keyCode: 34, |
| 16 | metaKey: false, |
| 17 | scrollHeight: 200, |
| 18 | scrollTop: 0, |
| 19 | shiftKey: false, |
| 20 | ...overrides, |
| 21 | }); |
| 22 | |
| 23 | test("leaves page keys to IME composition", () => { |
| 24 | expect(getTimelinePageScrollKey(composerPageScrollEvent({ isComposing: true }))).toBeNull(); |
| 25 | expect(getTimelinePageScrollKey(composerPageScrollEvent({ keyCode: 229 }))).toBeNull(); |
| 26 | }); |
| 27 | |
| 28 | test("leaves page keys to an overflowing composer until it reaches the boundary", () => { |
| 29 | expect( |
| 30 | getTimelinePageScrollKey(composerPageScrollEvent({ scrollHeight: 600, scrollTop: 0 })), |
| 31 | ).toBeNull(); |
| 32 | expect( |
| 33 | getTimelinePageScrollKey( |
| 34 | composerPageScrollEvent({ |
| 35 | key: "PageUp", |
| 36 | keyCode: 33, |
| 37 | scrollHeight: 600, |
| 38 | scrollTop: 400, |
| 39 | }), |
| 40 | ), |
| 41 | ).toBeNull(); |
| 42 | |
| 43 | expect( |
| 44 | getTimelinePageScrollKey( |
| 45 | composerPageScrollEvent({ |
| 46 | key: "PageUp", |
| 47 | keyCode: 33, |
| 48 | scrollHeight: 600, |
| 49 | scrollTop: 0, |
| 50 | }), |
| 51 | ), |
| 52 | ).toBe("PageUp"); |
| 53 | expect( |
| 54 | getTimelinePageScrollKey(composerPageScrollEvent({ scrollHeight: 600, scrollTop: 400 })), |
| 55 | ).toBe("PageDown"); |
| 56 | }); |
| 57 | |
| 58 | test("hands off page keys within a fractional pixel of the composer boundary", () => { |
| 59 | expect( |
| 60 | getTimelinePageScrollKey( |
| 61 | composerPageScrollEvent({ |
| 62 | key: "PageUp", |
| 63 | keyCode: 33, |
| 64 | scrollHeight: 600, |
| 65 | scrollTop: 0.5, |
| 66 | }), |
| 67 | ), |
| 68 | ).toBe("PageUp"); |
| 69 | expect( |
| 70 | getTimelinePageScrollKey(composerPageScrollEvent({ scrollHeight: 600, scrollTop: 399.5 })), |
| 71 | ).toBe("PageDown"); |
| 72 | }); |
| 73 | }); |