/**
 * PersonalBasicInfo 组件测试
 */
import React from 'react'
import { render, screen } from '@testing-library/react'
import '@testing-library/jest-dom'
import PersonalBasicInfo, { PersonalInfoResponse } from '../../../src/components/PersonalBasicInfo'
import { maskIdCard } from '../../../src/utils/maskUtils'

describe('PersonalBasicInfo', () => {
  const mockPersonalInfo: PersonalInfoResponse = {
    name: '张三',
    gender: '男',
    idCard: '110101199001011234',
    disabilityId: 'D1234567890',
    disabilityType: '肢体残疾',
    disabilityLevel: '一级',
    phone: '13800138000',
    province: '北京市',
    city: '北京市',
    district: '朝阳区',
    detailedAddress: '某某街道123号',
    birthDate: '1990-01-01',
    idAddress: '北京市朝阳区某某街道123号',
    idValidDate: '2030-01-01',
    disabilityValidDate: '2025-12-31',
    canDirectContact: 1,
    isMarried: 0,
    nation: '汉族',
    jobStatus: 0,
    specificDisability: '左腿小腿截肢'
  }

  it('应该正确渲染个人基本信息', () => {
    render(<PersonalBasicInfo personalInfo={mockPersonalInfo} loading={false} />)

    expect(screen.getByText('张三')).toBeInTheDocument()
    expect(screen.getByText('男')).toBeInTheDocument()
    expect(screen.getByText(maskIdCard('110101199001011234'))).toBeInTheDocument()
    expect(screen.getByText('肢体残疾')).toBeInTheDocument()
    expect(screen.getByText('一级')).toBeInTheDocument()
    expect(screen.getByText('13800138000')).toBeInTheDocument()
  })

  it('应该渲染加载状态', () => {
    render(<PersonalBasicInfo personalInfo={null} loading={true} />)

    // 检查骨架屏加载元素
    const skeletonElements = document.querySelectorAll('.animate-pulse')
    expect(skeletonElements.length).toBeGreaterThan(0)
  })

  it('应该在没有数据时显示空状态', () => {
    render(<PersonalBasicInfo personalInfo={null} loading={false} />)

    expect(screen.getByText('暂无个人信息')).toBeInTheDocument()
  })

  it('应该脱敏敏感信息', () => {
    render(<PersonalBasicInfo personalInfo={mockPersonalInfo} loading={false} />)

    // 检查身份证号是否已脱敏（前4位 + 10个星号 + 后4位）
    expect(screen.getByText('1101**********1234')).toBeInTheDocument()
    // 检查残疾证号是否已脱敏（D123 + 10个星号 + 7890）
    // D1234567890有11个字符，后4位是7890
    expect(screen.getByText('D123**********7890')).toBeInTheDocument()
  })
})
