| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- /**
- * CurrentEmploymentStatus组件测试
- */
- import React from 'react'
- import { render, screen } from '@testing-library/react'
- import '@testing-library/jest-dom'
- import Taro from '@tarojs/taro'
- import { CurrentEmploymentStatus } from '@/components/CurrentEmploymentStatus'
- import { WorkStatus } from '@/types/employment'
- describe('CurrentEmploymentStatus组件', () => {
- const mockStatus = {
- companyName: '测试科技有限公司',
- orderId: 1,
- orderName: '数据标注员',
- positionName: '数据标注员',
- joinDate: '2023-08-15',
- workStatus: WorkStatus.WORKING,
- salaryLevel: 4800,
- actualStartDate: '2023-08-15'
- }
- beforeEach(() => {
- // 清理 Taro API mock
- ;(Taro.showToast as jest.Mock).mockClear()
- })
- it('应该渲染当前就业状态', () => {
- render(<CurrentEmploymentStatus status={mockStatus} loading={false} />)
- expect(screen.getByText('当前就业状态')).toBeInTheDocument()
- expect(screen.getByText('测试科技有限公司')).toBeInTheDocument()
- expect(screen.getByText('数据标注员')).toBeInTheDocument()
- })
- it('应该显示在职状态为绿色标签', () => {
- const { container } = render(
- <CurrentEmploymentStatus status={mockStatus} loading={false} />
- )
- const statusElements = container.querySelectorAll('.bg-green-100')
- expect(statusElements.length).toBeGreaterThan(0)
- })
- it('应该显示离职状态为灰色标签', () => {
- const resignedStatus = { ...mockStatus, workStatus: WorkStatus.RESIGNED }
- const { container } = render(
- <CurrentEmploymentStatus status={resignedStatus} loading={false} />
- )
- const statusElements = container.querySelectorAll('.bg-gray-100')
- expect(statusElements.length).toBeGreaterThan(0)
- })
- it('应该显示加载状态', () => {
- render(<CurrentEmploymentStatus status={null} loading={true} />)
- expect(screen.getByText('加载中...')).toBeInTheDocument()
- })
- it('应该显示无数据状态', () => {
- render(<CurrentEmploymentStatus status={null} loading={false} />)
- expect(screen.getByText('暂无就业记录')).toBeInTheDocument()
- })
- it('应该显示订单编号和薪资水平', () => {
- render(<CurrentEmploymentStatus status={mockStatus} loading={false} />)
- expect(screen.getByText('#1')).toBeInTheDocument()
- expect(screen.getByText('¥4,800/月')).toBeInTheDocument()
- })
- it('应该显示入职日期', () => {
- render(<CurrentEmploymentStatus status={mockStatus} loading={false} />)
- expect(screen.getByText('2023-08-15')).toBeInTheDocument()
- })
- })
|