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

ChatView.queuedEdit.browser.test.tsx

79 lines3.2 KB

1import { createMemoryHistory } from "@tanstack/react-router";
2import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings";
3import type * as Context from "effect/Context";
4import { expect, it, vi } from "vite-plus/test";
5import { page, userEvent } from "vite-plus/test/browser";
6​
7import { AppRoot } from "~/AppRoot";
8// The route loads ChatView lazily, and its first transform (React Compiler over ~4k lines)
9// takes 6-11s; importing it here keeps that out of the test's timeout.
10import "~/components/ChatView";
11import { __setClientSettingsForTests } from "~/hooks/useSettings";
12import { getRouter } from "~/router";
13import {
14 CODEX_PROVIDER,
15 ENVIRONMENT_ID,
16 dispatchedCommands,
17 installFakeEnvironment,
18 threadWithHistory,
19 type FakeDriver,
20} from "../../test/fakeEnvironment";
21import { render } from "../../test/render";
22​
23// The socket is the only fake layer.
24vi.mock("../../../../packages/client-runtime/src/connection/driver.ts", async (importOriginal) => {
25 const [actual, { fakeDriver }, Layer] = await Promise.all([
26 importOriginal<{ readonly ConnectionDriver: Context.Key<unknown, FakeDriver> }>(),
27 import("../../test/fakeEnvironment"),
28 import("effect/Layer"),
29 ]);
30 return { ...actual, layer: Layer.succeed(actual.ConnectionDriver, fakeDriver) };
31});
32​
33// Its own file: the app's server config subscription outlives a test, and it must offer usage limits.
34it("Enter in a queued-message edit saves /usage-limits as its text", async () => {
35 const history = threadWithHistory("limits-edit", 2);
36 const queued = { ...history.runs[1]!, status: "queued" as const, completedAt: null };
37 const thread = { ...history, runs: [history.runs[0]!, queued] };
38 using _environment = installFakeEnvironment([thread], {
39 acceptCommands: true,
40 providers: [
41 {
42 ...CODEX_PROVIDER,
43 slashCommands: [{ name: "usage-limits" }],
44 usageLimits: {
45 checkedAt: "2026-03-17T19:12:28.000Z",
46 windows: [{ id: "primary", kind: "session", label: "Session", usedPercent: 40 }],
47 },
48 },
49 ],
50 });
51 __setClientSettingsForTests({
52 ...DEFAULT_CLIENT_SETTINGS,
53 onboardingCompletedAt: "2026-01-01T00:00:00.000Z",
54 });
55 const router = getRouter(
56 createMemoryHistory({ initialEntries: [`/${ENVIRONMENT_ID}/${thread.id}`] }),
57 );
58 await router.load();
59 await using _app = await render(<AppRoot router={router} />, {
60 // AppRoot brings its own router.
61 router: false,
62 });
63 await page.getByRole("button", { name: "Edit queued message" }).click();
64 await expect.element(page.getByRole("button", { name: "Update queued message" })).toBeVisible();
65​
66 await userEvent.click(page.getByTestId("composer-editor"));
67 await userEvent.keyboard("{ControlOrMeta>}a{/ControlOrMeta}/usage-limits");
68 const suggestion = page.getByRole("option", { name: /^\/usage-limits/ });
69 await expect.element(suggestion).toBeVisible();
70 await userEvent.keyboard("{Enter}");
71 await expect.element(suggestion).not.toBeInTheDocument();
72 await userEvent.keyboard("{Enter}");
73​
74 await vi.waitFor(() =>
75 expect(dispatchedCommands()).toContainEqual(
76 expect.objectContaining({ type: "queued-run.edit", runId: queued.id, text: "/usage-limits" }),
77 ),
78 );
79});