"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _react = _interopRequireDefault(require("react"));

var _enzyme = require("enzyme");

var _ = require(".");

var _Toggle = _interopRequireDefault(require("../../../../components/Toggle"));

describe('RefinementList', function () {
  var node;
  var props;
  beforeEach(function () {
    props = {
      attribute: 'subdomain',
      items: [{
        isRefined: true,
        label: 'project 1',
        value: 'test'
      }, {
        isRefined: false,
        label: 'project 2',
        value: 'test'
      }, {
        isRefined: false,
        label: 'project 3',
        value: 'test'
      }, {
        isRefined: false,
        label: 'project 4',
        value: 'test'
      }, {
        isRefined: true,
        label: 'project 5',
        value: 'test'
      }, {
        isRefined: false,
        label: 'project 6',
        value: 'test'
      }, {
        isRefined: false,
        label: 'project 7',
        value: 'test'
      }, {
        isRefined: false,
        label: 'project 8',
        value: 'test'
      }, {
        isRefined: false,
        label: 'project 9',
        value: 'test'
      }, {
        isRefined: false,
        label: 'project 10',
        value: 'test'
      }, {
        isRefined: false,
        label: 'project 11',
        value: 'test'
      }],
      showMore: false,
      onBlur: jest.fn(),
      onRefine: jest.fn(),
      refine: jest.fn()
    };
    node = (0, _enzyme.shallow)( /*#__PURE__*/_react["default"].createElement(_.CustomRefinementList, props));
  });
  it('displays the <RefinementList> element', function () {
    expect(node.find('details')).toHaveLength(1);
  });
  it('should handle blur events', function () {
    var li = node.find('li').first();
    li.simulate('keydown', {
      currentTarget: {
        matches: jest.fn().mockReturnValue(':last-of-type')
      },
      key: 'Tab',
      shiftKey: false
    });
    expect(props.onBlur).toHaveBeenCalled();
  });
  it('should handle toggle events', function () {
    var toggle = node.find(_Toggle["default"]);
    toggle.first().simulate('change');
    expect(props.refine).toHaveBeenCalled();
    expect(props.onRefine).toHaveBeenCalled();
  });
});