feat: add rate normalization helpers

This commit is contained in:
2026-04-20 20:01:43 +08:00
parent b6b350bbf7
commit 065b6380bf
2 changed files with 117 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
import { describe, expect, test } from "vitest";
import {
compareRateValues,
normalizeRateDisplay,
parseRateLowerBound
} from "../src/shared/rate-normalizer";
describe("rate-normalizer", () => {
test("normalizes compact ranges", () => {
expect(normalizeRateDisplay("0.5%-1%")).toBe("0.5% - 1%");
});
test("normalizes ranges with missing percent on the lower bound", () => {
expect(normalizeRateDisplay("0.02 - 0.1%")).toBe("0.02% - 0.1%");
});
test("parses the lower bound of a range", () => {
expect(parseRateLowerBound("0.02% - 0.1%")).toBe(0.02);
});
test("treats less-than values as smaller than the boundary range", () => {
expect(compareRateValues("<0.02%", "0.02% - 0.1%")).toBeLessThan(0);
});
test("orders missing values after real values", () => {
expect(compareRateValues(null, "0.02% - 0.1%")).toBeGreaterThan(0);
});
});