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

import { ASSETS_URL } from '../../consts/common';
import { Member } from './member';

afterEach(cleanup);
describe('<Member />', () => {
  it(`should render successfully`, () => {
    render(
      <Member
        fullName="John Snow"
        description="stark@gmail.com"
        label="Label"
        avatarProps={{
          initials: 'JS'
        }}
        icons={[
          {
            src: `${ASSETS_URL}/icons/icon_mail.svg`,
            clickHandler: noop
          },
          {
            src: `${ASSETS_URL}/icons/icon_phone.svg`,
            clickHandler: noop
          }
        ]}
      />
    );
  });

  it(`should render Member with tooltip`, async () => {
    const tooltipText = 'tooltipText';
    const { getByTestId, findByText } = render(
      <Member
        fullName="John Snow"
        description="stark@gmail.com"
        label="Label"
        avatarTooltipText={tooltipText}
        showAvatarTooltip={true}
        avatarProps={{
          initials: 'JS'
        }}
      />
    );
    const avatarElm = getByTestId('memberAvatar');
    fireEvent.mouseEnter(avatarElm);
    const tooltip = await findByText(tooltipText);
    expect(tooltip).toBeTruthy();
  });
});
