2013-11-02 13:54:05 +00:00
|
|
|
(function( $ ) {
|
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
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
test( "destroy", function() {
|
2013-11-22 13:55:04 +00:00
|
|
|
expect( 10 );
|
|
|
|
var input = $( "#datepicker" ).datepicker(),
|
|
|
|
inline = $( "#inline" ).datepicker();
|
2013-11-02 13:54:05 +00:00
|
|
|
|
2013-11-22 13:55:04 +00:00
|
|
|
ok( input.datepicker( "instance" ), "instance created" );
|
|
|
|
ok( input.attr( "aria-owns" ), "aria-owns attribute added" );
|
|
|
|
ok( input.attr( "aria-haspopup" ), "aria-haspopup attribute added" );
|
|
|
|
input.datepicker( "destroy" );
|
|
|
|
ok( !input.datepicker( "instance" ), "instance removed" );
|
|
|
|
ok( !input.attr( "aria-owns" ), "aria-owns attribute removed" );
|
|
|
|
ok( !input.attr( "aria-haspopup" ), "aria-haspopup attribute removed" );
|
2013-11-02 13:54:05 +00:00
|
|
|
|
2013-11-22 13:55:04 +00:00
|
|
|
ok( inline.datepicker( "instance" ), "instance created" );
|
|
|
|
ok( inline.children().length > 0, "inline datepicker has children" );
|
|
|
|
inline.datepicker( "destroy" );
|
|
|
|
ok( !inline.datepicker( "instance" ), "instance removed" );
|
|
|
|
ok( inline.children().length === 0, "inline picker no longer has children" );
|
2009-02-04 04:27:14 +00:00
|
|
|
});
|
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
test( "enable / disable", function() {
|
|
|
|
expect( 6 );
|
|
|
|
var inl,
|
|
|
|
inp = TestHelpers.datepicker.init( "#datepicker" ),
|
|
|
|
dp = inp.datepicker( "widget" );
|
|
|
|
|
|
|
|
ok( !inp.datepicker( "option", "disabled" ), "initially enabled" );
|
|
|
|
ok( !dp.hasClass( "ui-datepicker-disabled" ), "does not have disabled class name" );
|
|
|
|
|
|
|
|
inp.datepicker( "disable" );
|
|
|
|
ok( inp.datepicker( "option", "disabled" ), "disabled option is set" );
|
|
|
|
ok( dp.hasClass( "ui-datepicker-disabled" ), "datepicker has disabled class name" );
|
|
|
|
|
|
|
|
inp.datepicker( "enable" );
|
|
|
|
ok( !inp.datepicker( "option", "disabled" ), "enabled after enable() call" );
|
|
|
|
ok( !dp.hasClass( "ui-datepicker-disabled" ), "no longer has disabled class name" );
|
|
|
|
|
2009-02-04 04:27:14 +00:00
|
|
|
// Inline
|
2013-11-02 13:54:05 +00:00
|
|
|
inl = TestHelpers.datepicker.init( "#inline" );
|
|
|
|
dp = inl.datepicker( "instance" );
|
|
|
|
|
|
|
|
// TODO: Disabling inline pickers does not work.
|
|
|
|
// TODO: When changeMonth and changeYear options are implemented ensure their dropdowns
|
|
|
|
// are properly disabled when in an inline picker.
|
|
|
|
});
|
|
|
|
|
|
|
|
test( "widget", function() {
|
|
|
|
expect( 1 );
|
|
|
|
var actual = $( "#datepicker" ).datepicker().datepicker( "widget" );
|
|
|
|
deepEqual( $("body > .ui-front" )[ 0 ], actual[ 0 ] );
|
|
|
|
actual.remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
test( "close", function() {
|
|
|
|
expect( 0 );
|
|
|
|
});
|
|
|
|
|
|
|
|
test( "open", function() {
|
|
|
|
expect( 0 );
|
|
|
|
});
|
|
|
|
|
|
|
|
test( "value", function() {
|
2014-01-03 14:16:03 +00:00
|
|
|
expect( 6 );
|
2013-11-21 14:03:08 +00:00
|
|
|
var input = $( "#datepicker" ).datepicker(),
|
|
|
|
picker = input.datepicker( "widget" ),
|
|
|
|
inline = $( "#inline" ).datepicker();
|
|
|
|
|
2013-11-30 12:22:17 +00:00
|
|
|
input.datepicker( "value", "1/1/14" );
|
|
|
|
equal( input.val(), "1/1/14", "input's value set" );
|
2013-11-21 14:03:08 +00:00
|
|
|
ok( picker.find( "a[data-timestamp]:first" ).hasClass( "ui-state-focus" ),
|
|
|
|
"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" );
|
|
|
|
equal( input.datepicker( "value" ), "abc",
|
|
|
|
"Invalid values should be returned without formatting." );
|
|
|
|
|
2013-11-30 12:22:17 +00:00
|
|
|
inline.datepicker( "value", "1/1/14" );
|
2013-11-21 14:03:08 +00:00
|
|
|
ok( inline.find( "a[data-timestamp]:first" ).hasClass( "ui-state-focus" ),
|
|
|
|
"first day marked as selected" );
|
2013-11-30 12:22:17 +00:00
|
|
|
equal( inline.datepicker( "value" ), "1/1/14", "getter" );
|
2013-11-21 14:03:08 +00:00
|
|
|
|
|
|
|
input.datepicker( "destroy" );
|
|
|
|
inline.datepicker( "destroy" );
|
|
|
|
});
|
|
|
|
|
|
|
|
test( "valueAsDate", function() {
|
2014-01-03 14:16:03 +00:00
|
|
|
expect( 6 );
|
2013-11-21 14:03:08 +00:00
|
|
|
var input = $( "#datepicker" ).datepicker(),
|
|
|
|
picker = input.datepicker( "widget" ),
|
|
|
|
inline = $( "#inline" ).datepicker();
|
|
|
|
|
|
|
|
input.datepicker( "valueAsDate", new Date( 2014, 0, 1 ) );
|
2013-11-30 12:22:17 +00:00
|
|
|
equal( input.val(), "1/1/14", "input's value set" );
|
2013-11-21 14:03:08 +00:00
|
|
|
ok( picker.find( "a[data-timestamp]:first" ).hasClass( "ui-state-focus" ),
|
|
|
|
"first day marked as selected" );
|
|
|
|
TestHelpers.datepicker.equalsDate( input.datepicker( "valueAsDate" ),
|
|
|
|
new Date( 2014, 0, 1 ), "getter" );
|
|
|
|
|
2014-01-03 14:16:03 +00:00
|
|
|
input.val( "a/b/c" );
|
|
|
|
equal( input.datepicker( "valueAsDate" ), null, "Invalid dates return null" );
|
|
|
|
|
2013-11-21 14:03:08 +00:00
|
|
|
inline.datepicker( "valueAsDate", new Date( 2014, 0, 1 ) );
|
|
|
|
ok( inline.find( "a[data-timestamp]:first" ).hasClass( "ui-state-focus" ),
|
|
|
|
"first day marked as selected" );
|
|
|
|
TestHelpers.datepicker.equalsDate( inline.datepicker( "valueAsDate" ),
|
|
|
|
new Date( 2014, 0, 1 ), "getter" );
|
|
|
|
|
|
|
|
input.datepicker( "destroy" );
|
|
|
|
inline.datepicker( "destroy" );
|
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" );
|
|
|
|
});
|
|
|
|
|
2013-11-02 13:54:05 +00:00
|
|
|
})( jQuery );
|