Skip to content
Source
Sign inSign up

DeviceToolsPanel.browser.test.tsx

54 lines1.5 KB

1import type { DeviceSummary } from "@t3tools/contracts";
2import { expect, it, vi } from "vite-plus/test";
3import { userEvent } from "vite-plus/test/browser";
4​
5import { act, render } from "../../../test/render";
6import { DeviceToolsPanel } from "./DeviceToolsPanel";
7import type { DeviceControls } from "./useDeviceControls";
8​
9const device: DeviceSummary = {
10 hostId: "local",
11 id: "emulator",
12 name: "Pixel",
13 platform: "android",
14 version: "Android 15",
15 booted: true,
16 physical: false,
17};
18​
19it("keeps a typed URL until opening it succeeds", async () => {
20 const run = vi
21 .fn<DeviceControls["act"]>()
22 .mockResolvedValueOnce(false)
23 .mockResolvedValueOnce(true);
24 const controls: DeviceControls = {
25 detail: null,
26 pending: false,
27 error: null,
28 act: run,
29 disabled: false,
30 foregroundApp: null,
31 };
32 await using screen = await render(
33 <DeviceToolsPanel
34 controls={controls}
35 hostDiagnostics={undefined}
36 device={device}
37 access={null}
38 axOverlay={false}
39 onAxOverlayChange={() => {}}
40 onClose={() => {}}
41 />,
42 );
43 const url = "myapp://settings";
44 const field = screen.getByPlaceholder("https://… or myapp://");
45 const open = screen.getByRole("button", { name: "Open" });
46​
47 await userEvent.fill(field, url);
48 await userEvent.click(open);
49 await act(() => run.mock.results[0]?.value);
50 await expect.element(field).toHaveValue(url);
51​
52 await userEvent.click(open);
53 await expect.element(field).toHaveValue("");
54});