forked from angular/angular.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimateCssSpec.js
167 lines (125 loc) · 5.24 KB
/
animateCssSpec.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
'use strict';
describe("$animateCss", function() {
var triggerRAF, element;
beforeEach(inject(function($$rAF, $rootElement, $document) {
triggerRAF = function() {
$$rAF.flush();
};
var body = jqLite($document[0].body);
element = jqLite('<div></div>');
$rootElement.append(element);
body.append($rootElement);
}));
describe("without animation", function() {
it("should not alter the provided options input in any way", inject(function($animateCss) {
var initialOptions = {
from: { height: '50px' },
to: { width: '50px' },
addClass: 'one',
removeClass: 'two'
};
var copiedOptions = copy(initialOptions);
expect(copiedOptions).toEqual(initialOptions);
$animateCss(element, copiedOptions).start();
expect(copiedOptions).toEqual(initialOptions);
}));
it("should apply the provided [from] CSS to the element", inject(function($animateCss) {
$animateCss(element, { from: { height: '50px' }}).start();
expect(element.css('height')).toBe('50px');
}));
it("should apply the provided [to] CSS to the element after the first frame", inject(function($animateCss) {
$animateCss(element, { to: { width: '50px' }}).start();
expect(element.css('width')).not.toBe('50px');
triggerRAF();
expect(element.css('width')).toBe('50px');
}));
it("should apply the provided [addClass] CSS classes to the element after the first frame", inject(function($animateCss) {
$animateCss(element, { addClass: 'golden man' }).start();
expect(element).not.toHaveClass('golden man');
triggerRAF();
expect(element).toHaveClass('golden man');
}));
it("should apply the provided [removeClass] CSS classes to the element after the first frame", inject(function($animateCss) {
element.addClass('silver');
$animateCss(element, { removeClass: 'silver dude' }).start();
expect(element).toHaveClass('silver');
triggerRAF();
expect(element).not.toHaveClass('silver');
}));
it("should return an animator with a start method which returns a promise", inject(function($animateCss) {
var promise = $animateCss(element, { addClass: 'cool' }).start();
expect(isPromiseLike(promise)).toBe(true);
}));
it("should return an animator with an end method which returns a promise", inject(function($animateCss) {
var promise = $animateCss(element, { addClass: 'cool' }).end();
expect(isPromiseLike(promise)).toBe(true);
}));
it("should only resolve the promise once both a digest and RAF have passed after start",
inject(function($animateCss, $rootScope) {
var doneSpy = jasmine.createSpy();
var runner = $animateCss(element, { addClass: 'cool' }).start();
runner.then(doneSpy);
expect(doneSpy).not.toHaveBeenCalled();
triggerRAF();
expect(doneSpy).not.toHaveBeenCalled();
$rootScope.$digest();
expect(doneSpy).toHaveBeenCalled();
}));
it("should resolve immediately if runner.end() is called",
inject(function($animateCss, $rootScope) {
var doneSpy = jasmine.createSpy();
var runner = $animateCss(element, { addClass: 'cool' }).start();
runner.then(doneSpy);
runner.end();
expect(doneSpy).not.toHaveBeenCalled();
$rootScope.$digest();
expect(doneSpy).toHaveBeenCalled();
}));
it("should reject immediately if runner.end() is called",
inject(function($animateCss, $rootScope) {
var cancelSpy = jasmine.createSpy();
var runner = $animateCss(element, { addClass: 'cool' }).start();
runner.catch(cancelSpy);
runner.cancel();
expect(cancelSpy).not.toHaveBeenCalled();
$rootScope.$digest();
expect(cancelSpy).toHaveBeenCalled();
}));
it("should not resolve after the next frame if the runner has already been cancelled",
inject(function($animateCss, $rootScope) {
var doneSpy = jasmine.createSpy();
var cancelSpy = jasmine.createSpy();
var runner = $animateCss(element, { addClass: 'cool' }).start();
runner.then(doneSpy, cancelSpy);
runner.cancel();
$rootScope.$digest();
expect(cancelSpy).toHaveBeenCalled();
expect(doneSpy).not.toHaveBeenCalled();
triggerRAF();
expect(cancelSpy).toHaveBeenCalled();
expect(doneSpy).not.toHaveBeenCalled();
}));
it("should not bother applying the provided [from] and [to] styles to the element if [cleanupStyles] is present",
inject(function($animateCss, $rootScope) {
var animator = $animateCss(element, {
cleanupStyles: true,
from: { width: '100px' },
to: { width: '900px', height: '1000px' }
});
assertStyleIsEmpty(element, 'width');
assertStyleIsEmpty(element, 'height');
var runner = animator.start();
assertStyleIsEmpty(element, 'width');
assertStyleIsEmpty(element, 'height');
triggerRAF();
assertStyleIsEmpty(element, 'width');
assertStyleIsEmpty(element, 'height');
runner.end();
assertStyleIsEmpty(element, 'width');
assertStyleIsEmpty(element, 'height');
function assertStyleIsEmpty(element, prop) {
expect(element[0].style.getPropertyValue(prop)).toBeFalsy();
}
}));
});
});