master @ 23 LINES
[ HISTORY ] [ UP ]
┌─ TS ───────────────────────────────────────────────────────────────────────┐
│ import { describe, expect, it } from "vitest"; │
│ import { buildProgress, progressWidth } from "./Progress"; │
│ import { len } from "../../lib/ascii"; │
│ │
│ describe("buildProgress", () => { │
│ it("renders the exact declared width at any value", () => { │
│ for (const v of [0, 8, 50, 99, 100]) { │
│ expect(len(buildProgress(v, 20))).toBe(progressWidth(20)); │
│ } │
│ }); │
│ │
│ it("fills proportionally", () => { │
│ expect(buildProgress(0, 10)).toBe("[░░░░░░░░░░] 0%"); │
│ expect(buildProgress(50, 10)).toBe("[█████░░░░░] 50%"); │
│ expect(buildProgress(100, 10)).toBe("[██████████] 100%"); │
│ }); │
│ │
│ it("clamps out-of-range values", () => { │
│ expect(buildProgress(-5, 10)).toBe(buildProgress(0, 10)); │
│ expect(buildProgress(250, 10)).toBe(buildProgress(100, 10)); │
│ }); │
│ }); │
└────────────────────────────────────────────────────────────────────────────────────┘
┌─ TS ─────────────────────────────────┐
│ import { describe, expect, it } from "vitest │
│ "; │
│ import { buildProgress, progressWidth } from │
│ "./Progress"; │
│ import { len } from "../../lib/ascii"; │
│ │
│ describe("buildProgress", () => { │
│ it("renders the exact declared width at an │
│ y value", () => { │
│ for (const v of [0, 8, 50, 99, 100]) { │
│ expect(len(buildProgress(v, 20))).toBe │
│ (progressWidth(20)); │
│ } │
│ }); │
│ │
│ it("fills proportionally", () => { │
│ expect(buildProgress(0, 10)).toBe("[░░░░ │
│ ░░░░░░] 0%"); │
│ expect(buildProgress(50, 10)).toBe("[███ │
│ ██░░░░░] 50%"); │
│ expect(buildProgress(100, 10)).toBe("[██ │
│ ████████] 100%"); │
│ }); │
│ │
│ it("clamps out-of-range values", () => { │
│ expect(buildProgress(-5, 10)).toBe(build │
│ Progress(0, 10)); │
│ expect(buildProgress(250, 10)).toBe(buil │
│ dProgress(100, 10)); │
│ }); │
│ }); │
└──────────────────────────────────────────────┘
──────────────────────────────────────────────────────────────────────────────────────
OOKNET
────────────────────────────────────────────────
OOKNET