import '@testing-library/jest-dom/extend-expect';
import React from 'react';
import { render, fireEvent } from '@testing-library/react';
import { ButtonGroup, ButtonGroupItem } from '.';
import { COMPONENT_SIZE } from '../Forms';
describe('ButtonGroup', function () {
  var wrapper;
  var oneClickSpy;
  var twoClickSpy;
  var threeClickSpy;
  var consoleWarnSpy;
  beforeEach(function () {
    oneClickSpy = jest.fn();
    twoClickSpy = jest.fn();
    threeClickSpy = jest.fn();
    consoleWarnSpy = jest.spyOn(global.console, 'warn');
  });
  describe('default props', function () {
    beforeEach(function () {
      wrapper = render( /*#__PURE__*/React.createElement(ButtonGroup, null, /*#__PURE__*/React.createElement(ButtonGroupItem, {
        onClick: oneClickSpy
      }, "One"), /*#__PURE__*/React.createElement(ButtonGroupItem, {
        onClick: twoClickSpy
      }, "Two"), /*#__PURE__*/React.createElement(ButtonGroupItem, {
        onClick: threeClickSpy,
        isDisabled: true
      }, "Three")));
    });
    it('should apply the `role` attribute', function () {
      expect(wrapper.getByTestId('buttongroup')).toHaveAttribute('role', 'group');
    });
    it('should not warn the consumer about specifying sizes for each item', function () {
      expect(consoleWarnSpy).not.toHaveBeenCalled();
    });
    it('should render a button group wrapper', function () {
      expect(wrapper.getByTestId('buttongroup')).toBeInTheDocument();
    });
    it('should render 3 buttons', function () {
      expect(wrapper.getAllByTestId('button')).toHaveLength(3);
    });
    it('should default the type to "button"', function () {
      var buttons = wrapper.getAllByTestId('button');
      buttons.forEach(function (button) {
        return expect(button).toHaveAttribute('type', 'button');
      });
    });
    describe('when a button is clicked', function () {
      var buttons;
      beforeEach(function () {
        buttons = wrapper.getAllByTestId('button');
        fireEvent(buttons[1], new MouseEvent('click', {
          bubbles: true,
          cancelable: true
        }));
      });
      it('should notify which button was clicked', function () {
        expect(oneClickSpy).not.toHaveBeenCalled();
        expect(twoClickSpy).toHaveBeenCalledTimes(1);
        expect(threeClickSpy).not.toHaveBeenCalled();
      });
    });
  });
  describe('provide custom className', function () {
    beforeEach(function () {
      wrapper = render( /*#__PURE__*/React.createElement(ButtonGroup, {
        className: "Scooby"
      }, /*#__PURE__*/React.createElement(ButtonGroupItem, {
        onClick: oneClickSpy
      }, "One"), /*#__PURE__*/React.createElement(ButtonGroupItem, {
        onClick: twoClickSpy
      }, "Two"), /*#__PURE__*/React.createElement(ButtonGroupItem, {
        onClick: threeClickSpy,
        isDisabled: true
      }, "Three")));
    });
    it('should render a button group wrapper', function () {
      expect(wrapper.getByTestId('buttongroup')).toHaveClass('Scooby');
    });
  });
  describe('provide arbitrary props', function () {
    beforeEach(function () {
      wrapper = render( /*#__PURE__*/React.createElement(ButtonGroup, {
        "data-arbitrary": "arbitrary-buttongroup"
      }, /*#__PURE__*/React.createElement(ButtonGroupItem, {
        "data-arbitrary": "arbitrary-button",
        onClick: oneClickSpy
      }, "One"), /*#__PURE__*/React.createElement(ButtonGroupItem, {
        onClick: twoClickSpy
      }, "Two"), /*#__PURE__*/React.createElement(ButtonGroupItem, {
        onClick: threeClickSpy,
        isDisabled: true
      }, "Three")));
    });
    it('should spread arbitrary props to the button group', function () {
      expect(wrapper.getByTestId('buttongroup')).toHaveAttribute('data-arbitrary', 'arbitrary-buttongroup');
    });
    it('should spread arbitrary props to the button group item', function () {
      expect(wrapper.getAllByTestId('button')[0]).toHaveAttribute('data-arbitrary', 'arbitrary-button');
    });
  });
  describe('when a different size is provided for each item', function () {
    beforeEach(function () {
      wrapper = render( /*#__PURE__*/React.createElement(ButtonGroup, {
        size: COMPONENT_SIZE.FORMS
      }, /*#__PURE__*/React.createElement(ButtonGroupItem, {
        onClick: oneClickSpy,
        size: COMPONENT_SIZE.SMALL
      }, "One"), /*#__PURE__*/React.createElement(ButtonGroupItem, {
        onClick: twoClickSpy,
        size: COMPONENT_SIZE.FORMS
      }, "Two")));
    });
    it('should warn the consumer about specifying sizes for each item', function () {
      expect(consoleWarnSpy).toHaveBeenCalledTimes(2);
      expect(consoleWarnSpy).toHaveBeenCalledWith('WARN - MODDS - Prop `size` on `ButtonGroupItem` will be replaced by `size` from `ButtonGroup`');
    });
  });
});