Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

PullRequestCandidatePicker.browser.test.tsx

72 lines2.2 KB

1import { useState } from "react";
2import { expect, it, vi } from "vite-plus/test";
3import { cdp, page, userEvent } from "vite-plus/test/browser";
4​
5import "~/index.css";
6​
7import { render } from "../../../test/render";
8import { PullRequestCandidatePicker } from "./PullRequestCandidatePicker";
9​
10const people = Array.from({ length: 40 }, (_, index) => `person-${index}`);
11​
12function Picker() {
13 const [open, setOpen] = useState(false);
14 return (
15 <PullRequestCandidatePicker
16 icon="+"
17 label="Request a review"
18 allowed
19 disabledReason=""
20 open={open}
21 onOpenChange={setOpen}
22 query=""
23 onQueryChange={() => {}}
24 searchLabel="Search people"
25 isPending={false}
26 error={null}
27 candidates={people}
28 emptyLabel=""
29 noMatchLabel=""
30 errorLabel=""
31 truncated={false}
32 truncatedLabel=""
33 candidateKey={(person) => person}
34 onSelect={() => {}}
35 >
36 {(person) => person}
37 </PullRequestCandidatePicker>
38 );
40​
41it("holds the panel still while the picker is open", async () => {
42 await using screen = await render(
43 <div data-testid="panel" className="h-96 w-96 overflow-y-auto">
44 <div data-testid="header" className="h-24" />
45 <Picker />
46 <div data-testid="sticky" className="sticky top-0 z-10 h-10 bg-background" />
47 <div className="h-[200vh]" />
48 </div>,
49 );
50 await screen.getByLabelText("Request a review").click();
51 const list = page.getByRole("listbox").element();
52 const listViewport = list.closest("[data-slot=scroll-area-viewport]")!;
53 const panel = screen.getByTestId("panel").element();
54 const frame = window.frameElement?.getBoundingClientRect() ?? { left: 0, top: 0 };
55 const wheelOver = (testId: string) => {
56 const box = screen.getByTestId(testId).element().getBoundingClientRect();
57 return cdp().send("Input.dispatchMouseEvent", {
58 type: "mouseWheel",
59 x: frame.left + box.right - 24,
60 y: frame.top + box.top + box.height / 2,
61 deltaX: 0,
62 deltaY: 300,
63 });
64 };
65​
66 await wheelOver("header");
67 await wheelOver("sticky");
68 await userEvent.wheel(list, { delta: { y: 300 } });
69​
70 await vi.waitFor(() => expect(listViewport.scrollTop).toBeGreaterThan(0));
71 expect(panel.scrollTop).toBe(0);
72});