// src/pages/admin/AdminPage.test.tsx
import React from 'react';
import { render, screen } from '@testing-library/react';
import { describe, it, expect, vi } from 'vitest';
import { MemoryRouter } from 'react-router-dom';
import { AdminPage } from './AdminPage';

// Mock the child SystemCheck component to isolate the test
vi.mock('./components/SystemCheck', () => ({
  SystemCheck: () => <div data-testid="system-check-mock">System Health Checks</div>,
}));

// Mock the logger to prevent console output during tests
vi.mock('../../services/logger', () => ({
  logger: {
    info: vi.fn(),
    warn: vi.fn(),
    error: vi.fn(),
    debug: vi.fn(),
  },
}));

// Helper function to render the component within a router context
const renderWithRouter = () => {
  return render(
    <MemoryRouter>
      <AdminPage />
    </MemoryRouter>
  );
};

describe('AdminPage', () => {
  it('should render the main heading and description', () => {
    renderWithRouter();
    expect(screen.getByRole('heading', { name: /admin dashboard/i })).toBeInTheDocument();
    expect(screen.getByText('Tools and system health checks.')).toBeInTheDocument();
  });

  it('should render navigation links to other admin sections', () => {
    renderWithRouter();

    const correctionsLink = screen.getByRole('link', { name: /review corrections/i });
    expect(correctionsLink).toBeInTheDocument();
    expect(correctionsLink).toHaveAttribute('href', '/admin/corrections');

    const statsLink = screen.getByRole('link', { name: /view statistics/i });
    expect(statsLink).toBeInTheDocument();
    expect(statsLink).toHaveAttribute('href', '/admin/stats');

    const backLink = screen.getByRole('link', { name: /back to main app/i });
    expect(backLink).toBeInTheDocument();
    expect(backLink).toHaveAttribute('href', '/');
  });

  it('should render the SystemCheck component', () => {
    renderWithRouter();
    expect(screen.getByTestId('system-check-mock')).toBeInTheDocument();
    expect(screen.getByText('System Health Checks')).toBeInTheDocument();
  });
});