


























@@ -3,6 +3,7 @@ import { describe, expect, it, vi, afterEach } from "vitest";
33import {
44buildPeakErrorHours,
55buildUsageMosaicStats,
6+formatTokens,
67getHourAndWeekdayForUtcQuarterBucket,
78sessionTouchesSelectedHours,
89} from "./usage-metrics.ts";
@@ -411,3 +412,28 @@ describe("usage mosaic token buckets", () => {
411412expect(sessionTouchesSelectedHours(session, [11], "utc")).toBe(true);
412413});
413414});
415+416+describe("formatTokens", () => {
417+it("formats values below 1,000 verbatim", () => {
418+expect(formatTokens(0)).toBe("0");
419+expect(formatTokens(999)).toBe("999");
420+});
421+422+it("formats thousands with one decimal and a K suffix", () => {
423+expect(formatTokens(1_000)).toBe("1.0K");
424+expect(formatTokens(12_500)).toBe("12.5K");
425+expect(formatTokens(999_949)).toBe("999.9K");
426+});
427+428+it("rolls 999,950-999,999 over to the M branch instead of '1000.0K'", () => {
429+// These values round up to "1000.0" at one-decimal thousands precision.
430+// Without the rollover guard they render the nonsensical "1000.0K".
431+expect(formatTokens(999_950)).toBe("1.0M");
432+expect(formatTokens(999_999)).toBe("1.0M");
433+});
434+435+it("formats millions with one decimal and an M suffix", () => {
436+expect(formatTokens(1_000_000)).toBe("1.0M");
437+expect(formatTokens(2_500_000)).toBe("2.5M");
438+});
439+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。