import { describe, it, expect } from 'vitest'
import { render, screen } from '@testing-library/react'
import StatusIndicator from '../StatusIndicator'

describe('StatusIndicator', () => {
    describe('rendering', () => {
        it('renders with label', () => {
            render(<StatusIndicator status="connected" label="Test Label" />)
            expect(screen.getByText('Test Label')).toBeInTheDocument()
        })

        it('renders tooltip when provided', () => {
            render(<StatusIndicator status="connected" label="Test" tooltip="Tooltip text" />)
            expect(screen.getByText('Test')).toBeInTheDocument()
        })
    })

    describe('status colors', () => {
        it('shows success color for connected status', () => {
            render(<StatusIndicator status="connected" label="Connected" />)
            const chip = screen.getByText('Connected').closest('.MuiChip-root')
            expect(chip).toHaveClass('MuiChip-colorSuccess')
        })

        it('shows error color for error status', () => {
            render(<StatusIndicator status="error" label="Error" />)
            const chip = screen.getByText('Error').closest('.MuiChip-root')
            expect(chip).toHaveClass('MuiChip-colorError')
        })

        it('shows warning color for warning status', () => {
            render(<StatusIndicator status="warning" label="Warning" />)
            const chip = screen.getByText('Warning').closest('.MuiChip-root')
            expect(chip).toHaveClass('MuiChip-colorWarning')
        })

        it('shows default color for disconnected status', () => {
            render(<StatusIndicator status="disconnected" label="Disconnected" />)
            const chip = screen.getByText('Disconnected').closest('.MuiChip-root')
            expect(chip).toHaveClass('MuiChip-colorDefault')
        })

        it('shows default color for unknown status', () => {
            render(<StatusIndicator status="unknown" label="Unknown" />)
            const chip = screen.getByText('Unknown').closest('.MuiChip-root')
            expect(chip).toHaveClass('MuiChip-colorDefault')
        })
    })

    describe('icons', () => {
        it('renders CheckCircle icon for connected status', () => {
            render(<StatusIndicator status="connected" label="Connected" />)
            expect(document.querySelector('[data-testid="CheckCircleIcon"]')).toBeInTheDocument()
        })

        it('renders CloudOff icon for disconnected status', () => {
            render(<StatusIndicator status="disconnected" label="Disconnected" />)
            expect(document.querySelector('[data-testid="CloudOffIcon"]')).toBeInTheDocument()
        })

        it('renders Error icon for error status', () => {
            render(<StatusIndicator status="error" label="Error" />)
            expect(document.querySelector('[data-testid="ErrorIcon"]')).toBeInTheDocument()
        })

        it('renders Warning icon for warning status', () => {
            render(<StatusIndicator status="warning" label="Warning" />)
            expect(document.querySelector('[data-testid="WarningIcon"]')).toBeInTheDocument()
        })
    })
})
