2015-04-07 00:06:31 +00:00
|
|
|
define( [
|
|
|
|
"jquery",
|
2015-07-15 01:58:04 +00:00
|
|
|
"ui/widgets/datepicker"
|
2016-05-22 19:48:51 +00:00
|
|
|
], function( $ ) {
|
|
|
|
|
|
|
|
module( "datepicker: methods", {
|
|
|
|
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
|
|
|
|
2015-07-15 13:40:38 +00:00
|
|
|
test( "destroy", function( assert ) {
|
2016-10-11 23:23:24 +00:00
|
|
|
assert.expect( 3 );
|
2014-06-03 21:18:51 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
var input = $( "<input>" ).appendTo( "#qunit-fixture" );
|
|
|
|
|
2015-07-15 13:40:38 +00:00
|
|
|
assert.domEqual( input, function() {
|
2014-06-03 21:18:51 +00:00
|
|
|
input.datepicker();
|
|
|
|
ok( input.attr( "aria-owns" ), "aria-owns attribute added" );
|
|
|
|
ok( input.attr( "aria-haspopup" ), "aria-haspopup attribute added" );
|
|
|
|
input.datepicker( "destroy" );
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
|
|
|
} );
|
2009-02-04 04:27:14 +00:00
|
|
|
|
2016-10-11 23:23:24 +00:00
|
|
|
test( "enable / disable", function( assert ) {
|
|
|
|
assert.expect( 10 );
|
2013-11-02 13:54:05 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
this.element.datepicker( "disable" );
|
|
|
|
ok( this.element.datepicker( "option", "disabled" ), "disabled option is set" );
|
|
|
|
ok( this.widget.hasClass( "ui-datepicker-disabled" ), "has disabled widget class name" );
|
|
|
|
ok( this.element.hasClass( "ui-state-disabled" ), "has disabled state class name" );
|
|
|
|
equal( this.element.attr( "aria-disabled" ), "true", "has ARIA disabled" );
|
|
|
|
equal( this.element.attr( "disabled" ), "disabled", "input disabled" );
|
|
|
|
|
|
|
|
this.element.datepicker( "enable" );
|
|
|
|
ok( !this.element.datepicker( "option", "disabled" ), "enabled after enable() call" );
|
|
|
|
ok( !this.widget.hasClass( "ui-datepicker-disabled" ), "no longer has disabled widget class name" );
|
|
|
|
ok( !this.element.hasClass( "ui-state-disabled" ), "no longer has disabled state class name" );
|
|
|
|
equal( this.element.attr( "aria-disabled" ), "false", "no longer has ARIA disabled" );
|
|
|
|
equal( this.element.attr( "disabled" ), undefined, "input no longer disabled" );
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
2013-11-02 13:54:05 +00:00
|
|
|
|
2016-10-11 23:23:24 +00:00
|
|
|
test( "widget", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2014-06-03 21:18:51 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
deepEqual( $( "body > .ui-front" )[ 0 ], this.widget[ 0 ] );
|
|
|
|
this.widget.remove();
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
2013-11-02 13:54:05 +00:00
|
|
|
|
2016-10-11 23:23:24 +00:00
|
|
|
test( "open / close", function( assert ) {
|
|
|
|
assert.expect( 7 );
|
2014-06-16 22:46:08 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
ok( this.widget.is( ":hidden" ), "calendar hidden on init" );
|
2014-06-16 22:46:08 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
this.element.datepicker( "open" );
|
|
|
|
ok( this.widget.is( ":visible" ), "open: calendar visible" );
|
|
|
|
equal( this.widget.attr( "aria-hidden" ), "false", "open: calendar aria-hidden" );
|
|
|
|
equal( this.widget.attr( "aria-expanded" ), "true", "close: calendar aria-expanded" );
|
2014-06-16 22:46:08 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
this.element.datepicker( "close" );
|
|
|
|
ok( !this.widget.is( ":visible" ), "close: calendar hidden" );
|
|
|
|
equal( this.widget.attr( "aria-hidden" ), "true", "close: calendar aria-hidden" );
|
|
|
|
equal( this.widget.attr( "aria-expanded" ), "false", "close: calendar aria-expanded" );
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
2014-06-16 22:46:08 +00:00
|
|
|
|
2016-10-11 23:23:24 +00:00
|
|
|
test( "value", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
2014-05-15 22:19:32 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
this.element.datepicker( "value", "1/1/14" );
|
|
|
|
equal( this.element.val(), "1/1/14", "input's value set" );
|
2013-11-21 14:03:08 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
this.element.datepicker( "open" );
|
2015-01-20 17:23:49 +00:00
|
|
|
ok(
|
2016-10-11 23:31:22 +00:00
|
|
|
this.widget.find( "button[data-ui-calendar-timestamp]" ).eq( 0 ).hasClass( "ui-state-active" ),
|
2015-01-20 17:23:49 +00:00
|
|
|
"first day marked as selected"
|
|
|
|
);
|
2016-05-22 19:48:51 +00:00
|
|
|
equal( this.element.datepicker( "value" ), "1/1/14", "getter" );
|
2013-11-21 14:03:08 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
this.element.val( "abc" );
|
|
|
|
strictEqual( this.element.datepicker( "value" ), null, "Invalid values should return null." );
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
2013-11-21 14:03:08 +00:00
|
|
|
|
2016-05-22 19:12:10 +00:00
|
|
|
test( "valueAsDate", function( assert ) {
|
2016-10-11 23:23:24 +00:00
|
|
|
assert.expect( 5 );
|
2014-05-15 22:19:32 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
strictEqual( this.element.datepicker( "valueAsDate" ), null, "Default" );
|
2013-11-21 14:03:08 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
this.element.datepicker( "valueAsDate", new Date( 2014, 0, 1 ) );
|
|
|
|
equal( this.element.val(), "1/1/14", "Input's value set" );
|
2015-01-20 17:23:49 +00:00
|
|
|
ok(
|
2016-10-11 23:31:22 +00:00
|
|
|
this.widget.find( "button[data-ui-calendar-timestamp]" ).eq( 0 ).hasClass( "ui-state-active" ),
|
2015-01-20 17:23:49 +00:00
|
|
|
"First day marked as selected"
|
|
|
|
);
|
2016-05-22 19:48:51 +00:00
|
|
|
assert.dateEqual( this.element.datepicker( "valueAsDate" ), new Date( 2014, 0, 1 ), "Getter" );
|
2014-01-03 14:16:03 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
this.element.val( "a/b/c" );
|
|
|
|
equal( this.element.datepicker( "valueAsDate" ), null, "Invalid dates return null" );
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2016-10-11 23:23:24 +00:00
|
|
|
test( "isValid", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2014-01-03 14:07:38 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
this.element.val( "1/1/14" );
|
|
|
|
ok( this.element.datepicker( "isValid" ) );
|
2014-01-03 14:07:38 +00:00
|
|
|
|
2016-05-22 19:48:51 +00:00
|
|
|
this.element.val( "1/1/abc" );
|
|
|
|
ok( !this.element.datepicker( "isValid" ) );
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
2014-01-03 14:07:38 +00:00
|
|
|
|
2015-04-07 00:06:31 +00:00
|
|
|
} );
|