import { describe, it, expect, vi, beforeEach } from 'vitest';
import { screen, waitFor } from '../../../test/utils/test-utils';
import { renderWithRouter } from '../../../test/utils/test-utils';
import ServiceManagementPage from '../ServiceManagementPage';

describe('Admin ServiceManagementPage', () => {
  beforeEach(() => {
    vi.clearAllMocks();
  });

  it('should render the page', async () => {
    renderWithRouter(<ServiceManagementPage />);
    
    // Wait for loading to finish
    await waitFor(() => {
      expect(screen.queryByText(/Loading/i)).not.toBeInTheDocument();
    }, { timeout: 5000 });

    // Check if page content is displayed (use more specific query)
    await waitFor(() => {
      const pageTitle = screen.queryByRole('heading', { name: /Service Management/i });
      expect(pageTitle).toBeInTheDocument();
    });
  });

  it('should fetch and display services', async () => {
    renderWithRouter(<ServiceManagementPage />);

    await waitFor(() => {
      // Check if services are displayed
      const servicesSection = screen.queryByText(/Services/i);
      if (servicesSection) {
        expect(servicesSection).toBeInTheDocument();
      }
    }, { timeout: 5000 });
  });
});

