"use strict";

var React = _interopRequireWildcard(require("react"));

var _enzyme = require("enzyme");

var _ = require("..");

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

/*
Copyright (c) 2018 Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
describe('EmoticonRating', function () {
  var example, onChangeSpy;
  beforeEach(function () {
    onChangeSpy = jest.fn();
    example = (0, _enzyme.shallow)(React.createElement(_.EmoticonRating, {
      value: 2,
      onChange: onChangeSpy
    }));
  });
  describe('Root', function () {
    it('applies correct accessibility attributes to the Root element', function () {
      expect(example).toHaveProp('tabIndex', 0);
      expect(example).toHaveProp('role', 'radiogroup');
    });
    it('removes previewIndex if mouse leaves', function () {
      example.simulate('mouseLeave');
      expect(example).toHaveState('previewIndex', undefined);
    });
  });
  describe('RatingItem', function () {
    it('applies correct props if item is active', function () {
      expect(example.childAt(0)).toMatchSnapshot();
    });
    it('applies correct props if item is selected', function () {
      example.childAt(1).simulate('focus');
      example.update();
      expect(example.childAt(1)).toMatchSnapshot();
    });
    it('calls onChange if item is clicked', function () {
      example.childAt(1).simulate('click');
      expect(onChangeSpy).toHaveBeenCalledWith({
        value: 2
      });
    });
    it('calls onChange if item is keyed with spacebar', function () {
      example.childAt(1).simulate('keyDown', {
        keyCode: 32
      });
      expect(onChangeSpy).toHaveBeenCalledWith({
        value: 2
      });
    });
    it('calls onChange if item is keyed with enter', function () {
      example.childAt(1).simulate('keyDown', {
        keyCode: 13
      });
      expect(onChangeSpy).toHaveBeenCalledWith({
        value: 2
      });
    });
    it('updates previewIndex if item is focused', function () {
      example.childAt(3).simulate('focus');
      expect(example).toHaveState('previewIndex', 4);
    });
    it('updates previewIndex if item is moused over', function () {
      example.childAt(3).simulate('mouseOver');
      expect(example).toHaveState('previewIndex', 4);
    });
    it('removes previewIndex if item is blured', function () {
      example.childAt(3).simulate('blur');
      expect(example).toHaveState('previewIndex', undefined);
    });
  });
});