forked from angular/angular.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimateJsDriverSpec.js
179 lines (144 loc) · 4.42 KB
/
animateJsDriverSpec.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
'use strict';
describe('ngAnimate $$animateJsDriver', function() {
beforeEach(module('ngAnimate'));
beforeEach(module('ngAnimateMock'));
it('should register the $$animateJsDriver into the list of drivers found in $animateProvider',
module(function($animateProvider) {
expect($animateProvider.drivers).toContain('$$animateJsDriver');
}));
describe('with $$animateJs', function() {
var capturedAnimation = null;
var captureLog = [];
var element;
var driver;
beforeEach(module(function($provide) {
$provide.factory('$$animateJs', function($$AnimateRunner) {
return function() {
var runner = new $$AnimateRunner();
capturedAnimation = arguments;
captureLog.push({
args: capturedAnimation,
runner: runner
});
return {
start: function() {
return runner;
}
};
};
});
captureLog.length = 0;
element = jqLite('<div></div>');
return function($rootElement, $$animateJsDriver) {
$rootElement.append(element);
driver = function() {
return $$animateJsDriver.apply($$animateJsDriver, arguments);
};
};
}));
it('should trigger a standard animation call to $$animateJs when a regular animation is executed',
inject(function($rootScope) {
driver({
element: element,
event: 'enter'
});
$rootScope.$digest();
expect(captureLog.length).toBe(1);
var args = capturedAnimation;
expect(args[0]).toBe(element);
expect(args[1]).toBe('enter');
}));
it('should trigger two regular JS animations when a grouped animation is passed in',
inject(function($rootScope) {
var child1 = jqLite('<div></div>');
element.append(child1);
var child2 = jqLite('<div></div>');
element.append(child2);
driver({
from: {
structural: true,
element: child1,
event: 'leave'
},
to: {
structural: true,
element: child2,
event: 'enter'
}
});
$rootScope.$digest();
expect(captureLog.length).toBe(2);
var first = captureLog[0].args;
expect(first[0]).toBe(child1);
expect(first[1]).toBe('leave');
var second = captureLog[1].args;
expect(second[0]).toBe(child2);
expect(second[1]).toBe('enter');
}));
they('should $prop both animations when $prop() is called on the runner', ['end', 'cancel'], function(method) {
inject(function($rootScope, $animate) {
var child1 = jqLite('<div></div>');
element.append(child1);
var child2 = jqLite('<div></div>');
element.append(child2);
var animator = driver({
from: {
structural: true,
element: child1,
event: 'leave'
},
to: {
structural: true,
element: child2,
event: 'enter'
}
});
var runner = animator.start();
var animationsClosed = false;
var status;
runner.done(function(s) {
animationsClosed = true;
status = s;
});
$rootScope.$digest();
runner[method]();
$animate.flush();
expect(animationsClosed).toBe(true);
expect(status).toBe(method === 'end');
});
});
they('should fully $prop when all inner animations are complete', ['end', 'cancel'], function(method) {
inject(function($rootScope, $animate) {
var child1 = jqLite('<div></div>');
element.append(child1);
var child2 = jqLite('<div></div>');
element.append(child2);
var animator = driver({
from: {
structural: true,
element: child1,
event: 'leave'
},
to: {
structural: true,
element: child2,
event: 'enter'
}
});
var runner = animator.start();
var animationsClosed = false;
var status;
runner.done(function(s) {
animationsClosed = true;
status = s;
});
captureLog[0].runner[method]();
expect(animationsClosed).toBe(false);
captureLog[1].runner[method]();
$animate.flush();
expect(animationsClosed).toBe(true);
expect(status).toBe(method === 'end');
});
});
});
});