import { describe, expect, it } from "vitest"; import { formatMoney, formatShare } from "./display"; describe("portfolio display helpers", () => { it("formats decimal strings without financial arithmetic", () => { expect(formatMoney({ value: "-1234567.89", currency: "RUB" })).toBe( "-1 234 567,89 ₽", ); expect(formatMoney({ value: "10", currency: "RUB" })).toBe("10 ₽"); expect(formatMoney({ value: "0.5", currency: "USD" })).toBe("0,5 USD"); expect(formatMoney(null)).toBe("—"); }); it("formats a share as a display-only percentage", () => { expect( formatShare( { currency: "RUB", value: "150" }, { currency: "RUB", value: "1000" }, ), ).toBe("15 %"); expect( formatShare( { currency: "RUB", value: "123.45" }, { currency: "RUB", value: "999.99" }, ), ).toBe("12,3 %"); expect(formatShare(null, { currency: "RUB", value: "100" })).toBeNull(); expect(formatShare({ currency: "RUB", value: "100" }, null)).toBeNull(); expect( formatShare( { currency: "RUB", value: "100" }, { currency: "RUB", value: "0" }, ), ).toBeNull(); }); });