diff options
| author | Matias Niemelä | 2013-06-18 13:59:57 -0400 | 
|---|---|---|
| committer | Misko Hevery | 2013-07-26 23:49:54 -0700 | 
| commit | 81923f1e41560327f7de6e8fddfda0d2612658f3 (patch) | |
| tree | bbf8151bddf4d026f8f5fa3196b84a45ecd9c858 /test/ng/directive/ngIfSpec.js | |
| parent | 11521a4cde689c2bd6aaa227b1f45cb3fb53725b (diff) | |
| download | angular.js-81923f1e41560327f7de6e8fddfda0d2612658f3.tar.bz2 | |
feat(ngAnimate): complete rewrite of animations
- ngAnimate directive is gone and was replaced with class based animations/transitions
- support for triggering animations on css class additions and removals
- done callback was added to all animation apis
- $animation and $animator where merged into a single $animate service with api:
  - $animate.enter(element, parent, after, done);
  - $animate.leave(element, done);
  - $animate.move(element, parent, after, done);
  - $animate.addClass(element, className, done);
  - $animate.removeClass(element, className, done);
BREAKING CHANGE: too many things changed, we'll write up a separate doc with migration instructions
Diffstat (limited to 'test/ng/directive/ngIfSpec.js')
| -rwxr-xr-x | test/ng/directive/ngIfSpec.js | 86 | 
1 files changed, 21 insertions, 65 deletions
| diff --git a/test/ng/directive/ngIfSpec.js b/test/ng/directive/ngIfSpec.js index 0cca57d5..8f2cb793 100755 --- a/test/ng/directive/ngIfSpec.js +++ b/test/ng/directive/ngIfSpec.js @@ -75,8 +75,7 @@ describe('ngIf', function () {  }); -describe('ngIf ngAnimate', function () { -  var vendorPrefix, window; +describe('ngIf animations', function () {    var body, element, $rootElement;    function html(html) { @@ -85,6 +84,8 @@ describe('ngIf ngAnimate', function () {      return element;    } +  beforeEach(module('mock.animate')); +    beforeEach(module(function() {      // we need to run animation on attached elements;      return function(_$rootElement_) { @@ -99,97 +100,52 @@ describe('ngIf ngAnimate', function () {      dealoc(element);    }); -  beforeEach(module(function($animationProvider, $provide) { -    $provide.value('$window', window = angular.mock.createMockWindow()); -    return function($sniffer, $animator) { -      vendorPrefix = '-' + $sniffer.vendorPrefix + '-'; -      $animator.enabled(true); +  beforeEach(module(function($animateProvider, $provide) { +    return function($animate) { +      $animate.enabled(true);      };    })); -  it('should fire off the enter animation + add and remove the css classes', -    inject(function($compile, $rootScope, $sniffer) { +  it('should fire off the enter animation', +    inject(function($compile, $rootScope, $animate) { +      var item;        var $scope = $rootScope.$new(); -      var style = vendorPrefix + 'transition: 1s linear all';        element = $compile(html(          '<div>' + -          '<div ng-if="value" style="' + style + '" ng-animate="{enter: \'custom-enter\', leave: \'custom-leave\'}"><div>Hi</div></div>' + +          '<div ng-if="value"><div>Hi</div></div>' +          '</div>'        ))($scope);        $rootScope.$digest();        $scope.$apply('value = true'); +      item = $animate.process('enter').element; +      expect(item.text()).toBe('Hi');        expect(element.children().length).toBe(1); -      var first = element.children()[0]; - -      if ($sniffer.transitions) { -        expect(first.className).toContain('custom-enter'); -        window.setTimeout.expect(1).process(); -        expect(first.className).toContain('custom-enter-active'); -        window.setTimeout.expect(1000).process(); -      } else { -        expect(window.setTimeout.queue).toEqual([]); -      } - -      expect(first.className).not.toContain('custom-enter'); -      expect(first.className).not.toContain('custom-enter-active');    })); -  it('should fire off the leave animation + add and remove the css classes', -    inject(function ($compile, $rootScope, $sniffer) { +  it('should fire off the leave animation', +    inject(function ($compile, $rootScope, $animate) { +      var item;        var $scope = $rootScope.$new(); -      var style = vendorPrefix + 'transition: 1s linear all';        element = $compile(html(          '<div>' + -          '<div ng-if="value" style="' + style + '" ng-animate="{enter: \'custom-enter\', leave: \'custom-leave\'}"><div>Hi</div></div>' + +          '<div ng-if="value"><div>Hi</div></div>' +          '</div>'        ))($scope);        $scope.$apply('value = true'); -      expect(element.children().length).toBe(1); -      var first = element.children()[0]; - -      if ($sniffer.transitions) { -        window.setTimeout.expect(1).process(); -        window.setTimeout.expect(1000).process(); -      } else { -        expect(window.setTimeout.queue).toEqual([]); -      } +      item = $animate.process('enter').element; +      expect(item.text()).toBe('Hi');        $scope.$apply('value = false'); -      expect(element.children().length).toBe($sniffer.transitions ? 1 : 0); +      expect(element.children().length).toBe(1); -      if ($sniffer.transitions) { -        expect(first.className).toContain('custom-leave'); -        window.setTimeout.expect(1).process(); -        expect(first.className).toContain('custom-leave-active'); -        window.setTimeout.expect(1000).process(); -      } else { -        expect(window.setTimeout.queue).toEqual([]); -      } +      item = $animate.process('leave').element; +      expect(item.text()).toBe('Hi');        expect(element.children().length).toBe(0);    })); -  it('should catch and use the correct duration for animation', -    inject(function ($compile, $rootScope, $sniffer) { -      var $scope = $rootScope.$new(); -      var style = vendorPrefix + 'transition: 0.5s linear all'; -      element = $compile(html( -        '<div>' + -          '<div ng-if="value" style="' + style + '" ng-animate="{enter: \'custom-enter\', leave: \'custom-leave\'}"><div>Hi</div></div>' + -        '</div>' -      ))($scope); -      $scope.$apply('value = true'); - -      if ($sniffer.transitions) { -        window.setTimeout.expect(1).process(); -        window.setTimeout.expect(500).process(); -      } else { -        expect(window.setTimeout.queue).toEqual([]); -      } -  })); -  }); | 
