PersonalBasicInfo.test.tsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * PersonalBasicInfo 组件测试
  3. */
  4. import React from 'react'
  5. import { render, screen } from '@testing-library/react'
  6. import '@testing-library/jest-dom'
  7. import PersonalBasicInfo, { PersonalInfoResponse } from '../../../src/components/PersonalBasicInfo'
  8. import { maskIdCard } from '../../../src/utils/maskUtils'
  9. describe('PersonalBasicInfo', () => {
  10. const mockPersonalInfo: PersonalInfoResponse = {
  11. name: '张三',
  12. gender: '男',
  13. idCard: '110101199001011234',
  14. disabilityId: 'D1234567890',
  15. disabilityType: '肢体残疾',
  16. disabilityLevel: '一级',
  17. phone: '13800138000',
  18. province: '北京市',
  19. city: '北京市',
  20. district: '朝阳区',
  21. detailedAddress: '某某街道123号',
  22. birthDate: '1990-01-01',
  23. idAddress: '北京市朝阳区某某街道123号',
  24. idValidDate: '2030-01-01',
  25. disabilityValidDate: '2025-12-31',
  26. canDirectContact: 1,
  27. isMarried: 0,
  28. nation: '汉族',
  29. jobStatus: 0,
  30. specificDisability: '左腿小腿截肢'
  31. }
  32. it('应该正确渲染个人基本信息', () => {
  33. render(<PersonalBasicInfo personalInfo={mockPersonalInfo} loading={false} />)
  34. expect(screen.getByText('张三')).toBeInTheDocument()
  35. expect(screen.getByText('男')).toBeInTheDocument()
  36. expect(screen.getByText(maskIdCard('110101199001011234'))).toBeInTheDocument()
  37. expect(screen.getByText('肢体残疾')).toBeInTheDocument()
  38. expect(screen.getByText('一级')).toBeInTheDocument()
  39. expect(screen.getByText('13800138000')).toBeInTheDocument()
  40. })
  41. it('应该渲染加载状态', () => {
  42. render(<PersonalBasicInfo personalInfo={null} loading={true} />)
  43. // 检查骨架屏加载元素
  44. const skeletonElements = document.querySelectorAll('.animate-pulse')
  45. expect(skeletonElements.length).toBeGreaterThan(0)
  46. })
  47. it('应该在没有数据时显示空状态', () => {
  48. render(<PersonalBasicInfo personalInfo={null} loading={false} />)
  49. expect(screen.getByText('暂无个人信息')).toBeInTheDocument()
  50. })
  51. it('应该脱敏敏感信息', () => {
  52. render(<PersonalBasicInfo personalInfo={mockPersonalInfo} loading={false} />)
  53. // 检查身份证号是否已脱敏(前4位 + 10个星号 + 后4位)
  54. expect(screen.getByText('1101**********1234')).toBeInTheDocument()
  55. // 检查残疾证号是否已脱敏(D123 + 10个星号 + 7890)
  56. // D1234567890有11个字符,后4位是7890
  57. expect(screen.getByText('D123**********7890')).toBeInTheDocument()
  58. })
  59. })