建档改为四步。帮别人看写入已有人物档案,不新增数据库列。本人没有出生资料时不显示今日星语,「和我合盘」改成一句说明。起步三问只读已有上升和月亮:前两问直接发送,第三问只聚焦输入框。 自测:tsc 退出码 0;lint 0 error、121 warning;定向测试 142 项,pass 142,fail 0,cancelled 0;build 成功,/ 仍是 Static。首屏 gzip 592895,相对基线 578435 为 +2.50%。未跑全量 npm test、Python 快速门和 test:db。 Co-Authored-By: Grok (agent loop)
162 lines
6.6 KiB
TypeScript
162 lines
6.6 KiB
TypeScript
import assert from "node:assert/strict";
|
||
import { readFileSync } from "node:fs";
|
||
import test from "node:test";
|
||
import React from "react";
|
||
import { renderToStaticMarkup } from "react-dom/server";
|
||
|
||
import { HomeBootstrapError } from "../src/components/home-bootstrap-error.tsx";
|
||
import { HomeOnboardingShell } from "../src/components/home-onboarding-shell.tsx";
|
||
import type { BirthTimeGuidedController } from "../src/hooks/use-birth-time-guided-journey.ts";
|
||
import { emptyProfile, presetOnboardingMessage } from "../src/lib/home-types.ts";
|
||
import { createClientLifecycleHarness } from "./react-client-lifecycle-test-support.ts";
|
||
|
||
Object.assign(globalThis, { React });
|
||
|
||
const page = readFileSync(new URL("../src/app/(app)/page.tsx", import.meta.url), "utf8");
|
||
|
||
test("the fatal screen keeps its copy and retries through retryHomeBootstrap", async () => {
|
||
const accountError = "连接云端服务超时。请检查网络后重试,或返回登录页重新建立会话。";
|
||
const markup = renderToStaticMarkup(
|
||
<HomeBootstrapError accountError={accountError} onRetry={() => undefined} />,
|
||
);
|
||
assert.match(markup, /暂时无法进入 Jyotisha/);
|
||
assert.match(markup, /连接云端服务超时。请检查网络后重试,或返回登录页重新建立会话。/);
|
||
assert.match(markup, /重试/);
|
||
assert.match(markup, /返回登录/);
|
||
assert.match(markup, /app-loading app-loading-error/);
|
||
assert.match(markup, /role="alert"/);
|
||
|
||
const harness = createClientLifecycleHarness();
|
||
let retried = 0;
|
||
try {
|
||
await harness.render(<HomeBootstrapError accountError={accountError} onRetry={() => { retried += 1; }} />);
|
||
const retry = harness.elements().find((node) => node.tagName === "BUTTON" && node.text.includes("重试"));
|
||
assert.ok(retry);
|
||
await harness.event(retry);
|
||
assert.equal(retried, 1);
|
||
} finally {
|
||
await harness.close();
|
||
}
|
||
|
||
// 原值:错误屏按钮内联在 page.tsx,onClick 直接调用 retryHomeBootstrap。
|
||
// 新值:按钮在 HomeBootstrapError,page.tsx 把 onRetry 接到同一个 retryHomeBootstrap(...reloadSessionList)。
|
||
// 原因:错误屏抽成组件后,重试仍局部重跑,不整页刷新。
|
||
assert.match(page, /<HomeBootstrapError[\s\S]*onRetry=\{\(\) => retryHomeBootstrap\([\s\S]*reloadSessionList,[\s\S]*\)\}/);
|
||
assert.doesNotMatch(page, /window\.location\.reload\(\)/);
|
||
});
|
||
|
||
test("onboarding keeps the name prompt, birth card, and place card", () => {
|
||
const guided = {} as BirthTimeGuidedController;
|
||
const nameMarkup = renderToStaticMarkup(
|
||
<HomeOnboardingShell
|
||
profileComplete={false}
|
||
profileDraft={emptyProfile}
|
||
setProfileDraft={() => undefined}
|
||
onboardingStep="name"
|
||
presetMessageLength={presetOnboardingMessage.length}
|
||
currentOnboardingMessage={presetOnboardingMessage}
|
||
onboardingJustCompleted={false}
|
||
onboardingCardReady={false}
|
||
presetMessageFinished
|
||
birthTimeJourney={null}
|
||
birthTimeAssessmentPhase={null}
|
||
birthTimeError=""
|
||
birthTimeGuided={guided}
|
||
profileSaving={false}
|
||
saveOnboardingBirth={() => undefined}
|
||
saveOnboardingPlace={() => undefined}
|
||
retryBirthTimeAssessment={() => undefined}
|
||
/>,
|
||
);
|
||
assert.match(nameMarkup, /你好,我是 Jyotisha/);
|
||
assert.match(nameMarkup, /请问我该怎么称呼你/);
|
||
assert.doesNotMatch(nameMarkup, /出生日期与时间/);
|
||
|
||
const whoMarkup = renderToStaticMarkup(
|
||
<HomeOnboardingShell
|
||
profileComplete={false}
|
||
profileDraft={{ ...emptyProfile, name: "林遥" }}
|
||
setProfileDraft={() => undefined}
|
||
onboardingStep="who"
|
||
presetMessageLength={200}
|
||
currentOnboardingMessage="谁"
|
||
onboardingJustCompleted={false}
|
||
onboardingCardReady
|
||
presetMessageFinished
|
||
birthTimeJourney={null}
|
||
birthTimeAssessmentPhase={null}
|
||
birthTimeError=""
|
||
birthTimeGuided={guided}
|
||
profileSaving={false}
|
||
saveOnboardingBirth={() => undefined}
|
||
saveOnboardingPlace={() => undefined}
|
||
retryBirthTimeAssessment={() => undefined}
|
||
readerName="林遥"
|
||
onChooseSelf={() => undefined}
|
||
onChooseOther={() => undefined}
|
||
/>,
|
||
);
|
||
assert.match(whoMarkup, /好的,林遥。这次想先看谁的盘?以后随时可以再加别人。/);
|
||
assert.match(whoMarkup, /我自己/);
|
||
assert.match(whoMarkup, /看看自己的性格、事业和这几年的运势/);
|
||
assert.match(whoMarkup, /帮别人看/);
|
||
assert.match(whoMarkup, /伴侣、孩子、父母或朋友/);
|
||
assert.match(whoMarkup, /aria-label="建档进度"/);
|
||
assert.equal((whoMarkup.match(/<li/g) ?? []).length, 4);
|
||
|
||
const birthMarkup = renderToStaticMarkup(
|
||
<HomeOnboardingShell
|
||
profileComplete={false}
|
||
profileDraft={{ ...emptyProfile, name: "林遥" }}
|
||
setProfileDraft={() => undefined}
|
||
onboardingStep="birth"
|
||
presetMessageLength={80}
|
||
currentOnboardingMessage="出生时间"
|
||
onboardingJustCompleted={false}
|
||
onboardingCardReady
|
||
presetMessageFinished
|
||
birthTimeJourney={null}
|
||
birthTimeAssessmentPhase={null}
|
||
birthTimeError=""
|
||
birthTimeGuided={guided}
|
||
profileSaving={false}
|
||
saveOnboardingBirth={() => undefined}
|
||
saveOnboardingPlace={() => undefined}
|
||
retryBirthTimeAssessment={() => undefined}
|
||
/>,
|
||
);
|
||
assert.match(birthMarkup, /好,先看你自己的/);
|
||
assert.match(birthMarkup, /出生日期与时间/);
|
||
assert.match(birthMarkup, />继续</);
|
||
// 原值: 另渲一屏 onboardingStep="rectification",断言「出生时间尚未完成评估」和「重新评估」。
|
||
// 新值: 出生步不再出现这两句。
|
||
// 原因: BUG-1431,建档里的校正重试卡已删除。
|
||
assert.doesNotMatch(birthMarkup, /出生时间尚未完成评估/);
|
||
assert.doesNotMatch(birthMarkup, /重新评估/);
|
||
|
||
const placeMarkup = renderToStaticMarkup(
|
||
<HomeOnboardingShell
|
||
profileComplete={false}
|
||
profileDraft={{ ...emptyProfile, name: "林遥" }}
|
||
setProfileDraft={() => undefined}
|
||
onboardingStep="place"
|
||
presetMessageLength={80}
|
||
currentOnboardingMessage="出生地点"
|
||
onboardingJustCompleted={false}
|
||
onboardingCardReady
|
||
presetMessageFinished
|
||
birthTimeJourney={null}
|
||
birthTimeAssessmentPhase={null}
|
||
birthTimeError=""
|
||
birthTimeGuided={guided}
|
||
profileSaving={false}
|
||
saveOnboardingBirth={() => undefined}
|
||
saveOnboardingPlace={() => undefined}
|
||
retryBirthTimeAssessment={() => undefined}
|
||
/>,
|
||
);
|
||
assert.match(placeMarkup, /出生地点/);
|
||
assert.match(placeMarkup, /搜索全球城市或区县,系统会匹配出生当日的时区。/);
|
||
assert.match(placeMarkup, />确定</);
|
||
});
|