import React from 'react';
import { fireEvent } from '@testing-library/react';

import renderWithTheme from '../../../testUtils/renderWithTheme';

import Empty from '..';

describe('rendering', () => {
  it('shows text & extra', () => {
    const { getByText } = renderWithTheme(
      <Empty text="A text" extra={<button type="button">A button</button>} />
    );
    expect(getByText('A text')).toBeInTheDocument();
    expect(getByText('A button')).toBeInTheDocument();
  });
});

describe('interaction', () => {
  it('allows to interact on extra section', () => {
    const onClick = jest.fn();
    const { getByText } = renderWithTheme(
      <Empty
        text="A text"
        extra={
          <button type="button" onClick={(): void => onClick('A param')}>
            A button
          </button>
        }
      />
    );
    fireEvent.click(getByText('A button'));
    expect(onClick).toHaveBeenCalledTimes(1);
    expect(onClick).toHaveBeenCalledWith('A param');
  });
});
