Skip to content

The platform for continuously improving AI agents.

1.9 KB
Raw Blame
// @vitest-environment jsdom
// covers: console-logic
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
import { afterEach, expect, it } from "vitest";

import { ExecutionTrend } from "./execution-trend";

afterEach(cleanup);
it("inspects recorded steps and keeps unmeasured metrics unknown", () => {
  render(
    <ExecutionTrend
      metrics={[
        {
          id: "loss",
          label: "Train loss",
          points: [
            { id: "1", label: "Step 1", value: 2.5, x: 1 },
            { id: "4", label: "Step 4", value: 0.75, x: 4 },
          ],
        },
        {
          id: "validation",
          label: "Validation loss",
          points: [{ id: "4", label: "Step 4", value: null, x: 4 }],
        },
      ]}
    />
  );
  expect(screen.getAllByText("0.75").length).toBeGreaterThan(0);
  fireEvent.keyDown(screen.getByRole("img"), { key: "ArrowLeft" });
  expect(screen.getAllByText("2.5").length).toBeGreaterThan(0);
  fireEvent.click(screen.getByRole("button", { name: "Validation loss" }));
  expect(screen.queryByRole("img")).toBeNull();
  expect(screen.getByText(/Not measured/)).toBeTruthy();
});

it("shows percentage accuracy and the measured baseline difference", () => {
  render(
    <ExecutionTrend
      history
      metrics={[
        {
          baseline: 0.4,
          direction: "higher",
          id: "accuracy",
          label: "Accuracy",
          points: [
            { id: "base", label: "Base", value: 0.4, x: 0 },
            { id: "trained", label: "Trained", value: 0.6, x: 1 },
          ],
          unit: "percent",
        },
      ]}
    />
  );
  expect(screen.getAllByText("60.0%").length).toBeGreaterThan(0);
  expect(screen.getByText("+20.0 pp vs baseline (40.0%)")).toBeTruthy();
  expect(screen.getByText("Compared models")).toBeTruthy();
  expect(screen.getByText("Dashed line: Baseline · 40.0%")).toBeTruthy();
});