Skip to content

Commit

Permalink
fixed failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benmarch committed Mar 13, 2016
1 parent f83f609 commit dc88cbb
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 116 deletions.
70 changes: 32 additions & 38 deletions app/tour-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,14 @@
* @public
*/
self.start = function () {
var promise = $q.resolve();
if (options.onStart) {
promise = promise.then(options.onStart);
}
return promise.then(function () {
setCurrentStep(stepList[0]);
tourStatus = statuses.ON;
return showStep(getCurrentStep());
});
return serial([
options.onStart || $q.resolve,
function () {
setCurrentStep(stepList[0]);
tourStatus = statuses.ON;
return showStep(getCurrentStep());
}
]);
};

/**
Expand All @@ -272,21 +271,18 @@
* @public
*/
self.end = function () {
var step = getCurrentStep(),
promise = $q.resolve();
if (options.onEnd) {
promise = promise.then(options.onEnd);
}
promise.then(function () {
setCurrentStep(null);
tourStatus = statuses.OFF;
var step = getCurrentStep();
return serial([
options.onEnd || $q.resolve,
function () {
setCurrentStep(null);
tourStatus = statuses.OFF;

if (step) {
return hideStep(step);
if (step) {
return hideStep(step);
}
}
});

return promise;
]);
};

/**
Expand All @@ -295,14 +291,13 @@
* @public
*/
self.pause = function () {
var promise = $q.resolve();
if (options.onPause) {
promise = promise.then(options.onPause);
}
return promise.then(function () {
tourStatus = statuses.PAUSED;
return hideStep(getCurrentStep());
});
return serial([
options.onPause || $q.resolve,
function () {
tourStatus = statuses.PAUSED;
return hideStep(getCurrentStep());
}
]);
};

/**
Expand All @@ -311,14 +306,13 @@
* @public
*/
self.resume = function () {
var promise = $q.resolve();
if (options.onResume) {
promise = promise.then(options.onResume);
}
return promise.then(function () {
tourStatus = statuses.ON;
return showStep(getCurrentStep());
});
return serial([
options.onResume || $q.resolve,
function () {
tourStatus = statuses.ON;
return showStep(getCurrentStep());
}
]);
};

/**
Expand Down
92 changes: 60 additions & 32 deletions dist/angular-ui-tour.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@
tourStatus = statuses.OFF,
options = TourConfig.getAll();

/**
* Closer to $evalAsync, just resolves a promise
* after the next digest cycle
*
* @returns {Promise}
*/
function digest() {
return $q(function (resolve) {
$timeout(resolve);
Expand Down Expand Up @@ -229,7 +235,6 @@
/**
* show supplied step
*
* @
* @param step
* @returns {promise}
*/
Expand Down Expand Up @@ -264,7 +269,7 @@
/**
* hides the supplied step
* @param step
* @returns {promise}
* @returns {Promise}
*/
function hideStep(step) {
if (!step) {
Expand Down Expand Up @@ -299,6 +304,7 @@

/**
* set the current step (doesnt do anything else)
* @param {step} step Current step
*/
function setCurrentStep(step) {
currentStep = step;
Expand Down Expand Up @@ -415,12 +421,14 @@
* @public
*/
self.start = function () {
if (options.onStart) {
options.onStart();
}
setCurrentStep(stepList[0]);
tourStatus = statuses.ON;
showStep(getCurrentStep());
return serial([
options.onStart || $q.resolve,
function () {
setCurrentStep(stepList[0]);
tourStatus = statuses.ON;
return showStep(getCurrentStep());
}
]);
};

/**
Expand All @@ -429,14 +437,18 @@
* @public
*/
self.end = function () {
if (getCurrentStep()) {
hideStep(getCurrentStep());
}
if (options.onEnd) {
options.onEnd();
}
setCurrentStep(null);
tourStatus = statuses.OFF;
var step = getCurrentStep();
return serial([
options.onEnd || $q.resolve,
function () {
setCurrentStep(null);
tourStatus = statuses.OFF;

if (step) {
return hideStep(step);
}
}
]);
};

/**
Expand All @@ -445,11 +457,13 @@
* @public
*/
self.pause = function () {
if (options.onPause) {
options.onPause();
}
tourStatus = statuses.PAUSED;
hideStep(getCurrentStep());
return serial([
options.onPause || $q.resolve,
function () {
tourStatus = statuses.PAUSED;
return hideStep(getCurrentStep());
}
]);
};

/**
Expand All @@ -458,11 +472,13 @@
* @public
*/
self.resume = function () {
if (options.onResume) {
options.onResume();
}
tourStatus = statuses.ON;
showStep(getCurrentStep());
return serial([
options.onResume || $q.resolve,
function () {
tourStatus = statuses.ON;
return showStep(getCurrentStep());
}
]);
};

/**
Expand Down Expand Up @@ -523,14 +539,26 @@
]);
};

self.goToStep = function (stepOrIndex) {
/**
* Jumps to the provided step, step ID, or step index
*
* @param {step | string | number} stepOrStepIdOrIndex Step object, step ID string, or step index to jump to
* @returns {promise} Promise that resolves once the step is shown
*/
self.goTo = function (stepOrStepIdOrIndex) {
var stepToShow;

if (angular.isNumber(stepOrIndex) && angular.isDefined(stepList[stepOrIndex])) {
stepToShow = stepList[stepOrIndex];
} else if (~stepList.indexOf(stepOrIndex)) {
stepToShow = stepOrIndex;
} else {
if (angular.isNumber(stepOrStepIdOrIndex) && angular.isDefined(stepList[stepOrStepIdOrIndex])) {
stepToShow = stepList[stepOrStepIdOrIndex];
} else if (angular.isString(stepOrStepIdOrIndex)) {
stepToShow = stepList.filter(function (step) {
return step.id === stepOrStepIdOrIndex;
})[0];
} else if (~stepList.indexOf(stepOrStepIdOrIndex)) {
stepToShow = stepOrStepIdOrIndex;
}

if (!stepToShow) {
return $q.reject('No step.');
}

Expand Down
2 changes: 1 addition & 1 deletion dist/angular-ui-tour.min.js

Large diffs are not rendered by default.

21 changes: 12 additions & 9 deletions test/spec/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ describe('Tour Config', function () {
var $compile,
$templateCache,
$rootScope,
TourConfig;
TourConfig,
digestAfter = function (fn, argumentArray) {
fn.apply(null, argumentArray || []);
$rootScope.$digest();
};

beforeEach(module('bm.uiTour', 'test.templates'));

Expand Down Expand Up @@ -37,11 +41,10 @@ describe('Tour Config', function () {
started = true;
};
$compile($templateCache.get('tour-with-on-start-function.html'))(scope);
var tour = scope.$$childTail.tour;

//when
$rootScope.$digest();
scope.$$childTail.tour.start();
$rootScope.$digest();
digestAfter(tour.start);

//then
expect(started).toBe(true);
Expand All @@ -51,12 +54,13 @@ describe('Tour Config', function () {
//given
var scope = $rootScope.$new();
$compile($templateCache.get('tour-with-placement-override.html'))(scope);
var tour = scope.$$childTail.tour;

//when
$rootScope.$digest();

//then
expect(scope.$$childTail.tour.options.placement).toEqual('bottom');
expect(tour.options.placement).toEqual('bottom');
});

it('should initialize a new tour step with onNext overridden', inject(function ($q) {
Expand All @@ -68,12 +72,11 @@ describe('Tour Config', function () {
return $q.resolve();
};
$compile($templateCache.get('tour-step-with-on-next-function.html'))(scope);
var tour = scope.$$childTail.tour;

//when
$rootScope.$digest();
scope.$$childTail.tour.start();
scope.$$childTail.tour.next();
$rootScope.$digest();
digestAfter(tour.start);
digestAfter(tour.next);

//then
expect(called).toBe(true);
Expand Down
Loading

0 comments on commit dc88cbb

Please sign in to comment.