UNPKG

@uuv/assistant

Version:

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

79 lines (78 loc) 3.04 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. */ 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.steps = 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.steps = [ { keyword: stepCase, sentence }, { keyword: model_1.StepCaseEnum.THEN, sentence: 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 [ { keyword: stepCase, sentence: wording } ]; } else { const clickSentence = this.getSentenceFromKey("key.when.click.withRole"); return [ { keyword: stepCase, sentence: clickSentence.wording.replace("{string}", `"${accessibleRole}"`).replace("{string}", `"${accessibleName}"`) } ]; } } 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;