Skip to content

Commit

Permalink
Merge pull request #165 from wmde/betterVisible
Browse files Browse the repository at this point in the history
Handle browsers which cannot focus in test cases
  • Loading branch information
JanZerebecki committed Mar 13, 2015
2 parents c61d341 + 37de8f8 commit 5c235c9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
10 changes: 5 additions & 5 deletions tests/lib/jquery.ui/jquery.ui.inputextender.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@

QUnit.test( 'Initialization on focused input', function( assert ) {
var $input = $( '<input/>' ).appendTo( $( 'body' ) ).focus();
if( !$input.is( ':focus' ) ) {
assert.ok( true, 'Could not test since focussing does not work.' );
return;
}
var extender = newTestInputextender( $input );
var isOk = extender.extensionIsActive();

if( !isOk && 'hidden' in document && document.hidden ) {
assert.ok( true, 'Could not test since browser window is not focused' );
} else {
assert.ok( isOk, 'Extension active initially because input has focus.' );
}
assert.ok( isOk, 'Extension active initially because input has focus.' );
} );

QUnit.test( 'Destruction', 2, function( assert ) {
Expand Down
15 changes: 10 additions & 5 deletions tests/lib/jquery/jquery.focusAt.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@
$( ':focus' ).blur();
elem.appendTo( $dom );

// Check if focussing actually works
elem.focus();
if( !elem.is( ':focus' ) ) {
assert.ok( 'Could not test because focussing does not work.' );
return;
}
elem.blur();
assert.ok( !elem.is( ':focus' ) );

assert.ok(
elem.focusAt( 0 ),
'Can call focusAt on element in DOM'
Expand All @@ -141,11 +150,7 @@
);
} else {
isOk = $( ':focus' ).filter( elem ).length;
if( !isOk && 'hidden' in document && document.hidden ) {
assert.ok( true, 'Could not test since browser window is not focused' );
} else {
assert.ok( isOk, 'Focused element has focus set.' );
}
assert.ok( isOk, 'Focused element has focus set.' );
}
elem.remove();
} );
Expand Down
18 changes: 9 additions & 9 deletions tests/src/ExpertExtender/ExpertExtender.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@
} ] );

$input.focus();

// inputextender immediately extends if $input has focus
expertExtender.init();
// inputextender immediately extends if $input has focus
// If, after focussing, $input does not have focus, we are running in phantomjs
// or an unfocused firefox window. Force showing the extension, then.
if( !$input.is( ':focus' ) ) {
expertExtender._inputextender.showExtension();
}

window.setTimeout( function() {
if( !init.called && 'hidden' in document && document.hidden ) {
assert.ok( true, 'Could not test since browser window is not focused' );
} else {
sinon.assert.calledOnce( init );
sinon.assert.calledOnce( onInitialShow );
sinon.assert.calledOnce( draw );
}
sinon.assert.calledOnce( init );
sinon.assert.calledOnce( onInitialShow );
sinon.assert.calledOnce( draw );

$input.remove();

Expand Down

0 comments on commit 5c235c9

Please sign in to comment.