Files
Jyotisha/frontend/tests/birth-sky-caption.test.ts
T

69 lines
4.0 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import { birthSkyCaption, birthSkyCity } from "../src/lib/birth-sky/caption.ts";
// TASK-birth-sky-polish-20260928 P2. Fictional sample only.
test("China 省 · 市 · 区 labels give the prefecture city without 「市」", () => {
assert.equal(birthSkyCity("河北省 · 邯郸市 · 峰峰矿区"), "邯郸");
assert.equal(birthSkyCity("浙江省 · 杭州市 · 西湖区"), "杭州");
assert.equal(birthSkyCity("浙江省 · 杭州市"), "杭州");
assert.equal(birthSkyCity("广西壮族自治区 · 桂林市 · 秀峰区"), "桂林");
});
// BUG-1082: stored labels are built as 「中国 · 省 · 市 · 区」 (geoapify-location-service.ts);
// the fixtures above lacked the prefix, so real Chinese birthplaces printed no city.
test("stored China labels lead with 「中国 · 」 and still give the city", () => {
assert.equal(birthSkyCity("中国 · 河北省 · 邯郸市 · 峰峰矿区"), "邯郸");
assert.equal(birthSkyCity("中国 · 浙江省 · 杭州市"), "杭州");
assert.equal(birthSkyCity("中国 · 北京市 · 北京市 · 朝阳区"), "北京");
assert.equal(birthSkyCity("中国 · 浙江省"), null);
assert.equal(birthSkyCity("中国"), null);
assert.equal(birthSkyCaption({ date: "1994-05-18", time: "07:40", placeLabel: "中国 · 浙江省 · 杭州市 · 西湖区" }), "1994年5月18日 07:40 · 杭州");
});
test("municipalities and SARs use their own name", () => {
assert.equal(birthSkyCity("北京市 · 朝阳区"), "北京");
assert.equal(birthSkyCity("上海市"), "上海");
assert.equal(birthSkyCity("重庆市 · 渝中区"), "重庆");
assert.equal(birthSkyCity("香港特别行政区"), "香港");
assert.equal(birthSkyCity("澳门特别行政区"), "澳门");
});
test("no reliable city → none: province only, non-city prefectures, free text, empty", () => {
assert.equal(birthSkyCity("浙江省"), null);
assert.equal(birthSkyCity("内蒙古自治区 · 锡林郭勒盟 · 二连浩特市"), null);
assert.equal(birthSkyCity("吉林省 · 延边朝鲜族自治州 · 延吉市"), null);
assert.equal(birthSkyCity("黑龙江省 · 大兴安岭地区"), null);
assert.equal(birthSkyCity("台湾省"), null);
assert.equal(birthSkyCity("浙江省杭州市"), null);
assert.equal(birthSkyCity("杭州"), null);
assert.equal(birthSkyCity(""), null);
assert.equal(birthSkyCity(null), null);
assert.equal(birthSkyCity(undefined), null);
});
test("overseas world-table labels: exactly Country · Region · City, else none", () => {
assert.equal(birthSkyCity("Japan · Tokyo · Shinjuku"), "Shinjuku");
assert.equal(birthSkyCity("United States · California · San Francisco"), "San Francisco");
assert.equal(birthSkyCity("Singapore · Central Singapore"), null);
assert.equal(birthSkyCity("Hangzhou, Zhejiang, China"), null);
assert.equal(birthSkyCity("Japan · Tokyo · Shinjuku · Extra"), null);
});
test("caption: local date and zero-padded 24-hour time, then the city when certain", () => {
assert.equal(birthSkyCaption({ date: "1994-05-18", time: "07:40", placeLabel: "浙江省 · 杭州市 · 西湖区" }), "1994年5月18日 07:40 · 杭州");
assert.equal(birthSkyCaption({ date: "1994-05-18", time: "7:40:00", placeLabel: "北京市 · 朝阳区" }), "1994年5月18日 07:40 · 北京");
assert.equal(birthSkyCaption({ date: "1994-12-01", time: "19:10", placeLabel: "浙江省" }), "1994年12月1日 19:10");
assert.equal(birthSkyCaption({ date: "1994-05-18", time: "00:00" }), "1994年5月18日 00:00");
});
test("caption never carries the district, coordinates or anything malformed", () => {
const caption = birthSkyCaption({ date: "1994-05-18", time: "07:40", placeLabel: "浙江省 · 杭州市 · 西湖区" }) ?? "";
assert.doesNotMatch(caption, /西湖区|浙江|°|UTC|Asia\//);
assert.equal(birthSkyCaption({ date: "1994/05/18", time: "07:40" }), null);
assert.equal(birthSkyCaption({ date: "1994-05-18", time: "25:00" }), null);
assert.equal(birthSkyCaption({ date: "1994-05-18", time: "" }), null);
});