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

import { ASSETS_URL } from '../../../consts/common';
import { DialogTitle } from './dialog-title';

afterEach(cleanup);

const handleClose = jest.fn();

describe('<DialogTitle />', () => {
  it(`Should render with onClose prop`, () => {
    const { queryByTestId } = render(<DialogTitle onClose={handleClose}>Modal Title</DialogTitle>);

    const closeEl = queryByTestId('close');
    closeEl?.click();

    expect(handleClose).toHaveBeenCalled();
  });

  it(`Should render without onClose prop`, () => {
    render(<DialogTitle>Modal Title</DialogTitle>);
  });

  it(`Should render with icon and title`, () => {
    const { container } = render(
      <DialogTitle
        icon={{
          src: `${ASSETS_URL}/icons/icon_database.svg`
        }}
        onClose={handleClose}
      >
        Modal Title
      </DialogTitle>
    );

    const iconEl = container.getElementsByTagName('svg');
    expect(iconEl).toBeTruthy();
  });
});
