test: 修复因预发布模式文案变更导致的测试失败

- header/footer/mobile-menu/mobile-tab-bar: 更新导航项断言与 mock
- insight-card/page-header: 适配组件结构变更(InkGlowCard、Badge)
- about/products/news: 修复重复文本匹配,添加 PageNav/date-fns mock
- constants: 更新服务标题断言
- 修复 mock 组件缺少 displayName 的 ESLint 错误
This commit is contained in:
张翔
2026-05-03 13:36:40 +08:00
parent f69de14e45
commit d51a99e645
11 changed files with 237 additions and 123 deletions
+33 -13
View File
@@ -64,19 +64,39 @@ jest.mock('@/lib/constants', () => ({
shortName: '睿新致遠',
displayName: '睿新致远',
},
NAVIGATION: [
{ id: 'home', label: '首页', href: '/' },
{ id: 'services', label: '服务', href: '/#services' },
{ id: 'products', label: '产品', href: '/products' },
{ id: 'about', label: '关于', href: '/about' },
{ id: 'contact', label: '联系', href: '/contact' },
NAVIGATION_V2: [
{ id: 'products', label: '产品', href: '/products', hasDropdown: true, dropdownKey: 'products' },
{ id: 'solutions', label: '解决方案', href: '/solutions', hasDropdown: true, dropdownKey: 'solutions' },
{ id: 'services', label: '服务', href: '/services' },
{ id: 'about', label: '关于我们', href: '/about' },
{ id: 'contact', label: '联系我们', href: '/contact' },
],
MEGA_DROPDOWN_DATA: {
products: [
{ id: 'erp', title: 'ERP 管理系统', description: '财务·采购·销售·库存·生产', href: '/products/erp' },
{ id: 'crm', title: 'CRM 客户管理', description: '线索·商机·合同·服务', href: '/products/crm' },
],
solutions: [
{ id: 'manufacturing', title: '制造业', description: '智能制造·MES·质量管控', href: '/solutions/manufacturing' },
],
},
}));
jest.mock('@/hooks/use-focus-trap', () => ({
useFocusTrap: () => ({ current: null }),
}));
jest.mock('@/components/layout/mega-dropdown', () => ({
MegaDropdown: ({ label, items }: { label: string; items: Array<{ id: string; title: string; description: string; href: string }> }) => (
<div data-testid="mega-dropdown">
<span>{label}</span>
{items.map(item => (
<a key={item.id} href={item.href}>{item.title}</a>
))}
</div>
),
}));
import { Header } from './header';
describe('Header', () => {
@@ -107,11 +127,11 @@ describe('Header', () => {
it('should render navigation items', () => {
render(<Header />);
expect(screen.getByText('首页')).toBeInTheDocument();
expect(screen.getByText('服务')).toBeInTheDocument();
expect(screen.getByText('产品')).toBeInTheDocument();
expect(screen.getByText('关于')).toBeInTheDocument();
expect(screen.getByText('联系')).toBeInTheDocument();
expect(screen.getByText('解决方案')).toBeInTheDocument();
expect(screen.getByText('服务')).toBeInTheDocument();
expect(screen.getByText('关于我们')).toBeInTheDocument();
expect(screen.getByText('联系我们')).toBeInTheDocument();
});
it('should render consult button', () => {
@@ -194,11 +214,11 @@ describe('Header', () => {
describe('Navigation', () => {
it('should have correct href for navigation items', () => {
render(<Header />);
const homeLink = screen.getByText('首页').closest('a');
const contactLink = screen.getByText('联系').closest('a');
const contactLink = screen.getByText('联系我们').closest('a');
const serviceLink = screen.getByText('服务').closest('a');
expect(homeLink).toHaveAttribute('href', '/');
expect(contactLink).toHaveAttribute('href', '/contact');
expect(serviceLink).toHaveAttribute('href', '/services');
});
});
});