diff options
| author | Matias Niemelä | 2013-10-25 14:20:35 -0400 | 
|---|---|---|
| committer | Matias Niemelä | 2013-10-28 15:00:47 -0600 | 
| commit | 74848307443c00ab07552336c56ddfa1e9ef6eff (patch) | |
| tree | a355975cf7f48dcb0a2b2c9a87d2108f5628ade8 /test | |
| parent | 29e40c1f1c530f045e541e308ac5138ee749655a (diff) | |
| download | angular.js-74848307443c00ab07552336c56ddfa1e9ef6eff.tar.bz2 | |
feat(ngAnimate): provide support for staggering animations with CSS
Diffstat (limited to 'test')
| -rw-r--r-- | test/ngAnimate/animateSpec.js | 123 | 
1 files changed, 122 insertions, 1 deletions
diff --git a/test/ngAnimate/animateSpec.js b/test/ngAnimate/animateSpec.js index 4d3fdd1f..7bd9fc85 100644 --- a/test/ngAnimate/animateSpec.js +++ b/test/ngAnimate/animateSpec.js @@ -642,6 +642,66 @@ describe("ngAnimate", function() {              expect(element.hasClass('ng-hide-remove-active')).toBe(false);          })); + +        it("should stagger the items when the correct CSS class is provided", +          inject(function($animate, $rootScope, $compile, $sniffer, $timeout, $document, $rootElement) { + +          if(!$sniffer.animations) return; + +          $animate.enabled(true); + +          ss.addRule('.ani.ng-enter, .ani.ng-leave, .ani-fake.ng-enter, .ani-fake.ng-leave', +            '-webkit-animation:1s my_animation;' +  +            'transition:1s my_animation;'); + +          ss.addRule('.ani.ng-enter-stagger, .ani.ng-leave-stagger', +            '-webkit-animation-delay:0.1s;' + +            '-webkit-animation-duration:0s;' + +            'animation-delay:0.1s;' +  +            'animation-duration:0s;'); + +          ss.addRule('.ani-fake.ng-enter-stagger, .ani-fake.ng-leave-stagger', +            '-webkit-animation-delay:0.1s;' + +            '-webkit-animation-duration:1s;' + +            'animation-delay:0.1s;' +  +            'animation-duration:1s;'); + +          var container = $compile(html('<div></div>'))($rootScope); + +          var elements = []; +          for(var i = 0; i < 5; i++) { +            var newScope = $rootScope.$new(); +            var element = $compile('<div class="ani"></div>')(newScope); +            $animate.enter(element, container); +            elements.push(element); +          }; + +          $rootScope.$digest(); +          $timeout.flush(); + +          expect(elements[0].attr('style')).toBeFalsy(); +          expect(elements[1].attr('style')).toMatch(/animation-delay: 0\.1\d*s/); +          expect(elements[2].attr('style')).toMatch(/animation-delay: 0\.2\d*s/); +          expect(elements[3].attr('style')).toMatch(/animation-delay: 0\.3\d*s/); +          expect(elements[4].attr('style')).toMatch(/animation-delay: 0\.4\d*s/); + +          for(var i = 0; i < 5; i++) { +            dealoc(elements[i]); +            var newScope = $rootScope.$new(); +            var element = $compile('<div class="ani-fake"></div>')(newScope); +            $animate.enter(element, container); +            elements[i] = element; +          }; + +          $rootScope.$digest(); +          $timeout.flush(); + +          expect(elements[0].attr('style')).toBeFalsy(); +          expect(elements[1].attr('style')).not.toMatch(/animation-delay: 0\.1\d*s/); +          expect(elements[2].attr('style')).not.toMatch(/animation-delay: 0\.2\d*s/); +          expect(elements[3].attr('style')).not.toMatch(/animation-delay: 0\.3\d*s/); +          expect(elements[4].attr('style')).not.toMatch(/animation-delay: 0\.4\d*s/); +        }));        });        describe("Transitions", function() { @@ -785,6 +845,66 @@ describe("ngAnimate", function() {                expect(element.hasClass('ng-hide-add-active')).toBe(true);              }          })); + +        it("should stagger the items when the correct CSS class is provided", +          inject(function($animate, $rootScope, $compile, $sniffer, $timeout, $document, $rootElement) { + +          if(!$sniffer.transitions) return; + +          $animate.enabled(true); + +          ss.addRule('.ani.ng-enter, .ani.ng-leave, .ani-fake.ng-enter, .ani-fake.ng-leave', +            '-webkit-transition:1s linear all;' +  +            'transition:1s linear all;'); + +          ss.addRule('.ani.ng-enter-stagger, .ani.ng-leave-stagger', +            '-webkit-transition-delay:0.1s;' + +            '-webkit-transition-duration:0s;' + +            'transition-delay:0.1s;' +  +            'transition-duration:0s;'); + +          ss.addRule('.ani-fake.ng-enter-stagger, .ani-fake.ng-leave-stagger', +            '-webkit-transition-delay:0.1s;' + +            '-webkit-transition-duration:1s;' + +            'transition-delay:0.1s;' +  +            'transition-duration:1s;'); + +          var container = $compile(html('<div></div>'))($rootScope); + +          var elements = []; +          for(var i = 0; i < 5; i++) { +            var newScope = $rootScope.$new(); +            var element = $compile('<div class="ani"></div>')(newScope); +            $animate.enter(element, container); +            elements.push(element); +          }; + +          $rootScope.$digest(); +          $timeout.flush(); + +          expect(elements[0].attr('style')).toBeFalsy(); +          expect(elements[1].attr('style')).toMatch(/transition-delay: 0\.1\d*s/); +          expect(elements[2].attr('style')).toMatch(/transition-delay: 0\.2\d*s/); +          expect(elements[3].attr('style')).toMatch(/transition-delay: 0\.3\d*s/); +          expect(elements[4].attr('style')).toMatch(/transition-delay: 0\.4\d*s/); + +          for(var i = 0; i < 5; i++) { +            dealoc(elements[i]); +            var newScope = $rootScope.$new(); +            var element = $compile('<div class="ani-fake"></div>')(newScope); +            $animate.enter(element, container); +            elements[i] = element; +          }; + +          $rootScope.$digest(); +          $timeout.flush(); + +          expect(elements[0].attr('style')).toBeFalsy(); +          expect(elements[1].attr('style')).not.toMatch(/transition-delay: 0\.1\d*s/); +          expect(elements[2].attr('style')).not.toMatch(/transition-delay: 0\.2\d*s/); +          expect(elements[3].attr('style')).not.toMatch(/transition-delay: 0\.3\d*s/); +          expect(elements[4].attr('style')).not.toMatch(/transition-delay: 0\.4\d*s/); +        }));        });      }); @@ -2008,7 +2128,8 @@ describe("ngAnimate", function() {        $rootScope.$digest();        $timeout.flush(); -      expect(count).toBe(2); +      //called three times since the classname is the same +      expect(count).toBe(3);        dealoc(element);        count = 0;  | 
