import { describe, it, expect } from "vitest"; import { mount } from "@vue/test-utils"; import Waterfall from "../Waterfall.vue"; import type { TelemetryRecord, TraceNode } from "@/lib/telemetry"; const env = (messageId: string, causationId: string) => ({ messageId, causationId, correlationId: "c", }); function node(record: TelemetryRecord, children: TraceNode[] = []): TraceNode { return { record, children }; } const forest: TraceNode[] = [ node({ kind: "action.dispatched", name: "place", durationMs: 10, envelope: env("m1", "m1") }, [ node({ kind: "query.executed", name: "lookup", durationMs: 90, envelope: env("m2", "m1") }), node({ kind: "action.failed", name: "charge", error: { name: "E", message: "x" }, envelope: env("m3", "m1"), }), ]), ]; describe("Waterfall", () => { it("renders a row per node", () => { const w = mount(Waterfall, { props: { forest } }); expect(w.findAll('[data-testid="waterfall-row"]')).toHaveLength(3); }); it("marks the critical path and failed rows", () => { const w = mount(Waterfall, { props: { forest } }); expect(w.findAll('[data-critical="true"]').length).toBeGreaterThan(0); expect(w.find('[data-failed="true"]').exists()).toBe(true); }); it("emits select with the clicked row's record", async () => { const w = mount(Waterfall, { props: { forest } }); await w.findAll('[data-testid="waterfall-row"]')[1]!.trigger("click"); const ev = w.emitted("select"); expect(ev).toBeTruthy(); expect((ev![0]![0] as { record: TelemetryRecord }).record.name).toBe("lookup"); }); it("dims rows beyond the replay cursor", () => { const w = mount(Waterfall, { props: { forest, reveal: 1 } }); const rows = w.findAll('[data-testid="waterfall-row"]'); expect(rows[0]!.classes()).not.toContain("opacity-30"); expect(rows[1]!.classes()).toContain("opacity-30"); expect(rows[2]!.classes()).toContain("opacity-30"); }); });