import * as React from 'react';
import {
  render,
  screen
} from '@testing-library/react';
import '@testing-library/jest-dom';
import userEvent from '@testing-library/user-event';
import * as CheckControlBase from '@tesseract-design/web-base-checkcontrol';
import { RadioTickBox } from '.';

jest.mock('@tesseract-design/web-base-checkcontrol');

describe('RadioTickBox', () => {
  it('should render a radio button', () => {
    render(
      <RadioTickBox />
    );
    const checkbox = screen.getByRole('radio');
    expect(checkbox).toBeInTheDocument();
  });

  it('should render a compact tick box', () => {
    render(
      <RadioTickBox
        compact
      />
    );

    expect(CheckControlBase.CheckIndicatorArea).toBeCalledWith(expect.objectContaining({
      compact: true,
    }));
  });

  it('should render a block tick box', () => {
    render(
      <RadioTickBox
        block
      />
    );

    expect(CheckControlBase.ClickAreaWrapper).toBeCalledWith(expect.objectContaining({
      block: true,
    }));
  });

  it('should render a subtext', () => {
    render(
      <RadioTickBox
        subtext="subtext"
      />
    );
    const subtext: HTMLElement = screen.getByTestId('subtext');
    expect(subtext).toBeInTheDocument();
  });

  it('should handle click events', () => {
    const onClick = jest.fn();
    render(
      <RadioTickBox
        onClick={onClick}
      />
    );
    const radio: HTMLInputElement = screen.getByRole('radio');
    userEvent.click(radio);
    expect(onClick).toBeCalled();
  });

  it('should handle change events', () => {
    const onChange = jest.fn();
    render(
      <RadioTickBox
        onChange={onChange}
      />
    );
    const radio: HTMLInputElement = screen.getByRole('radio');
    userEvent.click(radio);
    expect(onChange).toBeCalled();
  });
});
