"use strict";

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

var _enzyme = _interopRequireWildcard(require("enzyme"));

var _enzymeAdapterReact = _interopRequireDefault(require("enzyme-adapter-react-16"));

var uut = _interopRequireWildcard(require("../DatePickerButton"));

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

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

_enzyme.default.configure({
  adapter: new _enzymeAdapterReact.default()
});

describe('DatePicker', function () {
  test('shows all four dates when there are two multi-day ranges', function () {
    expect((0, _enzyme.mount)(_react.default.createElement(uut.DateRangeDisplay, {
      locale: "en",
      ranges: [['2018-01-01', '2018-01-03'], ['2019-03-01', '2019-06-03']]
    })).text()).toMatch(/^Jan 1, 2018...Jan 3, 2018[^a-zA-Z]*Mar 1, 2019...Jun 3, 2019$/);
  });
  test('shows two dates when there are two one-day ranges', function () {
    expect((0, _enzyme.mount)(_react.default.createElement(uut.DateRangeDisplay, {
      locale: "en",
      ranges: [['2018-01-01', '2018-01-01'], ['2019-03-01', '2019-03-01']]
    })).text()).toMatch(/^Jan 1, 2018[^a-zA-Z]*Mar 1, 2019$/);
  });
  test('shows both dates when there is one multi-day range', function () {
    expect((0, _enzyme.mount)(_react.default.createElement(uut.DateRangeDisplay, {
      locale: "en",
      ranges: [['2018-01-01', '2018-01-03']]
    })).text()).toMatch(/^Jan 1, 2018...Jan 3, 2018$/);
  });
  test('shows one date when there is one single-day range', function () {
    expect((0, _enzyme.mount)(_react.default.createElement(uut.DateRangeDisplay, {
      locale: "en",
      ranges: [['2018-01-01', '2018-01-01']]
    })).text()).toMatch(/^Jan 1, 2018$/);
  });
  test('localizes dates correctly for ranges', function () {
    var expectedLocale = 'de';
    var actualLocale = [];

    var formatter = function formatter(locale) {
      return function () {
        actualLocale.push(locale);
        return '';
      };
    };

    var DateRangeDisplay = uut.dateRangeDisplayFactory(formatter);
    (0, _enzyme.mount)(_react.default.createElement(DateRangeDisplay, {
      locale: expectedLocale,
      ranges: [['2018-03-01', '2018-03-02']]
    }));
    expect(actualLocale).toEqual([expectedLocale, expectedLocale]);
  });
  test('localizes dates correctly for single day', function () {
    var expectedLocale = 'de';
    var actualLocale = [];

    var formatter = function formatter(locale) {
      return function () {
        actualLocale.push(locale);
        return '';
      };
    };

    var DateRangeDisplay = uut.dateRangeDisplayFactory(formatter);
    (0, _enzyme.mount)(_react.default.createElement(DateRangeDisplay, {
      locale: expectedLocale,
      ranges: [['2018-03-01', '2018-03-01']]
    }));
    expect(actualLocale).toEqual([expectedLocale]);
  });
});