Skip to content

πŸ™Œ OpenHands: AI-Driven Development

test: strengthen task tracking presentation (#17325)

aivong-openhands937ce3779ee7
diff --git a/__tests__/components/conversation-events/chat/task-tracking-item-status.test.tsx b/__tests__/components/conversation-events/chat/task-tracking-item-status.test.tsx
new file mode 100644
index 0000000000..621e3561c2
--- /dev/null
+++ b/__tests__/components/conversation-events/chat/task-tracking-item-status.test.tsx
@@ -0,0 +1,122 @@
+import { render, screen } from "@testing-library/react";
+import { describe, expect, it, vi } from "vitest";
+import { TaskItem } from "#/components/conversation-events/chat/task-tracking/task-item";
+import type { TaskItem as TaskItemData } from "#/types/agent-server/core/base/common";
+import { I18nKey } from "#/i18n/declaration";
+
+vi.mock("react-i18next", () => ({
+ useTranslation: (namespace?: string) => ({
+ t: (key: string) =>
+ namespace === "openhands" ? key : `missing-namespace:${key}`,
+ }),
+}));
+
+vi.mock("#/icons/u-circle.svg?react", () => ({
+ default: ({ className }: { className?: string }) => (
+ <svg data-testid="todo-icon" className={className} />
+ ),
+}));
+
+vi.mock("#/icons/u-check-circle-half.svg?react", () => ({
+ default: ({ className }: { className?: string }) => (
+ <svg data-testid="in-progress-icon" className={className} />
+ ),
+}));
+
+vi.mock("#/icons/u-check-circle.svg?react", () => ({
+ default: ({ className }: { className?: string }) => (
+ <svg data-testid="done-icon" className={className} />
+ ),
+}));
+
+function createTask(overrides: Partial<TaskItemData> = {}): TaskItemData {
+ return {
+ title: "Review the implementation",
+ notes: "",
+ status: "todo",
+ ...overrides,
+ };
+}
+
+describe("conversation task status display", () => {
+ it.each([
+ ["todo", "todo-icon", false],
+ ["in_progress", "in-progress-icon", false],
+ ["done", "done-icon", true],
+ ] as const)(
+ "renders the %s status with its matching icon and title treatment",
+ (status, iconTestId, isMuted) => {
+ const task = createTask({ status, title: `${status} task` });
+
+ const { container } = render(<TaskItem task={task} />);
+
+ expect(container.querySelector('[data-name="item"]')).toBeInTheDocument();
+ const icon = screen.getByTestId(iconTestId);
+ expect(icon).toBeInTheDocument();
+ const title = screen.getByText(`${status} task`);
+ expect(title).toHaveClass("text-[12px]");
+
+ if (isMuted) {
+ expect(icon).toHaveClass("text-[var(--oh-muted)]");
+ expect(title).toHaveClass("text-[var(--oh-muted)]");
+ } else {
+ expect(icon).toHaveClass("text-[#ffffff]");
+ expect(title).toHaveClass("text-white");
+ expect(title).not.toHaveClass("text-[var(--oh-muted)]");
+ }
+ },
+ );
+
+ it("shows translated notes beneath the task title", () => {
+ render(
+ <TaskItem
+ task={createTask({
+ title: "Document the behavior",
+ notes: "Include boundary cases",
+ })}
+ />,
+ );
+
+ expect(screen.getByText("Document the behavior")).toBeInTheDocument();
+ expect(
+ screen.getByText(
+ `${I18nKey.TASK_TRACKING_OBSERVATION$TASK_NOTES}: Include boundary cases`,
+ ),
+ ).toBeInTheDocument();
+ });
+
+ it("omits the notes row when notes are empty", () => {
+ render(<TaskItem task={createTask({ notes: "" })} />);
+
+ expect(
+ screen.queryByText(
+ new RegExp(I18nKey.TASK_TRACKING_OBSERVATION$TASK_NOTES),
+ ),
+ ).not.toBeInTheDocument();
+ });
+
+ it("uses the todo presentation for an unknown runtime status", () => {
+ const task = createTask({
+ status: "blocked" as TaskItemData["status"],
+ });
+
+ render(<TaskItem task={task} />);
+
+ expect(screen.getByTestId("todo-icon")).toHaveClass("text-[#ffffff]");
+ expect(screen.getByText("Review the implementation")).not.toHaveClass(
+ "text-[var(--oh-muted)]",
+ );
+ });
+
+ it("updates the status icon when task progress changes", () => {
+ const { rerender } = render(
+ <TaskItem task={createTask({ status: "todo" })} />,
+ );
+ expect(screen.getByTestId("todo-icon")).toBeInTheDocument();
+
+ rerender(<TaskItem task={createTask({ status: "in_progress" })} />);
+
+ expect(screen.queryByTestId("todo-icon")).not.toBeInTheDocument();
+ expect(screen.getByTestId("in-progress-icon")).toBeInTheDocument();
+ });
+});
diff --git a/src/components/conversation-events/chat/task-tracking/task-list-section.test.tsx b/src/components/conversation-events/chat/task-tracking/task-list-section.test.tsx
new file mode 100644
index 0000000000..1b96b6b681
--- /dev/null
+++ b/src/components/conversation-events/chat/task-tracking/task-list-section.test.tsx
@@ -0,0 +1,69 @@
+import { render, screen } from "@testing-library/react";
+import { afterEach, describe, expect, it, vi } from "vitest";
+import { I18nKey } from "#/i18n/declaration";
+import type { TaskItem as TaskItemType } from "#/types/agent-server/core/base/common";
+import { TaskListSection } from "./task-list-section";
+
+const useTranslationMock = vi.hoisted(() =>
+ vi.fn((namespace: string) => ({
+ t: (key: string) =>
+ namespace === "openhands" ? `translated:${key}` : `missing:${key}`,
+ })),
+);
+
+vi.mock("react-i18next", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("react-i18next")>()),
+ useTranslation: useTranslationMock,
+}));
+
+const createTask = (overrides: Partial<TaskItemType> = {}): TaskItemType => ({
+ title: "Inspect the behavior",
+ notes: "",
+ status: "todo",
+ ...overrides,
+});
+
+describe("task tracking list", () => {
+ afterEach(() => {
+ vi.restoreAllMocks();
+ });
+
+ it("shows every planned task in its supplied order", () => {
+ const consoleErrorSpy = vi
+ .spyOn(console, "error")
+ .mockImplementation(() => undefined);
+ const taskList = [
+ createTask({ title: "Inspect the behavior" }),
+ createTask({ title: "Add focused coverage", status: "in_progress" }),
+ createTask({ title: "Verify the result", status: "done" }),
+ ];
+
+ const { container } = render(<TaskListSection taskList={taskList} />);
+
+ expect(
+ screen.getByText(`translated:${I18nKey.COMMON$TASKS}`),
+ ).toBeInTheDocument();
+ const renderedTasks = container.querySelectorAll('[data-name="item"]');
+ expect(renderedTasks).toHaveLength(3);
+ expect(Array.from(renderedTasks, (task) => task.textContent)).toEqual([
+ "Inspect the behavior",
+ "Add focused coverage",
+ "Verify the result",
+ ]);
+ expect(
+ consoleErrorSpy.mock.calls.some(
+ ([message]) =>
+ typeof message === "string" && message.includes("same key"),
+ ),
+ ).toBe(false);
+ });
+
+ it("keeps the task section visible when the plan is empty", () => {
+ const { container } = render(<TaskListSection taskList={[]} />);
+
+ expect(
+ screen.getByText(`translated:${I18nKey.COMMON$TASKS}`),
+ ).toBeInTheDocument();
+ expect(container.querySelectorAll('[data-name="item"]')).toHaveLength(0);
+ });
+});
diff --git a/src/components/conversation-events/chat/task-tracking/task-tracking-observation-content.test.tsx b/src/components/conversation-events/chat/task-tracking/task-tracking-observation-content.test.tsx
new file mode 100644
index 0000000000..da60704cc6
--- /dev/null
+++ b/src/components/conversation-events/chat/task-tracking/task-tracking-observation-content.test.tsx
@@ -0,0 +1,66 @@
+import { render, screen } from "@testing-library/react";
+import { describe, expect, it } from "vitest";
+import { I18nKey } from "#/i18n/declaration";
+import type { ObservationEvent } from "#/types/agent-server/core";
+import type { TaskItem as TaskItemType } from "#/types/agent-server/core/base/common";
+import type { TaskTrackerObservation } from "#/types/agent-server/core/base/observation";
+import { TaskTrackingObservationContent } from "./task-tracking-observation-content";
+
+const createTask = (overrides: Partial<TaskItemType> = {}): TaskItemType => ({
+ title: "Inspect the behavior",
+ notes: "",
+ status: "todo",
+ ...overrides,
+});
+
+const createTaskTrackingEvent = (
+ observationOverrides: Partial<TaskTrackerObservation> = {},
+): ObservationEvent<TaskTrackerObservation> => ({
+ id: "observation-1",
+ timestamp: "2026-07-13T12:00:00.000Z",
+ source: "environment",
+ tool_name: "task_tracker",
+ tool_call_id: "tool-call-1",
+ action_id: "action-1",
+ observation: {
+ kind: "TaskTrackerObservation",
+ content: "Current plan",
+ command: "plan",
+ task_list: [createTask()],
+ ...observationOverrides,
+ },
+});
+
+describe("task tracking observations", () => {
+ it("shows a non-empty plan", () => {
+ const event = createTaskTrackingEvent({
+ task_list: [
+ createTask({ title: "Inspect the behavior" }),
+ createTask({ title: "Verify the result", status: "done" }),
+ ],
+ });
+
+ render(<TaskTrackingObservationContent event={event} />);
+
+ expect(screen.getByText(I18nKey.COMMON$TASKS)).toBeInTheDocument();
+ expect(screen.getByText("Inspect the behavior")).toBeInTheDocument();
+ expect(screen.getByText("Verify the result")).toBeInTheDocument();
+ });
+
+ it("hides task data emitted by commands other than plan", () => {
+ const event = createTaskTrackingEvent({ command: "update" });
+
+ render(<TaskTrackingObservationContent event={event} />);
+
+ expect(screen.queryByText(I18nKey.COMMON$TASKS)).not.toBeInTheDocument();
+ expect(screen.queryByText("Inspect the behavior")).not.toBeInTheDocument();
+ });
+
+ it("hides an empty plan", () => {
+ const event = createTaskTrackingEvent({ task_list: [] });
+
+ render(<TaskTrackingObservationContent event={event} />);
+
+ expect(screen.queryByText(I18nKey.COMMON$TASKS)).not.toBeInTheDocument();
+ });
+});