forked from angular/angular.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathngAnimateSwapSpec.js
More file actions
166 lines (123 loc) · 4.41 KB
/
ngAnimateSwapSpec.js
File metadata and controls
166 lines (123 loc) · 4.41 KB
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
'use strict';
describe('ngAnimateSwap', function() {
beforeEach(module('ngAnimate'));
beforeEach(module('ngAnimateMock'));
var element;
afterEach(function() {
dealoc(element);
});
var $rootScope, $compile, $animate;
beforeEach(inject(function(_$rootScope_, _$animate_, _$compile_) {
$rootScope = _$rootScope_;
$animate = _$animate_;
$compile = _$compile_;
$animate.enabled(false);
}));
it('should render a new container when the expression changes', inject(function() {
element = $compile('<div><div ng-animate-swap="exp">{{ exp }}</div></div>')($rootScope);
$rootScope.$digest();
var first = element.find('div')[0];
expect(first).toBeFalsy();
$rootScope.exp = 'yes';
$rootScope.$digest();
var second = element.find('div')[0];
expect(second.textContent).toBe('yes');
$rootScope.exp = 'super';
$rootScope.$digest();
var third = element.find('div')[0];
expect(third.textContent).toBe('super');
expect(third).not.toEqual(second);
expect(second.parentNode).toBeFalsy();
}));
it('should render a new container only when the expression property changes', inject(function() {
element = $compile('<div><div ng-animate-swap="exp.prop">{{ exp.value }}</div></div>')($rootScope);
$rootScope.exp = {
prop: 'hello',
value: 'world'
};
$rootScope.$digest();
var one = element.find('div')[0];
expect(one.textContent).toBe('world');
$rootScope.exp.value = 'planet';
$rootScope.$digest();
var two = element.find('div')[0];
expect(two.textContent).toBe('planet');
expect(two).toBe(one);
$rootScope.exp.prop = 'goodbye';
$rootScope.$digest();
var three = element.find('div')[0];
expect(three.textContent).toBe('planet');
expect(three).not.toBe(two);
}));
it('should watch the expression as a collection', inject(function() {
element = $compile('<div><div ng-animate-swap="exp">{{ exp.a }} {{ exp.b }} {{ exp.c }}</div></div>')($rootScope);
$rootScope.exp = {
a: 1,
b: 2
};
$rootScope.$digest();
var one = element.find('div')[0];
expect(one.textContent.trim()).toBe('1 2');
$rootScope.exp.a++;
$rootScope.$digest();
var two = element.find('div')[0];
expect(two.textContent.trim()).toBe('2 2');
expect(two).not.toEqual(one);
$rootScope.exp.c = 3;
$rootScope.$digest();
var three = element.find('div')[0];
expect(three.textContent.trim()).toBe('2 2 3');
expect(three).not.toEqual(two);
$rootScope.exp = { c: 4 };
$rootScope.$digest();
var four = element.find('div')[0];
expect(four.textContent.trim()).toBe('4');
expect(four).not.toEqual(three);
}));
they('should consider $prop as a falsy value', [false, undefined, null], function(value) {
inject(function() {
element = $compile('<div><div ng-animate-swap="value">{{ value }}</div></div>')($rootScope);
$rootScope.value = true;
$rootScope.$digest();
var one = element.find('div')[0];
expect(one).toBeTruthy();
$rootScope.value = value;
$rootScope.$digest();
var two = element.find('div')[0];
expect(two).toBeFalsy();
});
});
it('should consider "0" as a truthy value', inject(function() {
element = $compile('<div><div ng-animate-swap="value">{{ value }}</div></div>')($rootScope);
$rootScope.$digest();
var one = element.find('div')[0];
expect(one).toBeFalsy();
$rootScope.value = 0;
$rootScope.$digest();
var two = element.find('div')[0];
expect(two).toBeTruthy();
}));
describe('animations', function() {
it('should trigger a leave animation followed by an enter animation upon swap',
inject(function() {
element = $compile('<div><div ng-animate-swap="exp">{{ exp }}</div></div>')($rootScope);
$rootScope.exp = 1;
$rootScope.$digest();
var first = $animate.queue.shift();
expect(first.event).toBe('enter');
expect($animate.queue.length).toBe(0);
$rootScope.exp = 2;
$rootScope.$digest();
var second = $animate.queue.shift();
expect(second.event).toBe('leave');
var third = $animate.queue.shift();
expect(third.event).toBe('enter');
expect($animate.queue.length).toBe(0);
$rootScope.exp = false;
$rootScope.$digest();
var forth = $animate.queue.shift();
expect(forth.event).toBe('leave');
expect($animate.queue.length).toBe(0);
}));
});
});