forked from angular/angular.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimateCssSpec.js
2582 lines (1963 loc) · 85.5 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'use strict';
describe("ngAnimate $animateCss", function() {
beforeEach(module('ngAnimate'));
function assertAnimationRunning(element, not) {
var className = element.attr('class');
var regex = /\b\w+-active\b/;
not ? expect(className).toMatch(regex)
: expect(className).not.toMatch(regex);
}
var fakeStyle = {
color: 'blue'
};
var ss, prefix, triggerAnimationStartFrame;
beforeEach(module(function() {
return function($document, $window, $sniffer, $$rAF) {
prefix = '-' + $sniffer.vendorPrefix.toLowerCase() + '-';
ss = createMockStyleSheet($document, $window);
triggerAnimationStartFrame = function() {
$$rAF.flush();
};
};
}));
afterEach(function() {
if (ss) {
ss.destroy();
}
});
it("should return false if neither transitions or keyframes are supported by the browser",
inject(function($animateCss, $sniffer, $rootElement, $document) {
var animator;
var element = jqLite('<div></div>');
$rootElement.append(element);
jqLite($document[0].body).append($rootElement);
$sniffer.transitions = $sniffer.animations = false;
animator = $animateCss(element, {
duration: 10,
to: { 'background': 'red' }
});
expect(animator.$$willAnimate).toBeFalsy();
}));
describe('when active', function() {
if (!browserSupportsCssAnimations()) return;
describe("rAF usage", function() {
it("should buffer all requests into a single requestAnimationFrame call",
inject(function($animateCss, $$rAF, $rootScope, $document, $rootElement) {
jqLite($document[0].body).append($rootElement);
var count = 0;
var runners = [];
function makeRequest() {
var element = jqLite('<div></div>');
$rootElement.append(element);
var runner = $animateCss(element, { duration: 5, to: fakeStyle }).start();
runner.then(function() {
count++;
});
runners.push(runner);
}
makeRequest();
makeRequest();
makeRequest();
expect(count).toBe(0);
triggerAnimationStartFrame();
forEach(runners, function(runner) {
runner.end();
});
$rootScope.$digest();
expect(count).toBe(3);
}));
it("should cancel previous requests to rAF to avoid premature flushing", function() {
var count = 0;
module(function($provide) {
$provide.value('$$rAF', function() {
return function cancellationFn() {
count++;
};
});
});
inject(function($animateCss, $$rAF, $document, $rootElement) {
jqLite($document[0].body).append($rootElement);
function makeRequest() {
var element = jqLite('<div></div>');
$rootElement.append(element);
$animateCss(element, { duration: 5, to: fakeStyle }).start();
}
makeRequest();
makeRequest();
makeRequest();
expect(count).toBe(2);
});
});
});
describe("animator and runner", function() {
var animationDuration = 5;
var element, animator;
beforeEach(inject(function($animateCss, $rootElement, $document) {
element = jqLite('<div></div>');
$rootElement.append(element);
jqLite($document[0].body).append($rootElement);
animator = $animateCss(element, {
event: 'enter',
structural: true,
duration: animationDuration,
to: fakeStyle
});
}));
it('should expose start and end functions for the animator object', inject(function() {
expect(typeof animator.start).toBe('function');
expect(typeof animator.end).toBe('function');
}));
it('should expose end, cancel, resume and pause methods on the runner object', inject(function() {
var runner = animator.start();
triggerAnimationStartFrame();
expect(typeof runner.end).toBe('function');
expect(typeof runner.cancel).toBe('function');
expect(typeof runner.resume).toBe('function');
expect(typeof runner.pause).toBe('function');
}));
it('should start the animation', inject(function() {
expect(element).not.toHaveClass('ng-enter-active');
animator.start();
triggerAnimationStartFrame();
expect(element).toHaveClass('ng-enter-active');
}));
it('should end the animation when called from the animator object', inject(function() {
animator.start();
triggerAnimationStartFrame();
animator.end();
expect(element).not.toHaveClass('ng-enter-active');
}));
it('should end the animation when called from the runner object', inject(function() {
var runner = animator.start();
triggerAnimationStartFrame();
runner.end();
expect(element).not.toHaveClass('ng-enter-active');
}));
it('should permanently close the animation if closed before the next rAF runs', inject(function() {
var runner = animator.start();
runner.end();
triggerAnimationStartFrame();
expect(element).not.toHaveClass('ng-enter-active');
}));
it('should return a runner object at the start of the animation that contains a `then` method',
inject(function($rootScope) {
var runner = animator.start();
triggerAnimationStartFrame();
expect(isPromiseLike(runner)).toBeTruthy();
var resolved;
runner.then(function() {
resolved = true;
});
runner.end();
$rootScope.$digest();
expect(resolved).toBeTruthy();
}));
it('should cancel the animation and reject', inject(function($rootScope) {
var rejected;
var runner = animator.start();
triggerAnimationStartFrame();
runner.then(noop, function() {
rejected = true;
});
runner.cancel();
$rootScope.$digest();
expect(rejected).toBeTruthy();
}));
it('should run pause, but not effect the transition animation', inject(function() {
var blockingDelay = '-' + animationDuration + 's';
expect(element.css('transition-delay')).toEqual(blockingDelay);
var runner = animator.start();
triggerAnimationStartFrame();
expect(element.css('transition-delay')).not.toEqual(blockingDelay);
runner.pause();
expect(element.css('transition-delay')).not.toEqual(blockingDelay);
}));
it('should pause the transition, have no effect, but not end it', inject(function() {
var runner = animator.start();
triggerAnimationStartFrame();
runner.pause();
browserTrigger(element, 'transitionend',
{ timeStamp: Date.now(), elapsedTime: 5 });
expect(element).toHaveClass('ng-enter-active');
}));
it('should resume the animation', inject(function() {
var runner = animator.start();
triggerAnimationStartFrame();
runner.pause();
browserTrigger(element, 'transitionend',
{ timeStamp: Date.now(), elapsedTime: 5 });
expect(element).toHaveClass('ng-enter-active');
runner.resume();
expect(element).not.toHaveClass('ng-enter-active');
}));
it('should pause and resume a keyframe animation using animation-play-state',
inject(function($animateCss) {
element.attr('style', '');
ss.addRule('.ng-enter', '-webkit-animation:1.5s keyframe_animation;' +
'animation:1.5s keyframe_animation;');
animator = $animateCss(element, {
event: 'enter',
structural: true
});
var runner = animator.start();
triggerAnimationStartFrame();
runner.pause();
expect(element.css(prefix + 'animation-play-state')).toEqual('paused');
runner.resume();
expect(element.attr('style')).toBeFalsy();
}));
it('should remove the animation-play-state style if the animation is closed',
inject(function($animateCss) {
element.attr('style', '');
ss.addRule('.ng-enter', '-webkit-animation:1.5s keyframe_animation;' +
'animation:1.5s keyframe_animation;');
animator = $animateCss(element, {
event: 'enter',
structural: true
});
var runner = animator.start();
triggerAnimationStartFrame();
runner.pause();
expect(element.css(prefix + 'animation-play-state')).toEqual('paused');
runner.end();
expect(element.attr('style')).toBeFalsy();
}));
});
describe("CSS", function() {
describe("detected styles", function() {
var element, options;
function assertAnimationComplete(bool) {
var assert = expect(element);
if (bool) {
assert = assert.not;
}
assert.toHaveClass('ng-enter');
assert.toHaveClass('ng-enter-active');
}
function keyframeProgress(element, duration, delay) {
browserTrigger(element, 'animationend',
{ timeStamp: Date.now() + ((delay || 1) * 1000), elapsedTime: duration });
}
function transitionProgress(element, duration, delay) {
browserTrigger(element, 'transitionend',
{ timeStamp: Date.now() + ((delay || 1) * 1000), elapsedTime: duration });
}
beforeEach(inject(function($rootElement, $document) {
element = jqLite('<div></div>');
$rootElement.append(element);
jqLite($document[0].body).append($rootElement);
options = { event: 'enter', structural: true };
}));
it("should always return an object even if no animation is detected",
inject(function($animateCss) {
ss.addRule('.some-animation', 'background:red;');
element.addClass('some-animation');
var animator = $animateCss(element, options);
expect(animator).toBeTruthy();
expect(isFunction(animator.start)).toBeTruthy();
expect(animator.end).toBeTruthy();
expect(animator.$$willAnimate).toBe(false);
}));
it("should close the animation immediately, but still return an animator object if no animation is detected",
inject(function($animateCss) {
ss.addRule('.another-fake-animation', 'background:blue;');
element.addClass('another-fake-animation');
var animator = $animateCss(element, {
event: 'enter',
structural: true
});
expect(element).not.toHaveClass('ng-enter');
expect(isFunction(animator.start)).toBeTruthy();
}));
they("should close the animation, but still accept $prop callbacks if no animation is detected",
['done', 'then'], function(method) {
inject(function($animateCss, $$rAF, $rootScope) {
ss.addRule('.the-third-fake-animation', 'background:green;');
element.addClass('another-fake-animation');
var animator = $animateCss(element, {
event: 'enter',
structural: true
});
var done = false;
animator.start()[method](function() {
done = true;
});
expect(done).toBe(false);
$$rAF.flush();
if (method === 'then') {
$rootScope.$digest();
}
expect(done).toBe(true);
});
});
they("should close the animation, but still accept recognize runner.$prop if no animation is detected",
['done(cancel)', 'catch'], function(method) {
inject(function($animateCss, $$rAF, $rootScope) {
ss.addRule('.the-third-fake-animation', 'background:green;');
element.addClass('another-fake-animation');
var animator = $animateCss(element, {
event: 'enter',
structural: true
});
var cancelled = false;
var runner = animator.start();
if (method === 'catch') {
runner.catch(function() {
cancelled = true;
});
} else {
runner.done(function(status) {
cancelled = status === false;
});
}
expect(cancelled).toBe(false);
runner.cancel();
if (method === 'catch') {
$rootScope.$digest();
}
expect(cancelled).toBe(true);
});
});
it("should use the highest transition duration value detected in the CSS class", inject(function($animateCss) {
ss.addRule('.ng-enter', 'transition:1s linear all;' +
'transition-duration:10s, 15s, 20s;');
var animator = $animateCss(element, options);
animator.start();
triggerAnimationStartFrame();
transitionProgress(element, 10);
assertAnimationComplete(false);
transitionProgress(element, 15);
assertAnimationComplete(false);
transitionProgress(element, 20);
assertAnimationComplete(true);
}));
it("should use the highest transition delay value detected in the CSS class", inject(function($animateCss) {
ss.addRule('.ng-enter', 'transition:1s linear all;' +
'transition-delay:10s, 15s, 20s;');
var animator = $animateCss(element, options);
animator.start();
triggerAnimationStartFrame();
transitionProgress(element, 1, 10);
assertAnimationComplete(false);
transitionProgress(element, 1, 15);
assertAnimationComplete(false);
transitionProgress(element, 1, 20);
assertAnimationComplete(true);
}));
it("should only close when both the animation delay and duration have passed",
inject(function($animateCss) {
ss.addRule('.ng-enter', 'transition:10s 5s linear all;');
var animator = $animateCss(element, options);
animator.start();
triggerAnimationStartFrame();
transitionProgress(element, 10, 2);
assertAnimationComplete(false);
transitionProgress(element, 9, 6);
assertAnimationComplete(false);
transitionProgress(element, 10, 5);
assertAnimationComplete(true);
}));
it("should use the highest keyframe duration value detected in the CSS class", inject(function($animateCss) {
ss.addRule('.ng-enter', 'animation:animation 1s, animation 2s, animation 3s;' +
'-webkit-animation:animation 1s, animation 2s, animation 3s;');
var animator = $animateCss(element, options);
animator.start();
triggerAnimationStartFrame();
keyframeProgress(element, 1);
assertAnimationComplete(false);
keyframeProgress(element, 2);
assertAnimationComplete(false);
keyframeProgress(element, 3);
assertAnimationComplete(true);
}));
it("should use the highest keyframe delay value detected in the CSS class", inject(function($animateCss) {
ss.addRule('.ng-enter', 'animation:animation 1s 2s, animation 1s 10s, animation 1s 1000ms;' +
'-webkit-animation:animation 1s 2s, animation 1s 10s, animation 1s 1000ms;');
var animator = $animateCss(element, options);
animator.start();
triggerAnimationStartFrame();
keyframeProgress(element, 1, 1);
assertAnimationComplete(false);
keyframeProgress(element, 1, 2);
assertAnimationComplete(false);
keyframeProgress(element, 1, 10);
assertAnimationComplete(true);
}));
it("should use the highest keyframe duration value detected in the CSS class with respect to the animation-iteration-count property", inject(function($animateCss) {
ss.addRule('.ng-enter',
'animation:animation 1s 2s 3, animation 1s 10s 2, animation 1s 1000ms infinite;' +
'-webkit-animation:animation 1s 2s 3, animation 1s 10s 2, animation 1s 1000ms infinite;');
var animator = $animateCss(element, options);
animator.start();
triggerAnimationStartFrame();
keyframeProgress(element, 1, 1);
assertAnimationComplete(false);
keyframeProgress(element, 1, 2);
assertAnimationComplete(false);
keyframeProgress(element, 3, 10);
assertAnimationComplete(true);
}));
it("should use the highest duration value when both transitions and keyframes are used", inject(function($animateCss) {
ss.addRule('.ng-enter', 'transition:1s linear all;' +
'transition-duration:10s, 15s, 20s;' +
'animation:animation 1s, animation 2s, animation 3s 0s 7;' +
'-webkit-animation:animation 1s, animation 2s, animation 3s 0s 7;');
var animator = $animateCss(element, options);
animator.start();
triggerAnimationStartFrame();
transitionProgress(element, 10);
keyframeProgress(element, 10);
assertAnimationComplete(false);
transitionProgress(element, 15);
keyframeProgress(element, 15);
assertAnimationComplete(false);
transitionProgress(element, 20);
keyframeProgress(element, 20);
assertAnimationComplete(false);
// 7 * 3 = 21
transitionProgress(element, 21);
keyframeProgress(element, 21);
assertAnimationComplete(true);
}));
it("should use the highest delay value when both transitions and keyframes are used", inject(function($animateCss) {
ss.addRule('.ng-enter', 'transition:1s linear all;' +
'transition-delay:10s, 15s, 20s;' +
'animation:animation 1s 2s, animation 1s 16s, animation 1s 19s;' +
'-webkit-animation:animation 1s 2s, animation 1s 16s, animation 1s 19s;');
var animator = $animateCss(element, options);
animator.start();
triggerAnimationStartFrame();
transitionProgress(element, 1, 10);
keyframeProgress(element, 1, 10);
assertAnimationComplete(false);
transitionProgress(element, 1, 16);
keyframeProgress(element, 1, 16);
assertAnimationComplete(false);
transitionProgress(element, 1, 19);
keyframeProgress(element, 1, 19);
assertAnimationComplete(false);
transitionProgress(element, 1, 20);
keyframeProgress(element, 1, 20);
assertAnimationComplete(true);
}));
});
describe("staggering", function() {
it("should apply a stagger based when an active ng-EVENT-stagger class with a transition-delay is detected",
inject(function($animateCss, $document, $rootElement, $timeout) {
jqLite($document[0].body).append($rootElement);
ss.addRule('.ng-enter-stagger', 'transition-delay:0.2s');
ss.addRule('.ng-enter', 'transition:2s linear all');
var elements = [];
var i;
var elm;
for (i = 0; i < 5; i++) {
elm = jqLite('<div></div>');
elements.push(elm);
$rootElement.append(elm);
$animateCss(elm, { event: 'enter', structural: true }).start();
expect(elm).not.toHaveClass('ng-enter-stagger');
expect(elm).toHaveClass('ng-enter');
}
triggerAnimationStartFrame();
expect(elements[0]).toHaveClass('ng-enter-active');
for (i = 1; i < 5; i++) {
elm = elements[i];
expect(elm).not.toHaveClass('ng-enter-active');
$timeout.flush(200);
expect(elm).toHaveClass('ng-enter-active');
browserTrigger(elm, 'transitionend',
{ timeStamp: Date.now() + 1000, elapsedTime: 2 });
expect(elm).not.toHaveClass('ng-enter');
expect(elm).not.toHaveClass('ng-enter-active');
expect(elm).not.toHaveClass('ng-enter-stagger');
}
}));
it("should apply a stagger based when for all provided addClass/removeClass CSS classes",
inject(function($animateCss, $document, $rootElement, $timeout) {
jqLite($document[0].body).append($rootElement);
ss.addRule('.red-add-stagger,' +
'.blue-remove-stagger,' +
'.green-add-stagger', 'transition-delay:0.2s');
ss.addRule('.red-add,' +
'.blue-remove,' +
'.green-add', 'transition:2s linear all');
var elements = [];
var i;
var elm;
for (i = 0; i < 5; i++) {
elm = jqLite('<div class="blue"></div>');
elements.push(elm);
$rootElement.append(elm);
$animateCss(elm, {
addClass: 'red green',
removeClass: 'blue'
}).start();
}
triggerAnimationStartFrame();
for (i = 0; i < 5; i++) {
elm = elements[i];
expect(elm).not.toHaveClass('red-add-stagger');
expect(elm).not.toHaveClass('green-add-stagger');
expect(elm).not.toHaveClass('blue-remove-stagger');
expect(elm).toHaveClass('red-add');
expect(elm).toHaveClass('green-add');
expect(elm).toHaveClass('blue-remove');
}
expect(elements[0]).toHaveClass('red-add-active');
expect(elements[0]).toHaveClass('green-add-active');
expect(elements[0]).toHaveClass('blue-remove-active');
for (i = 1; i < 5; i++) {
elm = elements[i];
expect(elm).not.toHaveClass('red-add-active');
expect(elm).not.toHaveClass('green-add-active');
expect(elm).not.toHaveClass('blue-remove-active');
$timeout.flush(200);
expect(elm).toHaveClass('red-add-active');
expect(elm).toHaveClass('green-add-active');
expect(elm).toHaveClass('blue-remove-active');
browserTrigger(elm, 'transitionend',
{ timeStamp: Date.now() + 1000, elapsedTime: 2 });
expect(elm).not.toHaveClass('red-add-active');
expect(elm).not.toHaveClass('green-add-active');
expect(elm).not.toHaveClass('blue-remove-active');
expect(elm).not.toHaveClass('red-add-stagger');
expect(elm).not.toHaveClass('green-add-stagger');
expect(elm).not.toHaveClass('blue-remove-stagger');
}
}));
it("should block the transition animation between start and animate when staggered",
inject(function($animateCss, $document, $rootElement) {
jqLite($document[0].body).append($rootElement);
ss.addRule('.ng-enter-stagger', 'transition-delay:0.2s');
ss.addRule('.ng-enter', 'transition:2s linear all;');
var element;
var i;
var elms = [];
for (i = 0; i < 5; i++) {
element = jqLite('<div class="transition-animation"></div>');
$rootElement.append(element);
$animateCss(element, { event: 'enter', structural: true }).start();
elms.push(element);
}
triggerAnimationStartFrame();
for (i = 0; i < 5; i++) {
element = elms[i];
if (i === 0) {
expect(element.attr('style')).toBeFalsy();
} else {
expect(element.css('transition-delay')).toContain('-2s');
}
}
}));
it("should block (pause) the keyframe animation between start and animate when staggered",
inject(function($animateCss, $document, $rootElement) {
jqLite($document[0].body).append($rootElement);
ss.addRule('.ng-enter-stagger', prefix + 'animation-delay:0.2s');
ss.addRule('.ng-enter', prefix + 'animation:my_animation 2s;');
var i, element, elements = [];
for (i = 0; i < 5; i++) {
element = jqLite('<div class="transition-animation"></div>');
$rootElement.append(element);
$animateCss(element, { event: 'enter', structural: true }).start();
elements.push(element);
}
triggerAnimationStartFrame();
for (i = 0; i < 5; i++) {
element = elements[i];
if (i === 0) { // the first element is always run right away
expect(element.attr('style')).toBeFalsy();
} else {
expect(element.css(prefix + 'animation-play-state')).toBe('paused');
}
}
}));
it("should not apply a stagger if the transition delay value is inherited from a earlier CSS class",
inject(function($animateCss, $document, $rootElement) {
jqLite($document[0].body).append($rootElement);
ss.addRule('.transition-animation', 'transition:2s 5s linear all;');
for (var i = 0; i < 5; i++) {
var element = jqLite('<div class="transition-animation"></div>');
$rootElement.append(element);
$animateCss(element, { event: 'enter', structural: true }).start();
triggerAnimationStartFrame();
expect(element).toHaveClass('ng-enter-active');
}
}));
it("should apply a stagger only if the transition duration value is zero when inherited from a earlier CSS class",
inject(function($animateCss, $document, $rootElement) {
jqLite($document[0].body).append($rootElement);
ss.addRule('.transition-animation', 'transition:2s 5s linear all;');
ss.addRule('.transition-animation.ng-enter-stagger',
'transition-duration:0s; transition-delay:0.2s;');
var element, i, elms = [];
for (i = 0; i < 5; i++) {
element = jqLite('<div class="transition-animation"></div>');
$rootElement.append(element);
elms.push(element);
$animateCss(element, { event: 'enter', structural: true }).start();
}
triggerAnimationStartFrame();
for (i = 1; i < 5; i++) {
element = elms[i];
expect(element).not.toHaveClass('ng-enter-active');
}
}));
it("should ignore animation staggers if only transition animations were detected",
inject(function($animateCss, $document, $rootElement) {
jqLite($document[0].body).append($rootElement);
ss.addRule('.ng-enter-stagger', prefix + 'animation-delay:0.2s');
ss.addRule('.transition-animation', 'transition:2s 5s linear all;');
for (var i = 0; i < 5; i++) {
var element = jqLite('<div class="transition-animation"></div>');
$rootElement.append(element);
$animateCss(element, { event: 'enter', structural: true }).start();
triggerAnimationStartFrame();
expect(element).toHaveClass('ng-enter-active');
}
}));
it("should ignore transition staggers if only keyframe animations were detected",
inject(function($animateCss, $document, $rootElement) {
jqLite($document[0].body).append($rootElement);
ss.addRule('.ng-enter-stagger', 'transition-delay:0.2s');
ss.addRule('.transition-animation', prefix + 'animation:2s 5s my_animation;');
for (var i = 0; i < 5; i++) {
var elm = jqLite('<div class="transition-animation"></div>');
$rootElement.append(elm);
var animator = $animateCss(elm, { event: 'enter', structural: true }).start();
triggerAnimationStartFrame();
expect(elm).toHaveClass('ng-enter-active');
}
}));
it("should start on the highest stagger value if both transition and keyframe staggers are used together",
inject(function($animateCss, $document, $rootElement, $timeout, $browser) {
jqLite($document[0].body).append($rootElement);
ss.addRule('.ng-enter-stagger', 'transition-delay:0.5s;' +
prefix + 'animation-delay:1s');
ss.addRule('.ng-enter', 'transition:10s linear all;' +
prefix + 'animation:my_animation 20s');
var i, elm, elements = [];
for (i = 0; i < 5; i++) {
elm = jqLite('<div></div>');
elements.push(elm);
$rootElement.append(elm);
$animateCss(elm, { event: 'enter', structural: true }).start();
expect(elm).toHaveClass('ng-enter');
}
triggerAnimationStartFrame();
expect(elements[0]).toHaveClass('ng-enter-active');
for (i = 1; i < 5; i++) {
elm = elements[i];
expect(elm).not.toHaveClass('ng-enter-active');
$timeout.flush(500);
expect(elm).not.toHaveClass('ng-enter-active');
$timeout.flush(500);
expect(elm).toHaveClass('ng-enter-active');
}
}));
it("should apply the closing timeout ontop of the stagger timeout",
inject(function($animateCss, $document, $rootElement, $timeout, $browser) {
jqLite($document[0].body).append($rootElement);
ss.addRule('.ng-enter-stagger', 'transition-delay:1s;');
ss.addRule('.ng-enter', 'transition:10s linear all;');
var elm, i, elms = [];
for (i = 0; i < 5; i++) {
elm = jqLite('<div></div>');
elms.push(elm);
$rootElement.append(elm);
$animateCss(elm, { event: 'enter', structural: true }).start();
triggerAnimationStartFrame();
}
for (i = 1; i < 2; i++) {
elm = elms[i];
expect(elm).toHaveClass('ng-enter');
$timeout.flush(1000);
$timeout.flush(15000);
expect(elm).not.toHaveClass('ng-enter');
}
}));
it("should apply the closing timeout ontop of the stagger timeout with an added delay",
inject(function($animateCss, $document, $rootElement, $timeout, $browser) {
jqLite($document[0].body).append($rootElement);
ss.addRule('.ng-enter-stagger', 'transition-delay:1s;');
ss.addRule('.ng-enter', 'transition:10s linear all; transition-delay:50s;');
var elm, i, elms = [];
for (i = 0; i < 5; i++) {
elm = jqLite('<div></div>');
elms.push(elm);
$rootElement.append(elm);
$animateCss(elm, { event: 'enter', structural: true }).start();
triggerAnimationStartFrame();
}
for (i = 1; i < 2; i++) {
elm = elms[i];
expect(elm).toHaveClass('ng-enter');
$timeout.flush(1000);
$timeout.flush(65000);
expect(elm).not.toHaveClass('ng-enter');
}
}));
it("should issue a stagger if a stagger value is provided in the options",
inject(function($animateCss, $document, $rootElement, $timeout) {
jqLite($document[0].body).append($rootElement);
ss.addRule('.ng-enter', 'transition:2s linear all');
var elm, i, elements = [];
for (i = 0; i < 5; i++) {
elm = jqLite('<div></div>');
elements.push(elm);
$rootElement.append(elm);
$animateCss(elm, {
event: 'enter',
structural: true,
stagger: 0.5
}).start();
expect(elm).toHaveClass('ng-enter');
}
triggerAnimationStartFrame();
expect(elements[0]).toHaveClass('ng-enter-active');
for (i = 1; i < 5; i++) {
elm = elements[i];
expect(elm).not.toHaveClass('ng-enter-active');
$timeout.flush(500);
expect(elm).toHaveClass('ng-enter-active');
browserTrigger(elm, 'transitionend',
{ timeStamp: Date.now() + 1000, elapsedTime: 2 });
expect(elm).not.toHaveClass('ng-enter');
expect(elm).not.toHaveClass('ng-enter-active');
expect(elm).not.toHaveClass('ng-enter-stagger');
}
}));
it("should only add/remove classes once the stagger timeout has passed",
inject(function($animateCss, $document, $rootElement, $timeout) {
jqLite($document[0].body).append($rootElement);
var element = jqLite('<div class="green"></div>');
$rootElement.append(element);
$animateCss(element, {
addClass: 'red',
removeClass: 'green',
duration: 5,
stagger: 0.5,
staggerIndex: 3
}).start();
triggerAnimationStartFrame();
expect(element).toHaveClass('green');
expect(element).not.toHaveClass('red');
$timeout.flush(1500);
expect(element).not.toHaveClass('green');
expect(element).toHaveClass('red');
}));
});
describe("closing timeout", function() {
it("should close off the animation after 150% of the animation time has passed",
inject(function($animateCss, $document, $rootElement, $timeout) {
ss.addRule('.ng-enter', 'transition:10s linear all;');