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
| 1 | import { EnvironmentId } from "@t3tools/contracts"; |
| 2 | import { page, userEvent } from "vite-plus/test/browser"; |
| 3 | import { describe, expect, it, vi } from "vite-plus/test"; |
| 4 | |
| 5 | import { render } from "../../../test/render"; |
| 6 | |
| 7 | const updateSettings = vi.hoisted(() => vi.fn()); |
| 8 | |
| 9 | vi.mock(import("../../hooks/useSettings"), async (original) => ({ |
| 10 | ...(await original()), |
| 11 | useUpdateEnvironmentSettings: (() => updateSettings) as never, |
| 12 | })); |
| 13 | vi.mock(import("./SecretSourceInput"), async (original) => ({ |
| 14 | ...(await original()), |
| 15 | useSecretSources: () => [], |
| 16 | })); |
| 17 | |
| 18 | import { AddUsageLimitSourceDialog } from "./AddUsageLimitSourceDialog"; |
| 19 | |
| 20 | describe("AddUsageLimitSourceDialog", () => { |
| 21 | it("adds the hub when Enter is pressed in a field", async () => { |
| 22 | updateSettings.mockClear(); |
| 23 | const onOpenChange = vi.fn(); |
| 24 | await using _screen = await render( |
| 25 | <AddUsageLimitSourceDialog |
| 26 | open |
| 27 | onOpenChange={onOpenChange} |
| 28 | environmentId={EnvironmentId.make("local")} |
| 29 | environmentLabel="This Mac" |
| 30 | sources={{}} |
| 31 | />, |
| 32 | ); |
| 33 | |
| 34 | await userEvent.type(page.getByLabelText("Hub URL"), "https://hub.example.ts.net:8318"); |
| 35 | await userEvent.type(page.getByLabelText("Management key"), "secret-key{Enter}"); |
| 36 | |
| 37 | expect(updateSettings).toHaveBeenCalledOnce(); |
| 38 | expect(updateSettings).toHaveBeenCalledWith({ |
| 39 | usageLimitSources: { |
| 40 | "cliproxy-hub.example.ts.net-8318": expect.objectContaining({ |
| 41 | url: "https://hub.example.ts.net:8318", |
| 42 | managementKey: "secret-key", |
| 43 | }), |
| 44 | }, |
| 45 | }); |
| 46 | expect(onOpenChange).toHaveBeenCalledWith(false); |
| 47 | }); |
| 48 | }); |