Chat sidebar search now matches message content by default, not just the conversation title/agent, with an opt-out toggle to restore title-only filtering. - Add ChatStore.searchSessionsByMessageContent (parameterized LIKE ... ESCAPE) for server-side content search across sessions - GET /chat/sessions route (register-chat-routes.ts, legacy.ts) gains q/titleOnly query params, debounced server-side content lookup merged with local title/agent matches - useChat hook exposes searchInTitleOnly state and wires debounced content search into session list results - ChatView renders a "Search in title only" toggle beside the search box (desktop + mobile) and shows a "Matched: ..." preview snippet on content-matched rows - Task-planner sessions remain excluded from content matches via the same common-feed visibility guard used for the normal session list - Add unit/integration tests: chat-store content-search, chat-routes API test, ChatView content-search test - Update docs/dashboard-guide.md to document the new content search behavior and toggle - Add changeset fn-7631-chat-content-search.md (@runfusion/fusion minor) Files changed: .changeset/fn-7631-chat-content-search.md | 7 + docs/dashboard-guide.md | 2 + .../__tests__/chat-store.content-search.test.ts | 157 +++++++++++++++++++++ packages/core/src/chat-store.ts | 64 +++++++++ packages/core/src/chat-types.ts | 8 ++ packages/dashboard/app/api/legacy.ts | 23 ++- packages/dashboard/app/components/ChatView.css | 30 ++++ packages/dashboard/app/components/ChatView.tsx | 26 ++++ .../__tests__/ChatView.autosize.test.tsx | 2 + .../__tests__/ChatView.content-search.test.tsx | 114 +++++++++++++++ .../components/__tests__/ChatView.draft.test.tsx | 2 + .../__tests__/ChatView.hash-mention.test.tsx | 2 + .../__tests__/ChatView.mobile-render.test.tsx | 2 + .../components/__tests__/ChatView.rooms.test.tsx | 2 + .../__tests__/ChatView.scroll-to-top.test.tsx | 2 + .../components/__tests__/ChatView.test-harness.tsx | 2 + packages/dashboard/app/hooks/useChat.ts | 105 ++++++++++++-- .../dashboard/src/__tests__/chat-routes.test.ts | 78 ++++++++++ .../dashboard/src/routes/register-chat-routes.ts | 39 ++++- packages/i18n/locales/en/app.json | 2 + packages/i18n/locales/es/app.json | 2 + packages/i18n/locales/fr/app.json | 2 + packages/i18n/locales/ko/app.json | 2 + packages/i18n/locales/zh-CN/app.json | 2 + packages/i18n/locales/zh-TW/app.json | 2 + 25 files changed, 667 insertions(+), 12 deletions(-) Fusion-Task-Id: FN-7631 Fusion-Task-Lineage: bc68b489-26a7-453e-901b-bda816af364e Co-authored-by: Fusion (runfusion.ai) <noreply@runfusion.ai>
115 lines
4.3 KiB
TypeScript
115 lines
4.3 KiB
TypeScript
/*
|
|
FNXC:ChatSearch 2026-07-07-00:00:
|
|
Covers the "Search in title only" toggle affordance: renders on desktop AND mobile chat
|
|
sidebars (shared DOM, CSS-breakpoint driven), toggling calls setSearchInTitleOnly, the toggle
|
|
does not leak into the Rooms scope, and matchedMessagePreview renders when content-mode drove
|
|
a session's inclusion.
|
|
*/
|
|
import { describe, it, expect, vi } from "vitest";
|
|
import { screen } from "@testing-library/react";
|
|
import { userEvent } from "@testing-library/user-event";
|
|
import { ChatView } from "../ChatView";
|
|
import {
|
|
renderWithAct,
|
|
setupMockChat,
|
|
setupMockRooms,
|
|
mockViewportMode,
|
|
activeSessionFixture,
|
|
installChatViewEnv,
|
|
} from "./ChatView.test-harness";
|
|
|
|
vi.mock("../../hooks/useChat");
|
|
vi.mock("../../hooks/useChatRooms");
|
|
vi.mock("../../hooks/useNavigationHistory", async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import("../../hooks/useNavigationHistory")>();
|
|
return {
|
|
...actual,
|
|
useNavigationHistoryContext: () => ({ pushNav: vi.fn(), replaceCurrent: vi.fn() }),
|
|
};
|
|
});
|
|
vi.mock("lucide-react", async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import("lucide-react")>();
|
|
return { ...actual };
|
|
});
|
|
vi.mock("../../api", () => ({
|
|
fetchModels: vi.fn().mockResolvedValue({
|
|
models: [
|
|
{ provider: "anthropic", id: "claude-sonnet-4-5", name: "Claude Sonnet 4.5", reasoning: true, contextWindow: 200000 },
|
|
{ provider: "openai", id: "gpt-4o", name: "GPT-4o", reasoning: false, contextWindow: 128000 },
|
|
],
|
|
favoriteProviders: [],
|
|
favoriteModels: [],
|
|
defaultProvider: "anthropic",
|
|
defaultModelId: "claude-sonnet-4-5",
|
|
}),
|
|
fetchAgents: vi.fn().mockResolvedValue([]),
|
|
fetchDiscoveredSkills: vi.fn().mockResolvedValue([]),
|
|
fetchTasks: vi.fn().mockResolvedValue([]),
|
|
searchFiles: vi.fn().mockResolvedValue({ files: [] }),
|
|
}));
|
|
|
|
installChatViewEnv();
|
|
|
|
describe("ChatView content search toggle", () => {
|
|
it("renders the title-only toggle on the desktop sidebar and calls setSearchInTitleOnly on click", async () => {
|
|
mockViewportMode("desktop");
|
|
const setSearchInTitleOnly = vi.fn();
|
|
setupMockChat({ sessions: [], filteredSessions: [], searchInTitleOnly: false, setSearchInTitleOnly });
|
|
|
|
await renderWithAct(<ChatView projectId="proj-123" addToast={vi.fn()} />);
|
|
|
|
const toggle = screen.getByTestId("chat-search-title-only-toggle");
|
|
expect(toggle).toBeInTheDocument();
|
|
expect(toggle).toHaveAttribute("aria-pressed", "false");
|
|
|
|
await userEvent.click(toggle);
|
|
expect(setSearchInTitleOnly).toHaveBeenCalledWith(true);
|
|
});
|
|
|
|
it("renders the title-only toggle on the mobile sidebar and calls setSearchInTitleOnly on click", async () => {
|
|
mockViewportMode("mobile");
|
|
const setSearchInTitleOnly = vi.fn();
|
|
setupMockChat({ sessions: [], filteredSessions: [], searchInTitleOnly: true, setSearchInTitleOnly });
|
|
|
|
await renderWithAct(<ChatView projectId="proj-123" addToast={vi.fn()} />);
|
|
|
|
const toggle = screen.getByTestId("chat-search-title-only-toggle");
|
|
expect(toggle).toBeInTheDocument();
|
|
expect(toggle).toHaveAttribute("aria-pressed", "true");
|
|
|
|
await userEvent.click(toggle);
|
|
expect(setSearchInTitleOnly).toHaveBeenCalledWith(false);
|
|
});
|
|
|
|
it("does not render the toggle in Rooms scope", async () => {
|
|
setupMockChat({ sessions: [], filteredSessions: [] });
|
|
|
|
await renderWithAct(<ChatView projectId="proj-123" addToast={vi.fn()} experimentalFeatures={{ chatRooms: true }} />);
|
|
|
|
await userEvent.click(screen.getByTestId("chat-sidebar-scope-rooms"));
|
|
|
|
expect(screen.queryByTestId("chat-search-title-only-toggle")).toBeNull();
|
|
});
|
|
|
|
it("shows matchedMessagePreview for a session included via content match", async () => {
|
|
const contentMatchedSession = {
|
|
...activeSessionFixture,
|
|
id: "session-content-match",
|
|
title: "Weekend plans",
|
|
matchedMessagePreview: "quarterly roadmap discussion",
|
|
};
|
|
setupMockChat({
|
|
sessions: [contentMatchedSession],
|
|
filteredSessions: [contentMatchedSession],
|
|
searchQuery: "roadmap",
|
|
searchInTitleOnly: false,
|
|
});
|
|
|
|
await renderWithAct(<ChatView projectId="proj-123" addToast={vi.fn()} />);
|
|
|
|
expect(screen.getByTestId("chat-session-matched-preview-session-content-match")).toHaveTextContent(
|
|
"quarterly roadmap discussion",
|
|
);
|
|
});
|
|
});
|