import { render, screen } from '@testing-library/react';
import { ThemeProvider } from '../../../theme';
import PageHeader from './PageHeader';

describe('<PageHeader/>', () => {
  const wrap = (ui: React.ReactNode) => render(<ThemeProvider>{ui}</ThemeProvider>);

  it('renders the title and subtitle', () => {
    wrap(<PageHeader title="Patients" subtitle="Manage your family" />);
    expect(screen.getByRole('heading', { name: 'Patients' })).toBeInTheDocument();
    expect(screen.getByText('Manage your family')).toBeInTheDocument();
  });

  it('renders the actions slot when provided', () => {
    wrap(<PageHeader title="T" actions={<button>Do</button>} />);
    expect(screen.getByRole('button', { name: 'Do' })).toBeInTheDocument();
  });

  it('omits the back button when backTo is not given', () => {
    wrap(<PageHeader title="T" />);
    expect(screen.queryByRole('link')).not.toBeInTheDocument();
  });

  it('renders a back link when backTo is given', () => {
    wrap(<PageHeader title="T" backTo="/patients" backLabel="Back" />);
    expect(screen.getByRole('link')).toHaveAttribute('href', '/patients');
  });
});
