feat(FN-4857): complete Step 6 — wire room send dispatch in ChatView
Fusion-Task-Id: FN-4857 Fusion-Task-Lineage: 52e7b1cd-ec8f-4b6c-abfc-08c91e321b9e
This commit is contained in:
committed by
gsxdsm
parent
c7f98f8381
commit
74f0bd9e8d
@@ -745,8 +745,11 @@ const ChatMessageItem = memo(function ChatMessageItem({
|
||||
|
||||
const renderedAttachments = useMemo<ReactNode>(() => {
|
||||
const attachments = message.attachments;
|
||||
if (!attachments || attachments.length === 0 || !activeSessionId) return null;
|
||||
const attachmentUrlBase = `/api/chat/sessions/${encodeURIComponent(activeSessionId)}/attachments/`;
|
||||
if (!attachments || attachments.length === 0) return null;
|
||||
const attachmentUrlBase = message.roomId
|
||||
? `/api/chat/rooms/${encodeURIComponent(message.roomId)}/attachments/`
|
||||
: (activeSessionId ? `/api/chat/sessions/${encodeURIComponent(activeSessionId)}/attachments/` : null);
|
||||
if (!attachmentUrlBase) return null;
|
||||
return (
|
||||
<div className="chat-message-attachments">
|
||||
{attachments.map((attachment) => {
|
||||
@@ -787,8 +790,7 @@ const ChatMessageItem = memo(function ChatMessageItem({
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}, [message.attachments, activeSessionId]);
|
||||
|
||||
}, [message.attachments, message.roomId, activeSessionId]);
|
||||
const assistantBody = useMemo<ReactNode>(() => {
|
||||
if (!isAssistantMessage) return null;
|
||||
if (failureInfo) {
|
||||
@@ -1692,7 +1694,7 @@ export function ChatView({ projectId, addToast, experimentalFeatures }: ChatView
|
||||
clearComposerState();
|
||||
|
||||
try {
|
||||
await rooms.sendRoomMessage(trimmed);
|
||||
await rooms.sendRoomMessage(trimmed, { files: pendingAttachments.map((attachment) => attachment.file) });
|
||||
} catch (error) {
|
||||
setMessageInput(previousInput);
|
||||
const message = error instanceof Error && error.message.trim()
|
||||
@@ -1704,8 +1706,7 @@ export function ChatView({ projectId, addToast, experimentalFeatures }: ChatView
|
||||
}
|
||||
|
||||
handleSend();
|
||||
}, [messageInput, chatRoomsEnabled, chatScope, rooms, rooms.clearRoom, clearComposerState, addToast, handleSend]);
|
||||
|
||||
}, [messageInput, pendingAttachments, chatRoomsEnabled, chatScope, rooms, rooms.clearRoom, clearComposerState, addToast, handleSend]);
|
||||
const handleSkillSelect = useCallback(
|
||||
(skill: DiscoveredSkill) => {
|
||||
setMessageInput((currentInput) => {
|
||||
|
||||
@@ -320,13 +320,29 @@ describe("ChatView — rooms (FN-3805..FN-3811 contract)", () => {
|
||||
await userEvent.type(textarea, "Hello room{enter}");
|
||||
|
||||
await waitFor(() => {
|
||||
expect(sendRoomMessage).toHaveBeenCalledWith("Hello room");
|
||||
expect(sendRoomMessage).toHaveBeenCalledWith("Hello room", { files: [] });
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect((textarea as HTMLTextAreaElement).value).toBe("");
|
||||
});
|
||||
});
|
||||
|
||||
it("passes attachment file list shape to room sends", async () => {
|
||||
const addToast = vi.fn();
|
||||
const sendRoomMessage = vi.fn().mockResolvedValue(undefined);
|
||||
setup({}, { sendRoomMessage, activeRoom: roomA });
|
||||
|
||||
render(<ChatView projectId="proj-123" addToast={addToast} experimentalFeatures={{ chatRooms: true }} />);
|
||||
|
||||
const textarea = screen.getByTestId("chat-input") as HTMLTextAreaElement;
|
||||
await userEvent.type(textarea, "Room upload{enter}");
|
||||
|
||||
await waitFor(() => {
|
||||
expect(sendRoomMessage).toHaveBeenCalledWith("Room upload", { files: [] });
|
||||
});
|
||||
expect(addToast).not.toHaveBeenCalledWith(expect.stringMatching(/attach/i), "warning");
|
||||
});
|
||||
|
||||
it("keeps room composer text and toasts once when room send fails", async () => {
|
||||
const addToast = vi.fn();
|
||||
let rejectSend: (error?: unknown) => void;
|
||||
@@ -342,7 +358,7 @@ describe("ChatView — rooms (FN-3805..FN-3811 contract)", () => {
|
||||
await userEvent.type(textarea, "Will retry{enter}");
|
||||
|
||||
await waitFor(() => {
|
||||
expect(sendRoomMessage).toHaveBeenCalledWith("Will retry");
|
||||
expect(sendRoomMessage).toHaveBeenCalledWith("Will retry", { files: [] });
|
||||
});
|
||||
expect(textarea.value).toBe("");
|
||||
|
||||
@@ -369,7 +385,7 @@ describe("ChatView — rooms (FN-3805..FN-3811 contract)", () => {
|
||||
await userEvent.type(textarea, "Optimistic clear{enter}");
|
||||
|
||||
await waitFor(() => {
|
||||
expect(sendRoomMessage).toHaveBeenCalledWith("Optimistic clear");
|
||||
expect(sendRoomMessage).toHaveBeenCalledWith("Optimistic clear", { files: [] });
|
||||
});
|
||||
expect(textarea.value).toBe("");
|
||||
|
||||
@@ -423,7 +439,7 @@ describe("ChatView — rooms (FN-3805..FN-3811 contract)", () => {
|
||||
await userEvent.type(textarea, "/clear now{enter}");
|
||||
|
||||
await waitFor(() => {
|
||||
expect(sendRoomMessage).toHaveBeenCalledWith("/clear now");
|
||||
expect(sendRoomMessage).toHaveBeenCalledWith("/clear now", { files: [] });
|
||||
});
|
||||
expect(clearRoom).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user