JSFiddle - React, Tailwind, and code Playground
Gerar expressão cucumber a partir de tabela de exemplos
by Elvis de Freitas
HTML
<a href="https://bitbucket.org/snippets/ElvisDeFreitas/eKMqE">Como ler a expressão gerada no java</a>
<fieldset>
<legend>Header tabela cucumber</legend>
<textarea id="entradaJson">
| registerType | userType | email | cpf | ddd | cellphone | userName | password | address | optIn | addressNumber | addressDetails | district | city | state | postalCode | birthday | cnpj | companyName | securityPhrase | billIdentification | businessCategory | trademark | stateRegistration | stateRegistrationExempt | dddPhone | phone | dddWorkPhone | workPhone | dddWorkPhone2 | workPhone2 | modelo | mensagem | status | codigoErro |
</textarea>
</fieldset>
<fieldset>
<legend>saida expressão cucumber</legend>
<textarea id="saidaCucumber" readonly></textarea>
</fieldset>
<br />
<button>converter</button>
CSS
textarea {
width: 100%;
height: 50px;
}
#saidaCucumber{
height: 200px;
}
JavaScript
$("button").click(function() {
log(true);
try{
var express = headerGherkin2CucumberExpression($("#entradaJson").val());
console.debug('saida', express);
log(express);
$("#saidaCucumber").val(express);
}catch(e){
return log("please pass a JSON");
}
});
function headerGherkin2CucumberExpression(str){
str = str.replace(/[\ \n\r]+/gmi, "");
str = str.replace(/\|(\w+)/gmi, "\"$1\": \"<$1>\",");
str = str.substring(0, str.lastIndexOf('>')+2);
return "{" + str + "}";
}
function log(text) {
var out = $("#saidaCucumber");
out.val(out.val() + text);
if(text === true){out.val('');}
}