"use strict";

require("core-js/modules/es.symbol");

require("core-js/modules/es.symbol.description");

require("core-js/modules/es.symbol.iterator");

require("core-js/modules/es.array.filter");

require("core-js/modules/es.array.find");

require("core-js/modules/es.array.for-each");

require("core-js/modules/es.array.iterator");

require("core-js/modules/es.object.define-properties");

require("core-js/modules/es.object.define-property");

require("core-js/modules/es.object.get-own-property-descriptor");

require("core-js/modules/es.object.get-own-property-descriptors");

require("core-js/modules/es.object.keys");

require("core-js/modules/es.object.to-string");

require("core-js/modules/es.string.iterator");

require("core-js/modules/web.dom-collections.for-each");

require("core-js/modules/web.dom-collections.iterator");

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

var _enzyme = require("enzyme");

var _ = _interopRequireDefault(require("."));

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

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var values = {
  a: true,
  b: null,
  c: ['1', '2'],
  d: {
    d1: 'nested'
  }
};

var noop = function noop() {};

var context = {
  ffGetValue: function ffGetValue() {
    return values;
  },
  ffFullName: function ffFullName() {
    return [];
  },
  ffOnChange: noop,
  formSubscription: {
    subscribe: noop,
    unsubscribe: noop
  }
};
describe('components/WithValue', function () {
  test('should render the result of the render function', function () {
    var wrapper = (0, _enzyme.shallow)(_react["default"].createElement(_["default"], null, function () {
      return _react["default"].createElement("h1", null, "Test");
    }), {
      context: context
    });
    expect(wrapper.find('h1').length).toBe(1);
  });
  test('should pass the value into the render function', function () {
    var render = jest.fn(function () {
      return null;
    });
    (0, _enzyme.shallow)(_react["default"].createElement(_["default"], null, render), {
      context: context
    });
    expect(render.mock.calls[0][0]).toEqual(values);
    (0, _enzyme.shallow)(_react["default"].createElement(_["default"], {
      name: "c"
    }, render), {
      context: context
    });
    expect(render.mock.calls[1][0]).toEqual(values.c);
  });
  test('should pass a working onChange into the render function', function () {
    var render = jest.fn(function () {
      return null;
    });
    var ffOnChange = jest.fn();
    (0, _enzyme.shallow)(_react["default"].createElement(_["default"], null, render), {
      context: _objectSpread({}, context, {
        ffOnChange: ffOnChange
      })
    });
    expect(_typeof(render.mock.calls[0][1])).toBe('object');
    expect(_typeof(render.mock.calls[0][1].onChange)).toBe('function');
    var onChange = render.mock.calls[0][1].onChange;
    onChange({
      a: false
    });
    expect(ffOnChange).toHaveBeenCalledTimes(1);
    expect(ffOnChange.mock.calls[0][0].target).toEqual({
      name: [],
      value: {
        a: false
      }
    });
  });
});