import test from "node:test"; import assert from "node:assert/strict"; import { existsSync } from "node:fs"; import { COUNTRIES, countryCode, countryName, flagHtml, driverCountryCode } from "../src/country_flags.js"; test("a driver's country: name, English name, code or 3-letter code all give the flag", () => { for (const value of ["Sverige", "sweden", "SE", "SWE", " sverige "]) assert.equal(countryCode(value), "SE", value); assert.equal(countryCode("Norge"), "NO"); assert.equal(countryCode("GBR"), "GB"); assert.equal(countryName("NOR", "sv"), "Norge"); assert.equal(countryName("NO", "en"), "Norway"); }); test("no country, or an unknown one: no flag", () => { assert.equal(flagHtml(""), ""); assert.equal(flagHtml("Atlantis"), ""); assert.match(flagHtml("Sverige"), /SE { for (const [code] of COUNTRIES) assert.ok(existsSync(new URL(`../src/flags/${code.toLowerCase()}.svg`, import.meta.url)), code); }); test("the same person in another class: the country only has to be set once", () => { const drivers = [{ id: "a", profileId: "p", country: "Norge" }, { id: "b", profileId: "p", country: "" }, { id: "c", profileId: "q" }]; assert.equal(driverCountryCode(drivers, "b"), "NO"); assert.equal(driverCountryCode(drivers, "c"), ""); assert.equal(driverCountryCode(drivers, "missing"), ""); });