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

afterEach(cleanup);

const alertText = 'hello world';

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

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

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