wix-style-react
Version:
wix-style-react
205 lines (204 loc) • 11 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.calendarUniDriverFactory = void 0;
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _unidriver = require("../test-utils/utils/unidriver");
var _DropdownLayoutUni = require("../DropdownLayout/DropdownLayout.uni.driver");
var _IconButtonUni = require("../IconButton/IconButton.uni.driver");
var _constants = require("./constants");
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var calendarUniDriverFactory = base => {
var getCalendarWrapper = () => base.$('.DayPicker-wrapper');
var getDays = () => base.$$('[role="gridcell"]:not([class*="disabled"])>[data-outsideday="false"]');
var getNumberOfDays = () => getDays().length;
var getNthDay = n => getDays().get(n);
var getNthDayOfTheMonth = n => base.$$("[role=\"gridcell\"]>[data-outsideday=\"false\"]").get(n);
var getDayOfDate = (year, month, day) => base.$("[role=\"gridcell\"]>[data-outsideday=\"false\"][data-date='".concat(year, "-").concat(month, "-").concat(day, "']"));
var _getSelectedDay = () => base.$('[role="gridcell"][aria-selected="true"]>[data-outsideday="false"]');
var getVisibleDisabledList = () => base.$$('[role="gridcell"][aria-disabled="true"]');
var getYearDropdownButton = () => base.$('[data-hook="datepicker-year-dropdown-button"]');
var getMonthDropdownButton = () => base.$('[data-hook="datepicker-month-dropdown-button"]');
var getNthYear = n => base.$("[data-hook=\"dropdown-item-".concat(n, "\"]"));
var _getMonthCaption = () => base.$$('[data-hook="datepicker-month-caption"]').get(0);
var getYearCaption = () => base.$('[data-hook="datepicker-year-caption"]');
var getMonthAndYear = () => [_getMonthCaption(), getYearCaption()];
var _getNthWeekDayName = n => base.$$("[data-hook=\"weekday-day\"]").get(n);
var getPrevMonthButton = () => base.$('[data-hook="datepicker-left-arrow"]');
var getNextMonthButton = () => base.$('[data-hook="datepicker-right-arrow"]');
var _getFocusedDay = () => base.$('.DayPicker-Day:focus');
var getVisuallyUnfocusedDay = () => base.$('.unfocused');
var getMonthContainers = () => base.$$('.DayPicker-Month');
var getVisibleMonths = () => base.$$('[class*="DayPicker-Month"]');
var _getSelectedDays = () => base.$$('[role="gridcell"][aria-selected="true"]>[data-outsideday="false"]');
var getMonthDropdown = () => base.$('[data-hook="datepicker-month-dropdown"]');
var getYearDropdown = () => base.$('[data-hook="datepicker-year-dropdown"]');
var getHeader = () => base.$('[data-hook="datepicker-head"]');
return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base)), {}, {
close: () => _getFocusedDay().pressKey('Escape'),
getCurrentMonthWithYear: () => Promise.all(getMonthAndYear().map(elm => elm.text())).then(values => values.join(' ')),
getNthWeekDayName: function () {
var _getNthWeekDayName2 = (0, _asyncToGenerator2.default)(function* () {
var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
return (yield _getNthWeekDayName(n).exists()) ? _getNthWeekDayName(n).text() : '';
});
function getNthWeekDayName() {
return _getNthWeekDayName2.apply(this, arguments);
}
return getNthWeekDayName;
}(),
clickOnNthDay: function () {
var _clickOnNthDay = (0, _asyncToGenerator2.default)(function* () {
var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
return (yield getNthDay(n).exists()) && getNthDay(n).click();
});
function clickOnNthDay() {
return _clickOnNthDay.apply(this, arguments);
}
return clickOnNthDay;
}(),
clickDay: function () {
var _clickDay = (0, _asyncToGenerator2.default)(function* (date) {
var day = getDayOfDate(date.getFullYear(), date.getMonth(), date.getDate());
if (yield day.exists()) {
yield day.click();
} else {
throw new Error("ERROR: CalendarDriver.clickDay() - The given date (".concat(date.toString(), ") is not visible"));
}
});
function clickDay(_x) {
return _clickDay.apply(this, arguments);
}
return clickDay;
}(),
isDayActive: function () {
var _isDayActive = (0, _asyncToGenerator2.default)(function* (date) {
var year = date.getFullYear();
var month = date.getMonth();
var day = date.getDate();
var value = getDayOfDate(year, month, day);
if (yield value.exists()) {
return (yield getVisibleDisabledList().filter(/*#__PURE__*/function () {
var _ref = (0, _asyncToGenerator2.default)(function* (elm) {
return yield elm.$(":scope > [data-date='".concat(year, "-").concat(month, "-").concat(day, "']")).exists();
});
return function (_x3) {
return _ref.apply(this, arguments);
};
}()).count()) === 0;
} else {
throw new Error("ERROR: CalendarDriver.isDayActive() - The given date (".concat(date.toString(), ") is not visible"));
}
});
function isDayActive(_x2) {
return _isDayActive.apply(this, arguments);
}
return isDayActive;
}(),
clickOnNthDayOfTheMonth: function () {
var _clickOnNthDayOfTheMonth = (0, _asyncToGenerator2.default)(function* () {
var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
return (yield getNthDayOfTheMonth(n).exists()) && getNthDayOfTheMonth(n).click();
});
function clickOnNthDayOfTheMonth() {
return _clickOnNthDayOfTheMonth.apply(this, arguments);
}
return clickOnNthDayOfTheMonth;
}(),
clickOnSelectedDay: () => _getSelectedDay().click(),
clickOnYearDropdown: () => getYearDropdownButton().click(),
clickOnMonthDropdown: () => getMonthDropdownButton().click(),
clickOnNthYear: function clickOnNthYear() {
var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
return getNthYear(n).mouse.press();
},
clickOnPrevMonthButton: () => (0, _IconButtonUni.iconButtonDriverFactory)(getPrevMonthButton()).click(),
clickOnNextMonthButton: () => (0, _IconButtonUni.iconButtonDriverFactory)(getNextMonthButton()).click(),
keyboardNextYear: () => getCalendarWrapper().pressKey('ArrowDown'),
keyboardPrevYear: () => getCalendarWrapper().pressKey('ArrowUp'),
isHeaderExists: () => getHeader().exists(),
isYearDropdownExists: () => getYearDropdown().exists(),
isYearCaptionExists: () => getYearCaption().exists(),
isMonthDropdownExists: () => getMonthDropdown().exists(),
isMonthCaptionExists: () => _getMonthCaption().exists(),
getMonthCaption: () => _getMonthCaption().text(),
getMonthDropdownLabel: () => getMonthDropdownButton().text(),
getSelectedYear: () => getYearDropdownButton().text(),
/** Returns the text of the focused day or `null` if there is no focused day */
getFocusedDay: function () {
var _getFocusedDay2 = (0, _asyncToGenerator2.default)(function* () {
var focusedDayElement = _getFocusedDay();
return (yield focusedDayElement.exists()) ? focusedDayElement.text() : null;
});
function getFocusedDay() {
return _getFocusedDay2.apply(this, arguments);
}
return getFocusedDay;
}(),
getFocusedDayElement: () => _getFocusedDay(),
pressLeftArrow: () => _getFocusedDay().pressKey('ArrowLeft'),
pressRightArrow: () => _getFocusedDay().pressKey('ArrowRight'),
getSelectedDay: () => _getSelectedDay().text(),
triggerKeyDown: _ref2 => {
var {
key
} = _ref2;
return _getFocusedDay().pressKey(key);
},
isFocusedDayVisuallyUnfocused: () => _getFocusedDay().hasClass('unfocused'),
containsVisuallyUnfocusedDay: () => getVisuallyUnfocusedDay().exists(),
isTwoMonthsLayout: function () {
var _isTwoMonthsLayout = (0, _asyncToGenerator2.default)(function* () {
return (yield getMonthContainers().count()) === 2;
});
function isTwoMonthsLayout() {
return _isTwoMonthsLayout.apply(this, arguments);
}
return isTwoMonthsLayout;
}(),
getMonthDropdownDriver: function () {
var _getMonthDropdownDriver = (0, _asyncToGenerator2.default)(function* () {
yield getMonthDropdownButton().click();
return (0, _DropdownLayoutUni.dropdownLayoutDriverFactory)(yield getMonthDropdown());
});
function getMonthDropdownDriver() {
return _getMonthDropdownDriver.apply(this, arguments);
}
return getMonthDropdownDriver;
}(),
getYearDropdownDriver: function () {
var _getYearDropdownDriver = (0, _asyncToGenerator2.default)(function* () {
yield getYearDropdownButton().click();
return (0, _DropdownLayoutUni.dropdownLayoutDriverFactory)(yield getYearDropdown());
});
function getYearDropdownDriver() {
return _getYearDropdownDriver.apply(this, arguments);
}
return getYearDropdownDriver;
}(),
getNumOfVisibleMonths: () => getVisibleMonths().count(),
getNumOfSelectedDays: () => _getSelectedDays().count(),
getSelectedDays: () => {
var datesPromises = _getSelectedDays().map(/*#__PURE__*/function () {
var _ref3 = (0, _asyncToGenerator2.default)(function* (item) {
var attr = yield item.attr('data-date');
var date = attr.split('-').map(part => parseInt(part));
return new Date(date[0], date[1], date[2]);
});
return function (_x4) {
return _ref3.apply(this, arguments);
};
}());
return Promise.all(datesPromises);
},
/** Returns size property value currently set on component
* @returns {Promise<string>}
*/
getSize: () => base.$("[data-hook=\"".concat(_constants.dataHooks.baseCalendar, "\"]")).attr('data-size'),
getWeeks: () => base.$$('[class$="week"][role="row"]')
});
};
exports.calendarUniDriverFactory = calendarUniDriverFactory;
//# sourceMappingURL=Calendar.uni.driver.js.map