- Overview/Plant tiles and pages share one vehicle bucket rule (blank unit_type = fleet) - Plant landing equipment figures were always 0; hour diffs now reject 0 baselines and >24h/day jumps - km/L limits on plant (and L/h on vehicles) report unit-mismatch instead of false alerts - formatPercent/formatDecimal replace display toFixed (en-ZA) - POST /api/vehicles/[id]/merge + Merge duplicate dialog (dry run first) - Attention links go to equipment vs vehicles by unit type; PO upload view link fixed - Conditional hook fixed in DN document view; ESLint flat config (next lint removed in 16) - Docs: current modules/routes/env vars; login + Ask reports plans Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { formatDecimal, formatNumber, formatPercent, formatQtyDual } from "./utils";
|
|
|
|
describe("formatQtyDual", () => {
|
|
it("shows both figures when a conversion happened", () => {
|
|
expect(formatQtyDual(29.96, "ton", 29960, "kg")).toBe(
|
|
`${formatNumber(29.96)} ton · ${formatNumber(29960)} kg`,
|
|
);
|
|
});
|
|
|
|
it("shows one figure when the units match", () => {
|
|
expect(formatQtyDual(5, "ton", 5, "ton")).toBe("5 ton");
|
|
});
|
|
|
|
it("shows one figure when the slip recorded no unit", () => {
|
|
expect(formatQtyDual(5, "ton", 5, "")).toBe("5 ton");
|
|
});
|
|
|
|
it("omits the unit entirely when the PO line has none", () => {
|
|
expect(formatQtyDual(5, "", 5, "")).toBe("5");
|
|
});
|
|
|
|
it("falls back to the raw figure when nothing converted", () => {
|
|
expect(formatQtyDual(0, "ton", 12, "m3")).toBe("0 ton · 12 m3");
|
|
});
|
|
});
|
|
|
|
// en-ZA everywhere a person reads a number: comma decimal, space
|
|
// thousands. Mixing toFixed ("38.7%") with Intl ("61,3%") on one card
|
|
// was the bug these pin.
|
|
describe("formatPercent", () => {
|
|
it("uses the en-ZA decimal comma", () => {
|
|
expect(formatPercent(38.66)).toBe("38,7%");
|
|
});
|
|
|
|
it("keeps trailing zeros so a column lines up", () => {
|
|
expect(formatPercent(12, 1)).toBe("12,0%");
|
|
});
|
|
|
|
it("rounds to whole percent when asked", () => {
|
|
expect(formatPercent(7.4, 0)).toBe("7%");
|
|
});
|
|
|
|
it("signs a variance when asked", () => {
|
|
expect(formatPercent(4.25, 1, { signed: true })).toBe("+4,3%");
|
|
expect(formatPercent(-99.6, 1, { signed: true })).toBe("-99,6%");
|
|
expect(formatPercent(0, 1, { signed: true })).toBe("0,0%");
|
|
});
|
|
});
|
|
|
|
describe("formatDecimal", () => {
|
|
it("fixes the digits and uses en-ZA separators", () => {
|
|
expect(formatDecimal(0.07, 2)).toBe("0,07");
|
|
expect(formatDecimal(1234.5, 1)).toBe(formatNumber(1234.5, { minimumFractionDigits: 1, maximumFractionDigits: 1 }));
|
|
});
|
|
});
|