Skip to content

Commit

Permalink
Fixes #20
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagodp committed Jun 16, 2018
1 parent 7d83417 commit ffa7e4f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 12 deletions.
2 changes: 1 addition & 1 deletion dist/modules/app/TCGenController.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class TCGenController {
let newTestCaseDocuments = [];
for (let [key, value] of vertices) {
let doc = value;
if (!doc.feature || !doc.feature.scenarios) {
if (!doc || !doc.feature || !doc.feature.scenarios) {
continue;
}
// console.log( 'doc is', doc.fileInfo.path);
Expand Down
18 changes: 13 additions & 5 deletions dist/modules/testscenario/TSGen.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class TSGen {
// console.log( 'States to replace', allStatesToReplace.map( s=> s.name ) );
if (allStatesToReplace.length > 0) { // Preconditions + State Calls
for (let state of allStatesToReplace) {
// Already mapped?
if (TypeChecking_1.isDefined(pairMap[state.name])) {
continue;
}
Expand Down Expand Up @@ -114,6 +115,7 @@ class TSGen {
for (let obj of testScenariosToCombineByState) {
let ts = baseScenario.clone();
// console.log( "\nTS is\n", ts.steps.map( s => s.content ) );
let stepsAdded = 0;
for (let stateName in obj) {
const pair = obj[stateName];
let [state, tsToReplaceStep] = pair.toArray();
Expand All @@ -128,14 +130,16 @@ class TSGen {
// console.log( "\nPreTestCase\n", preTestCase.steps.map( s => s.content ) );
// Replace TestScenario steps with the new ones
tsToUse.steps = preTestCase.steps;
tsToUse.stepAfterPreconditions = null;
// Adjust the stepAfterPreconditions
tsToUse.stepAfterPreconditions = null;
let oldIndex = tsToReplaceStep.steps.indexOf(tsToReplaceStep.stepAfterPreconditions);
if (oldIndex >= 0) {
tsToUse.stepAfterPreconditions = tsToUse.steps[oldIndex];
}
// ---
this.replaceStepWithTestScenario(ts, state.stepIndex, tsToUse, isPrecondition);
// console.log( 'state to replace: ', ( state as State ).name );
state.stepIndex += stepsAdded > 0 ? stepsAdded - 1 : 0;
stepsAdded += this.replaceStepWithTestScenario(ts, state, tsToUse, isPrecondition);
}
// console.log( "\nTS modified is\n", ts.steps.map( s => s.content ) );
testScenarios.push(ts);
Expand Down Expand Up @@ -309,16 +313,20 @@ class TSGen {
containsIgnoreTag(tags, ignoreKeywords) {
return Tag_1.tagsWithAnyOfTheNames(tags, ignoreKeywords).length > 0;
}
replaceStepWithTestScenario(ts, stepIndex, tsToReplaceStep, isPrecondition) {
replaceStepWithTestScenario(ts, state, tsToReplaceStep, isPrecondition) {
let stepsToReplace = deepcopy(isPrecondition ? tsToReplaceStep.steps : tsToReplaceStep.stepsWithoutPreconditions());
// Set the flag "external"
for (let step of stepsToReplace) {
step.external = true;
}
// console.log( "\nBEFORE\n\n", ts.steps.map( s => s.content ).join( "\n" ) );
// console.log( "\nSTEPS to replace index", stepIndex, "\n\n", stepsToReplace.map( s => s.content ).join( "\n" ) );
ts.steps.splice(stepIndex, 1, ...stepsToReplace);
// console.log( "\nSTATE INDEX", state.stepIndex, "\n\nWILL REPLACE WITH\n\n", stepsToReplace.map( s => s.content ).join( "\n" ) );
ts.steps.splice(state.stepIndex, 1, ...stepsToReplace);
const stepsAdded = stepsToReplace.length;
state.stepIndex += stepsAdded;
// console.log( "\nSTATE INDEX after", state.stepIndex );
// console.log( "\nAFTER\n\n", ts.steps.map( s => s.content ).join( "\n" ) );
return stepsAdded;
}
}
exports.TSGen = TSGen;
10 changes: 10 additions & 0 deletions dist/modules/testscenario/TestScenario.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// import * as deepcopy from 'deepcopy';
/**
* Test Scenario
*
Expand Down Expand Up @@ -29,6 +30,15 @@ class TestScenario {
ts.ignoreForTestCaseGeneration = this.ignoreForTestCaseGeneration;
ts.stepAfterPreconditions = this.stepAfterPreconditions;
return ts;
// let ts = new TestScenario();
// ts.steps = [];
// for ( let step of this.steps ) {
// ts.steps.push( deepcopy( step ) as Step );
// }
// ts.ignoreForTestCaseGeneration = this.ignoreForTestCaseGeneration;
// const stepIndex = this.steps.indexOf( this.stepAfterPreconditions );
// ts.stepAfterPreconditions = stepIndex < 0 ? null : ts.steps[ stepIndex ];
// return ts;
}
stepsWithoutPreconditions() {
if (null === this.stepAfterPreconditions) {
Expand Down
2 changes: 1 addition & 1 deletion modules/app/TCGenController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class TCGenController {
for ( let [ key, value ] of vertices ) {

let doc: Document = value;
if ( ! doc.feature || ! doc.feature.scenarios ) {
if ( ! doc || ! doc.feature || ! doc.feature.scenarios ) {
continue;
}
// console.log( 'doc is', doc.fileInfo.path);
Expand Down
21 changes: 16 additions & 5 deletions modules/testscenario/TSGen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export class TSGen {

for ( let state of allStatesToReplace ) {

// Already mapped?
if ( isDefined( pairMap[ state.name ] ) ) {
continue;
}
Expand Down Expand Up @@ -151,6 +152,7 @@ export class TSGen {
let ts = baseScenario.clone();
// console.log( "\nTS is\n", ts.steps.map( s => s.content ) );

let stepsAdded = 0;
for ( let stateName in obj ) {
const pair = obj[ stateName ];
let [ state, tsToReplaceStep ] = pair.toArray();
Expand All @@ -175,16 +177,18 @@ export class TSGen {

// Replace TestScenario steps with the new ones
tsToUse.steps = preTestCase.steps;
tsToUse.stepAfterPreconditions = null;

// Adjust the stepAfterPreconditions
tsToUse.stepAfterPreconditions = null;
let oldIndex = tsToReplaceStep.steps.indexOf( tsToReplaceStep.stepAfterPreconditions );
if ( oldIndex >= 0 ) {
tsToUse.stepAfterPreconditions = tsToUse.steps[ oldIndex ];
}
// ---

this.replaceStepWithTestScenario( ts, state.stepIndex, tsToUse, isPrecondition );
// console.log( 'state to replace: ', ( state as State ).name );
state.stepIndex += stepsAdded > 0 ? stepsAdded - 1 : 0;
stepsAdded += this.replaceStepWithTestScenario( ts, state, tsToUse, isPrecondition );
}
// console.log( "\nTS modified is\n", ts.steps.map( s => s.content ) );
testScenarios.push( ts );
Expand Down Expand Up @@ -417,7 +421,7 @@ export class TSGen {

replaceStepWithTestScenario(
ts: TestScenario,
stepIndex: number,
state: State,
tsToReplaceStep: TestScenario,
isPrecondition: boolean
) {
Expand All @@ -431,9 +435,16 @@ export class TSGen {
}

// console.log( "\nBEFORE\n\n", ts.steps.map( s => s.content ).join( "\n" ) );
// console.log( "\nSTEPS to replace index", stepIndex, "\n\n", stepsToReplace.map( s => s.content ).join( "\n" ) );
ts.steps.splice( stepIndex, 1, ... stepsToReplace );
// console.log( "\nSTATE INDEX", state.stepIndex, "\n\nWILL REPLACE WITH\n\n", stepsToReplace.map( s => s.content ).join( "\n" ) );

ts.steps.splice( state.stepIndex, 1, ... stepsToReplace );
const stepsAdded = stepsToReplace.length;
state.stepIndex += stepsAdded;

// console.log( "\nSTATE INDEX after", state.stepIndex );
// console.log( "\nAFTER\n\n", ts.steps.map( s => s.content ).join( "\n" ) );

return stepsAdded;
}

}
10 changes: 10 additions & 0 deletions modules/testscenario/TestScenario.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Step } from "../ast/Step";
// import * as deepcopy from 'deepcopy';

/**
* Test Scenario
Expand Down Expand Up @@ -33,6 +34,15 @@ export class TestScenario {
ts.ignoreForTestCaseGeneration = this.ignoreForTestCaseGeneration;
ts.stepAfterPreconditions = this.stepAfterPreconditions;
return ts;
// let ts = new TestScenario();
// ts.steps = [];
// for ( let step of this.steps ) {
// ts.steps.push( deepcopy( step ) as Step );
// }
// ts.ignoreForTestCaseGeneration = this.ignoreForTestCaseGeneration;
// const stepIndex = this.steps.indexOf( this.stepAfterPreconditions );
// ts.stepAfterPreconditions = stepIndex < 0 ? null : ts.steps[ stepIndex ];
// return ts;
}

stepsWithoutPreconditions(): Step[] {
Expand Down

0 comments on commit ffa7e4f

Please sign in to comment.