| 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
 | 'use strict';
describe('ngShow / ngHide', function() {
  var element;
  afterEach(function() {
    dealoc(element);
  });
  describe('ngShow', function() {
    it('should show and hide an element', inject(function($rootScope, $compile) {
      element = jqLite('<div ng-show="exp"></div>');
      element = $compile(element)($rootScope);
      $rootScope.$digest();
      expect(isCssVisible(element)).toEqual(false);
      $rootScope.exp = true;
      $rootScope.$digest();
      expect(isCssVisible(element)).toEqual(true);
    }));
    it('should make hidden element visible', inject(function($rootScope, $compile) {
      element = jqLite('<div style="display: none" ng-show="exp"></div>');
      element = $compile(element)($rootScope);
      expect(isCssVisible(element)).toBe(false);
      $rootScope.exp = true;
      $rootScope.$digest();
      expect(isCssVisible(element)).toBe(true);
    }));
  });
  describe('ngHide', function() {
    it('should hide an element', inject(function($rootScope, $compile) {
      element = jqLite('<div ng-hide="exp"></div>');
      element = $compile(element)($rootScope);
      expect(isCssVisible(element)).toBe(true);
      $rootScope.exp = true;
      $rootScope.$digest();
      expect(isCssVisible(element)).toBe(false);
    }));
  });
});
describe('ngShow / ngHide - ngAnimate', function() {
  var window;
  var vendorPrefix;
  var body, element, $rootElement;
  function html(html) {
    body.append($rootElement);
    $rootElement.html(html);
    element = $rootElement.children().eq(0);
    return element;
  }
  beforeEach(function() {
    // we need to run animation on attached elements;
    body = jqLite(document.body);
  });
  afterEach(function(){
    dealoc(body);
    dealoc(element);
    body.removeAttr('ng-animation-running');
  });
  beforeEach(module(function($animationProvider, $provide) {
    $provide.value('$window', window = angular.mock.createMockWindow());
    return function($sniffer, _$rootElement_, $animator) {
      vendorPrefix = '-' + $sniffer.vendorPrefix + '-';
      $rootElement = _$rootElement_;
      $animator.enabled(true);
    };
  }));
  describe('ngShow', function() {
    it('should fire off the animator.show and animator.hide animation', inject(function($compile, $rootScope, $sniffer) {
      var $scope = $rootScope.$new();
      $scope.on = true;
      element = $compile(html(
        '<div ' +
          'style="'+vendorPrefix+'transition: 1s linear all"' +
          'ng-show="on" ' +
          'ng-animate="{show: \'custom-show\', hide: \'custom-hide\', animateFirst: true}">' +
        '</div>'
      ))($scope);
      $scope.$digest();
      if ($sniffer.transitions) {
        expect(element.attr('class')).toContain('custom-show');
        window.setTimeout.expect(1).process();
        expect(element.attr('class')).toContain('custom-show-active');
        window.setTimeout.expect(1000).process();
      } else {
        expect(window.setTimeout.queue).toEqual([]);
      }
      expect(element.attr('class')).not.toContain('custom-show-active');
      expect(element.attr('class')).not.toContain('custom-show');
      $scope.on = false;
      $scope.$digest();
      if ($sniffer.transitions) {
        expect(element.attr('class')).toContain('custom-hide');
        window.setTimeout.expect(1).process();
        expect(element.attr('class')).toContain('custom-hide-active');
        window.setTimeout.expect(1000).process();
      } else {
        expect(window.setTimeout.queue).toEqual([]);
      }
      expect(element.attr('class')).not.toContain('custom-hide-active');
      expect(element.attr('class')).not.toContain('custom-hide');
    }));
    it('should skip animation if parent animation running', function() {
      var fired = false;
      inject(function($animator, $compile, $rootScope, $sniffer) {
        $animator.enabled(true);
        $rootScope.$digest();
        $rootScope.val = true;
        var element = $compile(html('<div ng-show="val" ng-animate="\'animation\'">123</div>'))($rootScope);
        $rootElement.controller('ngAnimate').running = true;
        element.css('display','none');
        expect(element.css('display')).toBe('none');
        $rootScope.$digest();
        expect(element[0].style.display).toBe('');
        expect(fired).toBe(false);
        $rootElement.controller('ngAnimate').running = false;
        $rootScope.val = false;
        $rootScope.$digest();
        if ($sniffer.transitions) {
          window.setTimeout.expect(1).process();
          window.setTimeout.expect(0).process();
        } else {
          expect(window.setTimeout.queue).toEqual([]);
        }
        expect(element[0].style.display).toBe('none');
      });
    });
  });
  describe('ngHide', function() {
    it('should fire off the animator.show and animator.hide animation', inject(function($compile, $rootScope, $sniffer) {
      var $scope = $rootScope.$new();
      $scope.off = true;
      element = $compile(html(
          '<div ' +
              'style="'+vendorPrefix+'transition: 1s linear all"' +
              'ng-hide="off" ' +
              'ng-animate="{show: \'custom-show\', hide: \'custom-hide\', animateFirst: true}">' +
          '</div>'
      ))($scope);
      $scope.$digest();
      if ($sniffer.transitions) {
        expect(element.attr('class')).toContain('custom-hide');
        window.setTimeout.expect(1).process();
        expect(element.attr('class')).toContain('custom-hide-active');
        window.setTimeout.expect(1000).process();
      } else {
        expect(window.setTimeout.queue).toEqual([]);
      }
      expect(element.attr('class')).not.toContain('custom-hide-active');
      expect(element.attr('class')).not.toContain('custom-hide');
      $scope.off = false;
      $scope.$digest();
      if ($sniffer.transitions) {
        expect(element.attr('class')).toContain('custom-show');
        window.setTimeout.expect(1).process();
        expect(element.attr('class')).toContain('custom-show-active');
        window.setTimeout.expect(1000).process();
      } else {
        expect(window.setTimeout.queue).toEqual([]);
      }
      expect(element.attr('class')).not.toContain('custom-show-active');
      expect(element.attr('class')).not.toContain('custom-show');
    }));
    it('should disable animation when parent animation is running', function() {
      var fired = false;
      module(function($animationProvider) {
        $animationProvider.register('destructive-animation', function() {
          return {
            setup : function() {},
            start : function(element, done) {
              fired = true;
            }
          };
        });
      });
      inject(function($compile, $rootScope) {
        $rootScope.val = false;
        var element = $compile(html('<div ng-hide="val" ng-animate="{ hide:\'destructive-animation\' }">123</div>'))($rootScope);
        $rootElement.controller('ngAnimate').running = true;
        element.css('display','block');
        expect(element.css('display')).toBe('block');
        $rootScope.val = true;
        $rootScope.$digest();
        expect(element.css('display')).toBe('none');
        expect(fired).toBe(false);
      });
    });
  });
});
 |