-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #23. minDuration now accounted for even if no delay
- Loading branch information
Showing
8 changed files
with
126 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,8 @@ npm-debug.log | |
node_modules | ||
.DS_Store | ||
|
||
temp | ||
temp | ||
|
||
_SpecRunner.html | ||
|
||
.grunt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,137 @@ | ||
describe('cgBusy', function() { | ||
|
||
beforeEach(module('app')); | ||
beforeEach(module('app')); | ||
|
||
var scope,compile,q,httpBackend; | ||
var scope,compile,q,httpBackend,timeout; | ||
|
||
beforeEach(inject(function($rootScope,$compile,$q,$httpBackend,$templateCache) { | ||
scope = $rootScope.$new(); | ||
compile = $compile; | ||
q = $q; | ||
httpBackend = $httpBackend; | ||
httpBackend.whenGET('test-custom-template.html').respond(function(method, url, data, headers){ | ||
beforeEach(inject(function($rootScope,$compile,$q,$httpBackend,$templateCache,$timeout) { | ||
scope = $rootScope.$new(); | ||
compile = $compile; | ||
q = $q; | ||
httpBackend = $httpBackend; | ||
timeout = $timeout; | ||
httpBackend.whenGET('test-custom-template.html').respond(function(method, url, data, headers){ | ||
|
||
return [[200],'<div id="custom">test-custom-template-contents</div>']; | ||
}); | ||
})); | ||
return [[200],'<div id="custom">test-custom-template-contents</div>']; | ||
}); | ||
})); | ||
|
||
it('should show the overlay during promise', function() { | ||
it('should show the overlay during promise', function() { | ||
|
||
this.element = compile('<div cg-busy="my_promise"></div>')(scope); | ||
angular.element('body').append(this.element); | ||
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; | ||
this.testPromise = q.defer(); | ||
scope.my_promise = this.testPromise.promise; | ||
|
||
//httpBackend.flush(); | ||
//httpBackend.flush(); | ||
|
||
scope.$apply(); | ||
scope.$apply(); | ||
|
||
expect(this.element.children().length).toBe(1); //ensure element is added | ||
expect(this.element.children().length).toBe(1); //ensure element is added | ||
|
||
expect(this.element.children().css('display')).toBe('block');//ensure its visible (promise is ongoing) | ||
expect(this.element.children().css('display')).toBe('block');//ensure its visible (promise is ongoing) | ||
|
||
this.testPromise.resolve(); | ||
scope.$apply(); | ||
this.testPromise.resolve(); | ||
scope.$apply(); | ||
|
||
expect(this.element.children().css('display')).toBe('none'); //ensure its now invisible as the promise is resolved | ||
}); | ||
expect(this.element.children().css('display')).toBe('none'); //ensure its now invisible as the promise is resolved | ||
}); | ||
|
||
it('should show the overlay during multiple promises', function() { | ||
it('should show the overlay during multiple promises', function() { | ||
|
||
this.element = compile('<div cg-busy="[my_promise,my_promise2]"></div>')(scope); | ||
angular.element('body').append(this.element); | ||
this.element = compile('<div cg-busy="[my_promise,my_promise2]"></div>')(scope); | ||
angular.element('body').append(this.element); | ||
|
||
this.testPromise = q.defer(); | ||
scope.my_promise = this.testPromise.promise; | ||
this.testPromise = q.defer(); | ||
scope.my_promise = this.testPromise.promise; | ||
|
||
this.testPromise2 = q.defer(); | ||
scope.my_promise2 = this.testPromise2.promise; | ||
this.testPromise2 = q.defer(); | ||
scope.my_promise2 = this.testPromise2.promise; | ||
|
||
//httpBackend.flush(); | ||
//httpBackend.flush(); | ||
|
||
scope.$apply(); | ||
scope.$apply(); | ||
|
||
expect(this.element.children().length).toBe(1); //ensure element is added | ||
expect(this.element.children().length).toBe(1); //ensure element is added | ||
|
||
expect(this.element.children().css('display')).toBe('block');//ensure its visible (promise is ongoing) | ||
expect(this.element.children().css('display')).toBe('block');//ensure its visible (promise is ongoing) | ||
|
||
this.testPromise.resolve(); | ||
scope.$apply(); | ||
this.testPromise.resolve(); | ||
scope.$apply(); | ||
|
||
expect(this.element.children().css('display')).toBe('block'); //ensure its still visible (promise is ongoing) | ||
expect(this.element.children().css('display')).toBe('block'); //ensure its still visible (promise is ongoing) | ||
|
||
this.testPromise2.resolve(); | ||
scope.$apply(); | ||
expect(this.element.children().css('display')).toBe('none'); //ensure its now invisible as the promise is resolved | ||
}); | ||
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(){ | ||
it('should load custom templates', function(){ | ||
|
||
this.element = compile('<div cg-busy="{promise:my_promise,templateUrl:\'test-custom-template.html\'}"></div>')(scope); | ||
angular.element('body').append(this.element); | ||
this.element = compile('<div cg-busy="{promise:my_promise,templateUrl:\'test-custom-template.html\'}"></div>')(scope); | ||
angular.element('body').append(this.element); | ||
|
||
httpBackend.flush(); | ||
httpBackend.flush(); | ||
|
||
scope.$apply(); | ||
scope.$apply(); | ||
|
||
expect(angular.element('#custom').html()).toBe('test-custom-template-contents'); | ||
expect(angular.element('#custom').html()).toBe('test-custom-template-contents'); | ||
|
||
}); | ||
|
||
it('should delay when delay provided.', function() { | ||
|
||
this.element = compile('<div cg-busy="{promise:my_promise,delay:300}"></div>')(scope); | ||
angular.element('body').append(this.element); | ||
|
||
this.testPromise = q.defer(); | ||
scope.my_promise = this.testPromise.promise; | ||
|
||
scope.$apply(); | ||
|
||
expect(this.element.children().length).toBe(1); //ensure element is added | ||
|
||
expect(this.element.children().css('display')).toBe('none'); | ||
|
||
timeout.flush(200); | ||
expect(this.element.children().css('display')).toBe('none'); | ||
|
||
timeout.flush(301); | ||
expect(this.element.children().css('display')).toBe('block'); | ||
this.testPromise.resolve(); | ||
scope.$apply(); | ||
expect(this.element.children().css('display')).toBe('none'); | ||
|
||
}); | ||
|
||
it('should use minDuration correctly.', function() { | ||
|
||
this.element = compile('<div cg-busy="{promise:my_promise,minDuration:1000}"></div>')(scope); | ||
angular.element('body').append(this.element); | ||
|
||
this.testPromise = q.defer(); | ||
scope.my_promise = this.testPromise.promise; | ||
|
||
scope.$apply(); | ||
|
||
expect(this.element.children().length).toBe(1); //ensure element is added | ||
|
||
expect(this.element.children().css('display')).toBe('block'); | ||
|
||
timeout.flush(200); | ||
expect(this.element.children().css('display')).toBe('block'); | ||
|
||
this.testPromise.resolve(); | ||
timeout.flush(400); | ||
expect(this.element.children().css('display')).toBe('block'); | ||
|
||
timeout.flush(300); //900ms total | ||
expect(this.element.children().css('display')).toBe('block'); | ||
|
||
timeout.flush(101); //1001ms total | ||
expect(this.element.children().css('display')).toBe('none'); | ||
|
||
}); | ||
|
||
}) | ||
}); |