CurrentEmploymentStatus.test.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * CurrentEmploymentStatus组件测试
  3. */
  4. import React from 'react'
  5. import { render, screen } from '@testing-library/react'
  6. import '@testing-library/jest-dom'
  7. import Taro from '@tarojs/taro'
  8. import { CurrentEmploymentStatus } from '@/components/CurrentEmploymentStatus'
  9. import { WorkStatus } from '@/types/employment'
  10. describe('CurrentEmploymentStatus组件', () => {
  11. const mockStatus = {
  12. companyName: '测试科技有限公司',
  13. orderId: 1,
  14. orderName: '数据标注员',
  15. positionName: '数据标注员',
  16. joinDate: '2023-08-15',
  17. workStatus: WorkStatus.WORKING,
  18. salaryLevel: 4800,
  19. actualStartDate: '2023-08-15'
  20. }
  21. beforeEach(() => {
  22. // 清理 Taro API mock
  23. ;(Taro.showToast as jest.Mock).mockClear()
  24. })
  25. it('应该渲染当前就业状态', () => {
  26. render(<CurrentEmploymentStatus status={mockStatus} loading={false} />)
  27. expect(screen.getByText('当前就业状态')).toBeInTheDocument()
  28. expect(screen.getByText('测试科技有限公司')).toBeInTheDocument()
  29. expect(screen.getByText('数据标注员')).toBeInTheDocument()
  30. })
  31. it('应该显示在职状态为绿色标签', () => {
  32. const { container } = render(
  33. <CurrentEmploymentStatus status={mockStatus} loading={false} />
  34. )
  35. const statusElements = container.querySelectorAll('.bg-green-100')
  36. expect(statusElements.length).toBeGreaterThan(0)
  37. })
  38. it('应该显示离职状态为灰色标签', () => {
  39. const resignedStatus = { ...mockStatus, workStatus: WorkStatus.RESIGNED }
  40. const { container } = render(
  41. <CurrentEmploymentStatus status={resignedStatus} loading={false} />
  42. )
  43. const statusElements = container.querySelectorAll('.bg-gray-100')
  44. expect(statusElements.length).toBeGreaterThan(0)
  45. })
  46. it('应该显示加载状态', () => {
  47. render(<CurrentEmploymentStatus status={null} loading={true} />)
  48. expect(screen.getByText('加载中...')).toBeInTheDocument()
  49. })
  50. it('应该显示无数据状态', () => {
  51. render(<CurrentEmploymentStatus status={null} loading={false} />)
  52. expect(screen.getByText('暂无就业记录')).toBeInTheDocument()
  53. })
  54. it('应该显示订单编号和薪资水平', () => {
  55. render(<CurrentEmploymentStatus status={mockStatus} loading={false} />)
  56. expect(screen.getByText('#1')).toBeInTheDocument()
  57. expect(screen.getByText('¥4,800/月')).toBeInTheDocument()
  58. })
  59. it('应该显示入职日期', () => {
  60. render(<CurrentEmploymentStatus status={mockStatus} loading={false} />)
  61. expect(screen.getByText('2023-08-15')).toBeInTheDocument()
  62. })
  63. })