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

AddUsageLimitSourceDialog.browser.test.tsx

48 lines1.6 KB

1import { EnvironmentId } from "@t3tools/contracts";
2import { page, userEvent } from "vite-plus/test/browser";
3import { describe, expect, it, vi } from "vite-plus/test";
4​
5import { render } from "../../../test/render";
6​
7const updateSettings = vi.hoisted(() => vi.fn());
8​
9vi.mock(import("../../hooks/useSettings"), async (original) => ({
10 ...(await original()),
11 useUpdateEnvironmentSettings: (() => updateSettings) as never,
12}));
13vi.mock(import("./SecretSourceInput"), async (original) => ({
14 ...(await original()),
15 useSecretSources: () => [],
16}));
17​
18import { AddUsageLimitSourceDialog } from "./AddUsageLimitSourceDialog";
19​
20describe("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});