fix: close search when starting new chats

maintainer edit: Close the session search dialog when the global new-chat shortcut navigates to the blank chat route, and expose the new shortcut through the sidebar button title so the shortcut is discoverable.
This commit is contained in:
chengyongru
2026-06-04 14:01:21 +08:00
committed by Xubin Ren
parent 4275678b43
commit 54d8d3010b
3 changed files with 50 additions and 3 deletions
+43 -2
View File
@@ -1354,7 +1354,10 @@ describe("App layout", () => {
expect(createChatSpy).not.toHaveBeenCalled();
});
it("starts a new chat from the keyboard shortcut", async () => {
it.each([
["Command", { metaKey: true }],
["Control", { ctrlKey: true }],
])("starts a new chat from the %s keyboard shortcut", async (_label, modifier) => {
mockSessions = [
{
key: "websocket:chat-a",
@@ -1369,11 +1372,49 @@ describe("App layout", () => {
render(<App />);
await waitFor(() => expect(connectSpy).toHaveBeenCalled());
fireEvent.keyDown(window, { key: "O", shiftKey: true, metaKey: true });
fireEvent.keyDown(window, { key: "O", shiftKey: true, ...modifier });
expect(window.location.hash).toBe("#/new");
});
it("closes search when starting a new chat from the keyboard shortcut", async () => {
mockSessions = [
{
key: "websocket:chat-a",
channel: "websocket",
chatId: "chat-a",
createdAt: "2026-04-16T10:00:00Z",
updatedAt: "2026-04-16T10:00:00Z",
preview: "Existing chat",
},
];
render(<App />);
await waitFor(() => expect(connectSpy).toHaveBeenCalled());
fireEvent.keyDown(window, { key: "k", metaKey: true });
expect(await screen.findByRole("dialog", { name: "Search" })).toBeInTheDocument();
fireEvent.keyDown(window, { key: "O", shiftKey: true, metaKey: true });
await waitFor(() =>
expect(screen.queryByRole("dialog", { name: "Search" })).not.toBeInTheDocument(),
);
expect(window.location.hash).toBe("#/new");
});
it("exposes the new chat keyboard shortcut in the sidebar title", async () => {
render(<App />);
await waitFor(() => expect(connectSpy).toHaveBeenCalled());
const sidebar = screen.getByRole("navigation", { name: "Sidebar navigation" });
expect(within(sidebar).getByRole("button", { name: "New chat" })).toHaveAttribute(
"title",
"New chat (Cmd/Ctrl+Shift+O)",
);
});
it("keeps large sidebars light while search still covers every chat", async () => {
mockSessions = Array.from({ length: 170 }, (_, index) => {
const chatId = `chat-${index}`;