/**
 * AttendanceStats组件测试
 */
import React from 'react'
import { render, screen } from '@testing-library/react'
import '@testing-library/jest-dom'
import { AttendanceStats } from '@/components/AttendanceStats'
import { AttendanceStats as AttendanceStatsType } from '@/types/attendance'

describe('AttendanceStats组件', () => {
  const mockStats: AttendanceStatsType = {
    attendanceRate: 100,
    normalDays: 28,
    lateCount: 2,
    earlyLeaveCount: 1,
    absentCount: 0
  }

  test('应该渲染考勤统计数据', () => {
    render(<AttendanceStats stats={mockStats} />)

    expect(screen.getByText('100%')).toBeInTheDocument()
    expect(screen.getByText('28天')).toBeInTheDocument()
  })

  test('应该渲染出勤率标签', () => {
    render(<AttendanceStats stats={mockStats} />)

    expect(screen.getByText('出勤率')).toBeInTheDocument()
  })

  test('应该渲染正常出勤标签', () => {
    render(<AttendanceStats stats={mockStats} />)

    expect(screen.getByText('正常出勤')).toBeInTheDocument()
  })

  test('应该渲染异常统计数据', () => {
    render(<AttendanceStats stats={mockStats} />)

    expect(screen.getByText('迟到: 2次')).toBeInTheDocument()
    expect(screen.getByText('早退: 1次')).toBeInTheDocument()
    expect(screen.getByText('缺勤: 0次')).toBeInTheDocument()
  })

  test('应该正确渲染零统计数据', () => {
    const zeroStats: AttendanceStatsType = {
      attendanceRate: 0,
      normalDays: 0,
      lateCount: 0,
      earlyLeaveCount: 0,
      absentCount: 0
    }

    render(<AttendanceStats stats={zeroStats} />)

    expect(screen.getByText('0%')).toBeInTheDocument()
    expect(screen.getByText('0天')).toBeInTheDocument()
    expect(screen.getByText('迟到: 0次')).toBeInTheDocument()
    expect(screen.getByText('早退: 0次')).toBeInTheDocument()
    expect(screen.getByText('缺勤: 0次')).toBeInTheDocument()
  })
})
