-
Notifications
You must be signed in to change notification settings - Fork 256
/
Copy pathspec.js
executable file
·137 lines (86 loc) · 3.94 KB
/
spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
describe('cgBusy', function() {
beforeEach(module('app'));
var scope,compile,q,httpBackend,timeout;
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>'];
});
}));
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.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)
this.testPromise.resolve();
scope.$apply();
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() {
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.testPromise2 = q.defer();
scope.my_promise2 = this.testPromise2.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)
this.testPromise.resolve();
scope.$apply();
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
});
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);
httpBackend.flush();
scope.$apply();
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(2); //ensure the elements are 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(2); //ensure the elements are 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');
});
});