统一三端宿主桥接层结构
拆分移动壳能力清单与分发模块 拆分桌面壳能力清单与分发模块 补充微信壳协议与分发薄索引 同步三端桥接层门禁和文档
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
const payment = require('./payment');
|
||||
const protocol = require('./protocol');
|
||||
const shareGrid = require('./shareGrid');
|
||||
const subscribeMessage = require('./subscribeMessage');
|
||||
const webView = require('./webView');
|
||||
|
||||
module.exports = {
|
||||
payment,
|
||||
protocol,
|
||||
shareGrid,
|
||||
subscribeMessage,
|
||||
webView,
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
const WECHAT_HOST_CAPABILITIES = [
|
||||
'auth.requestLogin',
|
||||
'payment.request',
|
||||
'share.setTarget',
|
||||
'share.open',
|
||||
];
|
||||
|
||||
const WECHAT_WEB_VIEW_PAGE_URL = '/pages/web-view/index';
|
||||
const WECHAT_AUTH_PAGE_URL =
|
||||
`${WECHAT_WEB_VIEW_PAGE_URL}?authAction=login&returnTo=previous`;
|
||||
const WECHAT_PAY_PAGE_URL = '/pages/wechat-pay/index';
|
||||
const WECHAT_SHARE_GRID_PAGE_URL = '/pages/share-grid/index';
|
||||
const WECHAT_SUBSCRIBE_MESSAGE_PAGE_URL = '/pages/subscribe-message/index';
|
||||
const WECHAT_PAY_RESULT_HASH_KEY = 'wx_pay_result';
|
||||
const WECHAT_SUBSCRIBE_RESULT_HASH_KEY = 'wx_subscribe_result';
|
||||
const WECHAT_PAY_RESULT_STORAGE_KEY = 'genarrative:wechat-pay-result';
|
||||
const WECHAT_SUBSCRIBE_RESULT_STORAGE_KEY =
|
||||
'genarrative:wechat-subscribe-result';
|
||||
const WECHAT_SHARE_TARGET_MESSAGE_TYPE = 'genarrative:share-target';
|
||||
|
||||
module.exports = {
|
||||
WECHAT_AUTH_PAGE_URL,
|
||||
WECHAT_HOST_CAPABILITIES,
|
||||
WECHAT_PAY_PAGE_URL,
|
||||
WECHAT_PAY_RESULT_HASH_KEY,
|
||||
WECHAT_PAY_RESULT_STORAGE_KEY,
|
||||
WECHAT_SHARE_GRID_PAGE_URL,
|
||||
WECHAT_SHARE_TARGET_MESSAGE_TYPE,
|
||||
WECHAT_SUBSCRIBE_MESSAGE_PAGE_URL,
|
||||
WECHAT_SUBSCRIBE_RESULT_HASH_KEY,
|
||||
WECHAT_SUBSCRIBE_RESULT_STORAGE_KEY,
|
||||
WECHAT_WEB_VIEW_PAGE_URL,
|
||||
};
|
||||
@@ -0,0 +1,80 @@
|
||||
import path from 'node:path';
|
||||
|
||||
import { describe, expect, test } from 'vitest';
|
||||
|
||||
import { loadCommonJsModule } from '../test-utils/loadCommonJsModule.js';
|
||||
|
||||
const protocolPath = path.resolve(
|
||||
process.cwd(),
|
||||
'miniprogram/host-bridge/protocol.js',
|
||||
);
|
||||
const dispatchPath = path.resolve(
|
||||
process.cwd(),
|
||||
'miniprogram/host-bridge/dispatch.js',
|
||||
);
|
||||
const paymentPath = path.resolve(
|
||||
process.cwd(),
|
||||
'miniprogram/host-bridge/payment.js',
|
||||
);
|
||||
const shareGridPath = path.resolve(
|
||||
process.cwd(),
|
||||
'miniprogram/host-bridge/shareGrid.js',
|
||||
);
|
||||
const subscribeMessagePath = path.resolve(
|
||||
process.cwd(),
|
||||
'miniprogram/host-bridge/subscribeMessage.js',
|
||||
);
|
||||
const webViewPath = path.resolve(
|
||||
process.cwd(),
|
||||
'miniprogram/host-bridge/webView.js',
|
||||
);
|
||||
|
||||
describe('wechat mini program host bridge protocol index', () => {
|
||||
test('keeps native page routes and result keys centralized', () => {
|
||||
const protocol = loadCommonJsModule(protocolPath);
|
||||
|
||||
expect(protocol.WECHAT_HOST_CAPABILITIES).toEqual([
|
||||
'auth.requestLogin',
|
||||
'payment.request',
|
||||
'share.setTarget',
|
||||
'share.open',
|
||||
]);
|
||||
expect(protocol.WECHAT_AUTH_PAGE_URL).toBe(
|
||||
'/pages/web-view/index?authAction=login&returnTo=previous',
|
||||
);
|
||||
expect(protocol.WECHAT_PAY_PAGE_URL).toBe('/pages/wechat-pay/index');
|
||||
expect(protocol.WECHAT_SHARE_GRID_PAGE_URL).toBe('/pages/share-grid/index');
|
||||
expect(protocol.WECHAT_SUBSCRIBE_MESSAGE_PAGE_URL).toBe(
|
||||
'/pages/subscribe-message/index',
|
||||
);
|
||||
expect(protocol.WECHAT_PAY_RESULT_HASH_KEY).toBe('wx_pay_result');
|
||||
expect(protocol.WECHAT_SUBSCRIBE_RESULT_HASH_KEY).toBe(
|
||||
'wx_subscribe_result',
|
||||
);
|
||||
});
|
||||
|
||||
test('dispatch index exposes current bridge ability modules', () => {
|
||||
const payment = loadCommonJsModule(paymentPath);
|
||||
const protocol = loadCommonJsModule(protocolPath);
|
||||
const shareGrid = loadCommonJsModule(shareGridPath);
|
||||
const subscribeMessage = loadCommonJsModule(subscribeMessagePath);
|
||||
const webView = loadCommonJsModule(webViewPath);
|
||||
const dispatch = loadCommonJsModule(dispatchPath, {
|
||||
'./payment': payment,
|
||||
'./protocol': protocol,
|
||||
'./shareGrid': shareGrid,
|
||||
'./subscribeMessage': subscribeMessage,
|
||||
'./webView': webView,
|
||||
});
|
||||
|
||||
expect(dispatch.protocol.WECHAT_PAY_PAGE_URL).toBe('/pages/wechat-pay/index');
|
||||
expect(typeof dispatch.webView.resolveWebViewUrlFromRuntimeConfig).toBe(
|
||||
'function',
|
||||
);
|
||||
expect(typeof dispatch.payment.requestWechatPayment).toBe('function');
|
||||
expect(typeof dispatch.shareGrid.buildShareGridTilePlan).toBe('function');
|
||||
expect(typeof dispatch.subscribeMessage.buildSubscribeResultValue).toBe(
|
||||
'function',
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user