spb/datacenterindex
Public
HTML 53.9%
TypeScript 44.5%
JavaScript 0.6%
SQL 0.5%
1import { describe, expect, it } from "vitest";2import { parseMw, parseAllMw, parseMoney, parsePartialDate, inferStatus, normalizeStatus, countryFromText, parseAreaSqm } from "./normalize.js";34describe("parseMw", () => {5 it("parses plain figures and units", () => {6 expect(parseMw("36 MW")).toBe(36);7 expect(parseMw("36MW")).toBe(36);8 expect(parseMw("120 megawatts")).toBe(120);9 expect(parseMw("1.2 GW")).toBe(1200);10 expect(parseMw("36,000 kW")).toBe(36);11 expect(parseMw("40+MW")).toBe(40);12 });13 it("treats a single dot followed by three digits as a decimal (DataBank 0.779MW regression)", () => {14 expect(parseMw("0.779MW Critical IT Load")).toBe(0.779);15 expect(parseMw("1.250 MW")).toBe(1.25);16 expect(parseMw("2.500MW")).toBe(2.5);17 });18 it("still reads European thousands with two or more groups", () => {19 expect(parseMw("1.500.000 kW")).toBe(1500);20 });21 it("reads a comma decimal", () => {22 expect(parseMw("1,2 GW")).toBe(1200);23 });24 it("returns null without a unit", () => {25 expect(parseMw("300 million")).toBeNull();26 expect(parseMw(null)).toBeNull();27 });28});2930describe("parseAllMw", () => {31 it("dedupes and sorts descending, drops absurd figures", () => {32 expect(parseAllMw("a 36 MW hall in a 300MW campus, 36 MW again, 500,000 MW nonsense")).toEqual([300, 36]);33 });34});3536describe("parseMoney", () => {37 it("parses currencies and multipliers", () => {38 expect(parseMoney("$1.2 billion")).toEqual({ amount: 1_200_000_000, currency: "USD" });39 expect(parseMoney("€800m")).toEqual({ amount: 800_000_000, currency: "EUR" });40 expect(parseMoney("£2bn")).toEqual({ amount: 2_000_000_000, currency: "GBP" });41 expect(parseMoney("US$450 million")).toEqual({ amount: 450_000_000, currency: "USD" });42 });43});4445describe("parsePartialDate", () => {46 it("handles partial dates", () => {47 expect(parsePartialDate("Q2 2027")).toBe("2027-Q2");48 expect(parsePartialDate("June 2027")).toBe("2027-06");49 expect(parsePartialDate("2027")).toBe("2027");50 expect(parsePartialDate("15 June 2027")).toBe("2027-06-15");51 });52});5354describe("status", () => {55 it("infers and normalizes statuses", () => {56 expect(inferStatus("breaks ground on new campus")).toBe("under_construction");57 expect(inferStatus("planning application submitted")).toBe("permitting");58 expect(normalizeStatus("Under Construction")).toBe("under_construction");59 expect(normalizeStatus("coming soon")).toBe("announced");60 });61});6263describe("misc", () => {64 it("country from text and areas", () => {65 expect(countryFromText("a campus in the Netherlands")).toBe("NL");66 expect(parseAreaSqm("8,170 Square Feet")).toBe(759.0);67 });68});69