2015-04-07 00:06:31 +00:00
|
|
|
define( [
|
|
|
|
"jquery",
|
2015-08-20 13:48:11 +00:00
|
|
|
"ui/widgets/datepicker"
|
2016-05-22 19:48:51 +00:00
|
|
|
], function( $ ) {
|
|
|
|
|
|
|
|
module( "datepicker: core", {
|
|
|
|
setup: function() {
|
|
|
|
this.element = $( "#datepicker" ).datepicker( { show: false, hide: false } );
|
|
|
|
this.widget = this.element.datepicker( "widget" );
|
|
|
|
},
|
|
|
|
teardown: function() {
|
|
|
|
this.element.datepicker( "destroy" ).val( "" );
|
|
|
|
}
|
|
|
|
} );
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2016-10-11 23:23:24 +00:00
|
|
|
test( "input's value determines starting date", function( assert ) {
|
|
|
|
assert.expect( 3 );
|
2013-11-20 13:53:02 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
this.element = $( "<input>" ).appendTo( "#qunit-fixture" );
|
|
|
|
this.element.val( "1/1/14" ).datepicker();
|
|
|
|
this.widget = this.element.datepicker( "widget" );
|
2013-11-20 13:53:02 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
this.element.datepicker( "open" );
|
2013-11-20 13:53:02 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
equal( this.widget.find( ".ui-calendar-month" ).html(), "January", "correct month displayed" );
|
|
|
|
equal( this.widget.find( ".ui-calendar-year" ).html(), "2014", "correct year displayed" );
|
|
|
|
equal( this.widget.find( ".ui-state-active" ).html(), "1", "correct day highlighted" );
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
2013-11-20 13:53:02 +00:00
|
|
|
|
2016-10-11 23:23:24 +00:00
|
|
|
asyncTest( "base structure", function( assert ) {
|
|
|
|
assert.expect( 5 );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
var that = this;
|
2013-04-14 21:07:24 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
this.element.focus();
|
2013-04-14 21:07:24 +00:00
|
|
|
|
2015-10-08 13:06:55 +00:00
|
|
|
setTimeout( function() {
|
2016-05-22 19:48:51 +00:00
|
|
|
ok( that.widget.is( ":visible" ), "Datepicker visible" );
|
|
|
|
equal( that.widget.children().length, 3, "Child count" );
|
|
|
|
ok( that.widget.is( ".ui-calendar" ), "Class ui-calendar" );
|
|
|
|
ok( that.widget.is( ".ui-datepicker" ), "Class ui-datepicker" );
|
|
|
|
ok( that.widget.is( ".ui-front" ), "Class ui-front" );
|
2013-04-14 21:07:24 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
that.element.datepicker( "close" );
|
2013-11-02 13:54:05 +00:00
|
|
|
start();
|
2014-06-03 21:18:51 +00:00
|
|
|
}, 50 );
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
2013-04-14 21:07:24 +00:00
|
|
|
|
2016-10-11 23:23:24 +00:00
|
|
|
asyncTest( "Keyboard handling: focus", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2013-11-22 14:30:11 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
var that = this;
|
2014-05-15 22:19:32 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
ok( !this.widget.is( ":visible" ), "datepicker closed" );
|
2013-11-22 14:30:11 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
this.element.focus();
|
|
|
|
setTimeout( function() {
|
|
|
|
ok( that.widget.is( ":visible" ), "Datepicker opens when receiving focus" );
|
|
|
|
start();
|
|
|
|
}, 100 );
|
|
|
|
} );
|
2013-11-22 14:30:11 +00:00
|
|
|
|
2016-10-11 23:23:24 +00:00
|
|
|
asyncTest( "Keyboard handling: keystroke up", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2014-05-15 22:19:32 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
var that = this;
|
2013-11-22 14:30:11 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
ok( !this.widget.is( ":visible" ), "datepicker closed" );
|
2013-11-22 14:30:11 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
this.element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
|
|
|
|
setTimeout( function() {
|
|
|
|
ok( that.widget.is( ":visible" ), "Keystroke up opens datepicker" );
|
2014-05-15 22:19:32 +00:00
|
|
|
start();
|
2016-05-22 19:48:51 +00:00
|
|
|
}, 100 );
|
|
|
|
} );
|
2013-11-22 14:30:11 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
test( "Keyboard handling: input", function( assert ) {
|
2016-10-11 23:23:24 +00:00
|
|
|
assert.expect( 6 );
|
2016-05-22 19:48:51 +00:00
|
|
|
|
|
|
|
var that = this,
|
|
|
|
instance = that.element.datepicker( "instance" );
|
|
|
|
|
|
|
|
// Enter = Select preset date
|
|
|
|
that.element
|
|
|
|
.val( "1/1/14" )
|
|
|
|
.datepicker( "refresh" )
|
|
|
|
.datepicker( "open" )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
|
|
|
|
assert.dateEqual( that.element.datepicker( "valueAsDate" ), new Date( 2014, 0, 1 ),
|
|
|
|
"Keystroke enter - preset" );
|
|
|
|
|
|
|
|
that.element
|
|
|
|
.val( "" )
|
|
|
|
.datepicker( "open" );
|
|
|
|
ok( instance.isOpen, "datepicker is open before escape" );
|
|
|
|
|
|
|
|
that.element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
|
|
|
|
ok( !instance.isOpen, "escape closes the datepicker" );
|
|
|
|
|
|
|
|
that.element
|
|
|
|
.val( "1/1/14" )
|
|
|
|
.datepicker( "open" )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
|
|
|
|
assert.dateEqual( that.element.datepicker( "valueAsDate" ), new Date( 2014, 0, 1 ),
|
|
|
|
"Keystroke esc - preset" );
|
|
|
|
|
|
|
|
that.element
|
|
|
|
.val( "1/1/14" )
|
|
|
|
.datepicker( "open" )
|
|
|
|
.simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP } )
|
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
|
|
|
|
assert.dateEqual( that.element.datepicker( "valueAsDate" ), new Date( 2014, 0, 1 ),
|
|
|
|
"Keystroke esc - abandoned" );
|
|
|
|
|
|
|
|
that.element
|
|
|
|
.val( "1/2/14" )
|
|
|
|
.simulate( "keyup" );
|
|
|
|
assert.dateEqual( that.element.datepicker( "valueAsDate" ), new Date( 2014, 0, 2 ),
|
|
|
|
"Picker updated as user types into input" );
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
2013-11-22 14:30:11 +00:00
|
|
|
|
2014-06-03 21:18:51 +00:00
|
|
|
// TODO: implement
|
|
|
|
test( "ARIA", function() {
|
|
|
|
expect( 0 );
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
2013-12-27 13:28:00 +00:00
|
|
|
|
2016-05-22 19:12:10 +00:00
|
|
|
asyncTest( "mouse", function( assert ) {
|
2016-10-11 23:23:24 +00:00
|
|
|
assert.expect( 4 );
|
2014-05-15 22:19:32 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
var that = this;
|
2014-05-15 22:19:32 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
this.element.datepicker( "open" );
|
2014-05-15 22:19:32 +00:00
|
|
|
|
2015-10-08 13:06:55 +00:00
|
|
|
setTimeout( function() {
|
2016-05-22 19:48:51 +00:00
|
|
|
that.element.val( "4/4/08" ).datepicker( "refresh" ).datepicker( "open" );
|
|
|
|
$( ".ui-calendar-calendar tbody button:contains(12)", that.widget ).simulate( "mousedown", {} );
|
2016-05-22 19:12:10 +00:00
|
|
|
assert.dateEqual(
|
2016-05-22 19:48:51 +00:00
|
|
|
that.element.datepicker( "valueAsDate" ),
|
2014-06-03 21:18:51 +00:00
|
|
|
new Date( 2008, 4 - 1, 12 ),
|
|
|
|
"Mouse click - preset"
|
|
|
|
);
|
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
that.element.val( "" ).datepicker( "refresh" );
|
|
|
|
that.element.simulate( "click" );
|
|
|
|
strictEqual( that.element.datepicker( "valueAsDate" ), null, "Mouse click - close" );
|
2014-05-15 22:19:32 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
that.element.val( "4/4/08" ).datepicker( "refresh" ).datepicker( "open" );
|
|
|
|
that.element.simulate( "click" );
|
2016-05-22 19:12:10 +00:00
|
|
|
assert.dateEqual(
|
2016-05-22 19:48:51 +00:00
|
|
|
that.element.datepicker( "valueAsDate" ),
|
2014-06-03 21:18:51 +00:00
|
|
|
new Date( 2008, 4 - 1, 4 ),
|
2014-05-15 22:19:32 +00:00
|
|
|
"Mouse click - close + preset"
|
|
|
|
);
|
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
that.element.val( "4/4/08" ).datepicker( "refresh" ).datepicker( "open" );
|
|
|
|
that.widget.find( "a.ui-calendar-prev" ).simulate( "click" );
|
|
|
|
that.element.simulate( "click" );
|
2016-05-22 19:12:10 +00:00
|
|
|
assert.dateEqual(
|
2016-05-22 19:48:51 +00:00
|
|
|
that.element.datepicker( "valueAsDate" ),
|
2014-06-03 21:18:51 +00:00
|
|
|
new Date( 2008, 4 - 1, 4 ),
|
2014-05-15 22:19:32 +00:00
|
|
|
"Mouse click - abandoned"
|
|
|
|
);
|
|
|
|
|
|
|
|
start();
|
|
|
|
}, 100 );
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2015-04-07 00:06:31 +00:00
|
|
|
} );
|