Skip to content

Commit

Permalink
test(keyboard): keyboard tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tlancina committed Apr 15, 2015
1 parent 31de853 commit 598245c
Show file tree
Hide file tree
Showing 6 changed files with 411 additions and 130 deletions.
43 changes: 21 additions & 22 deletions js/utils/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
/**
* The current viewport height.
*/
var keyboardCurrentViewportHeight;
var keyboardCurrentViewportHeight = 0;

/**
* The viewport height when in portrait orientation.
Expand Down Expand Up @@ -442,7 +442,7 @@ function keyboardWaitForResize(callback, isOpening) {
}

// infer the keyboard height from the resize if not using the keyboard plugin
if ( !keyboardHasPlugin() ) {
if (!keyboardHasPlugin()) {
ionic.keyboard.height = Math.abs(initialHeight - window.innerHeight);
}

Expand All @@ -459,6 +459,8 @@ function keyboardWaitForResize(callback, isOpening) {
callback();

}, 50);

return maxCount; //for tests
}

/**
Expand Down Expand Up @@ -540,18 +542,18 @@ function keyboardShow() {
/* eslint no-unused-vars:0 */
function keyboardGetHeight() {
// check if we already have a keyboard height from the plugin or resize calculations
if ( ionic.keyboard.height ) {
if (ionic.keyboard.height) {
return ionic.keyboard.height;
}

if ( ionic.Platform.isAndroid() ) {
if (ionic.Platform.isAndroid()) {
// should be using the plugin, no way to know how big the keyboard is, so guess
if ( ionic.Platform.isFullScreen ) {
return 275;
}
// otherwise just calculate it
var contentHeight = window.innerHeight;
if ( contentHeight < keyboardCurrentViewportHeight ) {
if (contentHeight < keyboardCurrentViewportHeight) {
return keyboardCurrentViewportHeight - contentHeight;
} else {
return 0;
Expand All @@ -561,12 +563,12 @@ function keyboardGetHeight() {
// fallback for when it's the webview without the plugin
// or for just the standard web browser
// TODO: have these be based on device
if( ionic.Platform.isIOS() ) {
if ( ionic.keyboard.isLandscape ) {
if (ionic.Platform.isIOS()) {
if (ionic.keyboard.isLandscape) {
return 206;
}

if ( !ionic.Platform.isWebView() ) {
if (!ionic.Platform.isWebView()) {
return 216;
}

Expand All @@ -578,15 +580,15 @@ function keyboardGetHeight() {
}

function isPortraitViewportHeight(viewportHeight) {
return !ionic.keyboard.isLandscape &&
return !!(!ionic.keyboard.isLandscape &&
keyboardPortraitViewportHeight &&
( Math.abs(keyboardPortraitViewportHeight - viewportHeight) < 2 );
(Math.abs(keyboardPortraitViewportHeight - viewportHeight) < 2));
}

function isLandscapeViewportHeight(viewportHeight) {
return ionic.keyboard.isLandscape &&
return !!(ionic.keyboard.isLandscape &&
keyboardLandscapeViewportHeight &&
( Math.abs(keyboardLandscapeViewportHeight - viewportHeight) < 2 );
(Math.abs(keyboardLandscapeViewportHeight - viewportHeight) < 2));
}

function keyboardUpdateViewportHeight() {
Expand All @@ -611,7 +613,7 @@ function keyboardUpdateViewportHeight() {
}
}

function keyboardInitViewportHeight(e) {
function keyboardInitViewportHeight() {
var viewportHeight = getViewportHeight();
//console.log("Keyboard init VP: " + viewportHeight + " " + window.innerWidth);
// can't just use window.innerHeight in case the keyboard is opened immediately
Expand All @@ -620,15 +622,12 @@ function keyboardInitViewportHeight(e) {
}
//console.log("ionic.keyboard.isLandscape is: " + ionic.keyboard.isLandscape);

// initialize or update the current viewport height values if coming from a
// resume event
if ((e && viewportHeight != keyboardCurrentViewportHeight) || !e) {
keyboardCurrentViewportHeight = viewportHeight;
if (ionic.keyboard.isLandscape && !keyboardLandscapeViewportHeight) {
keyboardLandscapeViewportHeight = keyboardCurrentViewportHeight;
} else if (!ionic.keyboard.isLandscape && !keyboardPortraitViewportHeight) {
keyboardPortraitViewportHeight = keyboardCurrentViewportHeight;
}
// initialize or update the current viewport height values
keyboardCurrentViewportHeight = viewportHeight;
if (ionic.keyboard.isLandscape && !keyboardLandscapeViewportHeight) {
keyboardLandscapeViewportHeight = keyboardCurrentViewportHeight;
} else if (!ionic.keyboard.isLandscape && !keyboardPortraitViewportHeight) {
keyboardPortraitViewportHeight = keyboardCurrentViewportHeight;
}
}

Expand Down
3 changes: 1 addition & 2 deletions js/views/scrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ ionic.views.Scroll = ionic.views.View.inherit({
* into view.
*/
self.scrollChildIntoView = function(e) {
console.log("scrollChildIntoView at: " + Date.now());
//console.log("scrollChildIntoView at: " + Date.now());

// D
var scrollBottomOffsetToTop = container.getBoundingClientRect().bottom;
Expand Down Expand Up @@ -694,7 +694,6 @@ ionic.views.Scroll = ionic.views.View.inherit({
}

self.isShrunkForKeyboard = true;

}

/*
Expand Down
2 changes: 1 addition & 1 deletion test/unit/angular/directive/scroll.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('Ionic Scroll Directive', function() {
});

it('Should set start x and y', function() {
element = compile('<ion-content start-x="100" start-y="300" has-header="true"></ion-scroll>')(scope);
element = compile('<ion-content start-x="100" start-y="300" has-header="true"></ion-content>')(scope);
scope.$apply();
var scrollView = element.controller('$ionicScroll').scrollView;
var vals = scrollView.getValues();
Expand Down
9 changes: 8 additions & 1 deletion test/unit/utils/activator.unit.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
describe('Ionic Element Activator', function() {

var timeout, rAF;
beforeEach(function() {
timeout = window.setTimeout;
rAF = ionic.requestAnimationFrame;
window.setTimeout = ionic.requestAnimationFrame = function(cb) { cb(); };
});

afterEach(function(){
window.setTimeout = timeout;
ionic.requestAnimationFrame = rAF;
});

it('should not active an <a> if ionic.tap.requiresNativeClick is true', function() {
spyOn(ionic.tap, 'requiresNativeClick').andReturn(true);
var e = { target: document.createElement('a') };
Expand Down
Loading

0 comments on commit 598245c

Please sign in to comment.