"use strict";

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

var _enzyme = require("enzyme");

var _index = require("../index.js");

var _index2 = require("../../styles/index.js");

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

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, 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; }

describe('Stateless progress bar', function () {
  var wrapper,
      handlers = {};
  var allProps = {},
      mockFn;
  beforeEach(function () {
    mockFn = jest.fn();
    handlers = {
      getProgressLabel: mockFn
    };
    allProps = _objectSpread({
      value: 75
    }, handlers);
  });
  afterEach(function () {
    jest.restoreAllMocks();
    wrapper && wrapper.unmount();
  });
  test('should render component', function () {
    wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.ProgressBar, allProps));
    expect(wrapper).toMatchSnapshot('Component has correct render');
  });
  test('should render label', function () {
    allProps.showLabel = true;
    wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.ProgressBar, allProps));
    var label = wrapper.find(_index.StyledLabel);
    expect(label.length).toBe(1);
  });
  test.each([['BarProgress'], ['Label'], ['Bar'], ['Root']])('should render overridden subcomponent %s', function (subcomponentName) {
    var Subcomponent = (0, _index2.styled)('div', function () {
      return {};
    });
    Subcomponent.displayName = "Subcomponent";
    allProps.overrides = _defineProperty({}, subcomponentName, Subcomponent);
    allProps.showLabel = true;
    wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.ProgressBar, allProps));
    var instance = wrapper.find(Subcomponent);
    expect(instance.length).toBe(1);
  });
  describe('Custom progress label', function () {
    var customData = 'data-custom-label-for-progress-bar';
    beforeEach(function () {
      allProps.showLabel = true;
      allProps.getProgressLabel = jest.fn().mockImplementation(function () {
        return _react.default.createElement("div", _defineProperty({}, customData, true));
      });
      wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.ProgressBar, allProps));
    });
    test('should render custom label provided', function () {
      var customLabel = wrapper.find("[".concat(customData, "]"));
      expect(customLabel.length).toBe(1);
    });
  });
});