Skip to content

Commit 34a5101

Browse files
committed
fix(web): allow adding the displayed provider accent color
1 parent 03d1a90 commit 34a5101

3 files changed

Lines changed: 117 additions & 1 deletion

File tree

‎apps/web/src/components/settings/AddProviderInstanceDialog.environment.browser.test.tsx‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,25 @@ describe("AddProviderInstanceDialog environment routing", () => {
166166
});
167167
});
168168

169+
it("includes the explicitly added default accent color when creating a provider", async () => {
170+
setup();
171+
await using _screen = await render(dialog());
172+
await click("Use Kilo Code");
173+
await act(async () =>
174+
document
175+
.querySelector<HTMLButtonElement>('button[aria-label="Add accent color for Kilo Code"]')!
176+
.click(),
177+
);
178+
await click("Add color");
179+
await click("Continue to sign-in");
180+
181+
expect(settingsHooks.mutate).toHaveBeenCalledWith({
182+
operation: "create",
183+
instanceId: "acpRegistry_kilo_code",
184+
instance: expect.objectContaining({ accentColor: "#2563eb" }),
185+
});
186+
});
187+
169188
it("awaits an atomic create before closing and retains prepared ACP metadata", async () => {
170189
setup();
171190
const mutation = deferred<{ readonly _tag: "Success"; readonly value: unknown }>();

‎apps/web/src/components/settings/ProviderAccentColorPicker.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const FALLBACK_ACCENT_COLOR = "#2563eb";
1313
function ProviderCustomColorPanel(props: {
1414
readonly value: string;
1515
readonly onCommit: (value: string) => void;
16+
readonly showAddButton: boolean;
1617
}) {
1718
const { onCommit } = props;
1819
const [hsv, setHsv] = useState(() => hexToHsv(props.value));
@@ -54,6 +55,15 @@ function ProviderCustomColorPanel(props: {
5455
aria-label="Custom hex accent color"
5556
spellCheck={false}
5657
/>
58+
{props.showAddButton ? (
59+
<PopoverClose
60+
render={
61+
<Button type="button" size="compact" onClick={() => onCommit(currentColor)}>
62+
Add color
63+
</Button>
64+
}
65+
/>
66+
) : null}
5767
</div>
5868
</div>
5969
);
@@ -90,6 +100,7 @@ function ProviderCustomColorPicker(props: {
90100
<ProviderCustomColorPanel
91101
value={normalized ?? FALLBACK_ACCENT_COLOR}
92102
onCommit={props.onCommit}
103+
showAddButton={!normalized}
93104
/>
94105
{normalized ? (
95106
<div className="border-t border-border/60 p-1">

‎apps/web/src/components/settings/colorPickers.browser.test.tsx‎

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { describe, expect, it, vi } from "vite-plus/test";
2-
import { userEvent } from "vite-plus/test/browser";
2+
import { page, userEvent } from "vite-plus/test/browser";
33

44
import type { ReactNode } from "react";
55

66
import { act, render } from "../../../test/render";
77
import { ThemeColorField } from "./ThemeColorPicker";
8+
import { ProviderAccentColorPicker } from "./ProviderAccentColorPicker";
89

910
const HUE = "Accent color hue";
1011
const PLANE = "Accent color saturation and brightness";
@@ -82,3 +83,88 @@ describe("theme color field", () => {
8283
expect(slider(HUE).getAttribute("aria-valuenow")).toBe("10");
8384
});
8485
});
86+
87+
describe("provider accent color picker", () => {
88+
it("leaves the optional color unset when the preview is dismissed", async () => {
89+
const onCommit = vi.fn();
90+
await using _screen = await renderPicker(
91+
<ProviderAccentColorPicker
92+
displayName="Example provider"
93+
value={undefined}
94+
onCommit={onCommit}
95+
/>,
96+
);
97+
98+
await open("Add accent color for Example provider");
99+
expect(byLabel<HTMLInputElement>("Custom hex accent color").value).toBe("#2563eb");
100+
expect(onCommit).not.toHaveBeenCalled();
101+
await userEvent.keyboard("{Escape}");
102+
expect(onCommit).not.toHaveBeenCalled();
103+
});
104+
105+
it("adds the displayed default without adjusting a color control", async () => {
106+
const onCommit = vi.fn();
107+
await using screen = await renderPicker(
108+
<ProviderAccentColorPicker
109+
displayName="Example provider"
110+
value={undefined}
111+
onCommit={onCommit}
112+
/>,
113+
);
114+
115+
await open("Add accent color for Example provider");
116+
await userEvent.click(page.getByRole("button", { name: "Add color", exact: true }));
117+
118+
expect(onCommit).toHaveBeenCalledExactlyOnceWith("#2563eb");
119+
await expect
120+
.element(screen.getByRole("button", { name: "Change accent color for Example provider" }))
121+
.toBeVisible();
122+
await vi.waitFor(() =>
123+
expect(document.querySelector('[aria-label="Custom hex accent color"]')).toBeNull(),
124+
);
125+
});
126+
127+
it("lets keyboard users add the displayed default", async () => {
128+
const onCommit = vi.fn();
129+
await using screen = await renderPicker(
130+
<ProviderAccentColorPicker
131+
displayName="Example provider"
132+
value={undefined}
133+
onCommit={onCommit}
134+
/>,
135+
);
136+
137+
await open("Add accent color for Example provider");
138+
await act(async () => byLabel("Accent color saturation").focus());
139+
await userEvent.tab();
140+
await userEvent.tab();
141+
await userEvent.tab();
142+
await userEvent.tab();
143+
await userEvent.keyboard("{Enter}");
144+
145+
expect(onCommit).toHaveBeenCalledExactlyOnceWith("#2563eb");
146+
await expect
147+
.element(screen.getByRole("button", { name: "Change accent color for Example provider" }))
148+
.toBeVisible();
149+
});
150+
151+
it("keeps live color editing and allows clearing back to unset", async () => {
152+
const onCommit = vi.fn();
153+
await using screen = await renderPicker(
154+
<ProviderAccentColorPicker
155+
displayName="Example provider"
156+
value="#ff0000"
157+
onCommit={onCommit}
158+
/>,
159+
);
160+
161+
await open("Change accent color for Example provider");
162+
await press(HUE, "ArrowRight", true);
163+
expect(onCommit).toHaveBeenLastCalledWith("#ff2a00");
164+
await userEvent.click(page.getByRole("button", { name: "Clear color", exact: true }));
165+
expect(onCommit).toHaveBeenLastCalledWith("");
166+
await expect
167+
.element(screen.getByRole("button", { name: "Add accent color for Example provider" }))
168+
.toBeVisible();
169+
});
170+
});

0 commit comments

Comments
 (0)