The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type { DeviceSummary } from "@t3tools/contracts"; |
| 2 | import { expect, it, vi } from "vite-plus/test"; |
| 3 | import { userEvent } from "vite-plus/test/browser"; |
| 4 | |
| 5 | import { act, render } from "../../../test/render"; |
| 6 | import { DeviceToolsPanel } from "./DeviceToolsPanel"; |
| 7 | import type { DeviceControls } from "./useDeviceControls"; |
| 8 | |
| 9 | const 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 | |
| 19 | it("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 | }); |