Files
Genarrative/miniprogram/shell/shareGrid.test.js
kdletters 071faa482c 统一 Rust 与 TypeScript 格式化门禁
纳入 AGC Cargo workspace 的统一 rustfmt 检查与格式化入口

完成项目 TypeScript/Prettier 与 Rust 全量格式化

修复 Pingora expected executable 门禁的空白敏感误报

同步开发运维文档与 AGC skill pack 格式化忽略规则
2026-09-01 16:28:34 +08:00

78 lines
2.2 KiB
JavaScript

import path from 'node:path';
import { beforeEach, describe, expect, test, vi } from 'vitest';
import { loadCommonJsModule } from '../test-utils/loadCommonJsModule.js';
const shareGridBridgePath = path.resolve(
process.cwd(),
'miniprogram/host-bridge/shareGrid.js',
);
const shareGridShellPath = path.resolve(
process.cwd(),
'miniprogram/shell/shareGrid.js',
);
let createWechatShareGridPage;
function createPage() {
const page = createWechatShareGridPage();
return {
...page,
data: { ...page.data },
setData(patch) {
Object.assign(this.data, patch);
},
};
}
describe('wechat share-grid shell page', () => {
beforeEach(() => {
globalThis.wx = {
navigateBack: vi.fn(),
};
const shareGridBridge = loadCommonJsModule(shareGridBridgePath);
const shareGridShell = loadCommonJsModule(shareGridShellPath, {
'../host-bridge/shareGrid': shareGridBridge,
});
createWechatShareGridPage = shareGridShell.createWechatShareGridPage;
});
test('shows a clear error when imageUrl is missing', async () => {
const page = createPage();
await page.onLoad({});
expect(page.data.loading).toBe(false);
expect(page.data.errorMessage).toBe('缺少封面图。');
});
test('hides downloadFile native failure details from the page', async () => {
const consoleError = vi
.spyOn(console, 'error')
.mockImplementation(() => undefined);
globalThis.wx.downloadFile = vi.fn(({ fail }) => {
fail({ errMsg: 'private native download detail' });
});
const page = createPage();
await page.onLoad({
imageUrl: 'https://web.test/cover.png',
title: '九宫切图',
publicWorkCode: 'PZ-0001',
});
expect(page.data.loading).toBe(false);
expect(page.data.errorMessage).toBe('九宫切图保存失败。');
expect(page.data.errorMessage).not.toContain(
'private native download detail',
);
expect(consoleError).toHaveBeenCalledWith('[share-grid] download failed');
expect(consoleError).toHaveBeenCalledWith('[share-grid] save failed');
expect(consoleError.mock.calls.flat()).not.toContain(
'private native download detail',
);
consoleError.mockRestore();
});
});