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

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

  it('renders the title and subtitle', () => {
    wrap(<AdminPageHeader title="Backoffice" subtitle="Run the marketplace" />);
    expect(screen.getByRole('heading', { name: 'Backoffice' })).toBeInTheDocument();
    expect(screen.getByText('Run the marketplace')).toBeInTheDocument();
  });

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

  it('omits the subtitle when not given', () => {
    wrap(<AdminPageHeader title="T" />);
    expect(screen.getByRole('heading', { name: 'T' })).toBeInTheDocument();
  });
});
