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([