minishouyin/test/final-test.js
2025-11-12 11:35:57 +08:00

151 lines
4.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 迷你收银台最终验证测试脚本
* 验证菜单功能修复是否成功
*/
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
console.log('=== 迷你收银台最终验证测试 ===');
// 1. 检查文件是否存在
function checkFiles() {
console.log('\n1. 检查必要文件...');
const filesToCheck = [
'src/renderer/components/Layout.js',
'src/renderer/App.js',
'src/renderer/index.html',
'build/index.html',
'启动收银台.bat'
];
filesToCheck.forEach(file => {
const fullPath = path.join(__dirname, file);
if (fs.existsSync(fullPath)) {
console.log(`${file}`);
} else {
console.log(`${file}`);
}
});
}
// 2. 检查Layout.js中的关键修复
function checkLayoutFix() {
console.log('\n2. 检查Layout.js修复...');
try {
const layoutPath = path.join(__dirname, 'src', 'renderer', 'components', 'Layout.js');
const content = fs.readFileSync(layoutPath, 'utf8');
const checks = [
{ pattern: /console\.log\('菜单点击:', key\)/, desc: '菜单点击日志' },
{ pattern: /electronNavigate\(key, navigate\)/, desc: 'electronNavigate导航' },
{ pattern: /window\.location\.hash = key/, desc: 'window.location.hash导航' },
{ pattern: /window\.location\.reload\(\)/, desc: '页面刷新备选方案' }
];
checks.forEach(check => {
if (check.pattern.test(content)) {
console.log(`${check.desc}`);
} else {
console.log(`${check.desc}`);
}
});
} catch (error) {
console.error(' ❌ 检查Layout.js失败:', error.message);
}
}
// 3. 检查增强版启动脚本
function checkStartupScript() {
console.log('\n3. 检查启动脚本...');
try {
const batPath = path.join(__dirname, '启动收银台.bat');
const content = fs.readFileSync(batPath, 'utf8');
const checks = [
{ pattern: /ELECTRON_ENABLE_LOGGING=1/, desc: '启用Electron日志' },
{ pattern: /ELECTRON_FORCE_WINDOW_MENU_BAR=1/, desc: '强制窗口菜单栏' },
{ pattern: /NODE_ENV=production/, desc: '生产环境设置' },
{ pattern: /if not exist "build\\index\.html"/, desc: '自动构建检查' }
];
checks.forEach(check => {
if (check.pattern.test(content)) {
console.log(`${check.desc}`);
} else {
console.log(`${check.desc}`);
}
});
} catch (error) {
console.error(' ❌ 检查启动脚本失败:', error.message);
}
}
// 4. 检查构建文件
function checkBuild() {
console.log('\n4. 检查构建文件...');
const buildFiles = [
'build/index.html',
'build/js/main.js'
];
buildFiles.forEach(file => {
const fullPath = path.join(__dirname, file);
if (fs.existsSync(fullPath)) {
const stats = fs.statSync(fullPath);
console.log(`${file} (${(stats.size / 1024).toFixed(2)} KB)`);
} else {
console.log(`${file}`);
}
});
}
// 5. 检查依赖
function checkDependencies() {
console.log('\n5. 检查关键依赖...');
try {
const result = execSync('npm list antd react-router-dom electron', { encoding: 'utf8' });
console.log(' ✅ 关键依赖已安装');
} catch (error) {
console.log(' ⚠️ 检查依赖时出现警告:', error.message);
}
}
// 6. 显示使用说明
function showUsage() {
console.log('\n=== 使用说明 ===');
console.log('菜单功能修复已完成!');
console.log('\n现在您可以:');
console.log('1. 双击 "启动收银台.bat" 启动应用');
console.log('2. 点击左侧菜单项测试功能');
console.log('3. 如果仍有问题请查看MENU_FIX_README.md获取详细信息');
console.log('\n修复内容:');
console.log('- 增强了菜单点击处理函数');
console.log('- 提供了多重导航方案');
console.log('- 改进了错误处理机制');
console.log('- 增强了启动脚本');
}
// 主函数
function main() {
console.log('开始最终验证测试...\n');
checkFiles();
checkLayoutFix();
checkStartupScript();
checkBuild();
checkDependencies();
showUsage();
console.log('\n=== 最终验证测试完成 ===');
}
// 执行测试
main();