Skip to content

Commit 2094d83

Browse files
committed
keyboardGetHeight tests
1 parent 708fc85 commit 2094d83

File tree

1 file changed

+52
-58
lines changed

1 file changed

+52
-58
lines changed

Diff for: test/unit/utils/keyboard.unit.js

+52-58
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ describe('Ionic Keyboard', function() {
9090
ionic.Platform.setPlatform('');
9191
ionic.Platform.setVersion('');
9292
ionic.keyboard.isOpen = false;
93+
ionic.keyboard.height = null;
94+
ionic.Platform.isFullScreen = false;
95+
ionic.keyboard.landscape = false;
9396
}));
9497

9598
afterEach(function(){
@@ -107,74 +110,79 @@ describe('Ionic Keyboard', function() {
107110
expect( details.keyboardHeight ).toEqual(200);
108111
});
109112

110-
it('Should keyboardIsOverWebView()=false if Android and not isWebView', function(){
111-
// Android browser places the keyboard on top of the content and doesn't resize the window
112-
ionic.Platform.setPlatform('Android');
113-
expect( ionic.Platform.isAndroid() ).toEqual(true);
114-
expect( ionic.Platform.isWebView() ).toEqual(false);
113+
it('Should keyboardHasPlugin', function() {
114+
expect( keyboardHasPlugin() ).toEqual(false);
115+
116+
window.cordova = {};
117+
expect( keyboardHasPlugin() ).toEqual(false);
115118

116-
expect( ionic.Platform.isIOS() ).toEqual(false);
119+
window.cordova.plugins = {};
120+
expect( keyboardHasPlugin() ).toEqual(false);
117121

118-
expect( keyboardIsOverWebView() ).toEqual(false);
122+
window.cordova.plugins.Keyboard = {};
123+
expect( keyboardHasPlugin() ).toEqual(true);
119124
});
120125

121-
it('Should keyboardIsOverWebView()=true if Android and isWebView and isFullScreen', function(){
122-
// Android webview gets shrunk by cordova and the keyboard fills the gap
123-
ionic.Platform.setPlatform('Android');
124-
window.cordova = {};
125-
expect( ionic.Platform.isAndroid() ).toEqual(true);
126-
expect( ionic.Platform.isWebView() ).toEqual(true);
126+
it('keyboardGetHeight() should use the keyboard plugin if it is available', function(){
127+
ionic.keyboard.height = 216;
128+
expect( keyboardGetHeight() ).toEqual(216);
129+
});
127130

131+
it('keyboardGetHeight() should = 275 if Cordova Android and is fullscreen', function(){
132+
ionic.Platform.setPlatform('android');
133+
window.cordova = {};
128134
ionic.Platform.isFullScreen = true;
129135

130-
expect( keyboardIsOverWebView() ).toEqual(true);
136+
expect( keyboardGetHeight() ).toEqual(275);
131137
});
132138

133-
it('Should keyboardIsOverWebView()=false if Android and isWebView and not isFullScreen', function(){
134-
// Android webview gets shrunk by cordova and the keyboard fills the gap
135-
ionic.Platform.setPlatform('Android');
136-
window.cordova = {};
137-
expect( ionic.Platform.isAndroid() ).toEqual(true);
138-
expect( ionic.Platform.isWebView() ).toEqual(true);
139-
ionic.Platform.isFullScreen = false;
139+
it('keyboardGetHeight() should = (keyboardViewportHeight - window.innerHeight) if Android and not fullscreen', function(){
140+
ionic.Platform.setPlatform('android');
141+
expect( ionic.Platform.isFullScreen ).toEqual(false);
142+
143+
keyboardViewportHeight = 480;
144+
window.innerHeight = 280
140145

141-
expect( keyboardIsOverWebView() ).toEqual(false);
146+
expect( keyboardGetHeight() ).toEqual(200);
142147
});
143148

144-
it('Should keyboardIsOverWebView()=true if iOS 7.0 or greater', function(){
145-
ionic.Platform.setPlatform('iOS');
146-
ionic.Platform.setVersion('7.0');
147-
expect( ionic.Platform.isAndroid() ).toEqual(false);
148-
expect( ionic.Platform.isIOS() ).toEqual(true);
149+
it('keyboardGetHeight() should = 0 if keyboardViewportHeight = window.innerHeight and Android and not fullscreen', function(){
150+
ionic.Platform.setPlatform('android');
151+
expect( ionic.Platform.isFullScreen ).toEqual(false);
149152

150-
expect( keyboardIsOverWebView() ).toEqual(true);
153+
keyboardViewportHeight = 480;
154+
window.innerHeight = 480;
155+
156+
expect( keyboardGetHeight() ).toEqual(0);
151157
});
152158

153-
it('Should keyboardIsOverWebView()=true if less than iOS 7.0', function(){
159+
it('keyboardGetHeight() should = 206 if iOS and in landscape orientation', function(){
154160
ionic.Platform.setPlatform('iOS');
155-
ionic.Platform.setVersion('6.0');
156-
expect( ionic.Platform.isAndroid() ).toEqual(false);
157-
expect( ionic.Platform.isIOS() ).toEqual(true);
161+
ionic.keyboard.landscape = true;
158162

159-
expect( keyboardIsOverWebView() ).toEqual(true);
160-
});
163+
expect( keyboardGetHeight() ).toEqual(206);
164+
})
161165

162-
it('Should keyboardHasPlugin', function() {
163-
expect( keyboardHasPlugin() ).toEqual(false);
166+
it('keyboardGetHeight() should = 216 if iOS Safari', function(){
167+
ionic.Platform.setPlatform('iOS');
168+
169+
expect( ionic.Platform.isWebView() ).toEqual(false);
170+
expect( keyboardGetHeight() ).toEqual(216);
171+
})
164172

173+
it('keyboardGetHeight() should = 260 if iOS Cordova', function(){
174+
ionic.Platform.setPlatform('iOS');
165175
window.cordova = {};
166-
expect( keyboardHasPlugin() ).toEqual(false);
167176

168-
window.cordova.plugins = {};
169-
expect( keyboardHasPlugin() ).toEqual(false);
177+
expect( ionic.Platform.isWebView() ).toEqual(true);
178+
expect( keyboardGetHeight() ).toEqual(260);
179+
})
170180

171-
window.cordova.plugins.Keyboard = {};
172-
expect( keyboardHasPlugin() ).toEqual(true);
173-
});
181+
it('keyboardGetHeight() should = 275 if not Android or iOS', function(){
182+
ionic.Platform.setPlatform('WP8');
174183

175-
it('keyboardGetHeight() should = DEFAULT_KEYBOARD_HEIGHT if no plugin or resized view', function(){
176184
expect( keyboardGetHeight() ).toEqual(275);
177-
});
185+
})
178186

179187
it('keyboardUpdateViewportHeight() should update when window.innerHeight > keyboardViewportHeight', function(){
180188
window.innerHeight = 460;
@@ -215,18 +223,4 @@ describe('Ionic Keyboard', function() {
215223
expect( details.isElementUnderKeyboard ).toEqual(false);
216224
});
217225

218-
it('Should subtract the keyboard height from the contentHeight if keyboardIsOverWebView()', function(){
219-
ionic.Platform.setPlatform('iOS');
220-
ionic.Platform.setVersion('7.1');
221-
222-
var element = document.createElement('textarea');
223-
var elementTop = 300;
224-
var elementBottom = 400;
225-
var keyboardHeight = 200;
226-
var deviceHeight = 568;
227-
var details = keyboardShow(element, elementTop, elementBottom, deviceHeight, keyboardHeight);
228-
229-
expect( details.contentHeight ).toEqual(368);
230-
});
231-
232226
});

0 commit comments

Comments
 (0)