test(web): 添加 vitest 单元测试基础设施和初始测试用例
- 安装 vitest + @testing-library/react + @testing-library/jest-dom + jsdom - 创建 vitest.config.ts (jsdom 环境, 全局 API, e2e 目录排除) - 创建 test/setup.ts (@testing-library/jest-dom 匹配器) - 添加 29 个测试用例: health 常量 (14), useThemeMode hook (2), StatusTag 组件 (13)
This commit is contained in:
120
apps/web/src/pages/health/components/StatusTag.test.tsx
Normal file
120
apps/web/src/pages/health/components/StatusTag.test.tsx
Normal file
@@ -0,0 +1,120 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import { StatusTag } from './StatusTag'
|
||||
|
||||
describe('StatusTag', () => {
|
||||
describe('appointment statuses', () => {
|
||||
it('renders pending status with gold color', () => {
|
||||
const { container } = render(<StatusTag status="pending" />)
|
||||
const tag = container.querySelector('.ant-tag')
|
||||
expect(tag).toBeInTheDocument()
|
||||
expect(tag).toHaveClass('ant-tag-gold')
|
||||
expect(screen.getByText('待确认')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders confirmed status with blue color', () => {
|
||||
const { container } = render(<StatusTag status="confirmed" />)
|
||||
const tag = container.querySelector('.ant-tag')
|
||||
expect(tag).toHaveClass('ant-tag-blue')
|
||||
expect(screen.getByText('已确认')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders completed status with green color', () => {
|
||||
const { container } = render(<StatusTag status="completed" />)
|
||||
const tag = container.querySelector('.ant-tag')
|
||||
expect(tag).toHaveClass('ant-tag-green')
|
||||
expect(screen.getByText('已完成')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders cancelled status with default color', () => {
|
||||
const { container } = render(<StatusTag status="cancelled" />)
|
||||
const tag = container.querySelector('.ant-tag')
|
||||
expect(tag).toBeInTheDocument()
|
||||
expect(screen.getByText('已取消')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders no_show status with red color', () => {
|
||||
const { container } = render(<StatusTag status="no_show" />)
|
||||
const tag = container.querySelector('.ant-tag')
|
||||
expect(tag).toHaveClass('ant-tag-red')
|
||||
expect(screen.getByText('未到诊')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('follow-up statuses', () => {
|
||||
it('renders overdue status with red color', () => {
|
||||
const { container } = render(<StatusTag status="overdue" />)
|
||||
const tag = container.querySelector('.ant-tag')
|
||||
expect(tag).toHaveClass('ant-tag-red')
|
||||
expect(screen.getByText('逾期')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders in_progress status with processing color', () => {
|
||||
const { container } = render(<StatusTag status="in_progress" />)
|
||||
const tag = container.querySelector('.ant-tag')
|
||||
expect(tag).toHaveClass('ant-tag-processing')
|
||||
expect(screen.getByText('进行中')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('consultation statuses', () => {
|
||||
it('renders waiting status with gold color', () => {
|
||||
const { container } = render(<StatusTag status="waiting" />)
|
||||
const tag = container.querySelector('.ant-tag')
|
||||
expect(tag).toHaveClass('ant-tag-gold')
|
||||
expect(screen.getByText('等待中')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders active consultation status with green color', () => {
|
||||
const { container } = render(<StatusTag status="active" />)
|
||||
const tag = container.querySelector('.ant-tag')
|
||||
expect(tag).toHaveClass('ant-tag-green')
|
||||
expect(screen.getByText('进行中')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders closed status with default color', () => {
|
||||
const { container } = render(<StatusTag status="closed" />)
|
||||
const tag = container.querySelector('.ant-tag')
|
||||
expect(tag).toBeInTheDocument()
|
||||
expect(screen.getByText('已关闭')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('patient statuses', () => {
|
||||
it('renders inactive status with default color', () => {
|
||||
const { container } = render(<StatusTag status="inactive" />)
|
||||
const tag = container.querySelector('.ant-tag')
|
||||
expect(tag).toBeInTheDocument()
|
||||
expect(screen.getByText('停用')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders deceased status with default color', () => {
|
||||
const { container } = render(<StatusTag status="deceased" />)
|
||||
const tag = container.querySelector('.ant-tag')
|
||||
expect(tag).toBeInTheDocument()
|
||||
expect(screen.getByText('已故')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders verified status with green color', () => {
|
||||
const { container } = render(<StatusTag status="verified" />)
|
||||
const tag = container.querySelector('.ant-tag')
|
||||
expect(tag).toHaveClass('ant-tag-green')
|
||||
expect(screen.getByText('已认证')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('unknown status fallback', () => {
|
||||
it('renders unknown status text with default color', () => {
|
||||
const { container } = render(<StatusTag status="unknown_status" />)
|
||||
const tag = container.querySelector('.ant-tag')
|
||||
expect(tag).toBeInTheDocument()
|
||||
expect(screen.getByText('unknown_status')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders empty string status with default color', () => {
|
||||
const { container } = render(<StatusTag status="" />)
|
||||
const tag = container.querySelector('.ant-tag')
|
||||
expect(tag).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user