@uuv/assistant
Version:
UUV Helper used to improve the life of testers and developers by generating cucumber phrases from the GUI.
61 lines (60 loc) • 2.74 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClickTranslator = void 0;
const abstract_translator_1 = require("./abstract-translator");
const model_1 = require("./model");
const stepCase = model_1.StepCaseEnum.WHEN;
class ClickTranslator extends abstract_translator_1.Translator {
getSentenceFromAccessibleRoleAndName(accessibleRole, accessibleName) {
const response = this.initResponse();
response.sentences = this.buildSentencesWithRoleAndName(accessibleRole, accessibleName);
return response;
}
getSentenceFromAccessibleRoleAndNameAndContent(accessibleRole, accessibleName, content) {
return this.getSentenceFromAccessibleRoleAndName(accessibleRole, accessibleName);
}
getSentenceFromDomSelector(domSelector, htmlElem) {
const response = this.initResponse();
const computedKey = "key.when.withinElement.selector";
const sentence = this.computeSentenceFromKeyAndSelector(computedKey, domSelector);
const clickSentence = this.getSentenceFromKey("key.when.click.withContext");
response.sentences = [stepCase + sentence, model_1.StepCaseEnum.THEN + clickSentence.wording];
return response;
}
buildSentencesWithRoleAndName(accessibleRole, accessibleName) {
const role = this.dictionary.getDefinedRoles().find(role => role.shouldGenerateClickSentence && role.id === accessibleRole);
if (role) {
const wording = this.buildWording("key.when.click", accessibleRole, accessibleName);
return [stepCase + wording];
}
else {
const clickSentence = this.getSentenceFromKey("key.when.click.withRole");
return [stepCase + clickSentence.wording.replace("{string}", `"${accessibleRole}"`).replace("{string}", `"${accessibleName}"`)];
}
}
/* eslint-disable @typescript-eslint/no-explicit-any */
buildWording(computedKey, accessibleRole, accessibleName) {
const clickSentence = [
...this.dictionary.getRoleBasedSentencesTemplate(),
...this.dictionary.getBaseSentences()
].find((el) => (el.key === computedKey));
return this.dictionary.computeSentence({
sentence: clickSentence,
accessibleRole,
parameters: [accessibleName]
});
}
}
exports.ClickTranslator = ClickTranslator;