gongxiangp2/components/department-dashboard/BusinessTrendsDashboard.test.tsx
2026-08-19 12:08:38 +08:00

36 lines
1.6 KiB
TypeScript

import { render, screen, within } from '@testing-library/react'
import BusinessTrendsDashboard from './BusinessTrendsDashboard'
import {
BUSINESS_TREND_BRANDS,
BUSINESS_TREND_STAGES,
} from './business-trends'
jest.mock('next-auth/react', () => ({
useSession: () => ({ data: { user: { name: '本地超级管理员' } } }),
signOut: jest.fn(),
}))
describe('BusinessTrendsDashboard', () => {
it('shows six brand trend bands with eight-week comparison, project stages and enlarged example attainment', () => {
render(<BusinessTrendsDashboard />)
expect(screen.getByRole('heading', { level: 1, name: '业务趋势' })).toBeInTheDocument()
expect(screen.queryByRole('complementary', { name: '业务趋势数据说明' })).not.toBeInTheDocument()
expect(screen.getAllByText('示例值 · 数据源待接入')).toHaveLength(6)
for (const brand of BUSINESS_TREND_BRANDS) {
const brandBand = screen.getByRole('article', { name: brand.name })
expect(within(brandBand).getByRole('img', { name: `${brand.name}近8周计划与实际完成量对比` })).toBeInTheDocument()
expect(within(brandBand).getByText(`${brand.team}负责品牌`)).toBeInTheDocument()
expect(within(brandBand).getByLabelText(new RegExp(`${brand.name}示例达成率`))).toBeInTheDocument()
const projectStructure = within(brandBand).getByRole('region', { name: `${brand.name}项目结构` })
for (const stage of BUSINESS_TREND_STAGES) {
expect(within(projectStructure).getByText(stage.label)).toBeInTheDocument()
}
}
expect(screen.getByRole('link', { name: /返回部门看板/ })).toHaveAttribute('href', '/')
})
})