feat(webui): match session handles in Ctrl+K
This commit is contained in:
1 parent
e821144c7e
commit
d14c54c31c
4 files changed
+32
-1
No files matched your search
@@ -8,6 +8,7 @@ import type { ChatSummary } from "@/lib/types";
|
||||
const sessions: ChatSummary[] = Array.from({ length: 1000 }, (_, index) => ({
|
||||
key: `websocket:topic-${index}`, chatId: `topic-${index}`, channel: "websocket",
|
||||
title: `Topic ${index}`, preview: `Preview ${index}`, createdAt: null, updatedAt: null,
|
||||
...(index === 1 ? { handle: { id: "handle_00000000000000000000000000000001", name: "betu" } } : {}),
|
||||
}));
|
||||
|
||||
export function LoadedSessionSearchFixture() {
|
||||
|
||||
@@ -13,6 +13,12 @@ for (const viewport of [{ width: 1280, height: 800 }, { width: 390, height: 844
|
||||
const dialog = page.getByRole("dialog", { name: "Search", exact: true });
|
||||
const input = dialog.getByRole("textbox", { name: "Search", exact: true });
|
||||
await expect(dialog.getByRole("button")).toHaveCount(24);
|
||||
for (const query of ["@betu", "betu", "@BETU", "@be"]) {
|
||||
await input.fill(query);
|
||||
await expect(dialog.getByRole("button")).toHaveCount(1);
|
||||
await expect(dialog.getByText("Topic 1", { exact: true })).toBeVisible();
|
||||
await expect(dialog.getByText("Preview 1", { exact: true })).toBeVisible();
|
||||
}
|
||||
for (const query of ["权限", "full access", "25%", "session_history.py"]) {
|
||||
await input.fill(query);
|
||||
await expect(dialog.getByRole("button")).toHaveCount(1);
|
||||
|
||||
@@ -62,7 +62,8 @@ export function SessionSearchDialog({
|
||||
const searchPending = searchQuery !== normalizedQuery || searchRevision !== messageRevision;
|
||||
const searchableSessions = useMemo(() => sessions.map((session) => ({
|
||||
session,
|
||||
text: [titleOverrides[session.key], session.title, visibleSessionPreview(session.preview)]
|
||||
text: [titleOverrides[session.key], session.title, visibleSessionPreview(session.preview),
|
||||
session.handle ? `@${session.handle.name}` : undefined]
|
||||
.filter(Boolean).join(" ").toLowerCase(),
|
||||
})), [sessions, titleOverrides]);
|
||||
const sessionResults = useMemo<SessionSearchResult[]>(() => {
|
||||
|
||||
@@ -119,6 +119,29 @@ describe("SessionSearchDialog", () => {
|
||||
expect(screen.queryByText("Model chat")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("finds loaded session handles with or without @ and selects the matching session without requests", () => {
|
||||
const fetch = vi.fn();
|
||||
vi.stubGlobal("fetch", fetch);
|
||||
const onSelect = vi.fn();
|
||||
render(<SessionSearchDialog open sessions={[
|
||||
{ ...session(1), handle: { id: "handle_00000000000000000000000000000001", name: "betu" } },
|
||||
{ ...session(2), handle: { id: "handle_00000000000000000000000000000002", name: "mira" } },
|
||||
session(3),
|
||||
]} activeKey={null} loading={false} onOpenChange={() => {}} onSelect={onSelect} />);
|
||||
const input = screen.getByRole("textbox", { name: "Search" });
|
||||
for (const query of ["@betu", "betu", "@BETU", "@be", "etu"]) {
|
||||
fireEvent.change(input, { target: { value: query } });
|
||||
expect(screen.getAllByRole("button")).toHaveLength(1);
|
||||
expect(screen.getByText("Chat 1")).toBeInTheDocument();
|
||||
}
|
||||
fireEvent.change(input, { target: { value: "@mira" } });
|
||||
expect(screen.getAllByRole("button")).toHaveLength(1);
|
||||
expect(screen.getByText("Chat 2")).toBeInTheDocument();
|
||||
fireEvent.keyDown(input, { key: "Enter" });
|
||||
expect(onSelect).toHaveBeenCalledWith("websocket:chat-2");
|
||||
expect(fetch).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("finds cached body substrings with a bounded preview and no data requests", () => {
|
||||
const fetch = vi.fn();
|
||||
vi.stubGlobal("fetch", fetch);
|
||||
|
||||
Reference in new issue
Block a user