1
1
library animation_optimizer_spec;
2
2
3
3
import '../_specs.dart' ;
4
+ import 'dart:js' as js;
4
5
5
- main ( ) {
6
- describe ('AnimationLoop ' , () {
6
+ _run ({ bool animationsAllowed} ) {
7
+ describe ('animationsAllowed=$ animationsAllowed ' , () {
7
8
TestBed _;
8
9
AnimationOptimizer optimizer;
9
10
beforeEach (inject ((TestBed tb, Expando expand) {
10
11
_ = tb;
11
- optimizer = new AnimationOptimizer (expand);
12
+ optimizer = new AnimationOptimizer (expand)..animationsAllowed = animationsAllowed ;
12
13
}));
13
14
14
15
it ('should prevent animations on child elements' , () {
15
16
var animation = new NoOpAnimation ();
16
17
_.compile ('<div><div></div></div>' );
17
18
18
19
19
- expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBeTruthy ( );
20
+ expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBe (animationsAllowed );
20
21
optimizer.track (animation, _.rootElement);
21
22
expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBeFalsy ();
22
23
optimizer.forget (animation);
23
- expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBeTruthy ( );
24
+ expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBe (animationsAllowed );
24
25
});
25
26
26
27
it ('should allow multiple animations on the same element' , () {
27
28
var animation1 = new NoOpAnimation ();
28
29
var animation2 = new NoOpAnimation ();
29
30
_.compile ('<div><div></div></div>' );
30
31
31
- expect (optimizer.shouldAnimate (_.rootElement)).toBeTruthy ( );
32
+ expect (optimizer.shouldAnimate (_.rootElement)).toBe (animationsAllowed );
32
33
optimizer.track (animation1, _.rootElement);
33
- expect (optimizer.shouldAnimate (_.rootElement)).toBeTruthy ( );
34
+ expect (optimizer.shouldAnimate (_.rootElement)).toBe (animationsAllowed );
34
35
optimizer.track (animation2, _.rootElement);
35
- expect (optimizer.shouldAnimate (_.rootElement)).toBeTruthy ( );
36
+ expect (optimizer.shouldAnimate (_.rootElement)).toBe (animationsAllowed );
36
37
expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBeFalsy ();
37
38
optimizer.forget (animation1);
38
39
expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBeFalsy ();
39
40
optimizer.forget (animation2);
40
- expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBeTruthy ( );
41
+ expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBe (animationsAllowed );
41
42
});
42
43
43
44
it ('should always animate an element' , () {
44
45
_.compile ('<div><div></div></div>' );
45
46
optimizer.alwaysAnimate (_.rootElement.children[0 ], "never" );
46
47
expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBeFalsy ();
47
48
optimizer.alwaysAnimate (_.rootElement.children[0 ], "always" );
48
- expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBeTruthy ( );
49
+ expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBe (animationsAllowed );
49
50
optimizer.alwaysAnimate (_.rootElement.children[0 ], "auto" );
50
- expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBeTruthy ( );
51
+ expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBe (animationsAllowed );
51
52
});
52
53
53
54
it ('alwaysAnimate should not affect children' , () {
54
55
_.compile ('<div><div></div></div>' );
55
56
optimizer.alwaysAnimate (_.rootElement, "never" );
56
57
expect (optimizer.shouldAnimate (_.rootElement)).toBeFalsy ();
57
- expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBeTruthy ( );
58
+ expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBe (animationsAllowed );
58
59
optimizer.alwaysAnimate (_.rootElement, "always" );
59
- expect (optimizer.shouldAnimate (_.rootElement)).toBeTruthy ( );
60
- expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBeTruthy ( );
60
+ expect (optimizer.shouldAnimate (_.rootElement)).toBe (animationsAllowed );
61
+ expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBe (animationsAllowed );
61
62
optimizer.alwaysAnimate (_.rootElement, "auto" );
62
- expect (optimizer.shouldAnimate (_.rootElement)).toBeTruthy ( );
63
- expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBeTruthy ( );
63
+ expect (optimizer.shouldAnimate (_.rootElement)).toBe (animationsAllowed );
64
+ expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBe (animationsAllowed );
64
65
});
65
66
66
67
67
68
it ('alwaysAnimateChildren should not affect element' , () {
68
69
_.compile ('<div><div></div></div>' );
69
70
70
71
optimizer.alwaysAnimateChildren (_.rootElement, "never" );
71
- expect (optimizer.shouldAnimate (_.rootElement)).toBeTruthy ( );
72
+ expect (optimizer.shouldAnimate (_.rootElement)).toBe (animationsAllowed );
72
73
expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBeFalsy ();
73
74
74
75
optimizer.alwaysAnimateChildren (_.rootElement, "always" );
75
- expect (optimizer.shouldAnimate (_.rootElement)).toBeTruthy ( );
76
- expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBeTruthy ( );
76
+ expect (optimizer.shouldAnimate (_.rootElement)).toBe (animationsAllowed );
77
+ expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBe (animationsAllowed );
77
78
78
79
optimizer.alwaysAnimateChildren (_.rootElement, "auto" );
79
- expect (optimizer.shouldAnimate (_.rootElement)).toBeTruthy ( );
80
- expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBeTruthy ( );
80
+ expect (optimizer.shouldAnimate (_.rootElement)).toBe (animationsAllowed );
81
+ expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBe (animationsAllowed );
81
82
});
82
83
83
84
it ('alwaysAnimate should take priority over alwaysAnimateChildren' , () {
84
85
_.compile ('<div><div></div></div>' );
85
86
86
87
optimizer.alwaysAnimateChildren (_.rootElement, "never" );
87
88
optimizer.alwaysAnimate (_.rootElement.children[0 ], "always" );
88
- expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBeTruthy ( );
89
+ expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBe (animationsAllowed );
89
90
90
91
optimizer.alwaysAnimateChildren (_.rootElement, "always" );
91
92
optimizer.alwaysAnimate (_.rootElement.children[0 ], "never" );
@@ -100,13 +101,13 @@ main() {
100
101
expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBeFalsy ();
101
102
102
103
optimizer.alwaysAnimate (_.rootElement.children[0 ], "always" );
103
- expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBeTruthy ( );
104
+ expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBe (animationsAllowed );
104
105
105
106
optimizer.alwaysAnimate (_.rootElement.children[0 ], "auto" );
106
107
expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBeFalsy ();
107
108
108
109
optimizer.forget (animation);
109
- expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBeTruthy ( );
110
+ expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBe (animationsAllowed );
110
111
});
111
112
112
113
it ('alwaysAnimateChildren should take priority over running animations' ,
@@ -118,13 +119,13 @@ main() {
118
119
expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBeFalsy ();
119
120
120
121
optimizer.alwaysAnimateChildren (_.rootElement, "always" );
121
- expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBeTruthy ( );
122
+ expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBe (animationsAllowed );
122
123
123
124
optimizer.alwaysAnimateChildren (_.rootElement, "auto" );
124
125
expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBeFalsy ();
125
126
126
127
optimizer.forget (animation);
127
- expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBeTruthy ( );
128
+ expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBe (animationsAllowed );
128
129
129
130
optimizer.alwaysAnimateChildren (_.rootElement, "never" );
130
131
expect (optimizer.shouldAnimate (_.rootElement.children[0 ])).toBeFalsy ();
@@ -138,7 +139,7 @@ main() {
138
139
139
140
optimizer.alwaysAnimateChildren (_.rootElement, "always" );
140
141
expect (optimizer.shouldAnimate (_.rootElement.children[0 ].children[0 ]))
141
- .toBeTruthy ( );
142
+ .toBe (animationsAllowed );
142
143
143
144
optimizer.alwaysAnimateChildren (_.rootElement.children[0 ], "never" );
144
145
expect (optimizer.shouldAnimate (_.rootElement.children[0 ].children[0 ]))
@@ -148,7 +149,20 @@ main() {
148
149
optimizer.alwaysAnimateChildren (_.rootElement, "never" );
149
150
optimizer.alwaysAnimateChildren (_.rootElement.children[0 ], "always" );
150
151
expect (optimizer.shouldAnimate (_.rootElement.children[0 ].children[0 ]))
151
- .toBeTruthy ( );
152
+ .toBe (animationsAllowed );
152
153
});
153
154
});
154
155
}
156
+
157
+ main () {
158
+ describe ('AnimationLoop' , () {
159
+ _run (animationsAllowed: true );
160
+ if (! identical (1 , 1.0 ) && js.context['DART_VERSION' ].toString ().contains ("version: 1.5." )) {
161
+ // Remove this block when issue #1219 is fixed.
162
+ // In Dart 1.5's Dartium, running both describes in any order causes
163
+ // ng_model_spec to fails. This is not the case in Dart 1.4 or Dart 1.6.
164
+ return ;
165
+ }
166
+ _run (animationsAllowed: false );
167
+ });
168
+ }
0 commit comments