SPB Git

Repository Public

format.test.ts 1.7 KB 45 lines typescript

1import { describe, expect, it } from "vitest";2import { cleanCity, fmtDist, fmtPct, fmtShortPrice, slugify } from "../src/lib/format";3import { hasParking, priceOk } from "../src/lib/api";45describe("formats", () => {6  it("slug identique à celui du serveur", () => {7    expect(slugify("Trois-Rivières")).toBe("trois-rivieres");8    expect(slugify("4½")).toBe("4-1-2");9    expect(slugify("Sainte-Catherine-de-la-Jacques-Cartier")).toBe("sainte-catherine-de-la-jacques-cartier");10  });11  it("prix de pastille", () => {12    expect(fmtShortPrice(950)).toBe("950");13    expect(fmtShortPrice(1695).replace(/\s/g, " ")).toBe("1,7 k");14    expect(fmtShortPrice(null)).toBe("•");15  });16  it("écart en pourcentage", () => {17    expect(fmtPct(-0.167).replace(/\s/g, " ")).toBe("−17 %");18    expect(fmtPct(0.1).replace(/\s/g, " ")).toBe("+10 %");19    expect(fmtPct(null)).toBe("—");20  });21  it("distance", () => {22    expect(fmtDist(250)).toBe("250 m");23    expect(fmtDist(1240).replace(/\s/g, " ")).toBe("1,2 km");24  });25  it("nettoie les villes mal formées", () => {26    expect(cleanCity("Gatineau )")).toBe("Gatineau");27  });28});2930describe("données tolérantes", () => {31  it("stationnement : objet, nombre ou booléen", () => {32    expect(hasParking({ parking: { available: true } })).toBe(true);33    expect(hasParking({ parking: 2 })).toBe(true);34    expect(hasParking({ parking: false })).toBe(false);35    expect(hasParking({})).toBe(false);36  });37  it("écarte les loyers invraisemblables", () => {38    expect(priceOk(0)).toBe(false);39    expect(priceOk(329)).toBe(true);40    expect(priceOk(100)).toBe(false);41    expect(priceOk(1450)).toBe(true);42    expect(priceOk(null)).toBe(false);43  });44});45
Files main
Menu

Theme