Files
fusion/packages/dashboard/app/components/__tests__/AgentMentionPopup.room.test.tsx
Fusion b94fd232a6 feat(FN-3812): add rooms test scaffolds and coverage across core and dashbo
This branch establishes test scaffolding for rooms functionality across core and dashboard, adding test plans, room-specific test files for ChatView, AgentMentionPopup, QuickChatFAB, and core chat routes/stores, while also updating AgentMentionPopup with enhanced room-aware behavior and QuickChatFAB

Fusion-Task-Id: FN-3812
2026-05-10 07:59:40 -07:00

95 lines
3.3 KiB
TypeScript

import { fireEvent, render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import type { Agent } from "@fusion/core";
import { AgentMentionPopup } from "../AgentMentionPopup";
const agents: Agent[] = [
{ id: "agent-001", name: "Alpha", role: "executor", state: "idle", createdAt: "2026-04-01T00:00:00.000Z", updatedAt: "2026-04-01T00:00:00.000Z", metadata: {} },
{ id: "agent-002", name: "Alfred", role: "reviewer", state: "idle", createdAt: "2026-04-01T00:00:00.000Z", updatedAt: "2026-04-01T00:00:00.000Z", metadata: {} },
{ id: "agent-003", name: "Alex", role: "triage", state: "idle", createdAt: "2026-04-01T00:00:00.000Z", updatedAt: "2026-04-01T00:00:00.000Z", metadata: {} },
];
describe("AgentMentionPopup room behavior", () => {
it("shows only members with hint on empty filter", () => {
render(
<AgentMentionPopup
agents={agents}
filter=""
highlightedIndex={0}
visible={true}
onSelect={vi.fn()}
roomMemberIds={new Set(["agent-001", "agent-003"])}
/>,
);
expect(screen.getByTestId("agent-mention-item-agent-001")).toBeInTheDocument();
expect(screen.getByTestId("agent-mention-item-agent-003")).toBeInTheDocument();
expect(screen.queryByTestId("agent-mention-item-agent-002")).not.toBeInTheDocument();
expect(screen.getByTestId("agent-mention-other-hint")).toBeInTheDocument();
});
it("shows matching members before matching non-members when filtering", () => {
render(
<AgentMentionPopup
agents={agents}
filter="al"
highlightedIndex={0}
visible={true}
onSelect={vi.fn()}
roomMemberIds={new Set(["agent-003"])}
/>,
);
const options = screen.getAllByRole("option");
expect(options[0]).toHaveAttribute("data-testid", "agent-mention-item-agent-003");
expect(options[1]).toHaveAttribute("data-testid", "agent-mention-item-agent-001");
});
it("supports keyboard-index traversal across members then non-members", () => {
const roomMemberIds = new Set(["agent-003"]);
const { rerender } = render(
<AgentMentionPopup
agents={agents}
filter="al"
highlightedIndex={0}
visible={true}
onSelect={vi.fn()}
roomMemberIds={roomMemberIds}
/>,
);
expect(screen.getByTestId("agent-mention-item-agent-003")).toHaveClass("agent-mention-item--highlighted");
rerender(
<AgentMentionPopup
agents={agents}
filter="al"
highlightedIndex={1}
visible={true}
onSelect={vi.fn()}
roomMemberIds={roomMemberIds}
/>,
);
expect(screen.getByTestId("agent-mention-item-agent-001")).toHaveClass("agent-mention-item--highlighted");
});
it("selects non-members and includes accessible member dot labels", () => {
const onSelect = vi.fn();
render(
<AgentMentionPopup
agents={agents}
filter="al"
highlightedIndex={0}
visible={true}
onSelect={onSelect}
roomMemberIds={new Set(["agent-001"])}
/>,
);
fireEvent.click(screen.getByTestId("agent-mention-item-agent-002"));
expect(onSelect).toHaveBeenCalledWith(agents[1]);
expect(screen.getAllByLabelText("Room member")).toHaveLength(1);
});
});