From ae5ca403fb604366bd2a03862d6b94f861695632 Mon Sep 17 00:00:00 2001 From: PJ Date: Sat, 6 Jun 2026 12:55:19 +0530 Subject: [PATCH] test(replay-ui): pin shared statusFor precedence and ordering --- .../src/__tests__/property-status.test.ts | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 replay-ui/src/__tests__/property-status.test.ts diff --git a/replay-ui/src/__tests__/property-status.test.ts b/replay-ui/src/__tests__/property-status.test.ts new file mode 100644 index 0000000..b2746b0 --- /dev/null +++ b/replay-ui/src/__tests__/property-status.test.ts @@ -0,0 +1,44 @@ +import { describe, it, expect } from "bun:test"; +import { + STATUS_ORDER, + statusFor, + statusForStep, +} from "../lib/property-status"; +import type { Step } from "../types"; + +// Bug class: RunDetail and ViolationsPanel once carried two copies of this +// status logic; if they drift, the same property shows a different verdict in +// the timeline vs the violations list. Both panels now share statusFor, so its +// precedence and the violated-first ordering must stay pinned. +describe("statusFor", () => { + it("ranks violated over holds and defaults missing residuals to pending", () => { + const violations = new Set(["v"]); + expect(statusFor("v", violations, { v: { op: "true" } })).toBe("violated"); + expect(statusFor("h", violations, { h: { op: "true" } })).toBe("holds"); + expect(statusFor("p", violations, { p: { op: "false" } })).toBe("pending"); + expect(statusFor("x", violations, undefined)).toBe("pending"); + }); +}); + +describe("statusForStep", () => { + it("matches statusFor for the same step and is pending for a null step", () => { + const step: Step = { + step: 0, + timestamp: "1970-01-01T00:00:00.000Z", + violations: ["v"], + residuals: { v: { op: "true" }, h: { op: "true" } }, + }; + expect(statusForStep("v", step)).toBe("violated"); + expect(statusForStep("h", step)).toBe("holds"); + expect(statusForStep("v", null)).toBe("pending"); + }); +}); + +describe("STATUS_ORDER", () => { + it("sorts violated before pending before holds", () => { + const sorted = ["holds", "violated", "pending"].sort( + (a, b) => STATUS_ORDER[a as never] - STATUS_ORDER[b as never], + ); + expect(sorted).toEqual(["violated", "pending", "holds"]); + }); +});