import { describe, it, expect, vi, beforeEach } from 'vitest'
import { mount, flushPromises } from '@vue/test-utils'
import { createPinia, setActivePinia } from 'pinia'
import GatewayOperations from '@/views/GatewayOperations.vue'

vi.mock('@/api/operations', () => ({
  fetchGatewayFleet: vi.fn(),
  fetchGatewayDetail: vi.fn(),
}))

vi.mock('@/composables/usePolling', () => ({
  usePolling: (fn) => { fn(); return {} },
}))

import { fetchGatewayFleet } from '@/api/operations'

describe('GatewayOperations', () => {
  beforeEach(() => {
    setActivePinia(createPinia())
    fetchGatewayFleet.mockResolvedValue([
      {
        id: 'gw-1',
        gatewayCode: 'GW-ICU-3B',
        department: 'ICU',
        siteName: 'Demo Hospital',
        status: 'DEGRADED',
        reportedBufferDepth: 847,
        minutesSinceHeartbeat: 12,
        lastSyncAt: null,
      },
    ])
  })

  it('rendersFleetTableWithDegradedBadge', async () => {
    const wrapper = mount(GatewayOperations)
    await flushPromises()
    expect(wrapper.text()).toContain('GW-ICU-3B')
    expect(wrapper.text()).toContain('DEGRADED')
    expect(wrapper.text()).toContain('847')
  })
})