49 lines
2.6 KiB
TypeScript
49 lines
2.6 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
import { test } from "node:test";
|
|
|
|
const root = new URL("../", import.meta.url);
|
|
const index = JSON.parse(readFileSync(new URL("src/data/world-countries.json", root), "utf8")) as {
|
|
source: { repository: string; release: string; license: string };
|
|
countries: Array<{ code: string; name: string; regionCount: number }>;
|
|
};
|
|
const pickerSource = readFileSync(new URL("src/components/birth-place-picker.tsx", root), "utf8");
|
|
|
|
test("global location snapshot is country-split and sourced from the pinned release", () => {
|
|
assert.equal(index.source.repository, "dr5hn/countries-states-cities-database");
|
|
assert.equal(index.source.release, "v3.2-export.7");
|
|
assert.equal(index.source.license, "ODbL-1.0");
|
|
assert.equal(index.countries.length, 229);
|
|
assert.ok(index.countries.some((country) => country.code === "US"));
|
|
assert.ok(index.countries.every((country) => country.regionCount > 0));
|
|
|
|
const files = new Set(readdirSync(new URL("public/data/world-locations", root)));
|
|
assert.equal(files.size, index.countries.length);
|
|
for (const country of index.countries) assert.ok(files.has(`${country.code.toLowerCase()}.json`));
|
|
});
|
|
|
|
test("country data keeps the coordinates and IANA timezone needed for confirmation", () => {
|
|
const us = JSON.parse(readFileSync(new URL("public/data/world-locations/us.json", root), "utf8")) as {
|
|
code: string;
|
|
regions: Array<{ code: string; cities: Array<{ name: string; latitude: number; longitude: number; timezone: string }> }>;
|
|
};
|
|
const california = us.regions.find((region) => region.code === "US-CA");
|
|
const sanFrancisco = california?.cities.find((city) => city.name === "San Francisco");
|
|
assert.equal(us.code, "US");
|
|
assert.ok(california);
|
|
assert.ok(sanFrancisco);
|
|
assert.equal(typeof sanFrancisco?.latitude, "number");
|
|
assert.equal(typeof sanFrancisco?.longitude, "number");
|
|
assert.equal(sanFrancisco?.timezone, "America/Los_Angeles");
|
|
assert.equal(existsSync(new URL("src/data/WORLD_LOCATION_DATA.md", root)), true);
|
|
});
|
|
|
|
test("overseas UI uses cascading data files and has no search input", () => {
|
|
assert.match(pickerSource, /world-locations\/\$\{draft\.countryCode\.toLowerCase\(\)\}\.json/);
|
|
assert.match(pickerSource, /海外地点按国家、地区、城市逐级选择,不使用搜索/);
|
|
assert.match(pickerSource, /aria-label="出生国家或地区"/);
|
|
assert.match(pickerSource, /aria-label="出生州省或地区"/);
|
|
assert.match(pickerSource, /aria-label="出生海外城市"/);
|
|
assert.doesNotMatch(pickerSource, /role="combobox"/);
|
|
});
|