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

afterEach(cleanup);

const alertText = 'hello world';

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

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

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