Skip to content

Commit 35f710c

Browse files
only21milcodex
andcommitted
test(web): cover project name IME commit boundaries
Co-Authored-By: GPT-6.1 Sol <[email protected]>
1 parent 412b407 commit 35f710c

1 file changed

Lines changed: 124 additions & 0 deletions

File tree

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import { EnvironmentId, ProjectId, ProviderInstanceId } from "@t3tools/contracts";
2+
import { AsyncResult } from "effect/reactivity";
3+
import type { ReactNode } from "react";
4+
import { describe, expect, it, vi } from "vite-plus/test";
5+
import { userEvent } from "vite-plus/test/browser";
6+
7+
import { act, render } from "../../../test/render";
8+
import { buildSidebarProjectSnapshots } from "../../sidebarProjectGrouping";
9+
import type { Project } from "../../types";
10+
11+
const state = vi.hoisted(() => ({ projects: [] as Project[] }));
12+
const environmentId = EnvironmentId.make("local");
13+
14+
vi.mock(import("./useSettingsProjectGroups"), () => ({
15+
useSettingsProjectGroups: () =>
16+
buildSidebarProjectSnapshots({
17+
projects: state.projects,
18+
settings: { sidebarProjectGroupingMode: "repository", sidebarProjectGroupingOverrides: {} },
19+
primaryEnvironmentId: environmentId,
20+
resolveEnvironmentLabel: () => "Local",
21+
}),
22+
}));
23+
vi.mock("../../state/environments", async (original) => ({
24+
...(await original<typeof import("../../state/environments")>()),
25+
usePrimaryEnvironmentId: () => environmentId,
26+
useEnvironments: () => ({
27+
environments: [{ environmentId, connection: { phase: "connected" }, serverConfig: {} }],
28+
}),
29+
}));
30+
vi.mock("../../state/session", async (original) => ({
31+
...(await original<typeof import("../../state/session")>()),
32+
readEnvironmentScope: () => true,
33+
useEnvironmentsWithScope: () => new Set([environmentId]),
34+
}));
35+
vi.mock("../../state/entities", async (original) => ({
36+
...(await original<typeof import("../../state/entities")>()),
37+
useThreadShells: () => [],
38+
waitForProjectRemoval: vi.fn(),
39+
}));
40+
vi.mock("../../state/use-orchestration-command", () => ({
41+
useOrchestrationCommand:
42+
() =>
43+
async ({ input }: { input: { title: string } }) => {
44+
state.projects = state.projects.map((project) => ({ ...project, title: input.title }));
45+
return AsyncResult.success(undefined);
46+
},
47+
}));
48+
vi.mock(import("./ProjectDefaultsSettings"), () => ({ ProjectDefaultsSettings: () => <></> }));
49+
vi.mock(import("./ProjectActionsSettings"), () => ({ ProjectActionsSettings: () => <></> }));
50+
vi.mock(import("../ProjectFavicon"), () => ({ ProjectFavicon: () => <></> }));
51+
vi.mock(import("./ProjectFaviconPickerDialog"), () => ({
52+
canPickExternalProjectFavicon: () => false,
53+
ProjectFaviconPickerDialog: () => <></>,
54+
}));
55+
// Keep the real input and rename path; unrelated settings rows need a live settings scope.
56+
vi.mock("./settingsLayout", () => ({
57+
SettingsPageContainer: ({ children }: { children: ReactNode }) => children,
58+
SettingsSection: ({ children }: { children: ReactNode }) => children,
59+
SettingsRow: ({ control }: { control: ReactNode }) => control,
60+
SettingResetButton: () => null,
61+
}));
62+
63+
import { ProjectSettingsPanel } from "./ProjectSettingsPanel";
64+
65+
function setup() {
66+
state.projects = [
67+
{
68+
id: ProjectId.make("project"),
69+
environmentId,
70+
title: "Original",
71+
workspaceRoot: "/work/project",
72+
repositoryIdentity: null,
73+
defaultModelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5-codex" },
74+
createdAt: "2026-01-01T00:00:00.000Z",
75+
updatedAt: "2026-01-01T00:00:00.000Z",
76+
scripts: [],
77+
},
78+
];
79+
const [group] = buildSidebarProjectSnapshots({
80+
projects: state.projects,
81+
settings: { sidebarProjectGroupingMode: "repository", sidebarProjectGroupingOverrides: {} },
82+
primaryEnvironmentId: environmentId,
83+
resolveEnvironmentLabel: () => "Local",
84+
});
85+
return group!.projectKey;
86+
}
87+
88+
describe("project name composition", () => {
89+
it.each([
90+
{ isComposing: true, keyCode: 13 },
91+
{ isComposing: false, keyCode: 229 },
92+
])("does not save a partial name for $isComposing/$keyCode", async (composition) => {
93+
const projectKey = setup();
94+
await using screen = await render(<ProjectSettingsPanel projectKey={projectKey} />, {
95+
router: "/settings/projects",
96+
});
97+
const name = screen.getByRole("textbox", { name: "Project name" });
98+
await name.fill("日本");
99+
const input = name.element();
100+
await act(() => {
101+
input.dispatchEvent(
102+
new KeyboardEvent("keydown", {
103+
key: "Enter",
104+
bubbles: true,
105+
...composition,
106+
}),
107+
);
108+
});
109+
expect(state.projects[0]!.title).toBe("Original");
110+
expect(document.activeElement).toBe(input);
111+
112+
await userEvent.type(name, "語");
113+
await userEvent.keyboard("{Enter}");
114+
expect(state.projects[0]!.title).toBe("日本語");
115+
await screen.rerender(<ProjectSettingsPanel projectKey={projectKey} />);
116+
await expect
117+
.element(screen.getByRole("textbox", { name: "Project name" }))
118+
.toHaveValue("日本語");
119+
120+
await screen.getByRole("textbox", { name: "Project name" }).fill("日本語の名前");
121+
await userEvent.keyboard("{Tab}");
122+
expect(state.projects[0]!.title).toBe("日本語の名前");
123+
});
124+
});

0 commit comments

Comments
 (0)