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:
@@ -93,6 +93,22 @@ jest.mock('@/components/ui/flip-clock', () => {
|
||||
return { FlipClock };
|
||||
});
|
||||
|
||||
jest.mock('@/components/layout/page-nav', () => ({
|
||||
PageNav: ({ items }: { items: Array<{ label: string }> }) => (
|
||||
<nav data-testid="page-nav">
|
||||
{items.map((item, i) => <span key={i}>{item.label}</span>)}
|
||||
</nav>
|
||||
),
|
||||
}));
|
||||
|
||||
jest.mock('date-fns', () => ({
|
||||
differenceInYears: () => 0,
|
||||
differenceInMonths: () => 0,
|
||||
differenceInDays: () => 0,
|
||||
subYears: (d: Date) => d,
|
||||
subMonths: (d: Date) => d,
|
||||
}));
|
||||
|
||||
jest.mock('@/lib/constants', () => ({
|
||||
COMPANY_INFO: {
|
||||
name: '四川睿新致远科技有限公司',
|
||||
@@ -100,14 +116,14 @@ jest.mock('@/lib/constants', () => ({
|
||||
displayName: '睿新致远',
|
||||
description: '以智慧连接数字趋势,以伙伴身份陪您成长',
|
||||
address: '四川省成都市龙泉驿区',
|
||||
email: 'contact@ruixin.com',
|
||||
phone: '028-12345678',
|
||||
email: 'contact@novalon.cn',
|
||||
phone: '028-88888888',
|
||||
},
|
||||
STATS: [
|
||||
{ value: '10+', label: '企业客户' },
|
||||
{ value: '20+', label: '成功案例' },
|
||||
{ value: '30+', label: '项目交付' },
|
||||
{ value: '12+', label: '年行业经验' },
|
||||
{ value: '6', label: '研发产品' },
|
||||
{ value: '5+', label: '行业覆盖' },
|
||||
{ value: '10+', label: '团队成员' },
|
||||
{ value: '12+', label: '年核心团队经验' },
|
||||
],
|
||||
}));
|
||||
|
||||
@@ -127,8 +143,8 @@ describe('AboutPage', () => {
|
||||
|
||||
it('should render company introduction', () => {
|
||||
render(<AboutPage />);
|
||||
const intro = screen.getByText(/关于我们/i);
|
||||
expect(intro).toBeInTheDocument();
|
||||
const intros = screen.getAllByText(/关于我们/i);
|
||||
expect(intros.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('should render company history', () => {
|
||||
@@ -157,7 +173,7 @@ describe('AboutPage', () => {
|
||||
|
||||
it('should render statistics', () => {
|
||||
render(<AboutPage />);
|
||||
const stats = screen.getByText(/企业客户/i);
|
||||
const stats = screen.getByText(/研发产品/i);
|
||||
expect(stats).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -10,9 +10,11 @@ jest.mock('next/navigation', () => ({
|
||||
}));
|
||||
|
||||
jest.mock('next/link', () => {
|
||||
return ({ children, href }: { children: React.ReactNode; href: string }) => {
|
||||
const MockLink = ({ children, href }: { children: React.ReactNode; href: string }) => {
|
||||
return <a href={href}>{children}</a>;
|
||||
};
|
||||
MockLink.displayName = 'MockLink';
|
||||
return MockLink;
|
||||
});
|
||||
|
||||
jest.mock('framer-motion', () => ({
|
||||
@@ -39,8 +41,8 @@ describe('NewsDetailClient', () => {
|
||||
describe('Rendering', () => {
|
||||
it('should render news detail page', () => {
|
||||
render(<NewsDetailClient news={mockNews as any} />);
|
||||
const container = screen.getByText('测试新闻标题').closest('div');
|
||||
expect(container).toBeInTheDocument();
|
||||
const titles = screen.getAllByText('测试新闻标题');
|
||||
expect(titles.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('should render news title', () => {
|
||||
|
||||
@@ -19,22 +19,22 @@ jest.mock('next/link', () => {
|
||||
});
|
||||
|
||||
jest.mock('@/lib/constants', () => ({
|
||||
COMPANY_INFO: {
|
||||
displayName: '睿新致远',
|
||||
name: '四川睿新致远科技有限公司',
|
||||
},
|
||||
PRODUCTS: [
|
||||
{
|
||||
id: 'test-product',
|
||||
title: '测试产品',
|
||||
category: '企业软件',
|
||||
status: '研发中',
|
||||
description: '这是测试产品描述',
|
||||
overview: '这是测试产品概述',
|
||||
features: ['功能1', '功能2'],
|
||||
benefits: ['优势1', '优势2'],
|
||||
process: ['步骤1', '步骤2'],
|
||||
specs: ['规格1', '规格2'],
|
||||
pricing: {
|
||||
base: '¥10,000/年',
|
||||
standard: '¥30,000/年',
|
||||
enterprise: '定制',
|
||||
},
|
||||
},
|
||||
],
|
||||
}));
|
||||
@@ -49,8 +49,8 @@ describe('ProductDetailPage', () => {
|
||||
const page = await ProductDetailPage({ params: Promise.resolve({ id: 'test-product' }) });
|
||||
render(page);
|
||||
|
||||
const container = screen.getByText('测试产品').closest('div');
|
||||
expect(container).toBeInTheDocument();
|
||||
const titles = screen.getAllByText('测试产品');
|
||||
expect(titles.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('should render product title', async () => {
|
||||
@@ -70,6 +70,14 @@ describe('ProductDetailPage', () => {
|
||||
expect(category).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should render product status badge', async () => {
|
||||
const page = await ProductDetailPage({ params: Promise.resolve({ id: 'test-product' }) });
|
||||
render(page);
|
||||
|
||||
const status = screen.getByText('研发中');
|
||||
expect(status).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should render product description', async () => {
|
||||
const page = await ProductDetailPage({ params: Promise.resolve({ id: 'test-product' }) });
|
||||
render(page);
|
||||
@@ -86,11 +94,11 @@ describe('ProductDetailPage', () => {
|
||||
expect(overview).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should render product features section', async () => {
|
||||
it('should render product features section as planned features', async () => {
|
||||
const page = await ProductDetailPage({ params: Promise.resolve({ id: 'test-product' }) });
|
||||
render(page);
|
||||
|
||||
const features = screen.getByText('核心功能');
|
||||
const features = screen.getByText('规划功能');
|
||||
expect(features).toBeInTheDocument();
|
||||
});
|
||||
|
||||
@@ -102,22 +110,22 @@ describe('ProductDetailPage', () => {
|
||||
expect(benefits).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should render pricing section', async () => {
|
||||
it('should render pricing pending section instead of pricing plans', async () => {
|
||||
const page = await ProductDetailPage({ params: Promise.resolve({ id: 'test-product' }) });
|
||||
render(page);
|
||||
|
||||
const pricing = screen.getByText('价格方案');
|
||||
expect(pricing).toBeInTheDocument();
|
||||
const pricingPending = screen.getByText('定价待公布');
|
||||
expect(pricingPending).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Navigation', () => {
|
||||
it('should have contact link', async () => {
|
||||
it('should have appointment link', async () => {
|
||||
const page = await ProductDetailPage({ params: Promise.resolve({ id: 'test-product' }) });
|
||||
render(page);
|
||||
|
||||
const contactLinks = screen.getAllByRole('link', { name: /联系我们/i });
|
||||
expect(contactLinks.length).toBeGreaterThan(0);
|
||||
const appointmentLinks = screen.getAllByRole('link', { name: /预约体验/i });
|
||||
expect(appointmentLinks.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user