2015-04-07 00:06:31 +00:00
|
|
|
define( [
|
2016-12-11 16:53:53 +00:00
|
|
|
"qunit",
|
2015-04-07 00:06:31 +00:00
|
|
|
"jquery",
|
2015-07-15 01:58:04 +00:00
|
|
|
"ui/widgets/datepicker"
|
2016-12-11 16:53:53 +00:00
|
|
|
], function( QUnit, $ ) {
|
2016-05-22 19:48:51 +00:00
|
|
|
|
2016-12-11 16:53:53 +00:00
|
|
|
QUnit.module( "datepicker: events", {
|
|
|
|
beforeEach: function() {
|
2016-05-22 19:48:51 +00:00
|
|
|
this.element = $( "#datepicker" ).datepicker( { show: false, hide: false } );
|
|
|
|
this.widget = this.element.datepicker( "widget" );
|
|
|
|
},
|
2016-12-11 16:53:53 +00:00
|
|
|
afterEach: function() {
|
2016-05-22 19:48:51 +00:00
|
|
|
this.element.datepicker( "destroy" ).val( "" );
|
|
|
|
}
|
|
|
|
} );
|
2013-11-02 13:54:05 +00:00
|
|
|
|
2016-12-11 16:53:53 +00:00
|
|
|
QUnit.test( "beforeOpen", function( assert ) {
|
2016-10-11 23:23:24 +00:00
|
|
|
assert.expect( 3 );
|
2014-06-17 17:53:08 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
var that = this;
|
|
|
|
|
|
|
|
this.element.datepicker( {
|
|
|
|
beforeOpen: function() {
|
2016-12-11 16:53:53 +00:00
|
|
|
assert.ok( true, "beforeOpen event fired before open" );
|
|
|
|
assert.ok( that.element.datepicker( "widget" ).is( ":hidden" ), "calendar hidden on beforeOpen" );
|
2016-05-22 19:48:51 +00:00
|
|
|
},
|
|
|
|
open: function() {
|
2016-12-11 16:53:53 +00:00
|
|
|
assert.ok( that.element.datepicker( "widget" ).is( ":visible" ), "calendar open on open" );
|
2016-05-22 19:48:51 +00:00
|
|
|
}
|
|
|
|
} );
|
2014-06-17 17:53:08 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
this.element
|
2014-06-17 17:53:08 +00:00
|
|
|
.datepicker( "open" )
|
|
|
|
.datepicker( "close" )
|
|
|
|
.datepicker( "option", {
|
|
|
|
beforeOpen: function() {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
open: function() {
|
2016-12-11 16:53:53 +00:00
|
|
|
assert.ok( false, "calendar should not open when openBefore is canceled" );
|
2014-06-17 17:53:08 +00:00
|
|
|
}
|
2015-10-08 13:06:55 +00:00
|
|
|
} )
|
2014-06-17 17:53:08 +00:00
|
|
|
.datepicker( "open" );
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
2013-11-02 13:54:05 +00:00
|
|
|
|
2016-12-11 16:53:53 +00:00
|
|
|
QUnit.test( "change", function( assert ) {
|
2016-12-11 22:10:46 +00:00
|
|
|
assert.expect( 6 );
|
2016-05-29 08:57:35 +00:00
|
|
|
|
|
|
|
var shouldFire;
|
|
|
|
|
|
|
|
this.element.datepicker( {
|
2016-12-11 22:10:46 +00:00
|
|
|
change: function( event, ui ) {
|
2016-12-11 16:53:53 +00:00
|
|
|
assert.ok( shouldFire, "change event fired" );
|
|
|
|
assert.equal(
|
2016-05-29 08:57:35 +00:00
|
|
|
event.type,
|
|
|
|
"datepickerchange",
|
|
|
|
"change event"
|
|
|
|
);
|
2016-12-11 22:10:46 +00:00
|
|
|
assert.equal( $.type( ui.value ), "date", "value is a date object" );
|
2016-05-29 08:57:35 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
shouldFire = true;
|
|
|
|
this.element.datepicker( "open" );
|
|
|
|
this.widget.find( "tbody button" ).eq( 1 ).simulate( "mousedown" );
|
|
|
|
|
|
|
|
shouldFire = false;
|
|
|
|
this.element.datepicker( "open" );
|
|
|
|
this.widget.find( "tbody button" ).eq( 1 ).simulate( "mousedown" );
|
|
|
|
|
|
|
|
shouldFire = true;
|
|
|
|
this.element.datepicker( "open" );
|
|
|
|
this.widget.find( "tbody button" ).eq( 2 ).simulate( "mousedown" );
|
|
|
|
} );
|
|
|
|
|
2016-12-11 16:53:53 +00:00
|
|
|
QUnit.test( "close", function( assert ) {
|
2016-10-11 23:23:24 +00:00
|
|
|
assert.expect( 4 );
|
2014-06-16 22:46:08 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
var shouldFire;
|
|
|
|
|
|
|
|
this.element.datepicker( {
|
|
|
|
close: function() {
|
2016-12-11 16:53:53 +00:00
|
|
|
assert.ok( shouldFire, "close event fired" );
|
2016-05-22 19:48:51 +00:00
|
|
|
}
|
|
|
|
} );
|
2014-06-16 22:46:08 +00:00
|
|
|
|
|
|
|
shouldFire = false;
|
2016-05-22 19:48:51 +00:00
|
|
|
this.element.datepicker( "open" );
|
2014-06-16 22:46:08 +00:00
|
|
|
shouldFire = true;
|
2016-05-22 19:48:51 +00:00
|
|
|
this.element.datepicker( "close" );
|
2014-06-16 22:46:08 +00:00
|
|
|
|
|
|
|
shouldFire = false;
|
2016-05-22 19:48:51 +00:00
|
|
|
this.element.datepicker( "open" );
|
2014-06-16 22:46:08 +00:00
|
|
|
shouldFire = true;
|
|
|
|
$( "body" ).trigger( "mousedown" );
|
|
|
|
|
|
|
|
shouldFire = false;
|
2016-05-22 19:48:51 +00:00
|
|
|
this.element.datepicker( "open" );
|
2014-06-16 22:46:08 +00:00
|
|
|
shouldFire = true;
|
2016-05-22 19:48:51 +00:00
|
|
|
this.element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
|
2014-06-16 22:46:08 +00:00
|
|
|
|
|
|
|
shouldFire = false;
|
2016-05-22 19:48:51 +00:00
|
|
|
this.element.datepicker( "open" );
|
2014-06-16 22:46:08 +00:00
|
|
|
shouldFire = true;
|
2016-05-29 08:57:35 +00:00
|
|
|
this.widget.find( "tbody tr:first button:first" ).simulate( "mousedown" );
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2016-12-11 16:53:53 +00:00
|
|
|
QUnit.test( "open", function( assert ) {
|
2016-10-11 23:23:24 +00:00
|
|
|
assert.expect( 2 );
|
2013-11-02 13:54:05 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
var that = this;
|
2014-06-16 22:46:08 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
this.element.datepicker( {
|
|
|
|
open: function() {
|
2016-12-11 16:53:53 +00:00
|
|
|
assert.ok( true, "open event fired on open" );
|
|
|
|
assert.ok( that.widget.is( ":visible" ), "calendar open on open" );
|
2016-05-22 19:48:51 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.element.datepicker( "open" );
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2016-12-11 16:53:53 +00:00
|
|
|
QUnit.test( "select", function( assert ) {
|
|
|
|
var ready = assert.async();
|
2016-12-11 22:10:46 +00:00
|
|
|
assert.expect( 6 );
|
2014-06-17 17:53:08 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
var message = "",
|
|
|
|
that = this;
|
|
|
|
|
|
|
|
this.element.datepicker( {
|
2016-12-11 22:10:46 +00:00
|
|
|
select: function( event, ui ) {
|
2016-12-11 16:53:53 +00:00
|
|
|
assert.ok( true, "select event fired " + message );
|
|
|
|
assert.equal(
|
2016-05-22 19:48:51 +00:00
|
|
|
event.originalEvent.type,
|
|
|
|
"calendarselect",
|
|
|
|
"select originalEvent " + message
|
|
|
|
);
|
2016-12-11 22:10:46 +00:00
|
|
|
assert.equal( $.type( ui.value ), "date", "value is a date object" );
|
2016-05-22 19:48:51 +00:00
|
|
|
}
|
|
|
|
} );
|
2014-06-17 17:53:08 +00:00
|
|
|
|
|
|
|
function step1() {
|
|
|
|
message = "on calendar cell click";
|
2016-05-22 19:48:51 +00:00
|
|
|
that.element
|
2014-06-17 17:53:08 +00:00
|
|
|
.simulate( "focus" )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
2015-10-08 13:06:55 +00:00
|
|
|
setTimeout( function() {
|
2016-05-22 19:48:51 +00:00
|
|
|
that.widget.find( "tbody tr:first button:first" ).simulate( "mousedown" );
|
|
|
|
that.element.datepicker( "close" );
|
2014-06-17 17:53:08 +00:00
|
|
|
step2();
|
|
|
|
}, 100 );
|
|
|
|
}
|
|
|
|
|
|
|
|
function step2() {
|
|
|
|
message = "on calendar cell enter";
|
2016-05-22 19:48:51 +00:00
|
|
|
that.element
|
2014-06-17 17:53:08 +00:00
|
|
|
.simulate( "focus" )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
2015-10-08 13:06:55 +00:00
|
|
|
setTimeout( function() {
|
2015-01-19 16:56:11 +00:00
|
|
|
$( document.activeElement )
|
2014-06-17 17:53:08 +00:00
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
|
2016-05-22 19:48:51 +00:00
|
|
|
that.element.datepicker( "close" );
|
2014-06-17 17:53:08 +00:00
|
|
|
step3();
|
|
|
|
}, 100 );
|
|
|
|
}
|
|
|
|
|
|
|
|
function step3() {
|
|
|
|
message = "on calendar escape (not expected)";
|
2016-05-22 19:48:51 +00:00
|
|
|
that.element
|
2014-06-17 17:53:08 +00:00
|
|
|
.simulate( "focus" )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
2015-10-08 13:06:55 +00:00
|
|
|
setTimeout( function() {
|
2015-01-19 16:56:11 +00:00
|
|
|
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
|
2016-05-22 19:48:51 +00:00
|
|
|
that.element.datepicker( "close" );
|
2016-12-11 16:53:53 +00:00
|
|
|
ready();
|
2014-06-17 17:53:08 +00:00
|
|
|
}, 100 );
|
|
|
|
}
|
|
|
|
|
|
|
|
step1();
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2015-04-07 00:06:31 +00:00
|
|
|
} );
|