describe('keyboardAttach directive', function() { beforeEach(module('ionic')); function setup() { var el, content; inject(function($compile, $rootScope) { el = angular.element('
'); content = angular.element(''); content.append(el); $compile(content)($rootScope.$new()); $rootScope.$apply(); }); return {el: el, content: content}; } it('should move up when window fires native.showkeyboard event', function() { var el = setup().el; expect(el.css('bottom')).toEqual(''); ionic.trigger('native.showkeyboard', { target: window, keyboardHeight: 33 }); expect(el.css('bottom')).toEqual('33px'); el.scope().$destroy(); }); it('should move up when window fires native.showkeyboard event', function() { var directives = setup(); var el = directives.el; var content = directives.content; var keyboardHeight = 33; var elHeight = 50; spyOn(window, 'keyboardAttachGetClientHeight').andReturn(elHeight); expect(content.css('bottom')).toEqual(''); ionic.trigger('native.showkeyboard', { target: window, keyboardHeight: 33 }); expect(content.css('bottom')).toEqual(keyboardHeight + elHeight + 'px'); }); it('should remove listeners on destroy', function() { spyOn(window, 'removeEventListener'); var el = setup().el; el.scope().$destroy(); expect(window.removeEventListener).toHaveBeenCalledWith('native.showkeyboard', jasmine.any(Function)); expect(window.removeEventListener).toHaveBeenCalledWith('native.hidekeyboard', jasmine.any(Function)); }); it('should remove listeners on destroy', function() { spyOn(window, 'removeEventListener'); var el = setup().el; el.scope().$destroy(); expect(window.removeEventListener).toHaveBeenCalledWith('native.showkeyboard', jasmine.any(Function)); expect(window.removeEventListener).toHaveBeenCalledWith('native.hidekeyboard', jasmine.any(Function)); }); })