Skip to content

Commit ed6f814

Browse files
author
Peter Steinberger
committed
fix(ui): make session controls and failures accessible
1 parent 36b80ad commit ed6f814

4 files changed

Lines changed: 208 additions & 6 deletions

File tree

‎ui/src/e2e/session-management.groups.e2e.test.ts‎

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,64 @@ suite.define(() => {
331331
}
332332
});
333333

334+
it("sorts threads from the keyboard and identifies destructive selection targets", async () => {
335+
const context = await suite.browser.newContext({
336+
locale: "en-US",
337+
serviceWorkers: "block",
338+
viewport: { height: 900, width: 1280 },
339+
});
340+
const page = await context.newPage();
341+
await installMockGateway(page, {
342+
methodResponses: {
343+
"sessions.list": sessionsListResponse([
344+
sessionRow("agent:main:alpha", "Alpha thread", 1),
345+
sessionRow("agent:main:zulu", "Zulu thread", 2),
346+
]),
347+
},
348+
sessionKey: "agent:main:main",
349+
});
350+
351+
try {
352+
await page.goto(`${suite.server.baseUrl}sessions`);
353+
const table = page.locator(".sessions-table");
354+
const rowNames = () =>
355+
table.locator("tbody .session-data-row .session-label-chip").allTextContents();
356+
await expect.poll(rowNames).toEqual(["Zulu thread", "Alpha thread"]);
357+
358+
for (const name of ["Key", "Kind", "Updated", "Tokens"]) {
359+
await table.getByRole("columnheader", { name }).getByRole("button", { name }).waitFor();
360+
}
361+
362+
const updatedHeader = table.getByRole("columnheader", { name: "Updated" });
363+
expect(await updatedHeader.getAttribute("aria-sort")).toBe("descending");
364+
await updatedHeader.getByRole("button", { name: "Updated" }).press("Space");
365+
await expect.poll(rowNames).toEqual(["Alpha thread", "Zulu thread"]);
366+
expect(await updatedHeader.getAttribute("aria-sort")).toBe("ascending");
367+
368+
const keyHeader = table.getByRole("columnheader", { name: "Key" });
369+
await keyHeader.getByRole("button", { name: "Key" }).press("Enter");
370+
await expect.poll(rowNames).toEqual(["Zulu thread", "Alpha thread"]);
371+
expect(await keyHeader.getAttribute("aria-sort")).toBe("descending");
372+
expect(await updatedHeader.getAttribute("aria-sort")).toBeNull();
373+
374+
const keyHeaderBounds = await keyHeader.boundingBox();
375+
if (!keyHeaderBounds) {
376+
throw new Error("Expected visible session sort header");
377+
}
378+
await page.mouse.click(
379+
keyHeaderBounds.x + keyHeaderBounds.width - 2,
380+
keyHeaderBounds.y + keyHeaderBounds.height / 2,
381+
);
382+
await expect.poll(rowNames).toEqual(["Alpha thread", "Zulu thread"]);
383+
expect(await keyHeader.getAttribute("aria-sort")).toBe("ascending");
384+
385+
await table.getByRole("checkbox", { name: "Select thread: agent:main:alpha" }).waitFor();
386+
await table.getByRole("checkbox", { name: "Select thread: agent:main:zulu" }).waitFor();
387+
} finally {
388+
await context.close();
389+
}
390+
});
391+
334392
it("shows a rejected Sessions-page custom group instead of leaking a page error", async () => {
335393
const context = await suite.browser.newContext({
336394
locale: "en-US",
@@ -360,7 +418,7 @@ suite.define(() => {
360418
message: "group name exceeds 512 characters",
361419
});
362420

363-
const error = page.locator(".sessions-error");
421+
const error = page.getByRole("alert");
364422
await error.waitFor({ state: "visible" });
365423
await expect.poll(() => error.textContent()).toContain("group name exceeds 512 characters");
366424
expect(pageErrors).toEqual([]);

‎ui/src/pages/sessions/view.test.ts‎

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,139 @@ function sessionTableHeaders(container: HTMLElement): Array<string | undefined>
103103
const SESSION_TABLE_HEADERS = ["", "Key", "Kind", "Status", "Updated", "Tokens", "Actions"];
104104

105105
describe("sessions view", () => {
106+
it("makes every session sort header a keyboard-accessible button", async () => {
107+
const container = document.createElement("div");
108+
const onSortChange = vi.fn();
109+
render(
110+
renderSessions({
111+
...buildProps(buildMultiResult([])),
112+
onSortChange,
113+
}),
114+
container,
115+
);
116+
await Promise.resolve();
117+
118+
for (const [label, column] of [
119+
["Key", "key"],
120+
["Kind", "kind"],
121+
["Updated", "updated"],
122+
["Tokens", "tokens"],
123+
] as const) {
124+
const header = [...container.querySelectorAll<HTMLTableCellElement>("thead th")].find(
125+
(cell) => cell.textContent?.trim() === label,
126+
);
127+
const button = header?.querySelector("button");
128+
129+
expect(button, `${label} must be a native keyboard-accessible button`).toBeInstanceOf(
130+
HTMLButtonElement,
131+
);
132+
expect(button?.type).toBe("button");
133+
const initialCallCount = onSortChange.mock.calls.length;
134+
button?.click();
135+
expect(onSortChange).toHaveBeenCalledTimes(initialCallCount + 1);
136+
expect(onSortChange).toHaveBeenLastCalledWith(column, column === "updated" ? "asc" : "desc");
137+
138+
header?.click();
139+
expect(onSortChange).toHaveBeenCalledTimes(initialCallCount + 2);
140+
expect(onSortChange).toHaveBeenLastCalledWith(column, column === "updated" ? "asc" : "desc");
141+
}
142+
});
143+
144+
it.each([
145+
{ direction: "asc", ariaSort: "ascending" },
146+
{ direction: "desc", ariaSort: "descending" },
147+
] as const)(
148+
"announces only the active $direction session sort",
149+
async ({ direction, ariaSort }) => {
150+
const container = document.createElement("div");
151+
render(
152+
renderSessions({
153+
...buildProps(buildMultiResult([])),
154+
sortColumn: "kind",
155+
sortDir: direction,
156+
}),
157+
container,
158+
);
159+
await Promise.resolve();
160+
161+
const headers = [
162+
...container.querySelectorAll<HTMLTableCellElement>("thead th[data-sortable]"),
163+
];
164+
expect(headers).toHaveLength(4);
165+
expect(
166+
headers.find((header) => header.textContent?.trim() === "Kind")?.getAttribute("aria-sort"),
167+
).toBe(ariaSort);
168+
expect(
169+
headers
170+
.filter((header) => header.textContent?.trim() !== "Kind")
171+
.map((header) => header.hasAttribute("aria-sort")),
172+
).toEqual([false, false, false]);
173+
},
174+
);
175+
176+
it("announces session-list and mutation failures to assistive technology", async () => {
177+
const container = document.createElement("div");
178+
render(
179+
renderSessions({
180+
...buildProps(buildMultiResult([])),
181+
error: "group name exceeds 512 characters",
182+
}),
183+
container,
184+
);
185+
await Promise.resolve();
186+
187+
const alert = container.querySelector('[role="alert"]');
188+
expect(alert?.classList.contains("sessions-error")).toBe(true);
189+
expect(alert?.textContent).toContain("group name exceeds 512 characters");
190+
});
191+
192+
it("announces checkpoint failures in their expanded session details", async () => {
193+
const sessionKey = "agent:main:checkpoint-failure";
194+
const container = document.createElement("div");
195+
render(
196+
renderSessions({
197+
...buildProps(buildResult({ key: sessionKey, kind: "direct", updatedAt: 1 })),
198+
expandedSessionKey: sessionKey,
199+
checkpointErrorByKey: { [sessionKey]: "Checkpoint request timed out" },
200+
}),
201+
container,
202+
);
203+
await Promise.resolve();
204+
205+
const alert = container.querySelector('.session-details-panel [role="alert"]');
206+
expect(alert?.textContent).toContain("Checkpoint request timed out");
207+
});
208+
209+
it("identifies each selectable session before destructive bulk actions", async () => {
210+
const container = document.createElement("div");
211+
const onToggleSelect = vi.fn();
212+
render(
213+
renderSessions({
214+
...buildProps(
215+
buildMultiResult([
216+
{ key: "agent:main:first", kind: "direct", updatedAt: 2 },
217+
{ key: "agent:main:second", kind: "direct", updatedAt: 1 },
218+
]),
219+
),
220+
onToggleSelect,
221+
}),
222+
container,
223+
);
224+
await Promise.resolve();
225+
226+
const checkboxes = [
227+
...container.querySelectorAll<HTMLInputElement>('tbody input[type="checkbox"]'),
228+
];
229+
expect(checkboxes.map((checkbox) => checkbox.getAttribute("aria-label"))).toEqual([
230+
"Select thread: agent:main:first",
231+
"Select thread: agent:main:second",
232+
]);
233+
234+
checkboxes[0]?.dispatchEvent(new Event("change", { bubbles: true }));
235+
checkboxes[1]?.dispatchEvent(new Event("change", { bubbles: true }));
236+
expect(onToggleSelect.mock.calls).toEqual([["agent:main:first"], ["agent:main:second"]]);
237+
});
238+
106239
it("uses the stored face for generic session links", async () => {
107240
const container = document.createElement("div");
108241
render(

‎ui/src/pages/sessions/view.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,10 +1123,13 @@ export function renderSessions(props: SessionsProps) {
11231123
class=${extraClass}
11241124
data-sortable
11251125
data-sort-dir=${isActive ? props.sortDir : ""}
1126+
aria-sort=${isActive ? (props.sortDir === "asc" ? "ascending" : "descending") : nothing}
11261127
@click=${() => props.onSortChange(col, isActive ? nextDir : "desc")}
11271128
>
1128-
${label}
1129-
<span class="data-table-sort-icon">${icons.arrowUpDown}</span>
1129+
<button class="data-table-sort-button" type="button">
1130+
${label}
1131+
<span class="data-table-sort-icon" aria-hidden="true">${icons.arrowUpDown}</span>
1132+
</button>
11301133
</th>
11311134
`;
11321135
};
@@ -1158,7 +1161,7 @@ export function renderSessions(props: SessionsProps) {
11581161
</button>
11591162
`;
11601163
const children = [
1161-
props.error ? html`<div class="sessions-error">${props.error}</div>` : nothing,
1164+
props.error ? html`<div class="sessions-error" role="alert">${props.error}</div>` : nothing,
11621165
props.result
11631166
? renderSettingsSection({}, renderSessionsOverview(rawRows, liveCount, props.statusFilter))
11641167
: nothing,
@@ -1585,7 +1588,7 @@ function renderRows(row: GatewaySessionRow, props: SessionsProps) {
15851588
type="checkbox"
15861589
.checked=${props.selectedKeys.has(row.key)}
15871590
@change=${() => props.onToggleSelect(row.key)}
1588-
aria-label=${t("sessionsView.selectSession")}
1591+
aria-label=${`${t("sessionsView.selectSession")}: ${row.key}`}
15891592
/>
15901593
</td>
15911594
<td class="data-table-key-col">
@@ -1862,7 +1865,7 @@ function renderSessionDetailsRow(params: {
18621865
${t("sessionsView.loadingCheckpoints")}
18631866
</div>`
18641867
: checkpointError
1865-
? html`<div class="callout danger">${checkpointError}</div>`
1868+
? html`<div class="callout danger" role="alert">${checkpointError}</div>`
18661869
: !hasCheckpoints || checkpointItems.length === 0
18671870
? html`<div class="muted session-details-empty">
18681871
${t("sessionsView.noCheckpoints")}

‎ui/src/styles/components.css‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2522,6 +2522,14 @@ openclaw-chat-session-rail {
25222522
color: var(--text);
25232523
}
25242524

2525+
.data-table-sort-button {
2526+
padding: 0;
2527+
border: 0;
2528+
background: transparent;
2529+
letter-spacing: inherit;
2530+
text-transform: inherit;
2531+
}
2532+
25252533
.data-table-sort-icon {
25262534
display: inline-flex;
25272535
vertical-align: middle;

0 commit comments

Comments
 (0)