/**
 * WAF Dashboard Component Tests
 */

import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, waitFor } from '@testing-library/react'
import { MockedProvider } from '@apollo/client/testing'
import WAFDashboard from '../well-architected/WAFDashboard'
import { GET_PILLARS, GET_FINDINGS } from '@/lib/graphql/queries/well-architected'

const mocks = [
  {
    request: {
      query: GET_PILLARS,
    },
    result: {
      data: {
        pillars: [
          {
            id: 'pillar-1',
            code: 'SECURITY',
            name: 'Security',
            description: 'Security pillar',
            controls: [],
          },
        ],
      },
    },
  },
  {
    request: {
      query: GET_FINDINGS,
      variables: {
        filter: undefined,
      },
    },
    result: {
      data: {
        findings: [
          {
            id: 'finding-1',
            control: {
              id: 'control-1',
              code: 'SECURITY-001',
              name: 'Encryption',
              pillar: { code: 'SECURITY', name: 'Security' },
            },
            resource: {
              id: 'resource-1',
              name: 'test-resource',
              type: 'VM',
            },
            status: 'PASS',
            severity: 'LOW',
            title: 'Encryption enabled',
            description: 'Resource has encryption at rest enabled',
            recommendation: null,
            createdAt: new Date().toISOString(),
            updatedAt: new Date().toISOString(),
          },
        ],
      },
    },
  },
]

describe('WAFDashboard', () => {
  beforeEach(() => {
    vi.clearAllMocks()
  })

  it('should render WAF dashboard with pillars', async () => {
    render(
      <MockedProvider mocks={mocks} addTypename={false}>
        <WAFDashboard />
      </MockedProvider>
    )

    await waitFor(() => {
      expect(screen.getByText('Well-Architected Framework')).toBeInTheDocument()
    })

    expect(screen.getByText('Findings')).toBeInTheDocument()
  })

  it('should filter findings by selected lens', async () => {
    render(
      <MockedProvider mocks={mocks} addTypename={false}>
        <WAFDashboard />
      </MockedProvider>
    )

    await waitFor(() => {
      expect(screen.getByText('Well-Architected Framework')).toBeInTheDocument()
    })
  })
})

