Open History to see the last commit
1import { EnvironmentId } from "@t3tools/contracts";
2import { describe, expect, it, vi } from "vite-plus/test";
3import { page, userEvent } from "vite-plus/test/browser";
4
5import "~/index.css";
6import { render } from "../../../test/render";
7import { newSimlockDeviceHost } from "./simlockDeviceHostsSettings.logic";
8
9vi.mock(import("../../state/device"), async () => {
10 const { AsyncResult, Atom } = await import("effect/reactivity");
11 const identityAtom = Atom.make(AsyncResult.initial());
12 return {
13 deviceSimlockIdentityCheck: (() => identityAtom) as never,
14 };
15});
16vi.mock(import("./SecretSourceInput"), () => ({
17 useSecretSources: () => [],
18 SecretSourceInput: (() => <input />) as never,
19}));
20
21import { SimlockDeviceHostEditor } from "./SimlockDeviceHostEditor";
22
23describe("SimlockDeviceHostEditor", () => {
24 it("leaves a cleared limit field empty and keeps Save off until a number is entered", async () => {
25 await using _screen = await render(
26 <SimlockDeviceHostEditor
27 host={{
28 ...newSimlockDeviceHost("simlock"),
29 gatewayUrl: "https://gateway.example.ts.net:4700",
30 }}
31 isNew={false}
32 environments={[
33 { environmentId: EnvironmentId.make("local"), label: "This Mac", hosts: [] },
34 ]}
35 busy={false}
36 onSave={() => {}}
37 onClose={() => {}}
38 />,
39 );
40
41 const saveButton = page.getByRole("button", { name: "Save host" });
42 await expect.element(saveButton).not.toBeDisabled();
43
44 const input = page.getByLabelText("Devices at once");
45 await userEvent.clear(input);
46 await expect.element(input).toHaveDisplayValue("");
47 await expect.element(saveButton).toBeDisabled();
48
49 await userEvent.type(input, "5");
50 await expect.element(input).toHaveDisplayValue("5");
51 await expect.element(saveButton).not.toBeDisabled();
52 });
53});