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

import { ToggleButton } from './index';

const changeFn = jest.fn();

afterEach(() => {
  changeFn.mockClear();
  cleanup();
});

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

  it('should render disabled toggle button', () => {
    const { queryByTestId } = render(
      <ToggleButton disabled onChange={changeFn} onClick={changeFn} value="check" />
    );
    queryByTestId('toggleButton')?.click();
    expect(changeFn).not.toHaveBeenCalled();
  });

  it('should render selected toggle button', () => {
    const { queryByTestId } = render(
      <ToggleButton selected onChange={changeFn} onClick={changeFn} value="check" />
    );
    queryByTestId('toggleButton')?.click();
    expect(changeFn).toHaveBeenCalledTimes(2);
  });
});
