// jshint esversion: 6
'use strict';

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

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

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

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

var _propTypes = _interopRequireDefault(require("prop-types"));

var _enzyme = require("../../../build/enzyme");

var _CheckboxGroup = require("./CheckboxGroup");

var _Checkbox = require("./Checkbox");

describe('CheckboxGroup', function () {
  var cbGroup = function cbGroup(props) {
    var values = props.values,
        rest = (0, _objectWithoutPropertiesLoose2.default)(props, ["values"]);
    return _react.default.createElement(_CheckboxGroup.CheckboxGroup, (0, _extends2.default)({
      name: "group",
      value: values
    }, rest), Object.keys(values).map(function (key) {
      return _react.default.createElement(_Checkbox.Checkbox, {
        key: key,
        name: key
      });
    }));
  };

  cbGroup.propTypes = {
    values: _propTypes.default.object.isRequired
  };
  describe('returns main checkbox value (based on children)', function () {
    it('true if all nested checkboxes have truthy value', function () {
      var values = {
        a: true,
        b: true
      };
      var wrapper = (0, _enzyme.mount)(cbGroup({
        values: values
      }));
      expect(wrapper.instance().getMainCheckboxValue()).toBe(true);
    });
    it('false if all nested checkboxes have falsy value', function () {
      var values = {
        a: false,
        b: false
      };
      var wrapper = (0, _enzyme.mount)(cbGroup({
        values: values
      }));
      expect(wrapper.instance().getMainCheckboxValue()).toBe(false);
    });
    it('null if nested checkboxes have both truthy and false value', function () {
      var values = {
        a: true,
        b: false
      };
      var wrapper = (0, _enzyme.mount)(cbGroup({
        values: values
      }));
      expect(wrapper.instance().getMainCheckboxValue()).toBe(null);
    });
  });
});