This commit is contained in:
rain
2026-07-24 18:03:02 +08:00
parent c7f278fe79
commit ec8486b035
86 changed files with 7943 additions and 1841 deletions
+26 -3
View File
@@ -16,15 +16,21 @@ const pageScript = match[1].replace(
"",
);
const createHarnessFactory = (goRootResult = true, goRootError = null) => new Function(
const createHarnessFactory = (
goRootResult = true,
goRootError = null,
initialSessionToken = "",
) => new Function(
"goRootResult",
"goRootError",
"initialSessionToken",
`
"use strict";
const calls = [];
const ref = (value) => ({ value });
const onBackPress = () => {};
const onShow = (callback) => callback();
const showCallbacks = [];
const onShow = (callback) => showCallbacks.push(callback);
const onUnload = () => {};
const AuthPageShell = {};
const AppToast = {};
@@ -96,6 +102,9 @@ const createHarnessFactory = (goRootResult = true, goRootError = null) => new Fu
tenantId: "000000",
};
const calcMD5 = (value) => "md5:" + value;
const session = {
getToken: () => initialSessionToken,
};
const goRoot = async (pageId) => {
calls.push({ type: "go-root", pageId });
if (goRootError) throw goRootError;
@@ -124,17 +133,21 @@ const createHarnessFactory = (goRootResult = true, goRootError = null) => new Fu
submitLogin,
completeTac,
closeTac,
async triggerShow() {
for (const callback of showCallbacks) await callback();
},
setPendingTacAction(value) {
pendingTacAction = value;
},
};
`,
)(goRootResult, goRootError);
)(goRootResult, goRootError, initialSessionToken);
const createHarness = (options = {}) =>
createHarnessFactory(
options.goRootResult ?? true,
options.goRootError ?? null,
options.initialSessionToken ?? "",
);
const countCalls = (harness, type) =>
@@ -159,6 +172,16 @@ const completePasswordTac = (harness) =>
});
const run = async () => {
const restored = createHarness({ initialSessionToken: "persisted-token" });
await restored.triggerShow();
assert.deepStrictEqual(
restored.calls.map((call) => call.type),
["go-root"],
"冷启动时已有会话必须直接进入家谱根页",
);
assert.strictEqual(restored.calls[0].pageId, "G01");
assert.strictEqual(restored.authenticationCommitted.value, true);
const success = createHarness();
await preparePassword(success);
assert.strictEqual(countCalls(success, "password-login"), 0);