fix(webui): unify settings switch styles
This commit is contained in:
1 parent
af43292f6f
commit
70bf433018
7 files changed
+105
-53
No files matched your search
@@ -1204,6 +1204,7 @@ describe("App layout", () => {
|
||||
expect(screen.getByText(/Use GitHub CLI/)).toBeInTheDocument();
|
||||
const enabledSwitch = screen.getByRole("switch", { name: "Disable github" });
|
||||
expect(enabledSwitch).toHaveAttribute("aria-checked", "true");
|
||||
expect(enabledSwitch).toHaveClass("h-5", "w-9", "bg-foreground");
|
||||
fireEvent.click(enabledSwitch);
|
||||
await waitFor(() => {
|
||||
expect(screen.getByRole("switch", { name: "Enable github" })).toHaveAttribute(
|
||||
@@ -1211,6 +1212,7 @@ describe("App layout", () => {
|
||||
"false",
|
||||
);
|
||||
});
|
||||
expect(screen.getByRole("switch", { name: "Enable github" })).toHaveClass("h-5", "w-9", "bg-muted-foreground/25");
|
||||
});
|
||||
|
||||
it("deletes a custom skill from its detail sheet", async () => {
|
||||
|
||||
@@ -36,6 +36,8 @@ describe("Settings capabilities", () => {
|
||||
renderSettingsView({ initialSection: "capabilities", initialSettings: payload });
|
||||
const memory = screen.getByRole("switch", { name: "Memory consolidation" });
|
||||
const web = screen.getByRole("switch", { name: "Web access" });
|
||||
expect(memory).toHaveClass("h-5", "w-9", "bg-foreground");
|
||||
expect(web).toHaveClass("h-5", "w-9", "bg-foreground");
|
||||
const webStyle = web.className;
|
||||
fireEvent.click(memory);
|
||||
await waitFor(() => expect(memory).toBeDisabled());
|
||||
@@ -44,6 +46,7 @@ describe("Settings capabilities", () => {
|
||||
expect(web.className).toBe(webStyle);
|
||||
fireEvent.click(web);
|
||||
expect(web).not.toBeChecked();
|
||||
expect(web).toHaveClass("bg-muted-foreground/25");
|
||||
await act(async () => finishMemory(memorySaved));
|
||||
await waitFor(() => expect(requestMutationMock).toHaveBeenLastCalledWith(
|
||||
"settings.runtime_config.update", { values: { "tools.web.enable": false } }, 20_000,
|
||||
|
||||
@@ -502,6 +502,7 @@ describe("Settings models", () => {
|
||||
|
||||
const enableSwitch = within(codexRow).getByRole("switch", { name: "Enable preset" });
|
||||
expect(enableSwitch).not.toBeChecked();
|
||||
expect(enableSwitch).toHaveClass("h-5", "w-9", "bg-muted-foreground/25");
|
||||
fireEvent.click(enableSwitch);
|
||||
|
||||
await waitFor(() => {
|
||||
@@ -516,6 +517,16 @@ describe("Settings models", () => {
|
||||
expect(
|
||||
within(enabledCodexRow).getByRole("switch", { name: "Disable preset" }),
|
||||
).toBeChecked();
|
||||
expect(within(enabledCodexRow).getByRole("switch")).toHaveClass("h-5", "w-9", "bg-foreground");
|
||||
});
|
||||
|
||||
it("does not allow disabling the last preset", () => {
|
||||
renderSettingsView({ initialSection: "models", initialSettings: settingsPayload() });
|
||||
const toggle = screen.getByRole("switch", { name: "Disable preset" });
|
||||
expect(toggle).toBeChecked();
|
||||
expect(toggle).toBeDisabled();
|
||||
fireEvent.click(toggle);
|
||||
expect(requestMutationMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("appends a new model preset to the call order immediately", async () => {
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import { fireEvent, render, screen } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { ToggleButton } from "@/components/settings/ToggleButton";
|
||||
|
||||
describe("ToggleButton", () => {
|
||||
it("uses shared theme colors and compact dimensions in both states", () => {
|
||||
const onChange = vi.fn();
|
||||
const { rerender } = render(
|
||||
<ToggleButton checked label="Feature" onChange={onChange} />,
|
||||
);
|
||||
const toggle = screen.getByRole("switch", { name: "Feature" });
|
||||
expect(toggle).toBeChecked();
|
||||
expect(toggle).toHaveClass("h-5", "w-9", "bg-foreground", "after:h-11", "after:w-11");
|
||||
expect(toggle.firstElementChild).toHaveClass("h-4", "w-4", "bg-background", "translate-x-[16px]");
|
||||
|
||||
fireEvent.click(toggle);
|
||||
expect(onChange).toHaveBeenLastCalledWith(false);
|
||||
rerender(<ToggleButton checked={false} label="Feature" onChange={onChange} />);
|
||||
expect(toggle).not.toBeChecked();
|
||||
expect(toggle).toHaveClass("h-5", "w-9", "bg-muted-foreground/25");
|
||||
expect(toggle).not.toHaveClass("bg-foreground");
|
||||
expect(toggle.firstElementChild).toHaveClass("translate-x-0");
|
||||
fireEvent.click(toggle);
|
||||
expect(onChange).toHaveBeenLastCalledWith(true);
|
||||
});
|
||||
|
||||
it.each([false, true])("does not toggle while disabled (checked=%s)", (checked) => {
|
||||
const onChange = vi.fn();
|
||||
render(<ToggleButton checked={checked} disabled label="Feature" onChange={onChange} />);
|
||||
const toggle = screen.getByRole("switch", { name: "Feature" });
|
||||
expect(toggle).toBeDisabled();
|
||||
expect(toggle).toHaveClass(checked ? "bg-foreground" : "bg-muted-foreground/25", "opacity-60");
|
||||
fireEvent.click(toggle);
|
||||
expect(onChange).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("keeps accessible labeling, keyboard activation, and button semantics", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onChange = vi.fn();
|
||||
const onSubmit = vi.fn((event) => event.preventDefault());
|
||||
render(
|
||||
<form onSubmit={onSubmit}>
|
||||
<p id="toggle-help">Enable this feature.</p>
|
||||
<ToggleButton
|
||||
id="feature-toggle"
|
||||
checked={false}
|
||||
label="Feature"
|
||||
ariaLabel="Enable feature"
|
||||
aria-describedby="toggle-help"
|
||||
aria-invalid
|
||||
onChange={onChange}
|
||||
/>
|
||||
</form>,
|
||||
);
|
||||
const toggle = screen.getByRole("switch", { name: "Enable feature" });
|
||||
expect(toggle).toHaveAttribute("id", "feature-toggle");
|
||||
expect(toggle).toHaveAccessibleDescription("Enable this feature.");
|
||||
expect(toggle).toHaveAttribute("aria-invalid", "true");
|
||||
await user.tab();
|
||||
expect(toggle).toHaveFocus();
|
||||
await user.keyboard(" ");
|
||||
await user.keyboard("{Enter}");
|
||||
expect(onChange.mock.calls).toEqual([[true], [true]]);
|
||||
expect(onSubmit).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user