"use strict";

var _jsxRuntime = require("react/jsx-runtime");

var _enzyme = require("enzyme");

var _ColorPicker = _interopRequireDefault(require("../ColorPicker"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

var activate = function activate(slider) {
  return slider.simulate('keyup', {
    keyCode: 13
  });
};

var keyDown = function keyDown(keyCode) {
  return function (slider) {
    return slider.simulate('keydown', {
      keyCode: keyCode
    });
  };
};

var leftKeyDown = keyDown(37);
var rightKeyDown = keyDown(39);
describe('ColorPicker', function () {
  test('should change value when selecting a different color', function () {
    var handleChange = jest.fn();
    var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_ColorPicker["default"], {
      onChange: handleChange,
      value: "pink",
      children: ['red', 'blue', 'yellow', 'pink']
    })); // first extend color picker

    subject.find('SwatchButton').simulate('click'); // now click on blue color. it is the third SwatchButton in the component now

    subject.find('SwatchButton').at(2).simulate('click');
    var expected = 'blue';
    var actual = handleChange.mock.calls[0][0].value;
    expect(actual).toBe(expected);
  });
  test('should emit an onChange event when changing hue', function () {
    var handleChange = jest.fn();
    var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_ColorPicker["default"], {
      onChange: handleChange,
      value: "pink",
      children: ['red', 'blue', 'yellow', 'pink']
    })); // first extend color picker

    subject.find('SwatchButton').simulate('click'); // click on the "More" button

    subject.find('Button[aria-label=\'More\']').simulate('click'); // focus slider and move it with right key

    activate(subject.find('Cell[aria-label=\'Hue\'] Slider'));
    rightKeyDown(subject.find('Cell[aria-label=\'Hue\'] Slider'));
    var expected = 1;
    var actual = handleChange.mock.calls.length;
    expect(actual).toBe(expected);
  });
  test('should emit an onChange event when changing saturation', function () {
    var handleChange = jest.fn();
    var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_ColorPicker["default"], {
      onChange: handleChange,
      value: "pink",
      children: ['red', 'blue', 'yellow', 'pink']
    })); // first extend color picker

    subject.find('SwatchButton').simulate('click'); // click on the "More" button

    subject.find('Button[aria-label=\'More\']').simulate('click'); // focus slider and move it with left key

    activate(subject.find('Cell[aria-label=\'Saturation\'] Slider'));
    leftKeyDown(subject.find('Cell[aria-label=\'Saturation\'] Slider'));
    var expected = 1;
    var actual = handleChange.mock.calls.length;
    expect(actual).toBe(expected);
  });
  test('should emit an onChange event when changing lightness', function () {
    var handleChange = jest.fn();
    var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_ColorPicker["default"], {
      onChange: handleChange,
      value: "pink",
      children: ['red', 'blue', 'yellow', 'pink']
    })); // first extend color picker

    subject.find('SwatchButton').simulate('click'); // click on the "More" button

    subject.find('Button[aria-label=\'More\']').simulate('click'); // focus slider and move it with right key

    activate(subject.find('Cell[aria-label=\'Lightness\'] Slider'));
    rightKeyDown(subject.find('Cell[aria-label=\'Lightness\'] Slider'));
    var expected = 1;
    var actual = handleChange.mock.calls.length;
    expect(actual).toBe(expected);
  });
  test('should not extend palette when disabled', function () {
    var handleChange = jest.fn();
    var subject = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_ColorPicker["default"], {
      disabled: true,
      onChange: handleChange,
      value: "pink",
      children: ['red', 'blue', 'yellow', 'pink']
    })); // extend color picker

    subject.find('SwatchButton').simulate('click'); // there is only one SwatchButton. It means the palette is not extended

    expect(subject.find('SwatchButton').length).toBe(1);
  });
});