The best way to control Claude Code, Codex and more from any computer or phone

main
tsx 85 lines 2.81 KB
Raw
1 import { describe, expect, it, vi } from "vite-plus/test";
2 import { page, userEvent } from "vite-plus/test/browser";
3
4 import { render } from "../../../test/render";
5
6 const ENVIRONMENT_ID = vi.hoisted(() => "workstation");
7
8 vi.mock(import("~/state/presentation"), async (original) => {
9 const { Atom } = await import("effect/reactivity");
10 const actual = await original();
11 const presentation = {
12 entry: { target: { label: "workstation" } },
13 connection: { phase: "connected" },
14 serverConfig: {
15 environment: { capabilities: { usagePriceOverrides: true, usageModelAliases: true } },
16 },
17 };
18 return {
19 ...actual,
20 environmentPresentations: {
21 ...actual.environmentPresentations,
22 presentationsAtom: Atom.make(new Map([[ENVIRONMENT_ID, presentation]])) as never,
23 },
24 };
25 });
26 vi.mock(import("~/state/server"), async (original) => {
27 const { Atom } = await import("effect/reactivity");
28 const actual = await original();
29 const settings = Atom.make({ usagePriceOverrides: {}, usageModelAliases: {} });
30 return {
31 ...actual,
32 serverEnvironment: {
33 ...actual.serverEnvironment,
34 settingsValueAtom: (() => settings) as never,
35 },
36 };
37 });
38 vi.mock(import("~/state/session"), async (original) => {
39 const { AsyncResult, Atom } = await import("effect/reactivity");
40 const actual = await original();
41 const session = Atom.make(
42 AsyncResult.success({ authenticated: true, scopes: ["settings:write"] }),
43 );
44 return {
45 ...actual,
46 environmentSession: {
47 ...actual.environmentSession,
48 sessionStateAtom: (() => session) as never,
49 },
50 };
51 });
52 vi.mock(import("~/state/use-atom-command"), async (original) => ({
53 ...(await original()),
54 useAtomCommand: (() => vi.fn()) as never,
55 }));
56
57 import { UsagePriceOverrides } from "./UsagePriceOverrides";
58
59 const renderPrices = (initialModel?: string) =>
60 render(
61 <UsagePriceOverrides
62 usage={[]}
63 initialSelectedEnvironmentIds={null}
64 initialModel={initialModel}
65 onOpenChange={() => {}}
66 />,
67 );
68
69 describe("UsagePriceOverrides", () => {
70 it("waits for a price before flagging an unpriced model's new row", async () => {
71 await using _screen = await renderPrices("glm-5.3");
72 const modelId = page.getByLabelText("New model ID");
73 await expect.element(modelId).toHaveValue("glm-5.3");
74
75 expect(page.getByRole("alert").elements()).toEqual([]);
76 await expect.element(modelId).not.toHaveAttribute("aria-invalid");
77 await expect.element(page.getByRole("button", { name: "Save changes" })).toBeDisabled();
78
79 await userEvent.type(page.getByLabelText("Input price for glm-5.3"), "2");
80 await expect
81 .element(page.getByRole("alert"))
82 .toHaveTextContent("Output is required on workstation.");
83 await expect.element(page.getByRole("button", { name: "Save changes" })).toBeDisabled();
84 });
85 });