/** * 菜单导航功能测试脚本 * 用于验证Electron环境中菜单点击是否正常工作 */ console.log('=== 菜单导航功能测试 ==='); // 测试函数 function runTests() { console.log('\n开始测试...'); // 测试1: 检查必要的函数和对象是否存在 console.log('\n1. 检查必要组件:'); if (typeof window.electronNavigate === 'function') { console.log(' ✅ electronNavigate函数存在'); } else { console.log(' ❌ electronNavigate函数不存在'); } if (window.location) { console.log(' ✅ window.location对象存在'); } else { console.log(' ❌ window.location对象不存在'); } // 测试2: 模拟菜单点击 console.log('\n2. 模拟菜单点击测试:'); try { // 模拟点击收银台菜单 console.log(' 模拟点击收银台菜单...'); const cashierEvent = { key: '/cashier' }; // 如果electronNavigate存在,使用它进行测试 if (typeof window.electronNavigate === 'function') { console.log(' 使用electronNavigate进行导航测试...'); // 这里只是测试函数调用,不实际导航 console.log(' ✅ electronNavigate可以被调用'); } else { console.log(' ⚠️ electronNavigate不存在,跳过测试'); } } catch (error) { console.error(' ❌ 模拟菜单点击测试失败:', error); } // 测试3: 检查当前路由 console.log('\n3. 检查当前路由:'); try { const currentPath = window.location.hash || window.location.pathname; console.log(` 当前路径: ${currentPath}`); if (currentPath.includes('cashier')) { console.log(' ✅ 当前在收银台页面'); } else { console.log(' ℹ️ 当前不在收银台页面'); } } catch (error) { console.error(' ❌ 检查当前路由失败:', error); } // 测试4: 检查菜单组件 console.log('\n4. 检查菜单组件:'); try { // 查找菜单元素 const menuElements = document.querySelectorAll('.ant-menu-item'); console.log(` 找到 ${menuElements.length} 个菜单项`); if (menuElements.length > 0) { console.log(' ✅ 菜单组件已正确渲染'); // 检查第一个菜单项 const firstMenuItem = menuElements[0]; console.log(` 第一个菜单项文本: ${firstMenuItem.textContent.trim()}`); // 检查是否有点击事件监听器 const clickListeners = getEventListeners(firstMenuItem, 'click'); if (clickListeners && clickListeners.length > 0) { console.log(' ✅ 菜单项有点击事件监听器'); } else { console.log(' ⚠️ 菜单项可能没有点击事件监听器'); } } else { console.log(' ❌ 未找到菜单组件'); } } catch (error) { console.error(' ❌ 检查菜单组件失败:', error); } console.log('\n=== 测试完成 ==='); console.log('如果所有测试都通过✅,菜单导航应该正常工作。'); console.log('如果有任何⚠️或❌,可能需要进一步检查。'); } // 辅助函数:获取元素的事件监听器(仅在Chrome DevTools中可用) function getEventListeners(element, eventType) { // 这个函数在普通JavaScript环境中不可用,仅在开发者工具中可用 // 我们提供一个模拟实现 if (typeof window.getEventListeners !== 'undefined') { try { return window.getEventListeners(element)[eventType] || []; } catch (error) { return []; } } return []; // 在普通环境中返回空数组 } // 延迟执行测试,确保页面完全加载 setTimeout(() => { runTests(); }, 2000); // 导出函数供其他地方使用 if (typeof module !== 'undefined') { module.exports = { runTests }; }