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

describe('AttendanceRecordItem组件', () => {
  const mockRecord: AttendanceRecord = {
    date: '2023-11-25',
    weekday: '星期六',
    checkInTime: '08:30',
    checkOutTime: '17:30',
    status: AttendanceStatus.NORMAL
  }

  test('应该渲染打卡记录信息', () => {
    render(<AttendanceRecordItem record={mockRecord} />)

    // 日期和星期在同一元素中
    expect(screen.getByText((content) => content.includes('11月25日'))).toBeInTheDocument()
    expect(screen.getByText((content) => content.includes('星期六'))).toBeInTheDocument()
    expect(screen.getByText('上班: 08:30')).toBeInTheDocument()
    expect(screen.getByText('下班: 17:30')).toBeInTheDocument()
  })

  test('应该渲染正常状态标签', () => {
    render(<AttendanceRecordItem record={mockRecord} />)

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

  test('应该渲染迟到状态标签', () => {
    const lateRecord: AttendanceRecord = {
      ...mockRecord,
      status: AttendanceStatus.LATE,
      checkInTime: '09:15'
    }

    render(<AttendanceRecordItem record={lateRecord} />)

    expect(screen.getByText('迟到')).toBeInTheDocument()
    expect(screen.getByText('上班: 09:15')).toBeInTheDocument()
  })

  test('应该渲染早退状态标签', () => {
    const earlyRecord: AttendanceRecord = {
      ...mockRecord,
      status: AttendanceStatus.EARLY_LEAVE,
      checkOutTime: '16:30'
    }

    render(<AttendanceRecordItem record={earlyRecord} />)

    expect(screen.getByText('早退')).toBeInTheDocument()
    expect(screen.getByText('下班: 16:30')).toBeInTheDocument()
  })

  test('应该渲染缺勤状态标签', () => {
    const absentRecord: AttendanceRecord = {
      ...mockRecord,
      status: AttendanceStatus.ABSENT,
      checkInTime: '--:--',
      checkOutTime: '--:--'
    }

    render(<AttendanceRecordItem record={absentRecord} />)

    expect(screen.getByText('缺勤')).toBeInTheDocument()
    expect(screen.getByText('上班: --:--')).toBeInTheDocument()
    expect(screen.getByText('下班: --:--')).toBeInTheDocument()
  })

  test('应该正确处理未打卡情况', () => {
    const noCheckOutRecord: AttendanceRecord = {
      ...mockRecord,
      checkOutTime: '--:--'
    }

    render(<AttendanceRecordItem record={noCheckOutRecord} />)

    expect(screen.getByText('下班: --:--')).toBeInTheDocument()
  })
})
