| 1 | import { describe, expect, it } from "vitest"; |
| 2 | import { formatPriceRange, formatCompact, formatLatency, sourceInitials } from "./utils"; |
| 3 | |
| 4 | describe("formatPriceRange", () => { |
| 5 | it("formats a whole-dollar range with no cents", () => { |
| 6 | expect(formatPriceRange(4950, 89900, "USD")).toBe("$49.50 - $899"); |
| 7 | }); |
| 8 | it("collapses an equal min/max to a single value", () => { |
| 9 | expect(formatPriceRange(2500, 2500, "USD")).toBe("$25"); |
| 10 | }); |
| 11 | it("handles a missing range", () => { |
| 12 | expect(formatPriceRange(null, null)).toBe("Price TBA"); |
| 13 | }); |
| 14 | }); |
| 15 | |
| 16 | describe("formatCompact", () => { |
| 17 | it("keeps small numbers grouped", () => { |
| 18 | expect(formatCompact(1842)).toBe("1,842"); |
| 19 | }); |
| 20 | it("compacts large numbers", () => { |
| 21 | expect(formatCompact(28471)).toBe("28.5K"); |
| 22 | }); |
| 23 | }); |
| 24 | |
| 25 | describe("formatLatency", () => { |
| 26 | it("renders sub-second in ms", () => { |
| 27 | expect(formatLatency(412)).toBe("412ms"); |
| 28 | }); |
| 29 | it("renders >=1s in seconds", () => { |
| 30 | expect(formatLatency(8200)).toBe("8.2s"); |
| 31 | }); |
| 32 | it("renders null as a dash", () => { |
| 33 | expect(formatLatency(null)).toBe("-"); |
| 34 | }); |
| 35 | }); |
| 36 | |
| 37 | describe("sourceInitials", () => { |
| 38 | it("strips API/Discovery noise words", () => { |
| 39 | expect(sourceInitials("Ticketmaster Discovery API")).toBe("TI"); |
| 40 | }); |
| 41 | }); |