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