|
1
|
import { describe, expect, it } from "vitest" |
|
2
|
import { formatQuantity } from "../format-quantity" |
|
3
|
|
|
4
|
describe("formatQuantity", () => { |
|
5
|
it("renders whole quantities without decimals", () => { |
|
6
|
expect(formatQuantity(100)).toBe("100") |
|
7
|
}) |
|
8
|
|
|
9
|
it("renders fractional quantities", () => { |
|
10
|
expect(formatQuantity(98.25)).toBe("98.25") |
|
11
|
}) |
|
12
|
|
|
13
|
it("appends the unit of measure when set", () => { |
|
14
|
expect(formatQuantity(98.25, "lb")).toBe("98.25 lb") |
|
15
|
expect(formatQuantity(0.25, "lb")).toBe("0.25 lb") |
|
16
|
}) |
|
17
|
|
|
18
|
it("hides float artifacts from quantity arithmetic", () => { |
|
19
|
// stocked_quantity - reserved_quantity |
|
20
|
expect(formatQuantity(0.3 - 0.1, "lb")).toBe("0.2 lb") |
|
21
|
}) |
|
22
|
|
|
23
|
it("falls back to a placeholder for missing quantities", () => { |
|
24
|
expect(formatQuantity(undefined)).toBe("-") |
|
25
|
expect(formatQuantity(null, "lb")).toBe("-") |
|
26
|
expect(formatQuantity(NaN)).toBe("-") |
|
27
|
}) |
|
28
|
|
|
29
|
it("renders zero rather than the placeholder", () => { |
|
30
|
expect(formatQuantity(0, "lb")).toBe("0 lb") |
|
31
|
}) |
|
32
|
}) |