feat(FN-4103): add default agents selection in MailboxView

MailboxView's default agents selection logic was implemented and refactored to be more concise (14 lines removed), with corresponding test coverage for the all-agents default selection behavior added to MailboxView.test.tsx.

Fusion-Task-Id: FN-4103
This commit is contained in:
Fusion
2026-05-12 07:23:37 -07:00
committed by gsxdsm
parent db1bbda369
commit 266eafaecd
2 changed files with 27 additions and 15 deletions

View File

@@ -202,7 +202,7 @@ export function MailboxView({
const [showComposer, setShowComposer] = useState(false);
const [composeRecipient, setComposeRecipient] = useState<{ id: string; type: ParticipantType } | null>(null);
const [composeReplyContext, setComposeReplyContext] = useState<{ messageId: string; preview: string } | null>(null);
const [selectedAgentId, setSelectedAgentId] = useState<string | null>(null);
const [selectedAgentId, setSelectedAgentId] = useState<string>(ALL_AGENTS_MAILBOX_ID);
const [agentSubTab, setAgentSubTab] = useState<"inbox" | "outbox">("inbox");
const [agentMailbox, setAgentMailbox] = useState<AgentMailboxResponse | null>(null);
const [allAgentsMailbox, setAllAgentsMailbox] = useState<AllAgentsMailboxResponse | null>(null);
@@ -414,7 +414,6 @@ export function MailboxView({
// Load agent mailbox when selected
useEffect(() => {
if (!selectedAgentId) return;
if (selectedAgentId === ALL_AGENTS_MAILBOX_ID) {
void loadAllAgentsMailbox();
return;
@@ -900,11 +899,10 @@ export function MailboxView({
<div className="mailbox-agents-dropdown">
<select
className="message-composer-select mailbox-agent-select"
value={selectedAgentId ?? ""}
onChange={(e) => { setSelectedAgentId(e.target.value || null); setAgentSubTab("inbox"); }}
value={selectedAgentId}
onChange={(e) => { setSelectedAgentId(e.target.value); setAgentSubTab("inbox"); }}
data-testid="mailbox-agent-select"
>
<option value="">Select an agent</option>
<option value={ALL_AGENTS_MAILBOX_ID}>All agents</option>
{agents.map((agent) => (
<option key={agent.id} value={agent.id}>
@@ -947,12 +945,6 @@ export function MailboxView({
</div>
)}
<div className="mailbox-agents-content">
{!selectedAgentId && (
<div className="mailbox-empty">
<Bot size={32} />
<p>Select an agent to view their mailbox</p>
</div>
)}
{selectedAgentId === ALL_AGENTS_MAILBOX_ID && isLoading && !allAgentsMailbox && <MailboxSkeleton />}
{selectedAgentId === ALL_AGENTS_MAILBOX_ID && allAgentsMailbox && allAgentsMailbox.messages.length === 0 && (
<div className="mailbox-empty">

View File

@@ -1220,6 +1220,30 @@ describe("MailboxView", () => {
});
describe("agent mailbox sub-tabs", () => {
it("FN-4103 defaults the Agents tab selector to All agents without a placeholder", async () => {
mockFetchInbox.mockResolvedValue({ messages: [], unreadCount: 0, total: 0 });
mockFetchAllAgentMailbox.mockResolvedValue({ messages: [], total: 0, unreadCount: 0 });
render(<MailboxView {...defaultProps} />);
await act(async () => {
fireEvent.click(screen.getByTestId("mailbox-tab-agents"));
});
await waitFor(() => {
expect(mockFetchAllAgentMailbox).toHaveBeenCalledWith(undefined);
});
const agentSelect = screen.getByTestId("mailbox-agent-select") as HTMLSelectElement;
expect(agentSelect.value).toBe("__all_agents__");
const firstOption = agentSelect.options[0];
expect(firstOption?.value).toBe("__all_agents__");
expect(firstOption?.text).toBe("All agents");
expect(screen.queryByText("Select an agent to view their mailbox")).toBeNull();
expect(screen.getByText("No agent-to-agent messages")).toBeDefined();
});
it("shows All agents option and renders aggregate stream without subtabs", async () => {
const aggregateMessage: Message = {
...mockAgentToAgentMessage,
@@ -1243,8 +1267,6 @@ describe("MailboxView", () => {
fireEvent.click(screen.getByTestId("mailbox-tab-agents"));
});
fireEvent.change(screen.getByTestId("mailbox-agent-select"), { target: { value: "__all_agents__" } });
await waitFor(() => {
expect(mockFetchAllAgentMailbox).toHaveBeenCalledWith(undefined);
expect(screen.queryByTestId("mailbox-agent-subtabs")).toBeNull();
@@ -1262,7 +1284,6 @@ describe("MailboxView", () => {
await act(async () => {
fireEvent.click(screen.getByTestId("mailbox-tab-agents"));
});
fireEvent.change(screen.getByTestId("mailbox-agent-select"), { target: { value: "__all_agents__" } });
await act(async () => {
fireEvent.click(screen.getByTestId("mailbox-compose-btn"));
@@ -1283,7 +1304,6 @@ describe("MailboxView", () => {
await act(async () => {
fireEvent.click(screen.getByTestId("mailbox-tab-agents"));
});
fireEvent.change(screen.getByTestId("mailbox-agent-select"), { target: { value: "__all_agents__" } });
const latest = sseSubscriptions.at(-1);
await act(async () => {