UNPKG

@uuv/assistant

Version:

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

65 lines (64 loc) 2.1 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.TextualTranslator = void 0; const model_1 = require("./model"); const expect_translator_1 = require("./expect-translator"); const stepCase = model_1.StepCaseEnum.THEN; class TextualTranslator { static computeSentence(element) { if (!this.isTextualNode(element)) { return Promise.resolve(null); } const textContent = this.getTextContent(element); const response = TextualTranslator.computeTextContentSentence(textContent); return Promise.resolve(response); } static computeTextContentSentence(textContent) { const sentenceKey = "key.then.element.withContent"; const response = { suggestion: undefined, steps: [] }; response.steps = [ { keyword: stepCase, sentence: new expect_translator_1.ExpectTranslator().computeSentenceFromKeyAndContent(sentenceKey, textContent) } ]; return response; } static isTextualNode(element) { return [ "caption", "code", "del", "em", "span", "div", "ins", "p", "strong", "sub", "sup" ].includes(element.tagName.toLowerCase()) && element.childNodes.length === 1 && element.childNodes[0].nodeName.toLowerCase() === "#text"; } static getTextContent(element) { var _a; return (_a = element === null || element === void 0 ? void 0 : element.childNodes[0].textContent) !== null && _a !== void 0 ? _a : ""; } } exports.TextualTranslator = TextualTranslator;