Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calendar: Fix unit tests for CMD #1430

Merged
merged 2 commits into from Jan 20, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -175,7 +175,7 @@ grunt.initConfig({
},
qunit: {
files: expandFiles( "tests/unit/" + component + "/*.html" ).filter(function( file ) {
return !( /(all|index|test|datepicker)\.html$/ ).test( file );
return !( /(all|index|test)\.html$/ ).test( file );
}),
options: {
page: {
@@ -139,7 +139,7 @@ asyncTest( "keyboard handling", function() {
.focusGrid( element )
.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
setTimeout(function() {
$( ":focus" ).simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );

This comment has been minimized.

Copy link
@jzaefferer

jzaefferer Jan 19, 2015

Member

The focusGrid call above returns the to-be-focused element. Could store that in a variable and reuse it here. Applies to many other places as well. Not sure if its better to avoid a temp var at the cost of accessing globals.

This comment has been minimized.

Copy link
@fnagel

fnagel Jan 19, 2015

Author Member

Again: is this still the case when the focus is moved by using simulated keyboard events?

This comment has been minimized.

Copy link
@jzaefferer

jzaefferer Jan 20, 2015

Member

Here the focus stays on the grid, doesn't it? Either way, a separate assertion that verifies where the focus should be could help.

This comment has been minimized.

Copy link
@fnagel

fnagel Jan 20, 2015

Author Member

So you would like to add another test for verifying the focus is on the correct element? Like:

strictEqual( document.activeElement, assumedFocusedElement [ 0 ] );

This comment has been minimized.

Copy link
@jzaefferer

jzaefferer Jan 20, 2015

Member

Yeah, where it makes sense. In this case the focus should stay on the grid, when triggering tab events, it shouldn't. Currently the tests aren't explicit about that.

This comment has been minimized.

Copy link
@fnagel

fnagel Jan 20, 2015

Author Member

I guess that something for anther PR as we have a quite some more glitches to fix in the unit tests.

This comment has been minimized.

Copy link
@jzaefferer

jzaefferer Jan 20, 2015

Member

Alright, that's fine by me. Can you make a note on the list? And go ahead and merge this.

This comment has been minimized.

Copy link
@fnagel

fnagel Jan 20, 2015

Author Member

Done.

TestHelpers.calendar.equalsDate(
element.calendar( "valueAsDate" ),
new Date( 2013, 12 - 1, 31 ),
@@ -170,7 +170,7 @@ asyncTest( "keyboard handling", function() {

TestHelpers.calendar.focusGrid( element ).simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
setTimeout(function() {
$( ":focus" ).simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
TestHelpers.calendar.equalsDate(
element.calendar( "valueAsDate" ),
new Date( 2013, 12 - 1, 25 ),
@@ -186,7 +186,7 @@ asyncTest( "keyboard handling", function() {

TestHelpers.calendar.focusGrid( element ).simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
setTimeout(function() {
$( ":focus" ).simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
TestHelpers.calendar.equalsDate(
element.calendar( "valueAsDate" ),
new Date( 2014, 1 - 1, 8 ),
@@ -202,7 +202,7 @@ asyncTest( "keyboard handling", function() {

TestHelpers.calendar.focusGrid( element ).simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
setTimeout(function() {
$( ":focus" ).simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
TestHelpers.calendar.equalsDate(
element.calendar( "valueAsDate" ),
new Date( 2013, 12 - 1, 1 ),
@@ -219,7 +219,7 @@ asyncTest( "keyboard handling", function() {
TestHelpers.calendar.focusGrid( element )
.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP, altKey: true } );
setTimeout(function() {
$( ":focus" ).simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
TestHelpers.calendar.equalsDate(
element.calendar( "valueAsDate" ),
new Date( 2013, 1 - 1, 1 ),
@@ -235,7 +235,7 @@ asyncTest( "keyboard handling", function() {

TestHelpers.calendar.focusGrid( element ).simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
setTimeout(function() {
$( ":focus" ).simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
TestHelpers.calendar.equalsDate(
element.calendar( "valueAsDate" ),
new Date( 2014, 2 - 1, 1 ),
@@ -252,7 +252,7 @@ asyncTest( "keyboard handling", function() {
TestHelpers.calendar.focusGrid( element )
.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN, altKey: true } );
setTimeout(function() {
$( ":focus" ).simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
TestHelpers.calendar.equalsDate(
element.calendar( "valueAsDate" ),
new Date( 2015, 1 - 1, 1 ),
@@ -269,7 +269,7 @@ asyncTest( "keyboard handling", function() {

TestHelpers.calendar.focusGrid( element ).simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
setTimeout(function() {
$( ":focus" ).simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
TestHelpers.calendar.equalsDate(
element.calendar( "valueAsDate" ),
new Date( 2014, 2 - 1, 28 ),
@@ -285,7 +285,7 @@ asyncTest( "keyboard handling", function() {

TestHelpers.calendar.focusGrid( element ).simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
setTimeout(function() {
$( ":focus" ).simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
TestHelpers.calendar.equalsDate(
element.calendar( "valueAsDate" ),
new Date( 2016, 2 - 1, 29 ),
@@ -16,9 +16,9 @@ TestHelpers.calendar = {
},
focusGrid: function( element ) {
element.find( ":tabbable" ).last().simulate( "focus" );

This comment has been minimized.

Copy link
@jzaefferer

jzaefferer Jan 19, 2015

Member

Should store the selected element and use it for the next three calls, including the return.

This comment has been minimized.

Copy link
@fnagel

fnagel Jan 19, 2015

Author Member

Doesn't the tab move the focus so we need to retrieve it again?

This comment has been minimized.

Copy link
@jzaefferer

jzaefferer Jan 20, 2015

Member

It should, so this is probably fine.

$( ":focus" ).simulate( "keydown", { keyCode: $.ui.keyCode.TAB } );
$( ":focus" ).simulate( "keydown", { keyCode: $.ui.keyCode.TAB } );
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.TAB } );
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.TAB } );

return $( ":focus" );
return $( document.activeElement );
}
};
@@ -108,7 +108,7 @@ asyncTest( "select", function() {
.simulate( "focus" )
.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
setTimeout(function() {
$( ":focus" )
$( document.activeElement )

This comment has been minimized.

Copy link
@jzaefferer

jzaefferer Jan 19, 2015

Member

Why isn't using this the input variable? Same below.

This comment has been minimized.

Copy link
@fnagel

fnagel Jan 19, 2015

Author Member

Because the focus is no longer on the input at this point.

.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } )
.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
input.datepicker( "close" );
@@ -122,7 +122,7 @@ asyncTest( "select", function() {
.simulate( "focus" )
.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
setTimeout(function() {
$( ":focus" ).simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
input.datepicker( "close" );
start();
}, 100 );
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.