Skip to content

Commit 5181dbf

Browse files
author
Jacob Carter
committed
merge conflicts
2 parents 9d4315e + 2211595 commit 5181dbf

3 files changed

Lines changed: 65 additions & 7 deletions

File tree

‎package.json‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
"grunt-contrib-clean": "~0.4.1",
4343
"grunt-contrib-concat": "~0.3.0",
4444
"grunt-contrib-copy": "~0.4.1",
45-
"grunt-contrib-less": "~1.0.0",
4645
"grunt-contrib-cssmin": "~0.12.2",
46+
"grunt-contrib-less": "~1.0.0",
4747
"grunt-contrib-uglify": "~0.2.0",
4848
"grunt-conventional-changelog": "~0.1.1",
4949
"grunt-html2js": "~0.1.3",
@@ -53,10 +53,12 @@
5353
"grunt-ng-annotate": "^0.6.0",
5454
"grunt-zip": "*",
5555
"jasmine-core": "^2.1.3",
56+
"karma": "^0.12.0",
5657
"karma-chrome-launcher": "^0.1.7",
58+
"karma-coverage": "^1.1.1",
5759
"karma-firefox-launcher": "~0.1.x",
5860
"karma-jasmine": "~0.3.x",
5961
"karma-phantomjs-launcher": "~1.0.x"
6062
},
6163
"license": "MIT"
62-
}
64+
}

‎src/wizard.js‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ angular.module('mgo-angular-wizard').directive('wizard', function() {
111111
$scope.goTo($scope.getEnabledSteps()[0]);
112112
}
113113
};
114-
114+
115115
//called each time step directive is destroyed
116116
this.removeStep = function (step) {
117117
var index = $scope.steps.indexOf(step);
@@ -186,8 +186,15 @@ angular.module('mgo-angular-wizard').directive('wizard', function() {
186186
if(typeof step.canenter === 'boolean'){
187187
return step.canenter;
188188
}
189+
var canEnter;
190+
//If canenter is a string instead of a function, evaluate the function
191+
if(typeof step.canenter === 'string'){
192+
var splitFunction = step.canenter.split('(');
193+
canEnter = eval('$scope.$parent.' + splitFunction[0] + '($scope.context' + splitFunction[1])
194+
} else {
195+
canEnter = step.canenter($scope.context);
196+
}
189197
//Check to see if the canenter function is a promise which needs to be returned
190-
canEnter = step.canenter($scope.context);
191198
if(angular.isFunction(canEnter.then)){
192199
defer = $q.defer();
193200
canEnter.then(function(response){
@@ -210,8 +217,15 @@ angular.module('mgo-angular-wizard').directive('wizard', function() {
210217
if(typeof step.canexit === 'boolean'){
211218
return step.canexit;
212219
}
220+
var canExit;
221+
//If canenter is a string instead of a function, evaluate the function
222+
if(typeof step.canexit === 'string'){
223+
var splitFunction = step.canexit.split('(');
224+
canExit = eval('$scope.$parent.' + splitFunction[0] + '($scope.context' + splitFunction[1])
225+
} else {
226+
canExit = step.canexit($scope.context);
227+
}
213228
//Check to see if the canexit function is a promise which needs to be returned
214-
canExit = step.canexit($scope.context);
215229
if(angular.isFunction(canExit.then)){
216230
defer = $q.defer();
217231
canExit.then(function(response){
@@ -327,7 +341,7 @@ angular.module('mgo-angular-wizard').directive('wizard', function() {
327341
$scope.onFinish();
328342
}
329343
};
330-
344+
331345
this.previous = function() {
332346
//getting index of current step
333347
var index = stepIdx($scope.selectedStep);
@@ -375,4 +389,4 @@ angular.module('mgo-angular-wizard').directive('wizard', function() {
375389
};
376390
}]
377391
};
378-
});
392+
});

‎test/angularWizardSpec.js‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,27 @@ describe( 'AngularWizard', function() {
257257
$timeout.flush();
258258
expect(scope.referenceCurrentStep).toEqual('More steps');
259259
});
260+
it( "should go to the next step because the promise that the evaluated string of CANENTER resolves to true", function(done) {
261+
var scope = $rootScope.$new();
262+
scope.dynamicStepDisabled = 'Y';
263+
var view = createGenericView(scope);
264+
scope.enterValidation = 'stringEnterValidation()'
265+
scope.stringEnterValidation = function(){
266+
var deferred = $q.defer();
267+
$timeout(function () {
268+
deferred.resolve(true);
269+
done();
270+
});
271+
return deferred.promise;
272+
};
273+
expect(scope.referenceCurrentStep).toEqual('Starting');
274+
WizardHandler.wizard().next();
275+
$rootScope.$digest();
276+
expect(scope.referenceCurrentStep).toEqual('Continuing');
277+
WizardHandler.wizard().next();
278+
$timeout.flush();
279+
expect(scope.referenceCurrentStep).toEqual('More steps');
280+
});
260281
it( "should go to the next step because CANEXIT is set to true", function() {
261282
var scope = $rootScope.$new();
262283
scope.dynamicStepDisabled = 'Y';
@@ -270,6 +291,27 @@ describe( 'AngularWizard', function() {
270291
$rootScope.$digest();
271292
expect(scope.referenceCurrentStep).toEqual('More steps');
272293
});
294+
it( "should go to the next step because the promise that the evaluated string of CANEXIT resolves to true", function(done) {
295+
var scope = $rootScope.$new();
296+
scope.dynamicStepDisabled = 'Y';
297+
var view = createGenericView(scope);
298+
scope.stepValidation = 'stringStepValidation()'
299+
scope.stringStepValidation = function(){
300+
var deferred = $q.defer();
301+
$timeout(function () {
302+
deferred.resolve(true);
303+
done();
304+
});
305+
return deferred.promise;
306+
};
307+
expect(scope.referenceCurrentStep).toEqual('Starting');
308+
WizardHandler.wizard().next();
309+
$rootScope.$digest();
310+
expect(scope.referenceCurrentStep).toEqual('Continuing');
311+
WizardHandler.wizard().next();
312+
$timeout.flush();
313+
expect(scope.referenceCurrentStep).toEqual('More steps');
314+
});
273315
it( "should finish", function() {
274316
var scope = $rootScope.$new();
275317
scope.dynamicStepDisabled = 'Y';

0 commit comments

Comments
 (0)