|
| 1 | +import { describe, expect, test } from "bun:test"; |
| 2 | + |
| 3 | +import { |
| 4 | + formatReportedCost, |
| 5 | + formatStarted, |
| 6 | + formatStepCount, |
| 7 | +} from "./format.js"; |
| 8 | + |
| 9 | +describe("formatReportedCost", () => { |
| 10 | + test("is a dash when no span reports a cost", () => { |
| 11 | + expect(formatReportedCost([{}, { usage: {} }])).toBe("—"); |
| 12 | + }); |
| 13 | + |
| 14 | + test("shows zero when a span reports zero", () => { |
| 15 | + expect(formatReportedCost([{ usage: { costUsd: 0 } }])).toBe("$0"); |
| 16 | + }); |
| 17 | + |
| 18 | + test("sums the costs that were reported", () => { |
| 19 | + expect( |
| 20 | + formatReportedCost([ |
| 21 | + { usage: { costUsd: 1.5 } }, |
| 22 | + { usage: {} }, |
| 23 | + { usage: { costUsd: 2.25 } }, |
| 24 | + ]), |
| 25 | + ).toBe("$3.75"); |
| 26 | + }); |
| 27 | +}); |
| 28 | + |
| 29 | +describe("formatStepCount", () => { |
| 30 | + test("uses the run total when the page is shorter", () => { |
| 31 | + expect(formatStepCount({ stepCount: 12, spans: [{}, {}] })).toBe("12"); |
| 32 | + }); |
| 33 | + |
| 34 | + test("counts the loaded spans when no total was passed", () => { |
| 35 | + expect(formatStepCount({ spans: [{}, {}, {}] })).toBe("3"); |
| 36 | + }); |
| 37 | +}); |
| 38 | + |
| 39 | +describe("formatStarted", () => { |
| 40 | + test("returns an unparseable value unchanged", () => { |
| 41 | + expect(formatStarted("not-a-time")).toBe("not-a-time"); |
| 42 | + }); |
| 43 | + |
| 44 | + test("formats a timestamp as a local date and time", () => { |
| 45 | + const shown = formatStarted("2026-10-24T15:04:00.000Z"); |
| 46 | + expect(shown.includes("T")).toBe(false); |
| 47 | + expect(shown.includes("2026-10-24")).toBe(false); |
| 48 | + expect(/\bat\b/i.test(shown)).toBe(false); |
| 49 | + expect(shown.includes(" · ")).toBe(true); |
| 50 | + }); |
| 51 | + |
| 52 | + test("leaves a clock time unchanged", () => { |
| 53 | + expect(formatStarted("09:14:02")).toBe("09:14:02"); |
| 54 | + }); |
| 55 | +}); |
0 commit comments