File size: 2,283 Bytes
9b906ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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);
  });
});