mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
54 lines
2.0 KiB
JavaScript
54 lines
2.0 KiB
JavaScript
describe('keyboardAttach directive', function() {
|
|
beforeEach(module('ionic'));
|
|
|
|
function setup() {
|
|
var el, content;
|
|
inject(function($compile, $rootScope) {
|
|
el = angular.element('<div keyboard-attach></div>');
|
|
content = angular.element('<ion-content></ion-content>');
|
|
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));
|
|
});
|
|
})
|