import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it } from "vitest";
import { AgentLogPanel, buildAgentLogExportText } from "./AgentLogPanel";

describe("AgentLogPanel", () => {
  it("renders logs in chronological order so scrolling upward reveals older activity", () => {
    const html = renderToStaticMarkup(
      <AgentLogPanel
        busy={false}
        logs={[
          {
            id: "log-1",
            title: "First event",
            detail: "Hydrated the board.",
            level: "info",
            createdAt: "2026-01-01T10:00:00.000Z",
          },
          {
            id: "log-2",
            title: "Second event",
            detail: "Opened the package detail view.",
            level: "success",
            createdAt: "2026-01-01T10:01:00.000Z",
          },
        ]}
      />,
    );

    expect(html.indexOf("First event")).toBeLessThan(html.indexOf("Second event"));
  });

  it("exports thinking lines in the plain-text log export", () => {
    const content = buildAgentLogExportText({
      busy: true,
      logs: [
        {
          id: "log-1",
          title: "Thinking",
          detail: "Resolved scope to System Requirements Specification.",
          level: "info",
          createdAt: "2026-01-01T10:00:00.000Z",
        },
      ],
    });

    expect(content).toContain("Agent Log Export");
    expect(content).toContain("Status: Running");
    expect(content).toContain("Thinking");
    expect(content).toContain("Resolved scope to System Requirements Specification.");
  });
});
