feat(webui): search loaded message text in Ctrl+K
This commit is contained in:
1 parent
8af6313c56
commit
e821144c7e
22 files changed
+396
-23
No files matched your search
@@ -40,6 +40,7 @@ import { MobileChatLayoutFixture } from "./mobile-chat-layout-fixture";
|
||||
import { ThemeToggleFixture } from "./theme-toggle-fixture";
|
||||
import { DisplayMathFixture } from "./display-math-fixture";
|
||||
import { AttachmentLayoutFixture } from "./attachment-layout-fixture";
|
||||
import { LoadedSessionSearchFixture } from "./loaded-session-search-fixture";
|
||||
|
||||
const history: UIMessage[] = [
|
||||
{ id: "question", role: "user", content: "Earlier question", createdAt: 1_700_000_000_000 },
|
||||
@@ -213,7 +214,9 @@ if (parameters.get("case") === "skeleton-additions") installSkeletonPreviewApi()
|
||||
if (parameters.get("case") === "idle-compaction") installIdleCompactionApi();
|
||||
await initializeI18n();
|
||||
createRoot(document.getElementById("root")!).render(<TooltipProvider>
|
||||
{parameters.get("case") === "attachments"
|
||||
{parameters.get("case") === "loaded-session-search"
|
||||
? <LoadedSessionSearchFixture />
|
||||
: parameters.get("case") === "attachments"
|
||||
? <AttachmentLayoutFixture />
|
||||
: parameters.get("case") === "theme-toggle"
|
||||
? <ClientProvider client={railClient} token="fixture"><ThemeToggleFixture /></ClientProvider>
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { SessionSearchDialog } from "@/components/SessionSearchDialog";
|
||||
import { useAppViewport } from "@/hooks/useAppViewport";
|
||||
import { ThreadMessageCache } from "@/lib/thread-message-cache";
|
||||
import { ThreadTranscript } from "@/lib/thread-transcript";
|
||||
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,
|
||||
}));
|
||||
|
||||
export function LoadedSessionSearchFixture() {
|
||||
useAppViewport();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [selected, setSelected] = useState<string | null>(null);
|
||||
const [cache] = useState(() => {
|
||||
const value = new ThreadMessageCache(() => false);
|
||||
value.set("topic-1", new ThreadTranscript([
|
||||
{ id: "user", role: "user", content: "我们讨论权限与配对", createdAt: 1 },
|
||||
{ id: "answer", role: "assistant", content: `${"Earlier notes. ".repeat(500)}Use Full Access at 25% in session_history.py`, createdAt: 2 },
|
||||
]).save());
|
||||
return value;
|
||||
});
|
||||
useEffect(() => {
|
||||
const shortcut = (event: KeyboardEvent) => {
|
||||
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "k") {
|
||||
event.preventDefault();
|
||||
setOpen(true);
|
||||
}
|
||||
};
|
||||
window.addEventListener("keydown", shortcut);
|
||||
return () => window.removeEventListener("keydown", shortcut);
|
||||
}, []);
|
||||
return <main className="h-[100dvh] bg-background p-6 text-foreground">
|
||||
<button onClick={() => setOpen(true)}>Search</button>
|
||||
<textarea aria-label="Draft" defaultValue="Keep this unsent draft" className="block" />
|
||||
<output aria-label="Selected topic">{selected}</output>
|
||||
<SessionSearchDialog open={open} onOpenChange={setOpen} sessions={sessions}
|
||||
activeKey={selected} loading={false} messageCache={cache} onSelect={setSelected} />
|
||||
</main>;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
for (const viewport of [{ width: 1280, height: 800 }, { width: 390, height: 844 }]) {
|
||||
test(`searches only loaded body text without requests at ${viewport.width}px`, async ({ page }) => {
|
||||
await page.setViewportSize(viewport);
|
||||
const apiRequests: string[] = [];
|
||||
const errors: string[] = [];
|
||||
page.on("request", (request) => { if (new URL(request.url()).pathname.startsWith("/api/")) apiRequests.push(request.url()); });
|
||||
page.on("pageerror", (error) => errors.push(error.message));
|
||||
await page.goto("/browser/fixture.html?case=loaded-session-search");
|
||||
await page.getByRole("button", { name: "Search", exact: true }).waitFor();
|
||||
await page.keyboard.press("Control+k");
|
||||
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 ["权限", "full access", "25%", "session_history.py"]) {
|
||||
await input.fill(query);
|
||||
await expect(dialog.getByRole("button")).toHaveCount(1);
|
||||
await expect(dialog.getByText("Topic 1", { exact: true })).toBeVisible();
|
||||
await expect(dialog.getByText(query === "权限" ? "我们讨论权限与配对" : /Use Full Access at 25%/)).toBeVisible();
|
||||
}
|
||||
await input.fill("unloaded server content");
|
||||
await expect(dialog.getByText("No matching topics.")).toBeVisible();
|
||||
await input.fill("权限");
|
||||
const box = await dialog.boundingBox();
|
||||
expect(box).not.toBeNull();
|
||||
expect(box!.x).toBeGreaterThanOrEqual(0);
|
||||
expect(box!.x + box!.width).toBeLessThanOrEqual(viewport.width);
|
||||
await dialog.screenshot({ path: test.info().outputPath(`loaded-search-${viewport.width}.png`) });
|
||||
await input.press("Enter");
|
||||
await expect(dialog).not.toBeVisible();
|
||||
await expect(page.getByLabel("Selected topic")).toHaveText("websocket:topic-1");
|
||||
await expect(page.getByRole("textbox", { name: "Draft" })).toHaveValue("Keep this unsent draft");
|
||||
expect(apiRequests).toEqual([]);
|
||||
expect(errors).toEqual([]);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user