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

79 lines 4.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ElementPropertiesComparator = void 0; const Comparator_1 = require("./Comparator"); const UI5ControlHandler_1 = require("../utils/UI5ControlHandler"); class ElementPropertiesComparator { static compareToProperties(elementProperties, control) { return Object.entries(elementProperties ?? {}).every(([key, value]) => { if (["domProperties", "metadata", "ancestorProperties", "descendantProperties", "siblingProperties", "mProperties"].includes(key)) { return true; } if (key === "viewName") { return ElementPropertiesComparator.isControlInViewName(control, value); } if (key === "viewId") { return ElementPropertiesComparator.isControlInViewId(control, value); } if (key === "id") { return ElementPropertiesComparator.compareId(control, value); } if (key === "bindingContextPath") { return UI5ControlHandler_1.UI5ControlHandler.getControlBindingContextPaths(control).some((path) => Comparator_1.Comparator.compareWithWildCard(value, path)); } if (Array.isArray(value)) { return value.every((val) => { if (typeof val === "string") { return ElementPropertiesComparator.compareArrayStrElements(key, val, control); } else { return ElementPropertiesComparator.compareBindingPathAndModelProperty(key, val, control); } }); } if (typeof value === "object") { return ElementPropertiesComparator.compareBindingPathAndModelProperty(key, value, control); } return ElementPropertiesComparator.compareProperty(control, key, value); }); } static isControlInViewName(control, viewName) { return this.getAncestorViews(control).some((controlToCheck) => { return Comparator_1.Comparator.compareWithWildCard(viewName, controlToCheck.getViewName?.()); }); } static isControlInViewId(control, sViewId) { return this.getAncestorViews(control).some((controlToCheck) => { return Comparator_1.Comparator.compareWithWildCard(sViewId, controlToCheck.getId()); }); } static getAncestorViews(control) { return [control].concat(UI5ControlHandler_1.UI5ControlHandler.getUI5Ancestors(control)).filter((ancestor) => { return ancestor instanceof sap.ui.core.mvc.View; }); } static compareId(control, expectedId) { return expectedId === undefined || Comparator_1.Comparator.compareWithWildCard(expectedId, control.getId?.()); } static compareProperty(control, key, value) { const controlVal = UI5ControlHandler_1.UI5ControlHandler.getControlProperty(control, key); return Comparator_1.Comparator.compareWithWildCard(value, controlVal); } static compareBindingPathAndModelProperty(key, value, control) { const extrPath = UI5ControlHandler_1.UI5ControlHandler.extractBindingPathAndModelProperty(value); if (!extrPath.path) return true; const bindingInfo = UI5ControlHandler_1.UI5ControlHandler.getBindDataForProperty(control, key); return bindingInfo.some((info) => Comparator_1.Comparator.compareWithWildCard(extrPath.path, info.path) && (!extrPath.model || !info.model || Comparator_1.Comparator.compareWithWildCard(extrPath.model, info.model))); } static compareArrayStrElements(key, expectedValue, control) { const values = UI5ControlHandler_1.UI5ControlHandler.getControlProperty(control, key) || []; if (!values.length && !expectedValue) return true; if (values.length && !expectedValue) return false; return values.some((elem) => Comparator_1.Comparator.compareWithWildCard(expectedValue, elem.getId?.() ?? elem, true)); } } exports.ElementPropertiesComparator = ElementPropertiesComparator; //# sourceMappingURL=ElementPropertiesComparator.js.map