@@ -90,6 +90,9 @@ describe('Ionic Keyboard', function() {
90
90
ionic . Platform . setPlatform ( '' ) ;
91
91
ionic . Platform . setVersion ( '' ) ;
92
92
ionic . keyboard . isOpen = false ;
93
+ ionic . keyboard . height = null ;
94
+ ionic . Platform . isFullScreen = false ;
95
+ ionic . keyboard . landscape = false ;
93
96
} ) ) ;
94
97
95
98
afterEach ( function ( ) {
@@ -107,74 +110,79 @@ describe('Ionic Keyboard', function() {
107
110
expect ( details . keyboardHeight ) . toEqual ( 200 ) ;
108
111
} ) ;
109
112
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 ) ;
115
118
116
- expect ( ionic . Platform . isIOS ( ) ) . toEqual ( false ) ;
119
+ window . cordova . plugins = { } ;
120
+ expect ( keyboardHasPlugin ( ) ) . toEqual ( false ) ;
117
121
118
- expect ( keyboardIsOverWebView ( ) ) . toEqual ( false ) ;
122
+ window . cordova . plugins . Keyboard = { } ;
123
+ expect ( keyboardHasPlugin ( ) ) . toEqual ( true ) ;
119
124
} ) ;
120
125
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
+ } ) ;
127
130
131
+ it ( 'keyboardGetHeight() should = 275 if Cordova Android and is fullscreen' , function ( ) {
132
+ ionic . Platform . setPlatform ( 'android' ) ;
133
+ window . cordova = { } ;
128
134
ionic . Platform . isFullScreen = true ;
129
135
130
- expect ( keyboardIsOverWebView ( ) ) . toEqual ( true ) ;
136
+ expect ( keyboardGetHeight ( ) ) . toEqual ( 275 ) ;
131
137
} ) ;
132
138
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
140
145
141
- expect ( keyboardIsOverWebView ( ) ) . toEqual ( false ) ;
146
+ expect ( keyboardGetHeight ( ) ) . toEqual ( 200 ) ;
142
147
} ) ;
143
148
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 ) ;
149
152
150
- expect ( keyboardIsOverWebView ( ) ) . toEqual ( true ) ;
153
+ keyboardViewportHeight = 480 ;
154
+ window . innerHeight = 480 ;
155
+
156
+ expect ( keyboardGetHeight ( ) ) . toEqual ( 0 ) ;
151
157
} ) ;
152
158
153
- it ( 'Should keyboardIsOverWebView()=true if less than iOS 7.0 ' , function ( ) {
159
+ it ( 'keyboardGetHeight() should = 206 if iOS and in landscape orientation ' , function ( ) {
154
160
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 ;
158
162
159
- expect ( keyboardIsOverWebView ( ) ) . toEqual ( true ) ;
160
- } ) ;
163
+ expect ( keyboardGetHeight ( ) ) . toEqual ( 206 ) ;
164
+ } )
161
165
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
+ } )
164
172
173
+ it ( 'keyboardGetHeight() should = 260 if iOS Cordova' , function ( ) {
174
+ ionic . Platform . setPlatform ( 'iOS' ) ;
165
175
window . cordova = { } ;
166
- expect ( keyboardHasPlugin ( ) ) . toEqual ( false ) ;
167
176
168
- window . cordova . plugins = { } ;
169
- expect ( keyboardHasPlugin ( ) ) . toEqual ( false ) ;
177
+ expect ( ionic . Platform . isWebView ( ) ) . toEqual ( true ) ;
178
+ expect ( keyboardGetHeight ( ) ) . toEqual ( 260 ) ;
179
+ } )
170
180
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' ) ;
174
183
175
- it ( 'keyboardGetHeight() should = DEFAULT_KEYBOARD_HEIGHT if no plugin or resized view' , function ( ) {
176
184
expect ( keyboardGetHeight ( ) ) . toEqual ( 275 ) ;
177
- } ) ;
185
+ } )
178
186
179
187
it ( 'keyboardUpdateViewportHeight() should update when window.innerHeight > keyboardViewportHeight' , function ( ) {
180
188
window . innerHeight = 460 ;
@@ -215,18 +223,4 @@ describe('Ionic Keyboard', function() {
215
223
expect ( details . isElementUnderKeyboard ) . toEqual ( false ) ;
216
224
} ) ;
217
225
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
-
232
226
} ) ;
0 commit comments