TypeScript 87.7%
CSS 12.3%
1/**2 * Author: Simon-Pierre Boucher3 * Contact: contact@spboucher.ai4 * Project: Groupe Ka / Ka Maps5 */67import { describe, expect, it } from "vitest";8import {9 formatCompactPrice,10 formatFullPrice,11 formatPercent,12 median,13} from "../src/utils/format.js";1415describe("formatCompactPrice", () => {16 it("formats the spec examples", () => {17 expect(formatCompactPrice(289_000)).toBe("289 k$");18 expect(formatCompactPrice(499_900)).toBe("500 k$");19 expect(formatCompactPrice(1_250_000)).toBe("1,25 M$");20 expect(formatCompactPrice(2_800_000)).toBe("2,8 M$");21 });2223 it("keeps rents in whole dollars", () => {24 expect(formatCompactPrice(950)).toBe("950 $");25 // Group separator is U+202F (narrow no-break space), fr-CA convention.26 expect(formatCompactPrice(1450)).toBe("1 450 $");27 });2829 it("rounds 999 500+ into millions", () => {30 expect(formatCompactPrice(999_600)).toBe("1 M$");31 });3233 it("handles large and degenerate values", () => {34 expect(formatCompactPrice(12_300_000)).toBe("12,3 M$");35 expect(formatCompactPrice(Number.NaN)).toBe("");36 expect(formatCompactPrice(-5)).toBe("");37 });38});3940describe("formatFullPrice", () => {41 it("groups with narrow no-break spaces", () => {42 expect(formatFullPrice(589_000)).toBe("589 000 $");43 expect(formatFullPrice(1_250_000)).toBe("1 250 000 $");44 });45});4647describe("formatPercent", () => {48 it("signs and localizes", () => {49 expect(formatPercent(0.058)).toBe("+5,8 %");50 expect(formatPercent(-0.012)).toBe("-1,2 %");51 expect(formatPercent(0)).toBe("0,0 %");52 });53});5455describe("median", () => {56 it("computes odd/even medians and ignores junk", () => {57 expect(median([3, 1, 2])).toBe(2);58 expect(median([4, 1, 2, 3])).toBe(2.5);59 expect(median([1, Number.NaN, 3])).toBe(2);60 expect(median([])).toBeUndefined();61 });62});63