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