Skip to content

Commit c8193eb

Browse files
committed
fixes #23. minDuration now accounted for even if no delay
1 parent e8e9605 commit c8193eb

File tree

8 files changed

+126
-65
lines changed

8 files changed

+126
-65
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ npm-debug.log
1616
node_modules
1717
.DS_Store
1818

19-
temp
19+
temp
20+
21+
_SpecRunner.html
22+
23+
.grunt

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ Only the values you'd like overriden need to be specified.
8989

9090

9191
## Release History
92+
* v4.0.2 - Fix for min duration only being used when delay also being set.
9293
* v4.0.0 - Big update
9394
* Dependency on angular-promise-tracker has been removed. We now track promises directly.
9495
* Message is now configurable.

angular-busy.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ angular.module('cgBusy').factory('_cgBusyTrackerFactory',['$timeout',function($t
2626
return;
2727
}
2828

29-
if (options.delay > 0) {
29+
if (options.delay) {
3030
tracker.delayPromise = $timeout(function(){
3131
tracker.delayPromise = null;
32-
if (options.minDuration) {
33-
tracker.durationPromise = $timeout(function(){
34-
tracker.durationPromise = null;
35-
},options.minDuration);
36-
}
3732
},options.delay);
3833
}
34+
if (options.minDuration) {
35+
tracker.durationPromise = $timeout(function(){
36+
tracker.durationPromise = null;
37+
},options.minDuration);
38+
}
3939
};
4040

4141
tracker.getThen = function(promise){

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-busy",
3-
"version": "4.0.1",
3+
"version": "4.0.2",
44
"main": [
55
"dist/angular-busy.js",
66
"dist/angular-busy.css"

dist/angular-busy.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ angular.module('cgBusy').factory('_cgBusyTrackerFactory',['$timeout',function($t
2626
return;
2727
}
2828

29-
if (options.delay > 0) {
29+
if (options.delay) {
3030
tracker.delayPromise = $timeout(function(){
3131
tracker.delayPromise = null;
32-
if (options.minDuration) {
33-
tracker.durationPromise = $timeout(function(){
34-
tracker.durationPromise = null;
35-
},options.minDuration);
36-
}
3732
},options.delay);
3833
}
34+
if (options.minDuration) {
35+
tracker.durationPromise = $timeout(function(){
36+
tracker.durationPromise = null;
37+
},options.minDuration);
38+
}
3939
};
4040

4141
tracker.getThen = function(promise){

dist/angular-busy.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-busy",
3-
"version": "4.0.1",
3+
"version": "4.0.2",
44
"description": "",
55
"repository": {
66
"type": "git",

test/spec.js

Lines changed: 105 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,137 @@
11
describe('cgBusy', function() {
22

3-
beforeEach(module('app'));
3+
beforeEach(module('app'));
44

5-
var scope,compile,q,httpBackend;
5+
var scope,compile,q,httpBackend,timeout;
66

7-
beforeEach(inject(function($rootScope,$compile,$q,$httpBackend,$templateCache) {
8-
scope = $rootScope.$new();
9-
compile = $compile;
10-
q = $q;
11-
httpBackend = $httpBackend;
12-
httpBackend.whenGET('test-custom-template.html').respond(function(method, url, data, headers){
7+
beforeEach(inject(function($rootScope,$compile,$q,$httpBackend,$templateCache,$timeout) {
8+
scope = $rootScope.$new();
9+
compile = $compile;
10+
q = $q;
11+
httpBackend = $httpBackend;
12+
timeout = $timeout;
13+
httpBackend.whenGET('test-custom-template.html').respond(function(method, url, data, headers){
1314

14-
return [[200],'<div id="custom">test-custom-template-contents</div>'];
15-
});
16-
}));
15+
return [[200],'<div id="custom">test-custom-template-contents</div>'];
16+
});
17+
}));
1718

18-
it('should show the overlay during promise', function() {
19+
it('should show the overlay during promise', function() {
1920

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

23-
this.testPromise = q.defer();
24-
scope.my_promise = this.testPromise.promise;
24+
this.testPromise = q.defer();
25+
scope.my_promise = this.testPromise.promise;
2526

26-
//httpBackend.flush();
27+
//httpBackend.flush();
2728

28-
scope.$apply();
29+
scope.$apply();
2930

30-
expect(this.element.children().length).toBe(1); //ensure element is added
31+
expect(this.element.children().length).toBe(1); //ensure element is added
3132

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

34-
this.testPromise.resolve();
35-
scope.$apply();
35+
this.testPromise.resolve();
36+
scope.$apply();
3637

37-
expect(this.element.children().css('display')).toBe('none'); //ensure its now invisible as the promise is resolved
38-
});
38+
expect(this.element.children().css('display')).toBe('none'); //ensure its now invisible as the promise is resolved
39+
});
3940

40-
it('should show the overlay during multiple promises', function() {
41+
it('should show the overlay during multiple promises', function() {
4142

42-
this.element = compile('<div cg-busy="[my_promise,my_promise2]"></div>')(scope);
43-
angular.element('body').append(this.element);
43+
this.element = compile('<div cg-busy="[my_promise,my_promise2]"></div>')(scope);
44+
angular.element('body').append(this.element);
4445

45-
this.testPromise = q.defer();
46-
scope.my_promise = this.testPromise.promise;
46+
this.testPromise = q.defer();
47+
scope.my_promise = this.testPromise.promise;
4748

48-
this.testPromise2 = q.defer();
49-
scope.my_promise2 = this.testPromise2.promise;
49+
this.testPromise2 = q.defer();
50+
scope.my_promise2 = this.testPromise2.promise;
5051

51-
//httpBackend.flush();
52+
//httpBackend.flush();
5253

53-
scope.$apply();
54+
scope.$apply();
5455

55-
expect(this.element.children().length).toBe(1); //ensure element is added
56+
expect(this.element.children().length).toBe(1); //ensure element is added
5657

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

59-
this.testPromise.resolve();
60-
scope.$apply();
60+
this.testPromise.resolve();
61+
scope.$apply();
6162

62-
expect(this.element.children().css('display')).toBe('block'); //ensure its still visible (promise is ongoing)
63+
expect(this.element.children().css('display')).toBe('block'); //ensure its still visible (promise is ongoing)
6364

64-
this.testPromise2.resolve();
65-
scope.$apply();
66-
expect(this.element.children().css('display')).toBe('none'); //ensure its now invisible as the promise is resolved
67-
});
65+
this.testPromise2.resolve();
66+
scope.$apply();
67+
expect(this.element.children().css('display')).toBe('none'); //ensure its now invisible as the promise is resolved
68+
});
6869

69-
it('should load custom templates', function(){
70+
it('should load custom templates', function(){
7071

71-
this.element = compile('<div cg-busy="{promise:my_promise,templateUrl:\'test-custom-template.html\'}"></div>')(scope);
72-
angular.element('body').append(this.element);
72+
this.element = compile('<div cg-busy="{promise:my_promise,templateUrl:\'test-custom-template.html\'}"></div>')(scope);
73+
angular.element('body').append(this.element);
7374

74-
httpBackend.flush();
75+
httpBackend.flush();
7576

76-
scope.$apply();
77+
scope.$apply();
7778

78-
expect(angular.element('#custom').html()).toBe('test-custom-template-contents');
79+
expect(angular.element('#custom').html()).toBe('test-custom-template-contents');
80+
81+
});
82+
83+
it('should delay when delay provided.', function() {
84+
85+
this.element = compile('<div cg-busy="{promise:my_promise,delay:300}"></div>')(scope);
86+
angular.element('body').append(this.element);
87+
88+
this.testPromise = q.defer();
89+
scope.my_promise = this.testPromise.promise;
90+
91+
scope.$apply();
92+
93+
expect(this.element.children().length).toBe(1); //ensure element is added
94+
95+
expect(this.element.children().css('display')).toBe('none');
96+
97+
timeout.flush(200);
98+
expect(this.element.children().css('display')).toBe('none');
99+
100+
timeout.flush(301);
101+
expect(this.element.children().css('display')).toBe('block');
102+
this.testPromise.resolve();
103+
scope.$apply();
104+
expect(this.element.children().css('display')).toBe('none');
105+
106+
});
107+
108+
it('should use minDuration correctly.', function() {
109+
110+
this.element = compile('<div cg-busy="{promise:my_promise,minDuration:1000}"></div>')(scope);
111+
angular.element('body').append(this.element);
112+
113+
this.testPromise = q.defer();
114+
scope.my_promise = this.testPromise.promise;
115+
116+
scope.$apply();
117+
118+
expect(this.element.children().length).toBe(1); //ensure element is added
119+
120+
expect(this.element.children().css('display')).toBe('block');
121+
122+
timeout.flush(200);
123+
expect(this.element.children().css('display')).toBe('block');
124+
125+
this.testPromise.resolve();
126+
timeout.flush(400);
127+
expect(this.element.children().css('display')).toBe('block');
128+
129+
timeout.flush(300); //900ms total
130+
expect(this.element.children().css('display')).toBe('block');
131+
132+
timeout.flush(101); //1001ms total
133+
expect(this.element.children().css('display')).toBe('none');
134+
135+
});
79136

80-
})
81137
});

0 commit comments

Comments
 (0)