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

describe('Staff BookingManagementPage', () => {
  beforeEach(() => {
    vi.clearAllMocks();
  });

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

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

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

