Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix angular-busy promise-compare issues and added UT #85

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions angular-busy.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ angular.module('cgBusy').directive('cgBusy',['$compile','$templateCache','cgBusy

templateScope.$message = options.message;

if (options.promise) {
// Assign each promise a "id" field, so the equals below will work correctly
// Specifically - if we counter a new promise object, reset the tracker.
angular.forEach(options.promise, function(promise) {
if (promise) {
promise.id = promise.id || Math.random();
}
});
}

if (!angular.equals(tracker.promises,options.promise)) {
tracker.reset({
promises:options.promise,
Expand Down
10 changes: 10 additions & 0 deletions dist/angular-busy.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ angular.module('cgBusy').directive('cgBusy',['$compile','$templateCache','cgBusy

templateScope.$message = options.message;

if (options.promise) {
// Assign each promise a "id" field, so the equals below will work correctly
// Specifically - if we counter a new promise object, reset the tracker.
angular.forEach(options.promise, function(promise) {
if (promise) {
promise.id = promise.id || Math.random();
}
});
}

if (!angular.equals(tracker.promises,options.promise)) {
tracker.reset({
promises:options.promise,
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-busy.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 39 additions & 1 deletion test/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,44 @@ describe('cgBusy', function() {
expect(this.element.children().css('display')).toBe('none'); //ensure its now invisible as the promise is resolved
});


it('should show the overlay when changing an unresolved promise with other unresolved promise', function() {

this.element = compile('<div cg-busy="my_promise"></div>')(scope);
angular.element('body').append(this.element);

this.testPromise = q.defer();
scope.my_promise = this.testPromise.promise;

//httpBackend.flush();

scope.$apply();

expect(this.element.children().length).toBe(2); //ensure the elements are added

expect(this.element.children().css('display')).toBe('block');//ensure its visible (promise is ongoing)

// Change promise
this.testPromise2 = q.defer();
scope.my_promise = this.testPromise2.promise;
scope.$apply();

// Now resolve the first one promise, the overlay should still be visible
this.testPromise.resolve();
scope.$apply();

expect(this.element.children().length).toBe(2); //ensure the elements are added

expect(this.element.children().css('display')).toBe('block');//ensure its visible (promise is ongoing)

// Now resolve the second promise, and overlay should be removed
this.testPromise2.resolve();
scope.$apply();

expect(this.element.children().css('display')).toBe('none'); //ensure its now invisible as the promise is resolved

});

it('should load custom templates', function(){

this.element = compile('<div cg-busy="{promise:my_promise,templateUrl:\'test-custom-template.html\'}"></div>')(scope);
Expand Down Expand Up @@ -132,6 +170,6 @@ describe('cgBusy', function() {
timeout.flush(101); //1001ms total
expect(this.element.children().css('display')).toBe('none');

});
});

});