master @ 48 LINES
[ HISTORY ] [ UP ]
┌─ TS ───────────────────────────────────────────────────────────────────────┐
│ import { describe, expect, it } from "vitest"; │
│ import { buildBarChart } from "./BarChart"; │
│ import { len } from "../../lib/ascii"; │
│ │
│ const items = [ │
│ { label: "NIXOS", value: 12 }, │
│ { label: "WINDOWS-TROUBLESHOOTING", value: 3 }, │
│ { label: "EMPTY", value: 0 }, │
│ ]; │
│ │
│ describe("buildBarChart", () => { │
│ it("renders every row at the exact width", () => { │
│ for (const w of [86, 48]) { │
│ for (const line of buildBarChart(items, w).split("\n")) { │
│ expect(len(line)).toBe(w); │
│ } │
│ } │
│ }); │
│ │
│ it("fills the largest value to the full bar and zero to none", () => { │
│ const [top, , zero] = buildBarChart(items, 48).split("\n"); │
│ expect(top).not.toContain("░"); │
│ expect(zero).not.toContain("█"); │
│ }); │
│ │
│ it("truncates long labels with an ellipsis", () => { │
│ const lines = buildBarChart(items, 48).split("\n"); │
│ expect(lines[1]).toContain("WINDOWS-T..."); │
│ }); │
│ │
│ it("right-aligns values", () => { │
│ const lines = buildBarChart(items, 48).split("\n"); │
│ expect(lines[0].endsWith("12")).toBe(true); │
│ expect(lines[2].endsWith(" 0")).toBe(true); │
│ }); │
│ │
│ it("scales against an explicit max", () => { │
│ const line = buildBarChart([{ label: "HALF", value: 5 }], 48, { max: 10 }); │
│ const filled = [...line].filter((c) => c === "█").length; │
│ const track = [...line].filter((c) => c === "░").length; │
│ expect(Math.abs(filled - track)).toBeLessThanOrEqual(1); │
│ }); │
│ │
│ it("returns empty for no items", () => { │
│ expect(buildBarChart([], 48)).toBe(""); │
│ }); │
│ }); │
└────────────────────────────────────────────────────────────────────────────────────┘
┌─ TS ─────────────────────────────────┐
│ import { describe, expect, it } from "vitest │
│ "; │
│ import { buildBarChart } from "./BarChart"; │
│ import { len } from "../../lib/ascii"; │
│ │
│ const items = [ │
│ { label: "NIXOS", value: 12 }, │
│ { label: "WINDOWS-TROUBLESHOOTING", value: │
│ 3 }, │
│ { label: "EMPTY", value: 0 }, │
│ ]; │
│ │
│ describe("buildBarChart", () => { │
│ it("renders every row at the exact width", │
│ () => { │
│ for (const w of [86, 48]) { │
│ for (const line of buildBarChart(items │
│ , w).split("\n")) { │
│ expect(len(line)).toBe(w); │
│ } │
│ } │
│ }); │
│ │
│ it("fills the largest value to the full ba │
│ r and zero to none", () => { │
│ const [top, , zero] = buildBarChart(item │
│ s, 48).split("\n"); │
│ expect(top).not.toContain("░"); │
│ expect(zero).not.toContain("█"); │
│ }); │
│ │
│ it("truncates long labels with an ellipsis │
│ ", () => { │
│ const lines = buildBarChart(items, 48).s │
│ plit("\n"); │
│ expect(lines[1]).toContain("WINDOWS-T... │
│ "); │
│ }); │
│ │
│ it("right-aligns values", () => { │
│ const lines = buildBarChart(items, 48).s │
│ plit("\n"); │
│ expect(lines[0].endsWith("12")).toBe(tru │
│ e); │
│ expect(lines[2].endsWith(" 0")).toBe(tru │
│ e); │
│ }); │
│ │
│ it("scales against an explicit max", () => │
│ { │
│ const line = buildBarChart([{ label: "HA │
│ LF", value: 5 }], 48, { max: 10 }); │
│ const filled = [...line].filter((c) => c │
│ === "█").length; │
│ const track = [...line].filter((c) => c │
│ === "░").length; │
│ expect(Math.abs(filled - track)).toBeLes │
│ sThanOrEqual(1); │
│ }); │
│ │
│ it("returns empty for no items", () => { │
│ expect(buildBarChart([], 48)).toBe(""); │
│ }); │
│ }); │
└──────────────────────────────────────────────┘
──────────────────────────────────────────────────────────────────────────────────────
OOKNET
────────────────────────────────────────────────
OOKNET