58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
formatDate,
|
|
formatMoney,
|
|
formatSnapshotTime,
|
|
instrumentLogoUrl,
|
|
} from "./display";
|
|
|
|
describe("shared display helpers", () => {
|
|
it("uses padded Russian dates and preserves the UTC date of timestamps", () => {
|
|
expect(formatDate("2027-09-10")).toBe("10.09.2027");
|
|
expect(formatDate("2024-02-29")).toBe("29.02.2024");
|
|
expect(formatDate("2027-09-10T00:30:00+03:00")).toBe("09.09.2027");
|
|
});
|
|
it("formats snapshot time in the browser time zone", () => {
|
|
const instant = "2027-09-10T00:30:00+03:00";
|
|
|
|
const expected = new Intl.DateTimeFormat("ru-RU", {
|
|
dateStyle: "short",
|
|
timeStyle: "short",
|
|
}).format(new Date(instant));
|
|
|
|
expect(formatSnapshotTime(instant)).toBe(expected);
|
|
});
|
|
it("formats decimal strings without financial arithmetic", () => {
|
|
expect(formatMoney({ currency: "RUB", value: "-1234567.89" })).toBe(
|
|
"-1 234 567,89 ₽",
|
|
);
|
|
expect(formatMoney({ currency: "RUB", value: "10" })).toBe("10 ₽");
|
|
expect(formatMoney({ currency: "USD", value: "0.5" })).toBe("0,5 USD");
|
|
expect(formatMoney({ currency: "RUB", value: "0001234.50" })).toBe(
|
|
"0 001 234,50 ₽",
|
|
);
|
|
expect(
|
|
formatMoney({
|
|
currency: "RUB",
|
|
value: "123456789012345678901234567890.01",
|
|
}),
|
|
).toBe("123 456 789 012 345 678 901 234 567 890,01 ₽");
|
|
expect(
|
|
formatMoney({ currency: "RUB", value: "1.5" }, { withZeroCents: true }),
|
|
).toBe("1,50 ₽");
|
|
expect(formatMoney(null)).toBe("—");
|
|
});
|
|
|
|
it("builds the brand logo url from an upstream file name", () => {
|
|
expect(instrumentLogoUrl("sber3.png")).toBe(
|
|
"https://invest-brands.cdn-tinkoff.ru/sber3x160.png",
|
|
);
|
|
expect(instrumentLogoUrl(" RU000A0JPNM1.png ")).toBe(
|
|
"https://invest-brands.cdn-tinkoff.ru/RU000A0JPNM1x160.png",
|
|
);
|
|
expect(instrumentLogoUrl(null)).toBeNull();
|
|
expect(instrumentLogoUrl(" ")).toBeNull();
|
|
});
|
|
});
|