wix-style-react
Version:
wix-style-react
122 lines (116 loc) • 4.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _protractor = require('wix-ui-test-utils/protractor');
var EC = protractor.ExpectedConditions;
var datePickerDriverFactory = function datePickerDriverFactory(component) {
var getYear = function getYear(year) {
var MAX_YEAR = 2028;
var index = MAX_YEAR - year;
return component.$('[data-hook=\'dropdown-item-' + index + '\']');
};
var getInput = function getInput() {
return component.$('input');
};
var getCalendar = function getCalendar() {
return component.$('.DayPicker');
};
var getNthAvailableDay = function getNthAvailableDay(n) {
return component.$$('[role="gridcell"]:not([class*="outside"])').get(n);
};
var getYearDropdown = function getYearDropdown() {
return component.$('[data-hook="datepicker-year-dropdown-button"]');
};
var getNthYear = function getNthYear(n) {
return component.$('[data-hook="datepicker-year-dropdown"] [data-hook="dropdown-item-' + n + '"]');
};
var getMonthsDropdown = function getMonthsDropdown() {
return component.$('[data-hook="datepicker-month-dropdown-button"]');
};
var getNthMonth = function getNthMonth(n) {
return component.$('[data-hook="datepicker-month-dropdown-menu"] [data-hook="dropdown-item-' + (n === 0 ? n : n - 1) + '"]');
};
var getCalendarWrapper = function getCalendarWrapper() {
return component.$('.DayPicker-wrapper');
};
var getKeyboardSelectedDay = function getKeyboardSelectedDay() {
return component.$('.DayPicker-Day:focus');
};
return {
inputDriver: {
exists: function exists() {
return getInput().isPresent();
},
isVisible: function isVisible() {
return getInput().isDisplayed();
},
getValue: function getValue() {
return getInput().getAttribute('value');
},
click: function click() {
return getInput().click();
},
pressEnterKey: function pressEnterKey() {
return getInput().sendKeys(protractor.Key.ENTER);
},
pressEscKey: function pressEscKey() {
return getInput().sendKeys(protractor.Key.ESCAPE);
},
pressTabKey: function pressTabKey() {
return getInput().sendKeys(protractor.Key.TAB);
},
pressArrowRightKey: function pressArrowRightKey() {
return getInput().sendKeys(protractor.Key.ARROW_RIGHT);
},
isFocused: function isFocused() {
return (0, _protractor.isFocused)(getInput());
}
},
calendarDriver: {
getElement: function getElement() {
return getCalendar();
},
exists: function exists() {
return getCalendar().isPresent();
},
isYearInViewPort: function isYearInViewPort(year) {
return browser.wait(EC.visibilityOf(getYear(year)), 5000);
},
isVisible: function isVisible() {
return getCalendar().isDisplayed();
},
clickOnNthAvailableDay: function clickOnNthAvailableDay() {
var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
return getNthAvailableDay(n).click();
},
openYearDropdownOptions: function openYearDropdownOptions() {
return getYearDropdown().click();
},
clickOnNthYear: function clickOnNthYear() {
var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
return getNthYear(n).click();
},
openMonthDropdownOptions: function openMonthDropdownOptions() {
return getMonthsDropdown().click();
},
clickOnNthMonth: function clickOnNthMonth() {
var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
return getNthMonth(n).click();
},
pressEscKey: function pressEscKey() {
return getCalendarWrapper().sendKeys(protractor.Key.ESCAPE);
},
pressTabKey: function pressTabKey() {
return getCalendarWrapper().sendKeys(protractor.Key.TAB);
},
pressEnterKey: function pressEnterKey() {
return getKeyboardSelectedDay().sendKeys(protractor.Key.ENTER);
},
pressArrowRightKey: function pressArrowRightKey() {
return getKeyboardSelectedDay().sendKeys(protractor.Key.ARROW_RIGHT);
}
}
};
};
exports.default = datePickerDriverFactory;