@@ -36,7 +36,7 @@ describe("ngAnimate", function() {
36
36
37
37
describe ( "enable / disable" , function ( ) {
38
38
39
- it ( "should disable and enable the animations" , function ( ) {
39
+ it ( "should work for all animations" , function ( ) {
40
40
var $animate , initialState = null ;
41
41
42
42
angular . bootstrap ( body , [ 'ngAnimate' , function ( ) {
@@ -56,7 +56,6 @@ describe("ngAnimate", function() {
56
56
expect ( $animate . enabled ( 1 ) ) . toBe ( true ) ;
57
57
expect ( $animate . enabled ( ) ) . toBe ( true ) ;
58
58
} ) ;
59
-
60
59
} ) ;
61
60
62
61
describe ( "with polyfill" , function ( ) {
@@ -229,6 +228,7 @@ describe("ngAnimate", function() {
229
228
expect ( child . attr ( 'class' ) ) . toContain ( 'ng-enter' ) ;
230
229
expect ( child . attr ( 'class' ) ) . toContain ( 'ng-enter-active' ) ;
231
230
browserTrigger ( child , 'transitionend' , { timeStamp : Date . now ( ) + 1000 , elapsedTime : 1000 } ) ;
231
+ $timeout . flush ( ) ;
232
232
233
233
//move
234
234
element . append ( after ) ;
@@ -239,6 +239,7 @@ describe("ngAnimate", function() {
239
239
expect ( child . attr ( 'class' ) ) . toContain ( 'ng-move' ) ;
240
240
expect ( child . attr ( 'class' ) ) . toContain ( 'ng-move-active' ) ;
241
241
browserTrigger ( child , 'transitionend' , { timeStamp : Date . now ( ) + 1000 , elapsedTime : 1000 } ) ;
242
+ $timeout . flush ( ) ;
242
243
243
244
//hide
244
245
$animate . addClass ( child , 'ng-hide' ) ;
@@ -261,6 +262,7 @@ describe("ngAnimate", function() {
261
262
expect ( child . attr ( 'class' ) ) . toContain ( 'ng-leave' ) ;
262
263
expect ( child . attr ( 'class' ) ) . toContain ( 'ng-leave-active' ) ;
263
264
browserTrigger ( child , 'transitionend' , { timeStamp : Date . now ( ) + 1000 , elapsedTime : 1000 } ) ;
265
+ $timeout . flush ( ) ;
264
266
} ) ) ;
265
267
266
268
it ( "should not run if animations are disabled" ,
@@ -330,6 +332,29 @@ describe("ngAnimate", function() {
330
332
expect ( child . hasClass ( 'animation-cancelled' ) ) . toBe ( true ) ;
331
333
} ) ) ;
332
334
335
+ it ( "should skip a class-based animation if the same element already has an ongoing structural animation" ,
336
+ inject ( function ( $animate , $rootScope , $sniffer , $timeout ) {
337
+
338
+ var completed = false ;
339
+ $animate . enter ( child , element , null , function ( ) {
340
+ completed = true ;
341
+ } ) ;
342
+ $rootScope . $digest ( ) ;
343
+
344
+ expect ( completed ) . toBe ( false ) ;
345
+
346
+ $animate . addClass ( child , 'green' ) ;
347
+ expect ( element . hasClass ( 'green' ) ) ;
348
+
349
+ expect ( completed ) . toBe ( false ) ;
350
+ if ( $sniffer . transitions ) {
351
+ $timeout . flush ( ) ;
352
+ browserTrigger ( child , 'transitionend' , { timeStamp : Date . now ( ) + 1000 , elapsedTime : 1000 } ) ;
353
+ }
354
+ $timeout . flush ( ) ;
355
+
356
+ expect ( completed ) . toBe ( true ) ;
357
+ } ) ) ;
333
358
334
359
it ( "should fire the cancel/end function with the correct flag in the parameters" ,
335
360
inject ( function ( $animate , $rootScope , $sniffer , $timeout ) {
@@ -722,6 +747,7 @@ describe("ngAnimate", function() {
722
747
expect ( element . hasClass ( 'ng-enter-active' ) ) . toBe ( true ) ;
723
748
browserTrigger ( element , 'transitionend' , { timeStamp : Date . now ( ) + 22000 , elapsedTime : 22000 } ) ;
724
749
}
750
+ $timeout . flush ( ) ;
725
751
expect ( element . hasClass ( 'abc' ) ) . toBe ( true ) ;
726
752
727
753
$rootScope . klass = 'xyz' ;
@@ -735,6 +761,7 @@ describe("ngAnimate", function() {
735
761
expect ( element . hasClass ( 'ng-enter-active' ) ) . toBe ( true ) ;
736
762
browserTrigger ( element , 'transitionend' , { timeStamp : Date . now ( ) + 11000 , elapsedTime : 11000 } ) ;
737
763
}
764
+ $timeout . flush ( ) ;
738
765
expect ( element . hasClass ( 'xyz' ) ) . toBe ( true ) ;
739
766
} ) ) ;
740
767
@@ -767,7 +794,8 @@ describe("ngAnimate", function() {
767
794
browserTrigger ( element , 'transitionend' , { timeStamp : Date . now ( ) + 3000 , elapsedTime : 3000 } ) ;
768
795
}
769
796
770
- expect ( element . hasClass ( 'one two' ) ) . toBe ( true ) ;
797
+ expect ( element . hasClass ( 'one' ) ) . toBe ( true ) ;
798
+ expect ( element . hasClass ( 'two' ) ) . toBe ( true ) ;
771
799
} ) ) ;
772
800
} ) ;
773
801
@@ -1670,6 +1698,7 @@ describe("ngAnimate", function() {
1670
1698
1671
1699
expect ( animationState ) . toBe ( 'enter-cancel' ) ;
1672
1700
$rootScope . $digest ( ) ;
1701
+ $timeout . flush ( ) ;
1673
1702
1674
1703
$animate . addClass ( child , 'something' ) ;
1675
1704
expect ( animationState ) . toBe ( 'addClass' ) ;
@@ -1711,4 +1740,139 @@ describe("ngAnimate", function() {
1711
1740
expect ( element [ 0 ] . querySelectorAll ( '.ng-enter-active' ) . length ) . toBe ( 0 ) ;
1712
1741
} ) ) ;
1713
1742
1743
+
1744
+ it ( "should work to disable all child animations for an element" , function ( ) {
1745
+ var childAnimated = false ,
1746
+ containerAnimated = false ;
1747
+ module ( function ( $animateProvider ) {
1748
+ $animateProvider . register ( '.child' , function ( ) {
1749
+ return {
1750
+ addClass : function ( element , className , done ) {
1751
+ childAnimated = true ;
1752
+ done ( ) ;
1753
+ }
1754
+ }
1755
+ } ) ;
1756
+ $animateProvider . register ( '.container' , function ( ) {
1757
+ return {
1758
+ leave : function ( element , done ) {
1759
+ containerAnimated = true ;
1760
+ done ( ) ;
1761
+ }
1762
+ }
1763
+ } ) ;
1764
+ } ) ;
1765
+
1766
+ inject ( function ( $compile , $rootScope , $animate , $timeout , $rootElement ) {
1767
+ $animate . enabled ( true ) ;
1768
+
1769
+ var element = $compile ( '<div class="container"></div>' ) ( $rootScope ) ;
1770
+ jqLite ( $document [ 0 ] . body ) . append ( $rootElement ) ;
1771
+ $rootElement . append ( element ) ;
1772
+
1773
+ var child = $compile ( '<div class="child"></div>' ) ( $rootScope ) ;
1774
+ element . append ( child ) ;
1775
+
1776
+ $animate . enabled ( true , element ) ;
1777
+
1778
+ $animate . addClass ( child , 'awesome' ) ;
1779
+ expect ( childAnimated ) . toBe ( true ) ;
1780
+
1781
+ childAnimated = false ;
1782
+ $animate . enabled ( false , element ) ;
1783
+
1784
+ $animate . addClass ( child , 'super' ) ;
1785
+ expect ( childAnimated ) . toBe ( false ) ;
1786
+
1787
+ $animate . leave ( element ) ;
1788
+ $rootScope . $digest ( ) ;
1789
+ expect ( containerAnimated ) . toBe ( true ) ;
1790
+ } ) ;
1791
+ } ) ;
1792
+
1793
+ it ( "should disable all child animations on structural animations until the first reflow has passed" , function ( ) {
1794
+ var intercepted ;
1795
+ module ( function ( $animateProvider ) {
1796
+ $animateProvider . register ( '.animated' , function ( ) {
1797
+ return {
1798
+ enter : ani ( 'enter' ) ,
1799
+ leave : ani ( 'leave' ) ,
1800
+ move : ani ( 'move' ) ,
1801
+ addClass : ani ( 'addClass' ) ,
1802
+ removeClass : ani ( 'removeClass' )
1803
+ } ;
1804
+
1805
+ function ani ( type ) {
1806
+ return function ( element , className , done ) {
1807
+ intercepted = type ;
1808
+ ( done || className ) ( ) ;
1809
+ }
1810
+ }
1811
+ } ) ;
1812
+ } ) ;
1813
+
1814
+ inject ( function ( $animate , $rootScope , $sniffer , $timeout , $compile , _$rootElement_ ) {
1815
+ $rootElement = _$rootElement_ ;
1816
+
1817
+ $animate . enabled ( true ) ;
1818
+ $rootScope . $digest ( ) ;
1819
+
1820
+ var element = $compile ( '<div class="element animated">...</div>' ) ( $rootScope ) ;
1821
+ var child1 = $compile ( '<div class="child1 animated">...</div>' ) ( $rootScope ) ;
1822
+ var child2 = $compile ( '<div class="child2 animated">...</div>' ) ( $rootScope ) ;
1823
+ var container = $compile ( '<div class="container">...</div>' ) ( $rootScope ) ;
1824
+
1825
+ jqLite ( $document [ 0 ] . body ) . append ( $rootElement ) ;
1826
+ $rootElement . append ( container ) ;
1827
+ element . append ( child1 ) ;
1828
+ element . append ( child2 ) ;
1829
+
1830
+ $animate . move ( element , null , container ) ;
1831
+ $rootScope . $digest ( ) ;
1832
+
1833
+ expect ( intercepted ) . toBe ( 'move' ) ;
1834
+
1835
+ $animate . addClass ( child1 , 'test' ) ;
1836
+ expect ( child1 . hasClass ( 'test' ) ) . toBe ( true ) ;
1837
+
1838
+ expect ( intercepted ) . toBe ( 'move' ) ;
1839
+ $animate . leave ( child1 ) ;
1840
+ $rootScope . $digest ( ) ;
1841
+
1842
+ expect ( intercepted ) . toBe ( 'move' ) ;
1843
+
1844
+ //reflow has passed
1845
+ $timeout . flush ( ) ;
1846
+
1847
+ $animate . leave ( child2 ) ;
1848
+ $rootScope . $digest ( ) ;
1849
+ expect ( intercepted ) . toBe ( 'leave' ) ;
1850
+ } ) ;
1851
+ } ) ;
1852
+
1853
+ it ( "should not disable any child animations when any parent class-based animations are run" , function ( ) {
1854
+ var intercepted ;
1855
+ module ( function ( $animateProvider ) {
1856
+ $animateProvider . register ( '.animated' , function ( ) {
1857
+ return {
1858
+ enter : function ( element , done ) {
1859
+ intercepted = true ;
1860
+ done ( ) ;
1861
+ }
1862
+ }
1863
+ } ) ;
1864
+ } ) ;
1865
+
1866
+ inject ( function ( $animate , $rootScope , $sniffer , $timeout , $compile , $document , $rootElement ) {
1867
+ $animate . enabled ( true ) ;
1868
+
1869
+ var element = $compile ( '<div ng-class="{klass:bool}"> <div ng-if="bool" class="animated">value</div></div>' ) ( $rootScope ) ;
1870
+ $rootElement . append ( element ) ;
1871
+ jqLite ( $document [ 0 ] . body ) . append ( $rootElement ) ;
1872
+
1873
+ $rootScope . bool = true ;
1874
+ $rootScope . $digest ( ) ;
1875
+ expect ( intercepted ) . toBe ( true ) ;
1876
+ } ) ;
1877
+ } ) ;
1714
1878
} ) ;
0 commit comments