|
| 1 | +describe('showHide', function() { |
| 2 | + var $compile, $timeout, defered, scope, spy; |
| 3 | + |
| 4 | + beforeEach(module('material.components.showHide')); |
| 5 | + |
| 6 | + beforeEach(inject(function(_$compile_, $mdUtil, $q, $rootScope, _$timeout_) { |
| 7 | + $compile = _$compile_; |
| 8 | + $timeout = _$timeout_; |
| 9 | + defered = $q.defer(); |
| 10 | + scope = $rootScope.$new(); |
| 11 | + spy = jasmine.createSpy(); |
| 12 | + |
| 13 | + scope.$on('$md-resize', spy); |
| 14 | + spyOn($mdUtil.dom.animator, 'waitTransitionEnd').and.returnValue(defered.promise); |
| 15 | + })); |
| 16 | + |
| 17 | + afterEach(function() { |
| 18 | + scope.$destroy(); |
| 19 | + }); |
| 20 | + |
| 21 | + describe('ng-hide', function() { |
| 22 | + it('should notify when the node unhides', function() { |
| 23 | + scope.hide = true; |
| 24 | + var element = $compile('<div ng-hide="hide"></div>')(scope); |
| 25 | + scope.$apply(); |
| 26 | + expect(spy).not.toHaveBeenCalled(); |
| 27 | + |
| 28 | + // Expect a $broadcast when showing. |
| 29 | + scope.hide = false; |
| 30 | + scope.$apply(); |
| 31 | + $timeout.flush(); |
| 32 | + expect(spy).toHaveBeenCalled(); |
| 33 | + |
| 34 | + // Expect a $broadcast on transitionEnd after showing. |
| 35 | + spy.calls.reset(); |
| 36 | + defered.resolve(); |
| 37 | + scope.$apply(); |
| 38 | + expect(spy).toHaveBeenCalled(); |
| 39 | + }); |
| 40 | + |
| 41 | + it('should not notify on hide', function() { |
| 42 | + scope.hide = true; |
| 43 | + var element = $compile('<div ng-hide="hide"></div>')(scope); |
| 44 | + scope.$apply(); |
| 45 | + |
| 46 | + // Expect no $broadcasts when hiding. |
| 47 | + expect(spy).not.toHaveBeenCalled(); |
| 48 | + defered.resolve(); |
| 49 | + scope.$apply(); |
| 50 | + expect(spy).not.toHaveBeenCalled(); |
| 51 | + }); |
| 52 | + }); |
| 53 | + |
| 54 | + describe('ng-show', function() { |
| 55 | + it('should notify when the node unhides', function() { |
| 56 | + scope.show = false; |
| 57 | + var element = $compile('<div ng-show="show"></div>')(scope); |
| 58 | + scope.$apply(); |
| 59 | + expect(spy).not.toHaveBeenCalled(); |
| 60 | + |
| 61 | + // Expect a $broadcast when showing. |
| 62 | + scope.show = true; |
| 63 | + scope.$apply(); |
| 64 | + $timeout.flush(); |
| 65 | + expect(spy).toHaveBeenCalled(); |
| 66 | + |
| 67 | + // Expect a $broadcast on transitionEnd after showing. |
| 68 | + spy.calls.reset(); |
| 69 | + defered.resolve(); |
| 70 | + scope.$apply(); |
| 71 | + expect(spy).toHaveBeenCalled(); |
| 72 | + }); |
| 73 | + |
| 74 | + it('should not notify on hide', function() { |
| 75 | + scope.show = false; |
| 76 | + var element = $compile('<div ng-show="show"></div>')(scope); |
| 77 | + scope.$apply(); |
| 78 | + |
| 79 | + // Expect no $broadcasts when hiding. |
| 80 | + expect(spy).not.toHaveBeenCalled(); |
| 81 | + defered.resolve(); |
| 82 | + scope.$apply(); |
| 83 | + expect(spy).not.toHaveBeenCalled(); |
| 84 | + }); |
| 85 | + }); |
| 86 | +}); |
0 commit comments