EmploymentHistory.test.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * EmploymentHistory组件测试
  3. */
  4. import React from 'react'
  5. import { render, screen } from '@testing-library/react'
  6. import '@testing-library/jest-dom'
  7. import { EmploymentHistory } from '@/components/EmploymentHistory'
  8. import { WorkStatus } from '@/types/employment'
  9. describe('EmploymentHistory组件', () => {
  10. const mockHistory = [
  11. {
  12. orderId: 1,
  13. orderName: '数据标注员',
  14. companyName: '阿里巴巴集团',
  15. positionName: '数据标注员',
  16. joinDate: '2023-08-15',
  17. leaveDate: null,
  18. workStatus: WorkStatus.WORKING,
  19. salaryLevel: 4800
  20. },
  21. {
  22. orderId: 2,
  23. orderName: '内容审核员',
  24. companyName: '腾讯科技',
  25. positionName: '内容审核员',
  26. joinDate: '2023-03-10',
  27. leaveDate: '2023-07-31',
  28. workStatus: WorkStatus.RESIGNED,
  29. salaryLevel: 4500
  30. },
  31. {
  32. orderId: 3,
  33. orderName: '数据录入员',
  34. companyName: '字节跳动',
  35. positionName: '数据录入员',
  36. joinDate: '2022-09-01',
  37. leaveDate: '2023-02-28',
  38. workStatus: WorkStatus.RESIGNED,
  39. salaryLevel: 4200
  40. }
  41. ]
  42. it('应该渲染就业历史列表', () => {
  43. render(<EmploymentHistory history={mockHistory} loading={false} />)
  44. expect(screen.getByText('就业历史')).toBeInTheDocument()
  45. expect(screen.getByText('阿里巴巴集团')).toBeInTheDocument()
  46. expect(screen.getByText('腾讯科技')).toBeInTheDocument()
  47. expect(screen.getByText('字节跳动')).toBeInTheDocument()
  48. })
  49. it('应该显示加载状态', () => {
  50. render(<EmploymentHistory history={[]} loading={true} />)
  51. expect(screen.getByText('加载中...')).toBeInTheDocument()
  52. })
  53. it('应该显示无数据状态', () => {
  54. render(<EmploymentHistory history={[]} loading={false} />)
  55. expect(screen.getByText('暂无就业历史')).toBeInTheDocument()
  56. })
  57. it('应该显示时间范围信息', () => {
  58. render(<EmploymentHistory history={mockHistory} loading={false} />)
  59. expect(screen.getByText(/2023-08-15 至今/)).toBeInTheDocument()
  60. expect(screen.getByText(/2023-03-10 至 2023-07-31/)).toBeInTheDocument()
  61. })
  62. it('应该显示岗位名称', () => {
  63. render(<EmploymentHistory history={mockHistory} loading={false} />)
  64. expect(screen.getByText('数据标注员')).toBeInTheDocument()
  65. expect(screen.getByText('内容审核员')).toBeInTheDocument()
  66. expect(screen.getByText('数据录入员')).toBeInTheDocument()
  67. })
  68. })