Files
homepage/src/utils/rate-formatter.test.js
T
2c3b82a826
Docker CI / Docker Build & Push (push) Has been cancelled
Lint / Linting Checks (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Release Drafter / Auto Label PR (push) Has been cancelled
Tests / vitest (1) (push) Has been cancelled
Tests / vitest (2) (push) Has been cancelled
Tests / vitest (3) (push) Has been cancelled
Tests / vitest (4) (push) Has been cancelled
Fix: auto-scale binary rate units instead of pinning to MiB/s (#6866)
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
2026-07-13 15:27:07 +00:00

39 lines
1.3 KiB
JavaScript

import { createRequire } from "node:module";
import { describe, expect, it } from "vitest";
const require = createRequire(import.meta.url);
const i18nextConfig = require("../../next-i18next.config.js");
function getRateFormatter() {
let rateFormatter;
i18nextConfig.use[0].init({
services: {
formatter: {
add(name, formatter) {
if (name === "rate") rateFormatter = formatter;
},
},
},
});
return rateFormatter;
}
describe("rate formatter", () => {
const formatRate = getRateFormatter();
it.each([
["zero bytes", 0, { binary: true, bits: false, decimals: 1 }, "0 B/s"],
["decimal bytes", 15_000, { binary: false, bits: false, decimals: 1 }, "15.0 kB/s"],
["binary bytes", 512, { binary: true, bits: false, decimals: 1 }, "512.0 B/s"],
["binary kibibytes", 15 * 1024, { binary: true, bits: false, decimals: 1 }, "15.0 kiB/s"],
["binary mebibytes", 15 * 1024 ** 2, { binary: true, bits: false, decimals: 1 }, "15.0 MiB/s"],
["binary gibibytes", 2 * 1024 ** 3, { binary: true, bits: false, decimals: 1 }, "2.0 GiB/s"],
["binary bits", 15 * 1024, { binary: true, bits: true, decimals: 1 }, "15.0 kibit/s"],
])("formats %s", (_description, value, options, expected) => {
expect(formatRate(value, "en", options)).toBe(expected);
});
});