Files
Jyotisha/frontend/tests/birth-sky-caption.test.ts
T
Jesse_ChenandClaude Opus 5.5 dec36bce01 feat(birth-sky): poster-only dialog, date/time/city caption, slower reveal, paywall on first refused send (P1–P5, BUG-1080)
TASK-birth-sky-polish-20260928.
- P1: chart page dialog shows only the picture on a dimmed stage, 「保存图片」 below, icon × in the corner.
- P2: BFF returns one server-built `caption` (「1994年5月18日 07:40 · 杭州」); printed under the fact line in all three places; adopted time adds 「 · 校正后」.
- P3: convergence 3 s + words 2.5 s + fade 1 s; settled frame still equals the exported cover.
- P4: redeem paywall no longer opens when the starter home appears; first send refused for credits opens it, later ones open billing; convergence dialog portalled to <body>. BUG-1080 investigating (Chrome repro rules out the overlay covering the convergence).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N4f2nya58RoRu4yEmJgRGE
2026-09-29 00:03:46 +08:00

58 lines
3.2 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("广西壮族自治区 · 桂林市 · 秀峰区"), "桂林");
});
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);
});