Files
Jyotisha/frontend/tests/lagna-precheck.test.ts
T
jesse-uxandGrok (agent loop) 9ca933968c
Independent Staging Quality Gate / validate (push) Successful in 17m49s
Independent Staging Quality Gate / publish (push) Successful in 3m55s
Resume an unfinished rectification from the chart link.
The chart page now continues a case already open instead of showing a conflict. Someone else's chart no longer offers that link.

tsc exit 0. lint 0 errors, 122 warnings. Precheck and chart-page tests 56 pass. Opening tests 70 pass.

Co-Authored-By: Grok (agent loop)
2026-10-27 07:43:40 +08:00

148 lines
5.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Ascendant precheck window from the birth row the chart page already loaded.
* Fictional clock only. BUG-1444.
*/
import assert from "node:assert/strict";
import test from "node:test";
import { lagnaPrecheckLine, lagnaPrecheckWindow } from "../src/lib/lagna-precheck.ts";
import type { ChartViewLagnaPrecheck } from "../src/lib/chart-view-contract.ts";
function row(patch: Record<string, unknown>) {
return {
birth_date: "1990-06-15",
reported_birth_time: "12:00:00",
birth_time_status: "reported",
...patch,
};
}
test("each birth-time source becomes the scan window, or stays quiet", () => {
const hospital = lagnaPrecheckWindow({ row: row({ birth_time_source: "hospital_record" }) });
assert.equal(hospital?.start_at, "1990-06-15T11:58");
assert.equal(hospital?.end_at, "1990-06-15T12:02");
assert.equal(hospital?.minutes, 5);
assert.equal(hospital?.beforeMinutes, 2);
assert.equal(hospital?.afterMinutes, 2);
assert.equal(hospital?.precisionKind, "minutes");
const stated = lagnaPrecheckWindow({ row: row({
birth_time_source: "hospital_record",
uncertainty_before_minutes: 30,
uncertainty_after_minutes: "60",
}) });
assert.equal(stated?.start_at, "1990-06-15T11:30");
assert.equal(stated?.end_at, "1990-06-15T13:00");
assert.equal(stated?.beforeMinutes, 30);
assert.equal(stated?.afterMinutes, 60);
assert.equal(stated?.minutes, 91);
const family = lagnaPrecheckWindow({ row: row({ birth_time_source: "family_exact" }) });
assert.equal(family?.start_at, "1990-06-15T12:00");
assert.equal(family?.end_at, "1990-06-15T12:00");
assert.equal(family?.minutes, 1);
assert.equal(family?.beforeMinutes, 0);
const approximate = lagnaPrecheckWindow({ row: row({ birth_time_source: "approximate" }) });
assert.equal(approximate?.start_at, "1990-06-15T11:45");
assert.equal(approximate?.end_at, "1990-06-15T12:15");
assert.equal(approximate?.minutes, 31);
const morning = lagnaPrecheckWindow({ row: row({
birth_time_source: "period_only",
birth_time_period: "morning",
}) });
assert.equal(morning?.start_at, "1990-06-15T08:00");
assert.equal(morning?.end_at, "1990-06-15T11:59");
assert.equal(morning?.precisionKind, "period");
assert.equal(morning?.periodStart, "08:00");
assert.equal(morning?.periodEnd, "11:59");
const late = lagnaPrecheckWindow({ row: row({
birth_time_source: "period_only",
birth_time_period: "late_night",
}) });
assert.equal(late?.start_at, "1990-06-15T23:00");
assert.equal(late?.end_at, "1990-06-16T03:59");
assert.equal(late?.minutes, 300);
const custom = lagnaPrecheckWindow({ row: row({
birth_time_source: "period_only",
declared_window_start: "23:10",
declared_window_end: "00:20",
}) });
assert.equal(custom?.start_at, "1990-06-15T23:10");
assert.equal(custom?.end_at, "1990-06-16T00:20");
const unknown = lagnaPrecheckWindow({ row: row({ birth_time_source: "unknown" }) });
assert.equal(unknown?.start_at, "1990-06-15T00:00");
assert.equal(unknown?.end_at, "1990-06-15T23:59");
assert.equal(unknown?.minutes, 1440);
assert.equal(unknown?.precisionKind, "unknown");
const capped = lagnaPrecheckWindow({ row: row({
birth_time_source: "approximate",
uncertainty_before_minutes: 1440,
uncertainty_after_minutes: 1440,
}) });
assert.equal(capped?.start_at, "1990-06-14T12:00");
assert.equal(capped?.end_at, "1990-06-15T12:00");
assert.equal(capped?.minutes, 1441);
assert.equal(lagnaPrecheckWindow({ row: row({ birth_time_source: "hospital_record", birth_time_status: "accepted" }) }), null);
assert.equal(lagnaPrecheckWindow({ row: row({ birth_time_source: "hospital_record", birth_time_status: "confirmed" }) }), null);
assert.equal(lagnaPrecheckWindow({ row: row({ birth_time_source: "legacy_import" }) }), null);
assert.equal(lagnaPrecheckWindow({ row: row({ birth_time_source: "" }) }), null);
assert.equal(lagnaPrecheckWindow({ row: row({ birth_time_source: "hospital_record", reported_birth_time: "" }) }), null);
assert.equal(lagnaPrecheckWindow(null), null);
assert.equal(lagnaPrecheckWindow({ row: row({ birth_time_source: "hospital_record", birth_date: "not-a-date" }) }), null);
});
test("header sentences name the sign and link only when it can change", () => {
const fixed: ChartViewLagnaPrecheck = {
state: "fixed",
signs: ["白羊"],
windowMinutes: 5,
precisionKind: "minutes",
beforeMinutes: 2,
afterMinutes: 2,
};
assert.equal(lagnaPrecheckLine(fixed).linked, false);
assert.match(lagnaPrecheckLine(fixed).before, /前后约 2 分钟/);
const uneven: ChartViewLagnaPrecheck = { ...fixed, beforeMinutes: 2, afterMinutes: 15 };
assert.match(lagnaPrecheckLine(uneven).before, /前 2 分钟、后 15 分钟/);
const two: ChartViewLagnaPrecheck = {
state: "may_change",
signs: ["白羊", "金牛"],
changeAt: ["12:01"],
windowMinutes: 31,
precisionKind: "period",
periodStart: "11:45",
periodEnd: "12:15",
};
const twoLine = lagnaPrecheckLine(two);
assert.equal(twoLine.linked, true);
assert.match(twoLine.before, /按你给的时间段(11:45–12:15)/);
assert.match(twoLine.before, /大约 12:01 换座/);
const unknown: ChartViewLagnaPrecheck = {
state: "unknown_time",
signs: ["白羊", "金牛"],
windowMinutes: 1440,
precisionKind: "unknown",
};
assert.equal(lagnaPrecheckLine(unknown).linked, true);
assert.match(lagnaPrecheckLine(unknown).before, /不知道出生时间时/);
const otherTwo = lagnaPrecheckLine(two, { self: false });
assert.equal(otherTwo.linked, false);
assert.equal(otherTwo.after, "");
assert.match(otherTwo.before, /大约 12:01 换座)。$/);
assert.doesNotMatch(otherTwo.before, /出生时间校正|想定下来/);
const otherUnknown = lagnaPrecheckLine(unknown, { self: false });
assert.equal(otherUnknown.linked, false);
assert.equal(otherUnknown.before, "不知道出生时间时,上升星座定不下来。");
});