|
|
@@ -5,6 +5,7 @@ const path = require('path');
|
|
|
const root = path.resolve(__dirname, '..');
|
|
|
const pagesRoot = path.join(root, 'packageMRC', 'pages');
|
|
|
const demoState = require(path.join(root, 'packageMRC', 'common', 'mrcDemoState.js'));
|
|
|
+const adapterSource = fs.readFileSync(path.join(root, 'packageMRC', 'common', 'mrcDemoState.js'), 'utf8');
|
|
|
const failures = [];
|
|
|
const pageNames = ['my-applications', 'identity', 'record-config', 'record-select', 'manual-record', 'application-form', 'address-create', 'confirm-submit', 'order-detail', 'order-progress', 'settlement'];
|
|
|
|
|
|
@@ -104,9 +105,13 @@ function assertSnapshotExcludes(values, label) {
|
|
|
}
|
|
|
|
|
|
pageNames.forEach((name) => assertSafeMockBoundary(`${readOptional(name, 'wxml')}\n${readOptional(name, 'js')}`, name));
|
|
|
+assertSafeMockBoundary(adapterSource, 'MRC Demo Adapter');
|
|
|
|
|
|
const originalWx = global.wx;
|
|
|
const calls = { navigateTo: [], navigateBack: [], redirectTo: [], switchTab: [], showToast: [], external: [] };
|
|
|
+const addressAdapterCalls = [];
|
|
|
+const addressAdapterReturns = [];
|
|
|
+const originalCreateAnonymousAddress = demoState.createAnonymousAddress;
|
|
|
global.wx = {
|
|
|
navigateTo(options) { calls.navigateTo.push(options || {}); },
|
|
|
navigateBack(options) { calls.navigateBack.push(options || {}); },
|
|
|
@@ -118,6 +123,17 @@ global.wx = {
|
|
|
uploadFile() { calls.external.push('uploadFile'); }
|
|
|
};
|
|
|
|
|
|
+if (typeof originalCreateAnonymousAddress === 'function') {
|
|
|
+ demoState.createAnonymousAddress = function spyCreateAnonymousAddress(...args) {
|
|
|
+ addressAdapterCalls.push(args);
|
|
|
+ const result = originalCreateAnonymousAddress.apply(this, args);
|
|
|
+ addressAdapterReturns.push(result);
|
|
|
+ return result;
|
|
|
+ };
|
|
|
+} else {
|
|
|
+ failures.push('MRC Demo Adapter 必须提供 createAnonymousAddress,用于地址页的本地匿名回填');
|
|
|
+}
|
|
|
+
|
|
|
try {
|
|
|
demoState.resetScenario();
|
|
|
const mounted = Object.fromEntries(pageNames.map((name) => [name, mount(loadPage(name))]));
|
|
|
@@ -267,6 +283,17 @@ try {
|
|
|
const addressBackBefore = calls.navigateBack.length;
|
|
|
invoke(address, addressSaveHandler, {}, '完整地址保存');
|
|
|
expect(calls.navigateBack.length === addressBackBefore + 1, '匿名地址保存后必须返回申请表单');
|
|
|
+ expect(addressAdapterCalls.length === 1, '地址保存必须仅调用一次本地匿名地址 Adapter API');
|
|
|
+ addressAdapterCalls.forEach((args) => {
|
|
|
+ const allowed = args.length === 0 || (args.length === 1 && args[0] === 'CREATE_ANONYMOUS_ADDRESS');
|
|
|
+ expect(allowed, `匿名地址 Adapter 仅可接收无参或固定匿名意图,实际参数:${JSON.stringify(args)}`);
|
|
|
+ expect(!JSON.stringify(args).includes(rawAddress.name) && !JSON.stringify(args).includes(rawAddress.phone) && !JSON.stringify(args).includes(rawAddress.region) && !JSON.stringify(args).includes(rawAddress.detail), '四个原始地址字段不得作为任何 Adapter 参数传入');
|
|
|
+ });
|
|
|
+ addressAdapterReturns.forEach((result) => {
|
|
|
+ const returned = JSON.stringify(result || {});
|
|
|
+ expect(!returned.includes(rawAddress.name) && !returned.includes(rawAddress.phone) && !returned.includes(rawAddress.region) && !returned.includes(rawAddress.detail), '匿名地址 Adapter 返回值不得包含原始地址字段');
|
|
|
+ expect(Boolean(result && result.ok && result.data && /匿名|演示/.test(result.data.addressLabel || '')), '匿名地址 Adapter 只能返回带匿名地址标签的成功结果');
|
|
|
+ });
|
|
|
assertSnapshotExcludes(Object.values(rawAddress), '地址回填后');
|
|
|
invoke(form, 'onShow', {}, '地址回填后的表单刷新');
|
|
|
expect(/匿名|演示/.test(form.data.addressLabel || ''), '申请表单回填只能显示匿名地址标签');
|
|
|
@@ -314,6 +341,7 @@ try {
|
|
|
expect(calls.external.length === 0, `全链本地 Demo 不得触发外部 API:${calls.external.join(', ')}`);
|
|
|
} finally {
|
|
|
global.wx = originalWx;
|
|
|
+ if (typeof originalCreateAnonymousAddress === 'function') demoState.createAnonymousAddress = originalCreateAnonymousAddress;
|
|
|
demoState.resetScenario();
|
|
|
}
|
|
|
|