// Copyright (c) 2025-2026 Probo Inc . // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. import { describe, expect, it } from "vitest"; import { fileSize, humanizeSeconds } from "./index"; describe("fileSize", () => { it("formats byte counts with translated units", () => { const t = (key: string) => key.replace("size.", ""); expect(fileSize(4911, t)).toBe("4.8 KB"); expect(fileSize(20, t)).toBe("20 B"); }); }); describe("humanizeSeconds", () => { const t = (key: string, options?: { count?: number }) => { const unit = key.replace("duration.", ""); if (unit === "session" || unit === "persistent") return unit; return options?.count === 1 ? unit.slice(0, -1) : unit; }; it("formats durations with translated plural units", () => { expect(humanizeSeconds(4570, t)).toBe("1 hour, 16 minutes, 10 seconds"); expect(humanizeSeconds(120, t)).toBe("2 minutes"); }); it("formats trackers without a max age as session or persistent", () => { expect(humanizeSeconds(null, t)).toBe("session"); expect(humanizeSeconds(0, t, "LOCAL_STORAGE")).toBe("persistent"); }); });