UNPKG

@uuv/assistant

Version:

UUV Helper used to improve the life of testers and developers by generating cucumber phrases from the GUI.

91 lines (90 loc) 4.07 kB
"use strict"; /** * Software Name : UUV * * SPDX-License-Identifier: MIT * * This software is distributed under the MIT License, * see the "LICENSE" file for more details * * Authors: NJAKO MOLOM Louis Fredice & SERVICAL Stanley * Software description: Make test writing fast, understandable by any human * understanding English or French. */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DialogService = void 0; const informative_nodes_helper_1 = require("../helper/informative-nodes-helper"); const abstract_component_service_1 = require("./abstract-component-service"); class DialogService extends abstract_component_service_1.AbstractComponentService { constructor() { super(...arguments); this.TRACKED_CLASS = "uuv-dialog-clone"; } show(dom, layer, elements, onSelect, onReset) { const clones = []; let currentTop = 0; elements.forEach((dialog, index) => { const clone = document.createElement("div"); this.clone(clone, dialog); this.overrideStyles(currentTop, dialog, clone); const onClick = () => { onSelect(clone); clone.removeEventListener("click", onClick); document.body.removeChild(clone); Array.from(document.getElementsByClassName(this.TRACKED_CLASS)).forEach(el => el.remove()); }; clone.addEventListener("click", onClick); document.body.appendChild(clone); clones.push(clone); }); super.show(dom, layer, clones, onSelect, onReset); } overrideStyles(currentTop, dialog, clone) { currentTop = this.computeTopPosition(dialog, currentTop); clone.classList.add(this.TRACKED_CLASS); clone.style.position = "fixed"; clone.style.top = `${currentTop}px`; clone.style.left = "2rem"; clone.style.right = "2rem"; clone.style.zIndex = "9999"; clone.style.display = "block"; } computeTopPosition(dialog, currentTop) { const style = getComputedStyle(dialog); const marginBottom = parseFloat(style.marginBottom) || 0; const marginTop = parseFloat(style.marginTop) || 0; const height = dialog.getBoundingClientRect().height + marginTop + marginBottom; currentTop += height + 30; return currentTop; } clone(clone, dialog) { clone.innerHTML = dialog.innerHTML; const styles = getComputedStyle(dialog); for (let i = 0; i < styles.length; i++) { const prop = styles[i]; clone.style.setProperty(prop, styles.getPropertyValue(prop)); } for (let i = 0; i < dialog.attributes.length; i++) { const attr = dialog.attributes[i]; clone.setAttribute(attr.name, attr.value); } } buildResultSentence(selectedArray) { return __awaiter(this, void 0, void 0, function* () { var _a; const name = (_a = new informative_nodes_helper_1.InformativeNodesHelper().getDialogName(selectedArray)) !== null && _a !== void 0 ? _a : ""; const sentenceKey = "key.when.withinElement.roleAndName"; return this.expectTranslator.computeDialogSentenceFromKeyNameAndContent(sentenceKey, name, selectedArray); }); } } exports.DialogService = DialogService;