mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-12 15:15:58 -07:00
Create rate-formatter.test.js
This commit is contained in:
@@ -0,0 +1,38 @@
|
|||||||
|
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 as mebibytes", 512, { binary: true, bits: false, decimals: 1 }, "0.0 MiB/s"],
|
||||||
|
["binary kibibytes as mebibytes", 15 * 1024, { binary: true, bits: false, decimals: 1 }, "0.0 MiB/s"],
|
||||||
|
["binary mebibytes", 15 * 1024 ** 2, { binary: true, bits: false, decimals: 1 }, "15.0 MiB/s"],
|
||||||
|
["binary gibibytes as mebibytes", 2 * 1024 ** 3, { binary: true, bits: false, decimals: 1 }, "2,048.0 MiB/s"],
|
||||||
|
["binary bits as mebibits", 15 * 1024, { binary: true, bits: true, decimals: 1 }, "0.0 Mibit/s"],
|
||||||
|
])("formats %s", (_description, value, options, expected) => {
|
||||||
|
expect(formatRate(value, "en", options)).toBe(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user