import { cleanup } from '@testing-library/react';
import { render } from '../../../utils/theme-render-wrapper';
import { Alert } from './alert';

afterEach(cleanup);

const alertText = 'hello world';

describe('<Alert />', () => {
  it(`Should render successfully`, () => {
    const { baseElement } = render(<Alert children={alertText} />);
    expect(baseElement).toBeTruthy();
  });

  it(`Should render alert and emit onClose function`, () => {
    const onClose = jest.fn();
    const { container } = render(<Alert onClose={onClose}>{alertText}</Alert>);

    const buttonEl = container.querySelector('button');
    buttonEl?.click();
    expect(onClose).toHaveBeenCalled();
  });
});
