diff --git a/frontend/__tests__/components/features/conversation/agent-status.test.tsx b/frontend/__tests__/components/features/conversation/agent-status.test.tsx new file mode 100644 index 0000000000..a121ed37a8 --- /dev/null +++ b/frontend/__tests__/components/features/conversation/agent-status.test.tsx @@ -0,0 +1,71 @@ +import { render, screen } from "@testing-library/react"; +import { describe, it, expect, vi } from "vitest"; +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; +import { MemoryRouter } from "react-router"; +import { AgentStatus } from "#/components/features/controls/agent-status"; +import { AgentState } from "#/types/agent-state"; +import { useAgentState } from "#/hooks/use-agent-state"; +import { useConversationStore } from "#/state/conversation-store"; + +vi.mock("#/hooks/use-agent-state"); + +vi.mock("#/hooks/use-conversation-id", () => ({ + useConversationId: () => ({ conversationId: "test-id" }), +})); + +const wrapper = ({ children }: { children: React.ReactNode }) => ( + + + {children} + + +); + +const renderAgentStatus = ({ + isPausing = false, +}: { isPausing?: boolean } = {}) => + render( + , + { wrapper }, + ); + +describe("AgentStatus - isLoading logic", () => { + it("should show loading when curAgentState is INIT", () => { + vi.mocked(useAgentState).mockReturnValue({ + curAgentState: AgentState.INIT, + }); + + renderAgentStatus(); + + expect(screen.getByTestId("agent-loading-spinner")).toBeInTheDocument(); + }); + + it("should show loading when isPausing is true, even if shouldShownAgentLoading is false", () => { + vi.mocked(useAgentState).mockReturnValue({ + curAgentState: AgentState.AWAITING_USER_INPUT, + }); + + renderAgentStatus({ isPausing: true }); + + expect(screen.getByTestId("agent-loading-spinner")).toBeInTheDocument(); + }); + + it("should NOT update global shouldShownAgentLoading when only isPausing is true", () => { + vi.mocked(useAgentState).mockReturnValue({ + curAgentState: AgentState.AWAITING_USER_INPUT, + }); + + renderAgentStatus({ isPausing: true }); + + // Loading spinner shows (because isPausing) + expect(screen.getByTestId("agent-loading-spinner")).toBeInTheDocument(); + + // But global state should be false (because shouldShownAgentLoading is false) + const { shouldShownAgentLoading } = useConversationStore.getState(); + expect(shouldShownAgentLoading).toBe(false); + }); +}); diff --git a/frontend/src/components/features/controls/agent-status.tsx b/frontend/src/components/features/controls/agent-status.tsx index 078eb5f40f..675b5881a3 100644 --- a/frontend/src/components/features/controls/agent-status.tsx +++ b/frontend/src/components/features/controls/agent-status.tsx @@ -59,13 +59,15 @@ export function AgentStatus({ ); const shouldShownAgentLoading = - isPausing || curAgentState === AgentState.INIT || curAgentState === AgentState.LOADING || (webSocketStatus === "CONNECTING" && taskStatus !== "ERROR") || isTaskPolling(taskStatus) || isTaskPolling(subConversationTaskStatus); + // For UI rendering - includes pause state + const isLoading = shouldShownAgentLoading || isPausing; + const shouldShownAgentError = curAgentState === AgentState.ERROR || curAgentState === AgentState.RATE_LIMITED || @@ -93,25 +95,28 @@ export function AgentStatus({
- {shouldShownAgentLoading && } - {!shouldShownAgentLoading && shouldShownAgentStop && ( + {isLoading && } + {!isLoading && shouldShownAgentStop && ( )} - {!shouldShownAgentLoading && shouldShownAgentResume && ( + {!isLoading && shouldShownAgentResume && ( )} - {!shouldShownAgentLoading && shouldShownAgentError && ( - + {!isLoading && shouldShownAgentError && ( + )} - {!shouldShownAgentLoading && + {!isLoading && !shouldShownAgentStop && !shouldShownAgentResume && !shouldShownAgentError && }