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

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

  it('should render the page', async () => {
    renderWithRouter(<UserManagementPage />);
    
    // 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: /User Management/i });
      expect(pageTitle).toBeInTheDocument();
    });
  });

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

    await waitFor(() => {
      // Check if users table or list is displayed
      const usersSection = screen.queryByText(/Users/i);
      if (usersSection) {
        expect(usersSection).toBeInTheDocument();
      }
    }, { timeout: 5000 });
  });
});

