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

afterEach(cleanup);

const handleClick = jest.fn();

describe('<Input />', () => {
  it('should render successfully', () => {
    const { baseElement } = render(<Input />);
    expect(baseElement).toBeTruthy();
  });

  it('should render disabled password input', () => {
    const { baseElement } = render(<Input disabled toggleShowPassword />);
    expect(baseElement).toBeTruthy();
  });

  it('should render with password visibility toggler', () => {
    const { queryByTestId } = render(<Input toggleShowPassword />);
    const iconButton = queryByTestId('togglePasswordVisibilityIconButton');
    if (iconButton) {
      fireEvent.click(iconButton);
      fireEvent.mouseDown(iconButton);
    }
  });

  it('should render with endAdornmentButtonProps', () => {
    const { queryByTestId } = render(
      <Input
        endAdornmentButtonProps={{
          children: 'Lorem ipsum',
          onClick: handleClick
        }}
      />
    );
    queryByTestId('endAdornmentButton')?.click();
    expect(handleClick).toBeCalledTimes(1);
  });
});
