import { render, screen } from '@testing-library/react'
import { describe, expect, it } from 'vitest'
import { OPT_DATA_INTEGRITY_TILES } from './fixtures/forensics'
import { KpiTile } from './KpiTile'

describe('KpiTile', () => {
  it('formats a *Ms tile value as a duration', () => {
    // wallClockMs: 1_140_000ms -> 19m
    render(<KpiTile tile={OPT_DATA_INTEGRITY_TILES[0]!} />)
    expect(screen.getByText('19m')).toBeInTheDocument()
    expect(screen.getByText('Run span')).toBeInTheDocument()
  })

  it('renders a non-Ms tile value as a plain number', () => {
    render(<KpiTile tile={OPT_DATA_INTEGRITY_TILES[1]!} />)
    expect(screen.getByText('1')).toBeInTheDocument()
    expect(screen.getByText('Run attempts')).toBeInTheDocument()
  })

  it('renders every real tile from the forensics fixture without crashing', () => {
    for (const tile of OPT_DATA_INTEGRITY_TILES) {
      const { unmount } = render(<KpiTile tile={tile} />)
      expect(screen.getByText(tile.label)).toBeInTheDocument()
      unmount()
    }
  })
})
