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

import { ASSETS_URL } from '../../consts/common';
import { TextWithIcon } from './text-with-icon';

const src = `${ASSETS_URL}/icons/icon_linux.svg`;
const text = 'text';

describe('<TextWithIcon />', () => {
  it('should render successfully and pass text and src', () => {
    const { queryByText } = render(<TextWithIcon text={text} src={src} />);

    const textEl = queryByText(text);
    expect(textEl?.textContent).toBe(text);
  });

  it('should truncate long text and show tooltip', async () => {
    const { queryByText, getByTestId, findByText } = render(
      <TextWithIcon text={text} src={src} truncateText={true} width={100} />
    );

    const textEl = getByTestId('TextWithIcon');
    fireEvent.mouseEnter(textEl);
    const tooltip = await findByText(text);
    expect(tooltip).toBeTruthy();
  });
});
