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.44 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.computeSentence = computeSentence; exports.isTextualNode = isTextualNode; const model_1 = require("./model"); const expect_translator_1 = require("./expect-translator"); const stepCase = model_1.StepCaseEnum.THEN; function computeSentence(element) { return __awaiter(this, void 0, void 0, function* () { if (!isTextualNode(element)) { return null; } const sentenceKey = "key.then.element.withContent"; const sentence = getData(element); const response = { suggestion: undefined, sentences: [] }; response.sentences = [stepCase + new expect_translator_1.ExpectTranslator().computeSentenceFromKeyAndContent(sentenceKey, sentence)]; return Promise.resolve(response); }); } function 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"; } function getData(element) { var _a; return (_a = element === null || element === void 0 ? void 0 : element.childNodes[0].textContent) !== null && _a !== void 0 ? _a : ""; }