import { render, screen } from '@testing-library/react'
import { describe, it, expect } from 'vitest'
import { StatCards } from '@/pages/Stats/StatCards'
import type { UsageStats } from '@/types'

const mockStats: UsageStats[] = [
  {
    id: 1,
    providerId: 'openai',
    modelName: 'gpt-4o',
    requestCount: 100,
    date: '2024-01-01',
  },
  {
    id: 2,
    providerId: 'openai',
    modelName: 'gpt-3.5-turbo',
    requestCount: 200,
    date: '2024-01-01',
  },
  {
    id: 3,
    providerId: 'anthropic',
    modelName: 'claude-3',
    requestCount: 150,
    date: '2024-01-02',
  },
]

describe('StatCards', () => {
  it('renders all statistic cards', () => {
    render(<StatCards stats={mockStats} />)

    expect(screen.getByText('总请求量')).toBeInTheDocument()
    expect(screen.getByText('活跃模型数')).toBeInTheDocument()
    expect(screen.getByText('活跃供应商数')).toBeInTheDocument()
    expect(screen.getByText('今日请求量')).toBeInTheDocument()
  })

  it('renders with empty stats', () => {
    render(<StatCards stats={[]} />)

    expect(screen.getByText('总请求量')).toBeInTheDocument()
    expect(screen.getByText('活跃模型数')).toBeInTheDocument()
    expect(screen.getByText('活跃供应商数')).toBeInTheDocument()
    expect(screen.getByText('今日请求量')).toBeInTheDocument()
  })

  it('renders suffix units', () => {
    render(<StatCards stats={mockStats} />)

    expect(screen.getAllByText('次').length).toBeGreaterThan(0)
    expect(screen.getAllByText('个').length).toBeGreaterThan(0)
  })
})
