keyboardGetHeight tests

This commit is contained in:
Tim Lancina
2014-04-30 16:29:28 -05:00
parent 708fc85bf5
commit 2094d83c77

View File

@@ -90,6 +90,9 @@ describe('Ionic Keyboard', function() {
ionic.Platform.setPlatform('');
ionic.Platform.setVersion('');
ionic.keyboard.isOpen = false;
ionic.keyboard.height = null;
ionic.Platform.isFullScreen = false;
ionic.keyboard.landscape = false;
}));
afterEach(function(){
@@ -107,58 +110,6 @@ describe('Ionic Keyboard', function() {
expect( details.keyboardHeight ).toEqual(200);
});
it('Should keyboardIsOverWebView()=false if Android and not isWebView', function(){
// Android browser places the keyboard on top of the content and doesn't resize the window
ionic.Platform.setPlatform('Android');
expect( ionic.Platform.isAndroid() ).toEqual(true);
expect( ionic.Platform.isWebView() ).toEqual(false);
expect( ionic.Platform.isIOS() ).toEqual(false);
expect( keyboardIsOverWebView() ).toEqual(false);
});
it('Should keyboardIsOverWebView()=true if Android and isWebView and isFullScreen', function(){
// Android webview gets shrunk by cordova and the keyboard fills the gap
ionic.Platform.setPlatform('Android');
window.cordova = {};
expect( ionic.Platform.isAndroid() ).toEqual(true);
expect( ionic.Platform.isWebView() ).toEqual(true);
ionic.Platform.isFullScreen = true;
expect( keyboardIsOverWebView() ).toEqual(true);
});
it('Should keyboardIsOverWebView()=false if Android and isWebView and not isFullScreen', function(){
// Android webview gets shrunk by cordova and the keyboard fills the gap
ionic.Platform.setPlatform('Android');
window.cordova = {};
expect( ionic.Platform.isAndroid() ).toEqual(true);
expect( ionic.Platform.isWebView() ).toEqual(true);
ionic.Platform.isFullScreen = false;
expect( keyboardIsOverWebView() ).toEqual(false);
});
it('Should keyboardIsOverWebView()=true if iOS 7.0 or greater', function(){
ionic.Platform.setPlatform('iOS');
ionic.Platform.setVersion('7.0');
expect( ionic.Platform.isAndroid() ).toEqual(false);
expect( ionic.Platform.isIOS() ).toEqual(true);
expect( keyboardIsOverWebView() ).toEqual(true);
});
it('Should keyboardIsOverWebView()=true if less than iOS 7.0', function(){
ionic.Platform.setPlatform('iOS');
ionic.Platform.setVersion('6.0');
expect( ionic.Platform.isAndroid() ).toEqual(false);
expect( ionic.Platform.isIOS() ).toEqual(true);
expect( keyboardIsOverWebView() ).toEqual(true);
});
it('Should keyboardHasPlugin', function() {
expect( keyboardHasPlugin() ).toEqual(false);
@@ -172,10 +123,67 @@ describe('Ionic Keyboard', function() {
expect( keyboardHasPlugin() ).toEqual(true);
});
it('keyboardGetHeight() should = DEFAULT_KEYBOARD_HEIGHT if no plugin or resized view', function(){
it('keyboardGetHeight() should use the keyboard plugin if it is available', function(){
ionic.keyboard.height = 216;
expect( keyboardGetHeight() ).toEqual(216);
});
it('keyboardGetHeight() should = 275 if Cordova Android and is fullscreen', function(){
ionic.Platform.setPlatform('android');
window.cordova = {};
ionic.Platform.isFullScreen = true;
expect( keyboardGetHeight() ).toEqual(275);
});
it('keyboardGetHeight() should = (keyboardViewportHeight - window.innerHeight) if Android and not fullscreen', function(){
ionic.Platform.setPlatform('android');
expect( ionic.Platform.isFullScreen ).toEqual(false);
keyboardViewportHeight = 480;
window.innerHeight = 280
expect( keyboardGetHeight() ).toEqual(200);
});
it('keyboardGetHeight() should = 0 if keyboardViewportHeight = window.innerHeight and Android and not fullscreen', function(){
ionic.Platform.setPlatform('android');
expect( ionic.Platform.isFullScreen ).toEqual(false);
keyboardViewportHeight = 480;
window.innerHeight = 480;
expect( keyboardGetHeight() ).toEqual(0);
});
it('keyboardGetHeight() should = 206 if iOS and in landscape orientation', function(){
ionic.Platform.setPlatform('iOS');
ionic.keyboard.landscape = true;
expect( keyboardGetHeight() ).toEqual(206);
})
it('keyboardGetHeight() should = 216 if iOS Safari', function(){
ionic.Platform.setPlatform('iOS');
expect( ionic.Platform.isWebView() ).toEqual(false);
expect( keyboardGetHeight() ).toEqual(216);
})
it('keyboardGetHeight() should = 260 if iOS Cordova', function(){
ionic.Platform.setPlatform('iOS');
window.cordova = {};
expect( ionic.Platform.isWebView() ).toEqual(true);
expect( keyboardGetHeight() ).toEqual(260);
})
it('keyboardGetHeight() should = 275 if not Android or iOS', function(){
ionic.Platform.setPlatform('WP8');
expect( keyboardGetHeight() ).toEqual(275);
})
it('keyboardUpdateViewportHeight() should update when window.innerHeight > keyboardViewportHeight', function(){
window.innerHeight = 460;
keyboardViewportHeight = 320;
@@ -215,18 +223,4 @@ describe('Ionic Keyboard', function() {
expect( details.isElementUnderKeyboard ).toEqual(false);
});
it('Should subtract the keyboard height from the contentHeight if keyboardIsOverWebView()', function(){
ionic.Platform.setPlatform('iOS');
ionic.Platform.setVersion('7.1');
var element = document.createElement('textarea');
var elementTop = 300;
var elementBottom = 400;
var keyboardHeight = 200;
var deviceHeight = 568;
var details = keyboardShow(element, elementTop, elementBottom, deviceHeight, keyboardHeight);
expect( details.contentHeight ).toEqual(368);
});
});