UNPKG

@sap_oss/wdio-qmate-service

Version:

[![REUSE status](https://api.reuse.software/badge/github.com/SAP/wdio-qmate-service)](https://api.reuse.software/info/github.com/SAP/wdio-qmate-service)[![Node.js CI](https://github.com/SAP/wdio-qmate-service/actions/workflows/node.js.yml/badge.svg)](http

220 lines 10.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DateModule = void 0; const verboseLogger_1 = require("../../helper/verboseLogger"); const formatter_constants_1 = require("../util/constants/formatter.constants"); class DatePickerSelectorParams { selector = { elementProperties: { metadata: "sap.m.DatePicker" } }; index = 0; metadata = "sap.m.DatePicker"; } /** * @class date * @memberof ui5 */ class DateModule { vlf = new verboseLogger_1.VerboseLoggerFactory("ui5", "date"); // =================================== PICK =================================== /** * @function pick * @memberOf ui5.date * @description Picks the passed date using the "DatePicker" with the given selector. * @param {Selector} selector - The selector describing the element. * @param {Date} date - The date object. * @param {Number} [index=0] - The index of the selector (in case there are more than one elements visible at the same time). * @example const today = await common.date.calculate("today"); * await ui5.date.pick(selector, today); */ async pick(selector, date, index = 0) { const vl = this.vlf.initLog(this.pick); vl.log(`Picking date ${date} for selector ${selector}`); const datePickerSelector = await this._constructDatePickerSelector({ selector, index, metadata: "sap.m.DatePicker" }); await this._openDatePicker(datePickerSelector); await this._selectDate(datePickerSelector, date); } /** * @function pickRange * @memberOf ui5.date * @description Picks the passed date range using the "DatePicker" with the given selector. * Note that this will only work within the current month! * @param {Selector} selector - The selector describing the element. * @param {Object[]} range - The array of date objects containing start- and end date. * @param {Number} [index=0] - The index of the selector (in case there are more than one elements visible at the same time). * @example const start = await common.date.calculate("2020, 9, 20"); * const end = await common.date.calculate("2021, 1, 3"); * const range = [start, end]; * await ui5.date.pickRange(selector, range); */ async pickRange(selector, range, index = 0) { const vl = this.vlf.initLog(this.pickRange); vl.log(`Picking date range ${range} for selector ${selector}`); const datePickerSelector = await this._constructDatePickerSelector({ selector, index, metadata: "sap.m.DateRangeSelection" }); await this._openDatePicker(datePickerSelector); await this._selectDate(datePickerSelector, range[0]); await this._selectDate(datePickerSelector, range[1]); } /** * @function pickWithTime * @memberOf ui5.date * @description Picks the passed date with time using the "DateTimePicker" with the given selector. * @param {Selector} selector - The selector describing the element. * @param {Date} date - The date object. * @param {Number} [index=0] - The index of the selector (in case there are more than one elements visible at the same time). * @example const tomorrowMorning = await common.date.calculateWithTime("tomorrow", "09:30:45"); * await ui5.date.pickWithTime(selector, tomorrowMorning); */ async pickWithTime(selector, date, index = 0) { const vl = this.vlf.initLog(this.pickWithTime); vl.log(`Picking date with time ${date} for selector ${selector}`); const datePickerSelector = await this._constructDatePickerSelector({ selector, index, metadata: "sap.m.DateTimePicker" }); await this._openDatePicker(datePickerSelector); await this._selectDate(datePickerSelector, date); await this._selectTime(date); await this._clickOk(); } // =================================== FILL =================================== /** * @function fillRange * @memberOf ui5.date * @description Enters the passed date range to the date input with the given selector by providing the start- and end date. * @param {Selector} selector - The selector describing the element. * @param {Object[]} range - The array of date objects containing start- and end date. * @param {Number} [index=0] - The index of the selector (in case there are more than one elements visible at the same time). * @example const start = await common.date.getSpecific("2025, 9, 20"); * const end = await common.date.getSpecific("2025, 10, 30"); * const range = [start, end]; * await ui5.date.fillRange(selector, range); */ async fillRange(selector, range, index = 0) { const vl = this.vlf.initLog(this.fillRange); const start = util.formatter.formatDate(range[0], "mmm d, yyyy"); const end = util.formatter.formatDate(range[1], "mmm d, yyyy"); const value = `${start} - ${end}`; await ui5.userInteraction.clearAndFill(selector, value, index); } // =================================== HELPER =================================== async _constructDatePickerSelector(params) { let id = await ui5.element.getId(params.selector, params.index); if (params.selector.elementProperties.metadata === "sap.ui.core.Icon") { id = id.replace("-icon", ""); } return { elementProperties: { metadata: params.metadata, id: id } }; } async _openDatePicker(selector) { const vl = this.vlf.initLog(this._openDatePicker); const id = selector.elementProperties.id; const icon = await nonUi5.element.getById(`${id}-icon`); await nonUi5.userInteraction.click(icon); } async _selectDate(selector, date) { const vl = this.vlf.initLog(this._selectDate); const year = date.getFullYear(); const month = date.getMonth(); let found = false; const id = selector.elementProperties.id; const value = await ui5.element.getValue(selector); const currentDate = new Date(value); const currentYear = currentDate.getFullYear(); const currentMonth = currentDate.getMonth(); if (year !== currentYear) { const yearOverview = await nonUi5.element.getById(`${id}-cal--Head-B2`); await nonUi5.userInteraction.click(yearOverview); while (!found) { const yearSpanElem = await nonUi5.element.getById(`${id}-cal--Head-B2`); const yearSpan = await yearSpanElem.getText(); const yearMin = yearSpan.slice(0, 4); const yearMax = yearSpan.slice(7, 11); if (year < Number(yearMin)) { const prev = await nonUi5.element.getById(`${id}-cal--Head-prev`); await nonUi5.userInteraction.click(prev); } else if (year > Number(yearMax)) { const next = await nonUi5.element.getById(`${id}-cal--Head-next`); await nonUi5.userInteraction.click(next); } else { found = true; } } const yearPick = await nonUi5.element.getByCss(`[id*="${id}-cal--YP-y${year}"]`); await nonUi5.userInteraction.click(yearPick); } if (month !== currentMonth) { const monthOverview = await nonUi5.element.getById(`${id}-cal--Head-B1`); await nonUi5.userInteraction.click(monthOverview); const monthPick = await nonUi5.element.getByCss(`[id*="${id}-cal--MP-m${month}"]`); await nonUi5.userInteraction.click(monthPick); } const dayPick = await nonUi5.element.getByCss(`[id="${id}-cal"] .sapUiCalItem[data-sap-day="${util.formatter.formatDate(date, formatter_constants_1.DateFormats.YEAR_MONTH_DAY_PLAIN)}"] .sapUiCalItemText`); await nonUi5.userInteraction.click(dayPick); } async _selectTime(date) { const vl = this.vlf.initLog(this._selectTime); await this._selectAmPm(date.getHours() < 12 ? "AM" : "PM"); await this._selectHours(date.getHours()); await this._selectMinutes(date.getMinutes()); await this._selectSeconds(date.getSeconds()); } async _clickOk() { const selector = { "elementProperties": { "metadata": "sap.m.Button", "text": "OK" } }; await ui5.userInteraction.click(selector); } async _selectAmPm(amPm) { const vl = this.vlf.initLog(this._selectAmPm); const amPmSelector = { "elementProperties": { "metadata": "sap.m.Button", "text": amPm } }; await ui5.userInteraction.click(amPmSelector); } async _selectHours(hours) { const vl = this.vlf.initLog(this._selectHours); await ui5.userInteraction.click({ "elementProperties": { "metadata": "sap.m.internal.ToggleSpinButton", "id": "*Clocks-btnH" } }); await common.userInteraction.pressKey(util.formatter.addRemoveLeadingZeros((hours % 12).toString(), 2)); } async _selectMinutes(minutes) { const vl = this.vlf.initLog(this._selectMinutes); await ui5.userInteraction.click({ "elementProperties": { "metadata": "sap.m.internal.ToggleSpinButton", "id": "*Clocks-btnM" } }); await common.userInteraction.pressKey(util.formatter.addRemoveLeadingZeros(minutes.toString(), 2)); } async _selectSeconds(seconds) { const vl = this.vlf.initLog(this._selectSeconds); try { await ui5.userInteraction.click({ "elementProperties": { "metadata": "sap.m.internal.ToggleSpinButton", "id": "*Clocks-btnS" } }); await common.userInteraction.pressKey(util.formatter.addRemoveLeadingZeros(seconds.toString(), 2)); } catch (error) { vl.log("Cannot select seconds on this calendar, moving on."); } } } exports.DateModule = DateModule; exports.default = new DateModule(); //# sourceMappingURL=date.js.map