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>
117 lines
3.5 KiB
TypeScript
117 lines
3.5 KiB
TypeScript
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { ChatView } from "../ChatView";
|
|
import { FileBrowserProvider } from "../../context/FileBrowserContext";
|
|
import * as useChatModule from "../../hooks/useChat";
|
|
import * as apiModule from "../../api";
|
|
import type { UseChatReturn, ChatSessionInfo } from "../../hooks/useChat";
|
|
|
|
Element.prototype.scrollIntoView = vi.fn();
|
|
|
|
vi.mock("../../hooks/useChat");
|
|
vi.mock("../../hooks/useChatRooms", () => ({
|
|
useChatRooms: () => ({
|
|
rooms: [],
|
|
roomsLoading: false,
|
|
roomsError: null,
|
|
activeRoom: null,
|
|
activeRoomMembers: [],
|
|
messages: [],
|
|
messagesLoading: false,
|
|
selectRoom: vi.fn(),
|
|
createRoom: vi.fn(),
|
|
deleteRoom: vi.fn(),
|
|
sendRoomMessage: vi.fn(),
|
|
refreshRooms: vi.fn(),
|
|
}),
|
|
}));
|
|
vi.mock("../../hooks/useChatUnread", () => ({
|
|
useChatUnread: () => ({ isUnread: () => false, markRead: vi.fn() }),
|
|
}));
|
|
vi.mock("../../hooks/useNavigationHistory", () => ({
|
|
useNavigationHistoryContext: () => ({ pushNav: vi.fn(), replaceCurrent: vi.fn() }),
|
|
}));
|
|
vi.mock("../../api", () => ({
|
|
fetchAgents: vi.fn().mockResolvedValue([]),
|
|
fetchDiscoveredSkills: vi.fn().mockResolvedValue([]),
|
|
fetchModels: vi.fn().mockResolvedValue({ models: [], favoriteProviders: [], favoriteModels: [] }),
|
|
fetchTasks: vi.fn().mockResolvedValue([
|
|
{ id: "FN-5218", title: "Hash entries in chat", column: "todo" },
|
|
]),
|
|
searchFiles: vi.fn().mockResolvedValue({ files: [] }),
|
|
}));
|
|
|
|
const mockUseChat = vi.mocked(useChatModule.useChat);
|
|
const mockFetchTasks = vi.mocked(apiModule.fetchTasks);
|
|
|
|
const activeSession: ChatSessionInfo = {
|
|
id: "session-1",
|
|
agentId: "agent-1",
|
|
status: "active",
|
|
title: "Chat",
|
|
createdAt: "2026-05-19T00:00:00.000Z",
|
|
updatedAt: "2026-05-19T00:00:00.000Z",
|
|
};
|
|
|
|
const defaultChatState: UseChatReturn = {
|
|
sessions: [activeSession],
|
|
activeSession,
|
|
sessionsLoading: false,
|
|
messages: [],
|
|
messagesLoading: false,
|
|
isStreaming: false,
|
|
streamingText: "",
|
|
streamingThinking: "",
|
|
streamingToolCalls: [],
|
|
selectSession: vi.fn(),
|
|
createSession: vi.fn(),
|
|
archiveSession: vi.fn(),
|
|
deleteSession: vi.fn(),
|
|
sendMessage: vi.fn(),
|
|
editMessageAndResend: vi.fn(),
|
|
stopStreaming: vi.fn(),
|
|
pendingMessages: [],
|
|
clearPendingMessage: vi.fn(),
|
|
loadMoreMessages: vi.fn(),
|
|
hasMoreMessages: false,
|
|
searchQuery: "",
|
|
setSearchQuery: vi.fn(),
|
|
searchInTitleOnly: false,
|
|
setSearchInTitleOnly: vi.fn(),
|
|
filteredSessions: [activeSession],
|
|
refreshSessions: vi.fn(),
|
|
agentsMap: new Map(),
|
|
};
|
|
|
|
describe("ChatView hash mentions", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
mockUseChat.mockReturnValue(defaultChatState);
|
|
});
|
|
|
|
it("inserts a task id from the shared hash mention popup", async () => {
|
|
render(
|
|
<FileBrowserProvider>
|
|
<ChatView />
|
|
</FileBrowserProvider>,
|
|
);
|
|
|
|
const textarea = screen.getByPlaceholderText("Type a message...") as HTMLTextAreaElement;
|
|
fireEvent.change(textarea, {
|
|
target: { value: "#FN", selectionStart: 3, selectionEnd: 3 },
|
|
});
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByText("Tasks")).toBeInTheDocument();
|
|
});
|
|
expect(screen.getByTestId("task-mention-item-0")).toHaveTextContent("FN-5218");
|
|
|
|
fireEvent.keyDown(textarea, { key: "Enter" });
|
|
|
|
await waitFor(() => {
|
|
expect(textarea.value).toBe("#FN-5218");
|
|
});
|
|
expect(mockFetchTasks).toHaveBeenCalledWith(20, 0, undefined, "FN");
|
|
});
|
|
});
|