@uuv/assistant
Version:
UUV Helper used to improve the life of testers and developers by generating cucumber phrases from the GUI.
93 lines (92 loc) • 3.98 kB
JavaScript
;
/**
* 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.SelectionHelper = void 0;
const Commons_1 = require("../Commons");
const click_translator_1 = require("../translator/click-translator");
const expect_translator_1 = require("../translator/expect-translator");
const within_translator_1 = require("../translator/within-translator");
const type_translator_1 = require("../translator/type-translator");
const highlight_helper_1 = require("./highlight/highlight-helper");
class SelectionHelper {
constructor(onSelect, onReset, intelligentHighlight) {
this.onKeyDown = (e) => {
if (e.key === "Escape") {
this.onReset();
this.highLightHelper.cancel();
this.revertDisabledField();
document.removeEventListener("keydown", this.onKeyDown);
}
};
this.highLightHelper = new highlight_helper_1.HighlightHelper(onSelect);
this.onReset = onReset;
this.intelligentHighlight = intelligentHighlight;
}
startSelect(enableDisabledField) {
if (enableDisabledField) {
this.enableDisabledField();
}
document.addEventListener("keydown", this.onKeyDown);
if (this.intelligentHighlight) {
this.highLightHelper.enableRefinedHighlight();
}
else {
this.highLightHelper.enableBasicHighlight();
}
}
buildResultSentence(el, action, isDisabled) {
return __awaiter(this, void 0, void 0, function* () {
let translator;
switch (action) {
case Commons_1.ActionEnum.WITHIN:
translator = new within_translator_1.WithinTranslator();
break;
case Commons_1.ActionEnum.EXPECT:
translator = new expect_translator_1.ExpectTranslator();
break;
case Commons_1.ActionEnum.CLICK:
translator = new click_translator_1.ClickTranslator();
break;
case Commons_1.ActionEnum.TYPE:
translator = new type_translator_1.TypeTranslator();
break;
}
return translator.translate(el);
});
}
enableDisabledField() {
const disabledElement = document.querySelectorAll(":disabled");
disabledElement.forEach((elem) => {
elem.className = `${elem.className} ${Commons_1.UUV_DISABLED_CLASS}`;
elem.removeAttribute("disabled");
});
}
revertDisabledField() {
const disabledElement = document.querySelectorAll(`.${Commons_1.UUV_DISABLED_CLASS}`);
disabledElement.forEach((elem) => {
elem.className = elem.className.replaceAll(Commons_1.UUV_DISABLED_CLASS, "");
elem.setAttribute("disabled", "true");
});
}
}
exports.SelectionHelper = SelectionHelper;