import { describe, expect, test } from "bun:test";
import { createDevToolbarCollector } from "../../src/server/collector.ts";
import { createServerIssue } from "../../src/server/issues.ts";

describe("dev toolbar collector", () => {
  test("deduplicates by fingerprint", () => {
    const collector = createDevToolbarCollector();
    const issue = createServerIssue({
      ruleId: "route/not-found",
      category: "routing",
      severity: "warning",
      title: "Not found",
      message: "Missing page",
      pathname: "/missing",
    });
    collector.add(issue);
    collector.add({ ...issue, id: "new-id" });
    expect(collector.getIssues()).toHaveLength(1);
  });

  test("clears issues by pathname", () => {
    const collector = createDevToolbarCollector();
    collector.add(
      createServerIssue({
        ruleId: "route/not-found",
        category: "routing",
        severity: "warning",
        title: "Not found",
        message: "A",
        pathname: "/a",
      }),
    );
    collector.add(
      createServerIssue({
        ruleId: "route/not-found",
        category: "routing",
        severity: "warning",
        title: "Not found",
        message: "B",
        pathname: "/b",
      }),
    );
    collector.clear("/a");
    expect(collector.getIssues()).toHaveLength(1);
  });
});
