feat(webui): add compact batch archive actions

This commit is contained in:
chengyongru authored and chengyongru committed 2026-10-27 09:36:22 +08:00
1 parent 23c4acc216
commit d1451e30e9
19 files changed
+442 -82

No files matched your search

+48
View File
@@ -2375,6 +2375,40 @@ describe("App layout", () => {
expect(document.body.style.pointerEvents).not.toBe("none");
}, 15_000);
it("archives selected topics in one sidebar update and navigates outside the full selection", async () => {
mockSessions = ["a", "b", "c"].map((id) => ({
key: `websocket:chat-${id}`, channel: "websocket", chatId: `chat-${id}`,
createdAt: "2026-04-16T10:00:00Z", updatedAt: "2026-04-16T10:00:00Z",
title: `Topic ${id}`, preview: `Message ${id}`,
}));
mockFetchRoutes({
"/api/webui/sidebar-state": { pinned_keys: ["websocket:chat-a", "websocket:chat-b"] },
});
window.history.replaceState(null, "", "/#/chat/websocket%3Achat-a");
render(<App />);
await waitFor(() => expect(connectSpy).toHaveBeenCalled());
act(() => statusHandlers.forEach((handler) => handler("open")));
const sidebar = screen.getByRole("navigation", { name: "Sidebar navigation" });
await within(sidebar).findByRole("button", { name: "Topic a" });
fireEvent.pointerDown(within(sidebar).getByLabelText("Topic actions for Topic a"), { button: 0 });
fireEvent.click(await screen.findByRole("menuitem", { name: "Select" }));
fireEvent.click(within(sidebar).getByRole("button", { name: "Topic b" }));
fireEvent.click(within(sidebar).getByRole("button", { name: "Archive" }));
const dialog = await screen.findByRole("alertdialog", { name: "Archive 2 topics?" });
expect(setSidebarStateSpy).not.toHaveBeenCalled();
fireEvent.click(within(dialog).getByRole("button", { name: "Archive" }));
await waitFor(() => expect(setSidebarStateSpy).toHaveBeenCalledTimes(1));
expect(setSidebarStateSpy).toHaveBeenCalledWith(expect.objectContaining({
archived_keys: ["websocket:chat-a", "websocket:chat-b"], pinned_keys: [],
}));
expect(window.location.hash).toBe("#/chat/websocket%3Achat-c");
expect(within(sidebar).getByRole("button", { name: "Topic c" })).toBeInTheDocument();
expect(within(sidebar).queryByRole("button", { name: "Topic a" })).not.toBeInTheDocument();
expect(within(sidebar).queryByRole("button", { name: "Topic b" })).not.toBeInTheDocument();
expect(deleteChatSpy).not.toHaveBeenCalled();
});
it("deletes multiple selected topics through one confirmation", async () => {
mockSessions = [
{
@@ -2414,9 +2448,23 @@ describe("App layout", () => {
fireEvent.click(within(sidebar).getByRole("button", { name: "Second chat" }));
expect(within(sidebar).getByText("2 selected")).toBeInTheDocument();
const automationReads: Array<(jobs: SessionAutomationJob[]) => void> = [];
getSessionAutomationsSpy.mockImplementation(() => new Promise((resolve) => automationReads.push(resolve)));
fireEvent.click(within(sidebar).getByRole("button", { name: "Delete" }));
fireEvent.click(document.body);
expect(screen.getByTestId("delete-selection-bar")).toHaveTextContent("2 selected");
expect(deleteChatSpy).not.toHaveBeenCalled();
await act(async () => automationReads.forEach((resolve) => resolve([])));
expect(await screen.findByText("Delete 2 conversations?")).toBeInTheDocument();
fireEvent.keyDown(screen.getByRole("alertdialog"), { key: "Escape" });
expect(screen.getByTestId("delete-selection-bar")).toHaveTextContent("2 selected");
expect(deleteChatSpy).not.toHaveBeenCalled();
getSessionAutomationsSpy.mockResolvedValue([]);
fireEvent.click(within(sidebar).getByRole("button", { name: "Delete" }));
expect(await screen.findByText("Delete 2 conversations?")).toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Delete" }));
expect(screen.queryByTestId("delete-selection-bar")).not.toBeInTheDocument();
await waitFor(() => expect(deleteChatSpy).toHaveBeenCalledTimes(2));
expect(deleteChatSpy.mock.calls.map(([key]) => key)).toEqual([
+108 -2
View File
@@ -1,4 +1,4 @@
import { fireEvent, render, screen, within } from "@testing-library/react";
import { act, fireEvent, render, screen, within } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { ChatList } from "@/components/ChatList";
@@ -806,10 +806,116 @@ describe("ChatList", () => {
{ key: "websocket:root", label: "Root topic" },
{ key: "websocket:child", label: "Research pane" },
{ key: "websocket:target", label: "Target tab" },
]);
], expect.any(Function));
expect(screen.getByText("3 selected")).toBeInTheDocument();
act(() => onRequestDeleteMany.mock.calls[0][1](true));
expect(screen.queryByTestId("delete-selection-bar")).not.toBeInTheDocument();
});
it.each([
{ archivedKeys: [], action: "Archive", archive: true },
{ archivedKeys: ["websocket:root", "websocket:child"], action: "Unarchive", archive: false },
{ archivedKeys: ["websocket:child"], action: "Archive", archive: true },
])("confirms $action for selected panes without toggling mixed archive states", async ({ archivedKeys, action, archive }) => {
const onArchiveMany = vi.fn();
render(<ChatList
sessions={[session({ chatId: "root", title: "Root topic" })]}
activeKey="websocket:root"
paneGroups={{
"websocket:root": {
tabKey: "websocket:root",
title: "Root topic",
activePaneKey: "websocket:root",
panes: [
{ key: "websocket:root", chatId: "root", title: "Root topic" },
{ key: "websocket:child", chatId: "child", title: "Research pane" },
],
},
}}
archivedPaneKeys={archivedKeys}
onSelect={vi.fn()}
onRequestDelete={vi.fn()}
onTogglePin={vi.fn()}
onRequestRename={vi.fn()}
onToggleArchive={vi.fn()}
onArchiveMany={onArchiveMany}
/>);
fireEvent.pointerDown(screen.getByRole("button", { name: "Root topic pane actions" }), { button: 0 });
fireEvent.click(await screen.findByRole("menuitem", { name: "Select" }));
fireEvent.click(screen.getByRole("button", { name: "Group: Root topic" }));
const bar = screen.getByTestId("delete-selection-bar");
fireEvent.click(within(bar).getByRole("button", { name: action }));
const dialog = screen.getByRole("alertdialog");
expect(dialog).toHaveAccessibleName(`${action} 2 topics?`);
fireEvent.click(document.body);
expect(screen.getByText("2 selected")).toBeInTheDocument();
expect(onArchiveMany).not.toHaveBeenCalled();
if (archive) fireEvent.click(within(dialog).getByRole("button", { name: "Cancel" }));
else fireEvent.keyDown(dialog, { key: "Escape" });
expect(screen.getByText("2 selected")).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Research pane" })).toHaveAttribute("aria-pressed", "true");
expect(onArchiveMany).not.toHaveBeenCalled();
fireEvent.click(within(bar).getByRole("button", { name: action }));
fireEvent.click(within(screen.getByRole("alertdialog")).getByRole("button", { name: action }));
expect(onArchiveMany).toHaveBeenCalledTimes(1);
expect(onArchiveMany).toHaveBeenCalledWith(["websocket:root", "websocket:child"], archive);
expect(screen.queryByTestId("delete-selection-bar")).not.toBeInTheDocument();
});
it("disables batch archive when all topics are deselected", async () => {
render(<ChatList
sessions={[session({ chatId: "first", title: "First topic" })]}
activeKey={null}
onSelect={vi.fn()}
onRequestDelete={vi.fn()}
onTogglePin={vi.fn()}
onRequestRename={vi.fn()}
onToggleArchive={vi.fn()}
onArchiveMany={vi.fn()}
/>);
fireEvent.pointerDown(screen.getByRole("button", { name: "Topic actions for First topic" }), { button: 0 });
fireEvent.click(await screen.findByRole("menuitem", { name: "Select" }));
fireEvent.click(screen.getByRole("button", { name: "First topic" }));
expect(screen.getByRole("button", { name: "Archive" })).toBeDisabled();
expect(screen.getByRole("button", { name: "Delete" })).toBeDisabled();
});
it.each(["outside action", "list whitespace"])("exits selection from %s without consuming the click", async (target) => {
const outsideAction = vi.fn();
const onSelect = vi.fn();
const { container } = render(<>
<button onClick={outsideAction}>Outside action</button>
<ChatList
sessions={[session({ chatId: "first", title: "First topic" })]}
activeKey={null}
onSelect={onSelect}
onRequestDelete={vi.fn()}
onTogglePin={vi.fn()}
onRequestRename={vi.fn()}
onToggleArchive={vi.fn()}
onArchiveMany={vi.fn()}
/>
</>);
fireEvent.pointerDown(screen.getByRole("button", { name: "Topic actions for First topic" }), { button: 0 });
fireEvent.click(await screen.findByRole("menuitem", { name: "Select" }));
expect(screen.getByText("1 selected")).toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "First topic" }));
expect(screen.getByText("0 selected")).toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "First topic" }));
expect(screen.getByText("1 selected")).toBeInTheDocument();
expect(onSelect).not.toHaveBeenCalled();
fireEvent.click(target === "outside action"
? screen.getByRole("button", { name: "Outside action" })
: container.querySelector("[data-chat-list-content]")!);
expect(screen.queryByTestId("delete-selection-bar")).not.toBeInTheDocument();
expect(outsideAction).toHaveBeenCalledTimes(target === "outside action" ? 1 : 0);
fireEvent.click(screen.getByRole("button", { name: "First topic" }));
expect(onSelect).toHaveBeenCalledWith("websocket:first");
});
it("selects a contiguous session range with Shift-click", async () => {
render(
<ChatList