import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen } from '@testing-library/react'
import { useEngineStore } from '../store/engineStore'
import StatusBar from '../components/layout/StatusBar'

// useSSE does nothing in tests
vi.mock('../hooks/useSSE', () => ({ useSSE: () => {} }))

describe('StatusBar', () => {
  beforeEach(() => {
    useEngineStore.setState({
      status: 'Running',
      uptime_seconds: 3661,
      total_scanned: 99,
      total_alerts: 5,
      last_cycle: 'Never',
      isOffline: false,
      setStats: vi.fn(),
      setOffline: vi.fn(),
    })
  })

  it('shows engine status', () => {
    render(<StatusBar />)
    expect(screen.getByText(/RUNNING/i)).toBeTruthy()
  })

  it('formats uptime correctly', () => {
    render(<StatusBar />)
    expect(screen.getByText(/1h 1m/i)).toBeTruthy()
  })

  it('shows offline banner when isOffline', () => {
    useEngineStore.setState({ isOffline: true } as any)
    render(<StatusBar />)
    expect(screen.getByText(/OFFLINE/i)).toBeTruthy()
  })
})
