"use strict";

require("@testing-library/jest-dom");
var _react = require("@testing-library/react");
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
var _DatePicker = _interopRequireWildcard(require("../DatePicker"));
var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } // Note: Tests pass 'locale' because there's no I18nDecorator to provide a value via context and
// otherwise, nothing renders in the label.
describe('DatePicker', function () {
  test('should set the value to the current date when no value is provided', function () {
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_DatePicker["default"], {
      locale: "en-US"
    }));
    var currentDate = new Date();
    var currentYear = currentDate.getFullYear();
    var currentMonth = currentDate.getMonth() + 1;
    var currentDay = currentDate.getDate();
    var datePickerYear = _react.screen.getAllByRole('spinbutton')[2].children.item(1);
    var datePickerMonth = _react.screen.getAllByRole('spinbutton')[0].children.item(1);
    var datePickerDay = _react.screen.getAllByRole('spinbutton')[1].children.item(1);
    expect(datePickerYear).toHaveTextContent(currentYear);
    expect(datePickerMonth).toHaveTextContent(currentMonth);
    expect(datePickerDay).toHaveTextContent(currentDay);
  });
  test('should emit an onChange event when changing the day', /*#__PURE__*/_asyncToGenerator(function* () {
    var handleChange = jest.fn();
    var user = _userEvent["default"].setup();
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_DatePicker["default"], {
      locale: "en-US",
      onChange: handleChange,
      value: new Date(2000, 6, 15)
    }));
    yield user.click(_react.screen.getByLabelText('15 day decrease the value'));
    expect(handleChange).toHaveBeenCalled();
  }));
  test('should emit an onChange event when changing the month', /*#__PURE__*/_asyncToGenerator(function* () {
    var handleChange = jest.fn();
    var user = _userEvent["default"].setup();
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_DatePicker["default"], {
      locale: "en-US",
      onChange: handleChange,
      value: new Date(2000, 6, 15)
    }));
    yield user.click(_react.screen.getByLabelText('7 month decrease the value'));
    expect(handleChange).toHaveBeenCalled();
  }));
  test('should emit an onChange event when changing the year', /*#__PURE__*/_asyncToGenerator(function* () {
    var handleChange = jest.fn();
    var user = _userEvent["default"].setup();
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_DatePicker["default"], {
      locale: "en-US",
      onChange: handleChange,
      value: new Date(2000, 6, 15)
    }));
    yield user.click(_react.screen.getByLabelText('2000 year decrease the value'));
    expect(handleChange).toHaveBeenCalled();
  }));
  test('should accept a JavaScript Date for its value prop', function () {
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_DatePicker["default"], {
      locale: "en-US",
      value: new Date(2000, 0, 1)
    }));
    var year = _react.screen.getAllByRole('spinbutton')[2];
    var expected = '2000';
    expect(year).toHaveTextContent(expected);
  });
  test('should set "dayAriaLabel" to day picker', function () {
    var label = 'custom day aria-label';
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_DatePicker["default"], {
      dayAriaLabel: label,
      locale: "en-US",
      value: new Date(2000, 0, 1)
    }));
    var dayPicker = _react.screen.getByLabelText(label);
    var expected = '1';
    expect(dayPicker).toHaveTextContent(expected);
  });
  test('should set "monthAriaLabel" to month picker', function () {
    var label = 'custom month aria-label';
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_DatePicker["default"], {
      locale: "en-US",
      monthAriaLabel: label,
      value: new Date(2000, 0, 1)
    }));
    var monthPicker = _react.screen.getByLabelText(label);
    var expected = '1';
    expect(monthPicker).toHaveTextContent(expected);
  });
  test('should set "yearAriaLabel" to year picker', function () {
    var label = 'custom year aria-label';
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_DatePicker["default"], {
      locale: "en-US",
      value: new Date(2000, 0, 1),
      yearAriaLabel: label
    }));
    var yearPicker = _react.screen.getByLabelText(label);
    var expected = '2000';
    expect(yearPicker).toHaveTextContent(expected);
  });
  describe('#dateToLocaleString', function () {
    test('method should convert date to a localized string', function () {
      var date = new Date(2000, 0, 1);
      var expected = 'Saturday, January 1, 2000';
      var actual = (0, _DatePicker.dateToLocaleString)(date);
      expect(actual).toBe(expected);
    });
    test('method should return `null` for an invalid date', function () {
      var actual = (0, _DatePicker.dateToLocaleString)(null);
      expect(actual).toBeNull();
    });
  });
});