UNPKG

wix-style-react

Version:
620 lines (520 loc) • 21.3 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.calendarUniDriverFactory = void 0; var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _unidriver = require("../../test/utils/unidriver"); var _DropdownLayoutUni = require("../DropdownLayout/DropdownLayout.uni.driver"); var _IconButtonUni = require("../IconButton/IconButton.uni.driver"); 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(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } var calendarUniDriverFactory = function calendarUniDriverFactory(base) { var getCalendar = function getCalendar() { return base.$('.DayPicker'); }; var getCalendarWrapper = function getCalendarWrapper() { return base.$('.DayPicker-wrapper'); }; var getNthDay = function getNthDay(n) { return base.$$('[role="gridcell"]:not([class*="disabled"])>[data-outsideday="false"]').get(n); }; var getNthDayOfTheMonth = function getNthDayOfTheMonth(n) { return base.$$("[role=\"gridcell\"]>[data-outsideday=\"false\"]").get(n); }; var getDayOfDate = function getDayOfDate(year, month, day) { return base.$("[role=\"gridcell\"]>[data-outsideday=\"false\"][data-date='".concat(year, "-").concat(month, "-").concat(day, "']")); }; var _getSelectedDay = function getSelectedDay() { return base.$('[role="gridcell"][aria-selected="true"]>[data-outsideday="false"]'); }; var getVisibleDisabledList = function getVisibleDisabledList() { return base.$$('[role="gridcell"][aria-disabled="true"]'); }; var getYearDropdownButton = function getYearDropdownButton() { return base.$('[data-hook="datepicker-year-dropdown-button"]'); }; var getMonthDropdownButton = function getMonthDropdownButton() { return base.$('[data-hook="datepicker-month-dropdown-button"]'); }; var getNthYear = function getNthYear(n) { return base.$("[data-hook=\"dropdown-item-".concat(n, "\"]")); }; var _getMonthCaption = function getMonthCaption() { return base.$$('[data-hook="datepicker-month-caption"]').get(0); }; var getYearCaption = function getYearCaption() { return base.$('[data-hook="datepicker-year-caption"]'); }; var getMonthAndYear = function getMonthAndYear() { return [_getMonthCaption(), getYearCaption()]; }; var _getNthWeekDayName = function getNthWeekDayName(n) { return base.$$("[data-hook=\"weekday-day\"]").get(n); }; var getPrevMonthButton = function getPrevMonthButton() { return base.$('[data-hook="datepicker-left-arrow"]'); }; var getNextMonthButton = function getNextMonthButton() { return base.$('[data-hook="datepicker-right-arrow"]'); }; var _getFocusedDay = function getFocusedDay() { return base.$('.DayPicker-Day:focus'); }; var getVisuallyUnfocusedDay = function getVisuallyUnfocusedDay() { return base.$('.unfocused'); }; var getMonthContainers = function getMonthContainers() { return base.$$('.DayPicker-Month'); }; var getVisibleMonths = function getVisibleMonths() { return base.$$('[class*="DayPicker-Month"]'); }; var _getSelectedDays = function getSelectedDays() { return base.$$('[role="gridcell"][aria-selected="true"]>[data-outsideday="false"]'); }; var getMonthDropdown = function getMonthDropdown() { return base.$('[data-hook="datepicker-month-dropdown"]'); }; var getYearDropdown = function getYearDropdown() { return base.$('[data-hook="datepicker-year-dropdown"]'); }; var getHeader = function getHeader() { return base.$('[data-hook="datepicker-head"]'); }; return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base)), {}, { close: function close() { return _getFocusedDay().pressKey('Escape'); }, isVisible: function isVisible() { return getCalendar().exists(); }, getCurrentMonthWithYear: function getCurrentMonthWithYear() { return Promise.all(getMonthAndYear().map(function (elm) { return elm.text(); })).then(function (values) { return values.join(' '); }); }, getNthWeekDayName: function () { var _getNthWeekDayName2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() { var n, _args = arguments; return _regenerator["default"].wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: n = _args.length > 0 && _args[0] !== undefined ? _args[0] : 0; _context.next = 3; return _getNthWeekDayName(n).exists(); case 3: if (!_context.sent) { _context.next = 7; break; } _context.t0 = _getNthWeekDayName(n).text(); _context.next = 8; break; case 7: _context.t0 = ''; case 8: return _context.abrupt("return", _context.t0); case 9: case "end": return _context.stop(); } } }, _callee); })); function getNthWeekDayName() { return _getNthWeekDayName2.apply(this, arguments); } return getNthWeekDayName; }(), clickOnNthDay: function () { var _clickOnNthDay = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() { var n, _args2 = arguments; return _regenerator["default"].wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: n = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : 0; _context2.next = 3; return getNthDay(n).exists(); case 3: _context2.t0 = _context2.sent; if (!_context2.t0) { _context2.next = 6; break; } _context2.t0 = getNthDay(n).click(); case 6: return _context2.abrupt("return", _context2.t0); case 7: case "end": return _context2.stop(); } } }, _callee2); })); function clickOnNthDay() { return _clickOnNthDay.apply(this, arguments); } return clickOnNthDay; }(), clickDay: function () { var _clickDay = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(date) { var day; return _regenerator["default"].wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: day = getDayOfDate(date.getFullYear(), date.getMonth(), date.getDate()); _context3.next = 3; return day.exists(); case 3: if (!_context3.sent) { _context3.next = 8; break; } _context3.next = 6; return day.click(); case 6: _context3.next = 9; break; case 8: throw new Error("ERROR: CalendarDriver.clickDay() - The given date (".concat(date.toString(), ") is not visible")); case 9: case "end": return _context3.stop(); } } }, _callee3); })); function clickDay(_x) { return _clickDay.apply(this, arguments); } return clickDay; }(), isDayActive: function () { var _isDayActive = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(date) { var year, month, day, value; return _regenerator["default"].wrap(function _callee5$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: year = date.getFullYear(); month = date.getMonth(); day = date.getDate(); value = getDayOfDate(year, month, day); _context5.next = 6; return value.exists(); case 6: if (!_context5.sent) { _context5.next = 13; break; } _context5.next = 9; return getVisibleDisabledList().filter( /*#__PURE__*/function () { var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(elm) { return _regenerator["default"].wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: _context4.next = 2; return elm.$(":scope > [data-date='".concat(year, "-").concat(month, "-").concat(day, "']")).exists(); case 2: return _context4.abrupt("return", _context4.sent); case 3: case "end": return _context4.stop(); } } }, _callee4); })); return function (_x3) { return _ref.apply(this, arguments); }; }()).count(); case 9: _context5.t0 = _context5.sent; return _context5.abrupt("return", _context5.t0 === 0); case 13: throw new Error("ERROR: CalendarDriver.isDayActive() - The given date (".concat(date.toString(), ") is not visible")); case 14: case "end": return _context5.stop(); } } }, _callee5); })); function isDayActive(_x2) { return _isDayActive.apply(this, arguments); } return isDayActive; }(), clickOnNthDayOfTheMonth: function () { var _clickOnNthDayOfTheMonth = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6() { var n, _args6 = arguments; return _regenerator["default"].wrap(function _callee6$(_context6) { while (1) { switch (_context6.prev = _context6.next) { case 0: n = _args6.length > 0 && _args6[0] !== undefined ? _args6[0] : 0; _context6.next = 3; return getNthDayOfTheMonth(n).exists(); case 3: _context6.t0 = _context6.sent; if (!_context6.t0) { _context6.next = 6; break; } _context6.t0 = getNthDayOfTheMonth(n).click(); case 6: return _context6.abrupt("return", _context6.t0); case 7: case "end": return _context6.stop(); } } }, _callee6); })); function clickOnNthDayOfTheMonth() { return _clickOnNthDayOfTheMonth.apply(this, arguments); } return clickOnNthDayOfTheMonth; }(), clickOnSelectedDay: function clickOnSelectedDay() { return _getSelectedDay().click(); }, clickOnYearDropdown: function clickOnYearDropdown() { return getYearDropdownButton().click(); }, clickOnMonthDropdown: function clickOnMonthDropdown() { return getMonthDropdownButton().click(); }, clickOnNthYear: function clickOnNthYear() { var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; return getNthYear(n).mouse.press(); }, clickOnPrevMonthButton: function clickOnPrevMonthButton() { return (0, _IconButtonUni.iconButtonDriverFactory)(getPrevMonthButton()).click(); }, clickOnNextMonthButton: function clickOnNextMonthButton() { return (0, _IconButtonUni.iconButtonDriverFactory)(getNextMonthButton()).click(); }, keyboardNextYear: function keyboardNextYear() { return getCalendarWrapper().pressKey('ArrowDown'); }, keyboardPrevYear: function keyboardPrevYear() { return getCalendarWrapper().pressKey('ArrowUp'); }, isHeaderVisible: function isHeaderVisible() { return getHeader().exists(); }, isYearDropdownExists: function isYearDropdownExists() { return getYearDropdown().exists(); }, isYearCaptionExists: function isYearCaptionExists() { return getYearCaption().exists(); }, isMonthDropdownExists: function isMonthDropdownExists() { return getMonthDropdown().exists(); }, isMonthCaptionExists: function isMonthCaptionExists() { return _getMonthCaption().exists(); }, getMonthCaption: function getMonthCaption() { return _getMonthCaption().text(); }, getMonthDropdownLabel: function getMonthDropdownLabel() { return getMonthDropdownButton().text(); }, getSelectedYear: function getSelectedYear() { return getYearDropdownButton().text(); }, /** Returns the text of the focused day or `null` if there is no focused day */ getFocusedDay: function () { var _getFocusedDay2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7() { var focusedDayElement; return _regenerator["default"].wrap(function _callee7$(_context7) { while (1) { switch (_context7.prev = _context7.next) { case 0: focusedDayElement = _getFocusedDay(); _context7.next = 3; return focusedDayElement.exists(); case 3: if (!_context7.sent) { _context7.next = 7; break; } _context7.t0 = focusedDayElement.text(); _context7.next = 8; break; case 7: _context7.t0 = null; case 8: return _context7.abrupt("return", _context7.t0); case 9: case "end": return _context7.stop(); } } }, _callee7); })); function getFocusedDay() { return _getFocusedDay2.apply(this, arguments); } return getFocusedDay; }(), getFocusedDayElement: function getFocusedDayElement() { return _getFocusedDay(); }, pressLeftArrow: function pressLeftArrow() { return _getFocusedDay().pressKey('ArrowLeft'); }, pressRightArrow: function pressRightArrow() { return _getFocusedDay().pressKey('ArrowRight'); }, getSelectedDay: function getSelectedDay() { return _getSelectedDay().text(); }, getWidth: function getWidth() { return base._prop('style').then(function (style) { return style.width; }); }, triggerKeyDown: function triggerKeyDown(_ref2) { var key = _ref2.key; return _getFocusedDay().pressKey(key); }, isFocusedDayVisuallyUnfocused: function isFocusedDayVisuallyUnfocused() { return _getFocusedDay().hasClass('unfocused'); }, containsVisuallyUnfocusedDay: function containsVisuallyUnfocusedDay() { return getVisuallyUnfocusedDay().exists(); }, isTwoMonthsLayout: function () { var _isTwoMonthsLayout = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8() { return _regenerator["default"].wrap(function _callee8$(_context8) { while (1) { switch (_context8.prev = _context8.next) { case 0: _context8.next = 2; return getMonthContainers().count(); case 2: _context8.t0 = _context8.sent; return _context8.abrupt("return", _context8.t0 === 2); case 4: case "end": return _context8.stop(); } } }, _callee8); })); function isTwoMonthsLayout() { return _isTwoMonthsLayout.apply(this, arguments); } return isTwoMonthsLayout; }(), getMonthDropdownDriver: function () { var _getMonthDropdownDriver = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9() { return _regenerator["default"].wrap(function _callee9$(_context9) { while (1) { switch (_context9.prev = _context9.next) { case 0: _context9.next = 2; return getMonthDropdownButton().click(); case 2: _context9.t0 = _DropdownLayoutUni.dropdownLayoutDriverFactory; _context9.next = 5; return getMonthDropdown(); case 5: _context9.t1 = _context9.sent; return _context9.abrupt("return", (0, _context9.t0)(_context9.t1)); case 7: case "end": return _context9.stop(); } } }, _callee9); })); function getMonthDropdownDriver() { return _getMonthDropdownDriver.apply(this, arguments); } return getMonthDropdownDriver; }(), getYearDropdownDriver: function () { var _getYearDropdownDriver = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10() { return _regenerator["default"].wrap(function _callee10$(_context10) { while (1) { switch (_context10.prev = _context10.next) { case 0: _context10.next = 2; return getYearDropdownButton().click(); case 2: _context10.t0 = _DropdownLayoutUni.dropdownLayoutDriverFactory; _context10.next = 5; return getYearDropdown(); case 5: _context10.t1 = _context10.sent; return _context10.abrupt("return", (0, _context10.t0)(_context10.t1)); case 7: case "end": return _context10.stop(); } } }, _callee10); })); function getYearDropdownDriver() { return _getYearDropdownDriver.apply(this, arguments); } return getYearDropdownDriver; }(), getNumOfVisibleMonths: function getNumOfVisibleMonths() { return getVisibleMonths().count(); }, getNumOfSelectedDays: function getNumOfSelectedDays() { return _getSelectedDays().count(); }, getSelectedDays: function getSelectedDays() { var datesPromises = _getSelectedDays().map( /*#__PURE__*/function () { var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee11(item) { var attr, date; return _regenerator["default"].wrap(function _callee11$(_context11) { while (1) { switch (_context11.prev = _context11.next) { case 0: _context11.next = 2; return item.attr('data-date'); case 2: attr = _context11.sent; date = attr.split('-').map(function (part) { return parseInt(part); }); return _context11.abrupt("return", new Date(date[0], date[1], date[2])); case 5: case "end": return _context11.stop(); } } }, _callee11); })); return function (_x4) { return _ref3.apply(this, arguments); }; }()); return Promise.all(datesPromises); }, mouseClickOutside: function mouseClickOutside() { return _unidriver.ReactBase.clickBody(); } }); }; exports.calendarUniDriverFactory = calendarUniDriverFactory;