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-08-20 13:48:11 +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: core", {
|
|
|
|
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( "" );
|
|
|
|
}
|
|
|
|
} );
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2016-12-11 16:53:53 +00:00
|
|
|
QUnit.test( "input's value determines starting date", function( assert ) {
|
2016-10-11 23:23:24 +00:00
|
|
|
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-12-11 16:53:53 +00:00
|
|
|
assert.equal( this.widget.find( ".ui-calendar-month" ).html(), "January", "correct month displayed" );
|
|
|
|
assert.equal( this.widget.find( ".ui-calendar-year" ).html(), "2014", "correct year displayed" );
|
|
|
|
assert.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-12-11 16:53:53 +00:00
|
|
|
QUnit.test( "base structure", function( assert ) {
|
|
|
|
var ready = assert.async();
|
2016-10-11 23:23:24 +00:00
|
|
|
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-12-11 16:53:53 +00:00
|
|
|
assert.ok( that.widget.is( ":visible" ), "Datepicker visible" );
|
|
|
|
assert.equal( that.widget.children().length, 3, "Child count" );
|
|
|
|
assert.ok( that.widget.is( ".ui-calendar" ), "Class ui-calendar" );
|
|
|
|
assert.ok( that.widget.is( ".ui-datepicker" ), "Class ui-datepicker" );
|
|
|
|
assert.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" );
|
2016-12-11 16:53:53 +00:00
|
|
|
ready();
|
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-12-11 16:53:53 +00:00
|
|
|
QUnit.test( "Keyboard handling: focus", function( assert ) {
|
|
|
|
var ready = assert.async();
|
2016-10-11 23:23:24 +00:00
|
|
|
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-12-11 16:53:53 +00:00
|
|
|
assert.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() {
|
2016-12-11 16:53:53 +00:00
|
|
|
assert.ok( that.widget.is( ":visible" ), "Datepicker opens when receiving focus" );
|
|
|
|
ready();
|
2016-05-22 19:48:51 +00:00
|
|
|
}, 100 );
|
|
|
|
} );
|
2013-11-22 14:30:11 +00:00
|
|
|
|
2016-12-11 16:53:53 +00:00
|
|
|
QUnit.test( "Keyboard handling: keystroke up", function( assert ) {
|
|
|
|
var ready = assert.async();
|
2016-10-11 23:23:24 +00:00
|
|
|
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-12-11 16:53:53 +00:00
|
|
|
assert.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() {
|
2016-12-11 16:53:53 +00:00
|
|
|
assert.ok( that.widget.is( ":visible" ), "Keystroke up opens datepicker" );
|
|
|
|
ready();
|
2016-05-22 19:48:51 +00:00
|
|
|
}, 100 );
|
|
|
|
} );
|
2013-11-22 14:30:11 +00:00
|
|
|
|
2016-12-11 16:53:53 +00:00
|
|
|
QUnit.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" );
|
2016-12-11 16:53:53 +00:00
|
|
|
assert.ok( instance.isOpen, "datepicker is open before escape" );
|
2016-05-22 19:48:51 +00:00
|
|
|
|
|
|
|
that.element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
|
2016-12-11 16:53:53 +00:00
|
|
|
assert.ok( !instance.isOpen, "escape closes the datepicker" );
|
2016-05-22 19:48:51 +00:00
|
|
|
|
|
|
|
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
|
2016-12-11 16:53:53 +00:00
|
|
|
QUnit.test( "ARIA", function( assert ) {
|
|
|
|
assert.expect( 0 );
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
2013-12-27 13:28:00 +00:00
|
|
|
|
2016-12-11 16:53:53 +00:00
|
|
|
QUnit.test( "mouse", function( assert ) {
|
|
|
|
var ready = assert.async();
|
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" );
|
2016-12-11 16:53:53 +00:00
|
|
|
assert.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"
|
|
|
|
);
|
|
|
|
|
2016-12-11 16:53:53 +00:00
|
|
|
ready();
|
2014-05-15 22:19:32 +00:00
|
|
|
}, 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
|
|
|
} );
|