UNPKG

@nova-ui/bits

Version:

SolarWinds Nova Framework

204 lines 10.1 kB
"use strict"; // © 2022 SolarWinds Worldwide, LLC. All rights reserved. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. Object.defineProperty(exports, "__esModule", { value: true }); exports.DatepickerAtom = void 0; const tslib_1 = require("tslib"); const moment_1 = tslib_1.__importDefault(require("moment/moment")); const protractor_1 = require("protractor"); const atom_1 = require("../../atom"); const helpers_1 = require("../../helpers"); const overlay_atom_1 = require("../overlay/overlay.atom"); const textbox_atom_1 = require("../textbox/textbox.atom"); class DatepickerAtom extends atom_1.Atom { constructor() { super(...arguments); this.overlay = atom_1.Atom.findIn(overlay_atom_1.OverlayAtom, this.getElement()); this.textbox = atom_1.Atom.findIn(textbox_atom_1.TextboxAtom, this.getElement()); this.selectDate = (day) => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.clickCalendarItem(day.toString()); }); this.selectMonth = (month) => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.clickCalendarItem(month); }); this.selectYear = (year) => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.clickCalendarItem(year.toString()); }); this.getInput = () => this.getElement().element(protractor_1.by.css("input.form-control")); this.isDisabled = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.textbox.disabled(); }); this.getInputValue = () => tslib_1.__awaiter(this, void 0, void 0, function* () { const el = this.getInput(); yield helpers_1.Helpers.waitElementVisible(el); return el.getAttribute("value"); }); this.acceptText = (text) => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.getInput().sendKeys(text, protractor_1.protractor.Key.ENTER); }); this.clearText = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.getInput().clear(); }); this.getMonthElement = (month, index) => this.selectButton(month, index); this.getPopup = () => this.getElementByCss(".nui-popup__area"); this.getYearElement = (year, index) => this.selectButton(year, index); this.deleteTextManually = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.getInput().sendKeys(protractor_1.Key.chord(protractor_1.Key.CONTROL, "a"), protractor_1.Key.DELETE); }); this.clickTodayButton = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.getElementByCss("button.today-button").click(); }); /** @deprecated As of Nova v11, use 'toggle' method instead. Removal: NUI-5865 */ this.clickCalendarIcon = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.toggle(); }); this.toggle = () => tslib_1.__awaiter(this, void 0, void 0, function* () { const el = this.getElementByCss(".nui-datepicker__icon"); yield helpers_1.Helpers.waitElementToBeClickable(el); yield el.click(); }); this.clickChangeModeButton = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.getElementByCss(".change-mode-button").click(); }); this.clickFirstCalendarDate = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.selectDayButtonByIndex(0).click(); }); this.isInputValid = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return !(yield this.textbox.hasClass("has-error")); }); this.getActiveDay = () => this.getElementByCss(".btn.selected"); this.getActiveDayText = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.getElementText(".btn.selected"); }); this.clickInput = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.getInput().click(); }); this.isTodayButtonEnabled = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.getElement().element(protractor_1.by.css("button.today-button")).isEnabled(); }); this.getMonthFromTitle = () => tslib_1.__awaiter(this, void 0, void 0, function* () { return (yield this.getTitleText()).split(" ")[0]; }); this.getElementText = (identifier) => tslib_1.__awaiter(this, void 0, void 0, function* () { return this.getElementByCss(identifier).getText(); }); } getTextbox() { return this.getElement().element(protractor_1.by.className("nui-textbox")); } formatDate(date, localeDateStringFormat) { return date .locale(localeDateStringFormat) .format(DatepickerAtom.EXPECTED_FORMAT); } /** * Gets title which will be after current title is clicked. * For example, when daypicker mode is enabled then it gets title of monthpicker. * In monthpicker mode gets title of yearpicker. * @returns {Promise<string>} */ getLargerPeriodTitle() { return tslib_1.__awaiter(this, void 0, void 0, function* () { let newTitle; return this.getTitleText().then((currentTitle) => tslib_1.__awaiter(this, void 0, void 0, function* () { if (currentTitle.length === 4) { const currentYear = Math.floor(parseInt(currentTitle, 10)); const rangeStart = currentYear; const rangeEnd = currentYear + 19; newTitle = `${rangeStart} - ${rangeEnd}`; } else { newTitle = currentTitle.substring(currentTitle.length - 4); } return newTitle; })); }); } clickTitle() { const _super = Object.create(null, { getElement: { get: () => super.getElement } }); return tslib_1.__awaiter(this, void 0, void 0, function* () { return _super.getElement.call(this) .element(protractor_1.by.css("button[id*='title']")) .click(); }); } getTitleText() { const _super = Object.create(null, { getElement: { get: () => super.getElement } }); return tslib_1.__awaiter(this, void 0, void 0, function* () { return _super.getElement.call(this) .element(protractor_1.by.css("button[id*='title']")) .getText(); }); } goNext() { const _super = Object.create(null, { getElement: { get: () => super.getElement } }); return tslib_1.__awaiter(this, void 0, void 0, function* () { return _super.getElement.call(this) .element(protractor_1.by.css("button[icon='caret-right']")) .click(); }); } goBack() { const _super = Object.create(null, { getElement: { get: () => super.getElement } }); return tslib_1.__awaiter(this, void 0, void 0, function* () { return _super.getElement.call(this) .element(protractor_1.by.css("button[icon='caret-left']")) .click(); }); } getPreviousMonthTitle(currentMonth, format = "MMMM") { const previousMonth = (0, moment_1.default)().month(currentMonth).subtract(1, "month"); return previousMonth.format(format); } getNextMonthTitle(currentMonth, format = "MMMM") { const nextMonth = (0, moment_1.default)().month(currentMonth).add(1, "month"); return nextMonth.format(format); } clickCalendarItem(buttonText) { const _super = Object.create(null, { getElement: { get: () => super.getElement } }); return tslib_1.__awaiter(this, void 0, void 0, function* () { const button = _super.getElement.call(this) .all(protractor_1.by.cssContainingText("tbody button span:not(.text-muted)", buttonText)) .first(); return button.click(); }); } selectButton(identifier, index = 0) { return super .getElement() .all(protractor_1.by.cssContainingText(".nui-button span", identifier)) .get(index); } selectDayButtonByIndex(index = 0) { return super.getElement().all(protractor_1.by.css("td.day .nui-button")).get(index); } getElementByCss(identifier) { // if deep is passed then look in shadow DOM return super.getElement().element(protractor_1.by.css(identifier)); } } exports.DatepickerAtom = DatepickerAtom; DatepickerAtom.EXPECTED_FORMAT = "DD MMM YYYY"; DatepickerAtom.CSS_CLASS = "nui-datepicker"; DatepickerAtom.MONTHNAMES_SHORT = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", ]; DatepickerAtom.MONTHNAMES_LONG = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", ]; //# sourceMappingURL=datepicker.atom.js.map