@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

main
tsx 109 lines 3.77 KB
Raw
1 import { describe, expect, it } from "vite-plus/test";
2 import { userEvent } from "vite-plus/test/browser";
3
4 import { render } from "../../../test/render";
5 import { attachTimelineViewport } from "./timelineViewport";
6
7 describe("attachTimelineViewport", () => {
8 it("reports an upward scroll only while input is on an embedded frame", async () => {
9 // A plain scroller; the viewport needs no routes.
10 await using screen = await render(
11 <div>
12 <div data-testid="outside" style={{ height: 40 }} />
13 <div data-testid="timeline" style={{ height: 300, overflowY: "auto" }}>
14 <div style={{ height: 1200 }} />
15 <iframe
16 title="render"
17 sandbox=""
18 srcDoc="<p>frame</p>"
19 style={{ display: "block", height: 200 }}
20 />
21 <div data-testid="tail" style={{ height: 1200 }} />
22 </div>
23 </div>,
24 { router: false },
25 );
26 const timeline = screen.getByTestId("timeline").element() as HTMLElement;
27 const tail = screen.getByTestId("tail").element() as HTMLElement;
28 const scrolled = () =>
29 new Promise<void>((resolve) =>
30 timeline.addEventListener("scroll", () => resolve(), { once: true }),
31 );
32 let scroll = scrolled();
33 timeline.scrollTop = 1500;
34 await scroll;
35 const viewport = attachTimelineViewport(timeline);
36 const sources: string[] = [];
37 viewport.subscribe((navigation) => sources.push(navigation.source));
38
39 await userEvent.hover(screen.getByTestId("outside"));
40 scroll = scrolled();
41 timeline.scrollTop -= 100;
42 await scroll;
43 // Content that shrinks and grows back in one task clamps scrollTop with no input at all.
44 scroll = scrolled();
45 timeline.scrollTop = timeline.scrollHeight;
46 await scroll;
47 scroll = scrolled();
48 tail.style.height = "400px";
49 void timeline.scrollTop;
50 tail.style.height = "1200px";
51 await scroll;
52 expect(sources).toEqual([]);
53
54 await userEvent.hover(screen.getByTitle("render"));
55 scroll = scrolled();
56 timeline.scrollTop -= 100;
57 await scroll;
58 expect(sources).toEqual(["scroll"]);
59 const frame = screen.getByTitle("render").element() as HTMLIFrameElement;
60 const resize = (height: number, source: Window | null = frame.contentWindow) =>
61 window.dispatchEvent(
62 new MessageEvent("message", {
63 source,
64 data: { jsonrpc: "2.0", method: "ui/notifications/size-changed", params: { height } },
65 }),
66 );
67 sources.length = 0;
68 resize(200);
69 resize(400);
70 expect(sources).toEqual([]);
71 frame.focus();
72 resize(400, window);
73 resize(400);
74 expect(sources).toEqual([]);
75 resize(600);
76 resize(200);
77 expect(sources).toEqual(["command", "command"]);
78 viewport.dispose();
79 resize(800);
80 expect(sources).toEqual(["command", "command"]);
81 });
82
83 it("reports a scrollbar press but not a click on the scroller's empty padding", async () => {
84 await using screen = await render(
85 <div
86 data-testid="timeline"
87 style={{ height: 300, width: 400, overflowY: "auto", padding: "0 42px" }}
88 >
89 <div style={{ height: 1200 }} />
90 </div>,
91 { router: false },
92 );
93 const timeline = screen.getByTestId("timeline").element() as HTMLElement;
94 const viewport = attachTimelineViewport(timeline);
95 const navigations: unknown[] = [];
96 viewport.subscribe((navigation) => navigations.push(navigation));
97
98 await userEvent.click(screen.getByTestId("timeline"), { position: { x: 10, y: 150 } });
99 await userEvent.click(screen.getByTestId("timeline"), {
100 position: { x: timeline.offsetWidth - 2, y: 150 },
101 });
102
103 expect(navigations).toEqual([
104 { source: "pointer", onScrollbar: false },
105 { source: "pointer", onScrollbar: true },
106 ]);
107 viewport.dispose();
108 });
109 });