Files
openclaw/packages/normalization-core/src/format.test.ts
T
Peter Steinberger a5b8b7052b fix(ui): preserve advanced cron delivery settings when cloning (#117909)
* refactor(ui): consolidate task and log contracts

* fix(cron): preserve advanced delivery routing

* refactor(ui): share relative-time bucketing

* fix(ui): retain narrow cron view types

* fix(ui): keep cron form field keys total

* style(ui): use narrowed task result boolean
2026-08-02 02:13:38 -07:00

43 lines
1.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { bucketRelativeTimeMs, formatByteSize } from "./format.js";
describe("bucketRelativeTimeMs", () => {
it.each([
[0, { value: 0, unit: "second" }],
[59_499, { value: 59, unit: "second" }],
[59_500, { value: 1, unit: "minute" }],
[59 * 60_000, { value: 59, unit: "minute" }],
[60 * 60_000, { value: 1, unit: "hour" }],
[47 * 3_600_000, { value: 47, unit: "hour" }],
[48 * 3_600_000, { value: 2, unit: "day" }],
] as const)("buckets %sms with nested rounding", (durationMs, expected) => {
expect(bucketRelativeTimeMs(durationMs)).toEqual(expected);
});
});
describe("formatByteSize", () => {
it.each([
[1024, { style: "iec", maxUnit: "mega", separator: " ", fractionDigits: 1 }, "1.0 KiB"],
[1024, { style: "legacy-binary", maxUnit: "mega", separator: "", fractionDigits: 1 }, "1.0KB"],
[
5 * 1024 * 1024,
{ style: "legacy-binary", maxUnit: "kilo", separator: " ", fractionDigits: 1 },
"5120.0 KB",
],
] as const)("formats %s bytes", (bytes, options, expected) => {
expect(formatByteSize(bytes, options)).toBe(expected);
});
it("supports caller-owned dynamic precision and rounding", () => {
expect(
formatByteSize(Math.floor(99.6 * 1024 * 1024), {
style: "legacy-binary",
maxUnit: "giga",
separator: " ",
fractionDigits: (_value, unit) => (unit === "giga" ? 1 : unit === "byte" ? null : 0),
floorUnits: ["kilo", "mega"],
}),
).toBe("99 MB");
});
});