"use strict";

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

var _enzyme = require("enzyme");

var _Dropdown = _interopRequireWildcard(require("../Dropdown"));

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

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

var children = ['option1', 'option2', 'option3'];
var title = 'Dropdown select';
describe('Dropdown', function () {
  test('should have `title`', function () {
    var dropDown = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Dropdown.DropdownBase, {
      title: title,
      children: children
    }));
    var expected = title;
    var actual = dropDown.find('.text').text();
    expect(actual).toBe(expected);
  });
  test('should have `title` that reflects `selected` option', function () {
    var selectedIndex = 1;
    var dropDown = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Dropdown.DropdownBase, {
      selected: selectedIndex,
      title: title,
      children: children
    }));
    var expected = children[selectedIndex];
    var actual = dropDown.find('.text').text();
    expect(actual).toBe(expected);
  });
  test('should apply id to dropdown', function () {
    var dropDown = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Dropdown.DropdownBase, {
      id: "drop",
      children: children
    }));
    var expected = 'drop'; // NOTE: Using `#id` as a find will pass because Enzyme will find the id prop and use that
    // instead of what is rendered into the DOM.

    var actual = dropDown.getDOMNode().id;
    expect(actual).toBe(expected);
  });
  test('should apply aria label to `title`', function () {
    var dropDown = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Dropdown.DropdownBase, {
      title: title,
      "aria-label": "Please select",
      children: children
    }));
    var expected = 'Please select';
    var actual = dropDown.find('Item.dropdown').prop('aria-label');
    expect(actual).toBe(expected);
  });
  test('should be disabled when there are no `children`', function () {
    var dropDown = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Dropdown.DropdownBase, {
      title: title,
      children: []
    }));
    var expected = true;
    var actual = dropDown.find('Item.dropdown').prop('disabled');
    expect(actual).toBe(expected);
  });
  test('should update when children are added', function () {
    var dropDown = (0, _enzyme.shallow)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Dropdown.DropdownBase, {
      title: title,
      children: children
    }));
    var updatedChildren = children.concat('option4', 'option5');
    dropDown.setProps({
      children: updatedChildren
    });
    var expected = 5;
    var actual = dropDown.find('.group').children().length;
    expect(actual).toBe(expected);
  });
  test('should set the `role` of items to "checkbox"', function () {
    var dropDown = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Dropdown["default"], {
      open: true,
      title: title,
      children: ['item1']
    }));
    var expected = 'checkbox';
    var actual = dropDown.find('.dropdownList Item').prop('role');
    expect(actual).toBe(expected);
  });
  test('should set the `aria-checked` state of the `selected` item', function () {
    var dropDown = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Dropdown["default"], {
      open: true,
      title: title,
      selected: 0,
      children: ['item']
    }));
    var expected = true;
    var actual = dropDown.find('.dropdownList Item').prop('aria-checked');
    expect(actual).toBe(expected);
  });
  test('should pass through members of child objects to props for each item', function () {
    var dropDown = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Dropdown["default"], {
      open: true,
      title: title,
      children: [{
        disabled: true,
        children: 'child',
        key: 'item-0'
      }]
    }));
    var expected = true;
    var actual = dropDown.find('.dropdownList Item').prop('disabled');
    expect(actual).toBe(expected);
  });
  test('should allow members in child object to override injected aria values', function () {
    var dropDown = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Dropdown["default"], {
      open: true,
      title: title,
      selected: 0,
      children: [{
        disabled: true,
        children: 'child',
        key: 'item-0',
        role: 'button',
        'aria-checked': false
      }]
    }));
    var expected = {
      role: 'button',
      'aria-checked': false
    };
    var actual = {
      role: dropDown.find('.dropdownList Item').prop('role'),
      'aria-checked': dropDown.find('.dropdownList Item').prop('aria-checked')
    };
    expect(actual).toMatchObject(expected);
  });
});