Skip to content

Commit 9185fdf

Browse files
cliffhallclaude
andcommitted
test(network): use ListToggle aria-label in panel + modal tests
Cleanup spotted in PR review follow-up: - HistoryListPanel + ServerSettingsModal previously fished the ListToggle out by empty text content because the toggle had no accessible name. Now that ListToggle exposes "Expand all" / "Collapse all", both tests can use getByRole + name and the stale comments go away. - ListToggle's own tests now assert the aria-label contract so a future refactor can't silently drop it. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 80a2bc1 commit 9185fdf

3 files changed

Lines changed: 25 additions & 20 deletions

File tree

clients/web/src/components/elements/ListToggle/ListToggle.test.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,34 @@ import userEvent from "@testing-library/user-event";
44
import { ListToggle } from "./ListToggle";
55

66
describe("ListToggle", () => {
7-
it("renders a Button by default", () => {
7+
it("renders a Button by default with 'Expand all' aria-label when compact", () => {
88
renderWithMantine(<ListToggle compact onToggle={() => {}} />);
9-
expect(screen.getByRole("button")).toBeInTheDocument();
9+
expect(
10+
screen.getByRole("button", { name: "Expand all" }),
11+
).toBeInTheDocument();
1012
});
1113

12-
it("renders an ActionIcon for the subtle variant", () => {
14+
it("renders 'Collapse all' aria-label when not compact", () => {
15+
renderWithMantine(<ListToggle compact={false} onToggle={() => {}} />);
16+
expect(
17+
screen.getByRole("button", { name: "Collapse all" }),
18+
).toBeInTheDocument();
19+
});
20+
21+
it("renders an ActionIcon for the subtle variant and labels it", () => {
1322
renderWithMantine(
1423
<ListToggle compact variant="subtle" onToggle={() => {}} />,
1524
);
16-
expect(screen.getByRole("button")).toBeInTheDocument();
25+
expect(
26+
screen.getByRole("button", { name: "Expand all" }),
27+
).toBeInTheDocument();
1728
});
1829

1930
it("invokes onToggle when clicked (default variant)", async () => {
2031
const user = userEvent.setup();
2132
const onToggle = vi.fn();
2233
renderWithMantine(<ListToggle compact onToggle={onToggle} />);
23-
await user.click(screen.getByRole("button"));
34+
await user.click(screen.getByRole("button", { name: "Expand all" }));
2435
expect(onToggle).toHaveBeenCalledTimes(1);
2536
});
2637

@@ -30,7 +41,7 @@ describe("ListToggle", () => {
3041
renderWithMantine(
3142
<ListToggle compact={false} variant="subtle" onToggle={onToggle} />,
3243
);
33-
await user.click(screen.getByRole("button"));
44+
await user.click(screen.getByRole("button", { name: "Collapse all" }));
3445
expect(onToggle).toHaveBeenCalledTimes(1);
3546
});
3647
});

clients/web/src/components/groups/HistoryListPanel/HistoryListPanel.test.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,19 +224,13 @@ describe("HistoryListPanel", () => {
224224
renderWithMantine(
225225
<HistoryListPanel {...baseProps} entries={sampleEntries} />,
226226
);
227-
// Initially expanded — Collapse buttons exist on each entry
227+
// Initially expanded — Collapse buttons exist on each entry, and the
228+
// ListToggle exposes its aria-label as "Collapse all".
228229
expect(
229230
screen.getAllByRole("button", { name: "Collapse" }).length,
230231
).toBeGreaterThan(0);
231232

232-
// Find the ListToggle button (last subtle toolbar button at top — has no accessible name)
233-
const buttons = screen.getAllByRole("button");
234-
const toggle = buttons.find(
235-
(b) =>
236-
b.textContent === "" && b.classList.contains("mantine-Button-root"),
237-
);
238-
expect(toggle).toBeDefined();
239-
await user.click(toggle!);
233+
await user.click(screen.getByRole("button", { name: "Collapse all" }));
240234

241235
// After toggle, entries collapsed — they show Expand
242236
expect(

clients/web/src/components/groups/ServerSettingsModal/ServerSettingsModal.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,16 +246,16 @@ describe("ServerSettingsModal", () => {
246246
expect(headersControl.getAttribute("aria-expanded")).toBe("true");
247247
expect(metadataControl.getAttribute("aria-expanded")).toBe("false");
248248

249-
// ListToggle is the first button in the header row; click to expand all.
250-
const allButtons = screen.getAllByRole("button");
251-
await user.click(allButtons[0]);
249+
// Not every section is expanded → ListToggle starts in compact mode
250+
// and exposes "Expand all" as its aria-label.
251+
await user.click(screen.getByRole("button", { name: "Expand all" }));
252252

253253
expect(metadataControl.getAttribute("aria-expanded")).toBe("true");
254254
expect(timeoutsControl.getAttribute("aria-expanded")).toBe("true");
255255
expect(oauthControl.getAttribute("aria-expanded")).toBe("true");
256256

257-
// Clicking again should collapse all.
258-
await user.click(allButtons[0]);
257+
// After expanding every section the toggle flips to "Collapse all".
258+
await user.click(screen.getByRole("button", { name: "Collapse all" }));
259259
expect(headersControl.getAttribute("aria-expanded")).toBe("false");
260260
expect(metadataControl.getAttribute("aria-expanded")).toBe("false");
261261
});

0 commit comments

Comments
 (0)