import { describe, it, expect } from "vitest";
import { mount } from "@vue/test-utils";
import ErrorCard from "../ErrorCard.vue";
import type { TelemetryRecord } from "@/lib/telemetry";
const stubs = { RouterLink: { template: "" } };
const mountCard = (record: TelemetryRecord, props: Record = {}) =>
mount(ErrorCard, { props: { record, ...props }, global: { stubs } });
describe("ErrorCard", () => {
it("renders the friendly title + summary and tags the severity", () => {
const w = mountCard({
kind: "dlq.recorded",
action: "orders.ship",
attempts: 5,
error: { name: "TypeError", message: "boom" },
ts: "2026-01-01T00:00:00.000Z",
envelope: { messageId: "m", causationId: "m", correlationId: "c-123" },
});
expect(w.get('[data-testid="error-title"]').text()).toBe("Dead-lettered");
expect(w.get('[data-testid="error-summary"]').text()).toContain("orders.ship");
expect(w.get('[data-testid="error-card"]').attributes("data-severity")).toBe("critical");
expect(w.get('[data-testid="error-severity"]').text()).toBe("Critical");
});
it("shows the retry narrative when the record carries attempts", () => {
const w = mountCard({
kind: "action.failed",
action: "orders.charge",
attempt: 2,
maxAttempts: 3,
willRetry: true,
error: { name: "E", message: "x" },
});
expect(w.get('[data-testid="error-retry"]').text()).toContain("attempt 2 of 3");
});
it("renders a correlation chip linking to the trace", () => {
const w = mountCard({
kind: "action.failed",
action: "a",
error: { name: "E", message: "x" },
envelope: { messageId: "m", causationId: "m", correlationId: "c-abcdef-1" },
});
expect(w.get('[data-testid="error-correlation"]').text()).toContain("c");
});
it("emits select on click and reflects the selected state", async () => {
const w = mountCard(
{ kind: "action.failed", action: "a", error: { name: "E", message: "x" } },
{ selected: true },
);
await w.get('[data-testid="error-card"]').trigger("click");
expect(w.emitted("select")).toBeTruthy();
expect(w.get('[data-testid="error-card"]').classes()).toContain("border-zinc-600");
});
it("hides the correlation chip when asked", () => {
const w = mountCard(
{
kind: "action.failed",
action: "a",
error: { name: "E", message: "x" },
envelope: { messageId: "m", causationId: "m", correlationId: "c-1" },
},
{ showCorrelation: false },
);
expect(w.find('[data-testid="error-correlation"]').exists()).toBe(false);
});
});