统一微信壳桥接目录
新增 miniprogram/shell 承接微信 Page 生命周期与 wx 容器调用 收窄微信页面入口为 shell 页面工厂装配 更新三端 host-bridge/shell 目录门禁与认证 smoke 补充微信 shell 测试与 CommonJS 测试加载工具 同步宿主壳架构文档和项目共享记忆 补齐 api-server 外部生成测试 fixture 更新时间字段
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
import path from 'node:path';
|
||||
|
||||
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
||||
|
||||
import { loadCommonJsModule } from '../test-utils/loadCommonJsModule.js';
|
||||
|
||||
const webViewBridgePath = path.resolve(
|
||||
process.cwd(),
|
||||
'miniprogram/host-bridge/wechatHostBridgeWebView.js',
|
||||
);
|
||||
const webViewShellPath = path.resolve(
|
||||
process.cwd(),
|
||||
'miniprogram/shell/wechatShellWebView.js',
|
||||
);
|
||||
const config = {
|
||||
API_BASE_URL: 'https://www.genarrative.world',
|
||||
DEV_API_BASE_URL: 'https://dev.genarrative.world',
|
||||
DEV_WEB_VIEW_ENTRY_URL: 'https://dev.genarrative.world',
|
||||
MINI_PROGRAM_APP_ID: 'wx-test-app',
|
||||
MINI_PROGRAM_ENV: 'release',
|
||||
WEB_VIEW_ENTRY_URL: 'https://www.genarrative.world',
|
||||
WEB_VIEW_SOURCE_QUERY: {
|
||||
clientType: 'mini_program',
|
||||
clientRuntime: 'wechat_mini_program',
|
||||
},
|
||||
};
|
||||
|
||||
let createWechatWebViewPage;
|
||||
|
||||
function createPage() {
|
||||
const page = createWechatWebViewPage();
|
||||
return {
|
||||
...page,
|
||||
data: { ...page.data },
|
||||
setData(patch) {
|
||||
Object.assign(this.data, patch);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe('wechat web-view shell page', () => {
|
||||
beforeEach(() => {
|
||||
globalThis.wx = {
|
||||
getAccountInfoSync: vi.fn(() => ({
|
||||
miniProgram: { envVersion: 'release' },
|
||||
})),
|
||||
getStorageSync: vi.fn(() => ''),
|
||||
getSystemInfoSync: vi.fn(() => ({ platform: 'ios' })),
|
||||
login: vi.fn(),
|
||||
navigateBack: vi.fn(),
|
||||
removeStorageSync: vi.fn(),
|
||||
request: vi.fn(),
|
||||
setStorageSync: vi.fn(),
|
||||
showShareMenu: vi.fn(),
|
||||
};
|
||||
const webViewBridge = loadCommonJsModule(webViewBridgePath);
|
||||
const webViewShell = loadCommonJsModule(webViewShellPath, {
|
||||
'../config': config,
|
||||
'../host-bridge/wechatHostBridgeWebView': webViewBridge,
|
||||
});
|
||||
createWechatWebViewPage = webViewShell.createWechatWebViewPage;
|
||||
});
|
||||
|
||||
test('opens anonymous H5 web-view without eager login', async () => {
|
||||
const page = createPage();
|
||||
|
||||
await page.onLoad({});
|
||||
|
||||
expect(globalThis.wx.login).not.toHaveBeenCalled();
|
||||
expect(globalThis.wx.request).not.toHaveBeenCalled();
|
||||
expect(page.data.loading).toBe(false);
|
||||
expect(page.data.webViewUrl).toBe(
|
||||
'https://www.genarrative.world?clientType=mini_program&clientRuntime=wechat_mini_program',
|
||||
);
|
||||
expect(globalThis.wx.showShareMenu).toHaveBeenCalledWith({
|
||||
withShareTicket: true,
|
||||
menus: ['shareAppMessage', 'shareTimeline'],
|
||||
});
|
||||
});
|
||||
|
||||
test('stores latest H5 share target for native share menu', () => {
|
||||
const page = createPage();
|
||||
page.handleWebViewMessage({
|
||||
detail: {
|
||||
data: [
|
||||
{
|
||||
data: {
|
||||
type: 'genarrative:share-target',
|
||||
payload: {
|
||||
targetPath: '/works/detail',
|
||||
work: 'BB-12345678',
|
||||
title: '汪汪声浪',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
expect(page.onShareAppMessage()).toEqual({
|
||||
title: '陶泥儿',
|
||||
path: '/pages/web-view/index?targetPath=%2Fworks%2Fdetail&work=BB-12345678',
|
||||
});
|
||||
expect(page.onShareTimeline()).toEqual({
|
||||
title: '陶泥儿',
|
||||
query: 'targetPath=%2Fworks%2Fdetail&work=BB-12345678',
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user