2015-04-07 00:06:31 +00:00
|
|
|
define( [
|
2016-04-03 15:11:33 +00:00
|
|
|
"qunit",
|
2015-04-07 00:06:31 +00:00
|
|
|
"jquery",
|
2015-04-07 14:55:52 +00:00
|
|
|
"./helper",
|
2015-07-15 01:58:04 +00:00
|
|
|
"ui/widgets/datepicker"
|
2016-04-03 15:11:33 +00:00
|
|
|
], function( QUnit, $, testHelper ) {
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2016-04-03 15:11:33 +00:00
|
|
|
QUnit.module( "datepicker: methods" );
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2016-04-03 15:11:33 +00:00
|
|
|
QUnit.test( "destroy", function( assert ) {
|
|
|
|
assert.expect( 33 );
|
2012-04-19 15:17:35 +00:00
|
|
|
var inl,
|
2015-08-24 13:00:11 +00:00
|
|
|
inp = testHelper.init( "#inp" );
|
2016-04-03 15:11:33 +00:00
|
|
|
assert.ok( inp.is( ".hasDatepicker" ), "Default - marker class set" );
|
|
|
|
assert.ok( $.data( inp[ 0 ], testHelper.PROP_NAME ), "Default - instance present" );
|
|
|
|
assert.ok( inp.next().is( "#alt" ), "Default - button absent" );
|
2015-08-24 13:00:11 +00:00
|
|
|
inp.datepicker( "destroy" );
|
|
|
|
inp = $( "#inp" );
|
2016-04-03 15:11:33 +00:00
|
|
|
assert.ok( !inp.is( ".hasDatepicker" ), "Default - marker class cleared" );
|
|
|
|
assert.ok( !$.data( inp[ 0 ], testHelper.PROP_NAME ), "Default - instance absent" );
|
|
|
|
assert.ok( inp.next().is( "#alt" ), "Default - button absent" );
|
2015-08-24 13:00:11 +00:00
|
|
|
|
2009-02-04 04:27:14 +00:00
|
|
|
// With button
|
2015-08-24 13:00:11 +00:00
|
|
|
inp = testHelper.init( "#inp", { showOn: "both" } );
|
2016-04-03 15:11:33 +00:00
|
|
|
assert.ok( inp.is( ".hasDatepicker" ), "Button - marker class set" );
|
|
|
|
assert.ok( $.data( inp[ 0 ], testHelper.PROP_NAME ), "Button - instance present" );
|
|
|
|
assert.ok( inp.next().text() === "...", "Button - button added" );
|
2015-08-24 13:00:11 +00:00
|
|
|
inp.datepicker( "destroy" );
|
|
|
|
inp = $( "#inp" );
|
2016-04-03 15:11:33 +00:00
|
|
|
assert.ok( !inp.is( ".hasDatepicker" ), "Button - marker class cleared" );
|
|
|
|
assert.ok( !$.data( inp[ 0 ], testHelper.PROP_NAME ), "Button - instance absent" );
|
|
|
|
assert.ok( inp.next().is( "#alt" ), "Button - button removed" );
|
2015-08-24 13:00:11 +00:00
|
|
|
|
2009-02-04 04:27:14 +00:00
|
|
|
// With append text
|
2015-08-24 13:00:11 +00:00
|
|
|
inp = testHelper.init( "#inp", { appendText: "Testing" } );
|
2016-04-03 15:11:33 +00:00
|
|
|
assert.ok( inp.is( ".hasDatepicker" ), "Append - marker class set" );
|
|
|
|
assert.ok( $.data( inp[ 0 ], testHelper.PROP_NAME ), "Append - instance present" );
|
|
|
|
assert.ok( inp.next().text() === "Testing", "Append - append text added" );
|
2015-08-24 13:00:11 +00:00
|
|
|
inp.datepicker( "destroy" );
|
|
|
|
inp = $( "#inp" );
|
2016-04-03 15:11:33 +00:00
|
|
|
assert.ok( !inp.is( ".hasDatepicker" ), "Append - marker class cleared" );
|
|
|
|
assert.ok( !$.data( inp[ 0 ], testHelper.PROP_NAME ), "Append - instance absent" );
|
|
|
|
assert.ok( inp.next().is( "#alt" ), "Append - append text removed" );
|
2015-08-24 13:00:11 +00:00
|
|
|
|
2009-02-04 04:27:14 +00:00
|
|
|
// With both
|
2015-08-24 13:00:11 +00:00
|
|
|
inp = testHelper.init( "#inp", { showOn: "both", buttonImageOnly: true,
|
|
|
|
buttonImage: "images/calendar.gif", appendText: "Testing" } );
|
2016-04-03 15:11:33 +00:00
|
|
|
assert.ok( inp.is( ".hasDatepicker" ), "Both - marker class set" );
|
|
|
|
assert.ok( $.data( inp[ 0 ], testHelper.PROP_NAME ), "Both - instance present" );
|
|
|
|
assert.ok( inp.next()[ 0 ].nodeName.toLowerCase() === "img", "Both - button added" );
|
|
|
|
assert.ok( inp.next().next().text() === "Testing", "Both - append text added" );
|
2015-08-24 13:00:11 +00:00
|
|
|
inp.datepicker( "destroy" );
|
|
|
|
inp = $( "#inp" );
|
2016-04-03 15:11:33 +00:00
|
|
|
assert.ok( !inp.is( ".hasDatepicker" ), "Both - marker class cleared" );
|
|
|
|
assert.ok( !$.data( inp[ 0 ], testHelper.PROP_NAME ), "Both - instance absent" );
|
|
|
|
assert.ok( inp.next().is( "#alt" ), "Both - button and append text absent" );
|
2015-08-24 13:00:11 +00:00
|
|
|
|
2009-02-04 04:27:14 +00:00
|
|
|
// Inline
|
2015-08-24 13:00:11 +00:00
|
|
|
inl = testHelper.init( "#inl" );
|
2016-04-03 15:11:33 +00:00
|
|
|
assert.ok( inl.is( ".hasDatepicker" ), "Inline - marker class set" );
|
|
|
|
assert.ok( inl.html() !== "", "Inline - datepicker present" );
|
|
|
|
assert.ok( $.data( inl[ 0 ], testHelper.PROP_NAME ), "Inline - instance present" );
|
|
|
|
assert.ok( inl.next().length === 0 || inl.next().is( "p" ), "Inline - button absent" );
|
2015-08-24 13:00:11 +00:00
|
|
|
inl.datepicker( "destroy" );
|
|
|
|
inl = $( "#inl" );
|
2016-04-03 15:11:33 +00:00
|
|
|
assert.ok( !inl.is( ".hasDatepicker" ), "Inline - marker class cleared" );
|
|
|
|
assert.ok( inl.html() === "", "Inline - datepicker absent" );
|
|
|
|
assert.ok( !$.data( inl[ 0 ], testHelper.PROP_NAME ), "Inline - instance absent" );
|
|
|
|
assert.ok( inl.next().length === 0 || inl.next().is( "p" ), "Inline - button absent" );
|
2015-08-24 13:00:11 +00:00
|
|
|
} );
|
2009-02-04 04:27:14 +00:00
|
|
|
|
2016-04-03 15:11:33 +00:00
|
|
|
QUnit.test( "enableDisable", function( assert ) {
|
|
|
|
assert.expect( 33 );
|
2012-04-19 15:17:35 +00:00
|
|
|
var inl, dp,
|
2015-08-24 13:00:11 +00:00
|
|
|
inp = testHelper.init( "#inp" );
|
2016-04-03 15:11:33 +00:00
|
|
|
assert.ok( !inp.datepicker( "isDisabled" ), "Enable/disable - initially marked as enabled" );
|
|
|
|
assert.ok( !inp[ 0 ].disabled, "Enable/disable - field initially enabled" );
|
2015-08-24 13:00:11 +00:00
|
|
|
inp.datepicker( "disable" );
|
2016-04-03 15:11:33 +00:00
|
|
|
assert.ok( inp.datepicker( "isDisabled" ), "Enable/disable - now marked as disabled" );
|
|
|
|
assert.ok( inp[ 0 ].disabled, "Enable/disable - field now disabled" );
|
2015-08-24 13:00:11 +00:00
|
|
|
inp.datepicker( "enable" );
|
2016-04-03 15:11:33 +00:00
|
|
|
assert.ok( !inp.datepicker( "isDisabled" ), "Enable/disable - now marked as enabled" );
|
|
|
|
assert.ok( !inp[ 0 ].disabled, "Enable/disable - field now enabled" );
|
2015-08-24 13:00:11 +00:00
|
|
|
inp.datepicker( "destroy" );
|
|
|
|
|
2009-02-04 04:27:14 +00:00
|
|
|
// With a button
|
2015-08-24 13:00:11 +00:00
|
|
|
inp = testHelper.init( "#inp", { showOn: "button" } );
|
2016-04-03 15:11:33 +00:00
|
|
|
assert.ok( !inp.datepicker( "isDisabled" ), "Enable/disable button - initially marked as enabled" );
|
|
|
|
assert.ok( !inp[ 0 ].disabled, "Enable/disable button - field initially enabled" );
|
|
|
|
assert.ok( !inp.next( "button" )[ 0 ].disabled, "Enable/disable button - button initially enabled" );
|
2015-08-24 13:00:11 +00:00
|
|
|
inp.datepicker( "disable" );
|
2016-04-03 15:11:33 +00:00
|
|
|
assert.ok( inp.datepicker( "isDisabled" ), "Enable/disable button - now marked as disabled" );
|
|
|
|
assert.ok( inp[ 0 ].disabled, "Enable/disable button - field now disabled" );
|
|
|
|
assert.ok( inp.next( "button" )[ 0 ].disabled, "Enable/disable button - button now disabled" );
|
2015-08-24 13:00:11 +00:00
|
|
|
inp.datepicker( "enable" );
|
2016-04-03 15:11:33 +00:00
|
|
|
assert.ok( !inp.datepicker( "isDisabled" ), "Enable/disable button - now marked as enabled" );
|
|
|
|
assert.ok( !inp[ 0 ].disabled, "Enable/disable button - field now enabled" );
|
|
|
|
assert.ok( !inp.next( "button" )[ 0 ].disabled, "Enable/disable button - button now enabled" );
|
2015-08-24 13:00:11 +00:00
|
|
|
inp.datepicker( "destroy" );
|
|
|
|
|
2009-02-04 04:27:14 +00:00
|
|
|
// With an image button
|
2015-08-24 13:00:11 +00:00
|
|
|
inp = testHelper.init( "#inp", { showOn: "button", buttonImageOnly: true,
|
|
|
|
buttonImage: "images/calendar.gif" } );
|
2016-04-03 15:11:33 +00:00
|
|
|
assert.ok( !inp.datepicker( "isDisabled" ), "Enable/disable image - initially marked as enabled" );
|
|
|
|
assert.ok( !inp[ 0 ].disabled, "Enable/disable image - field initially enabled" );
|
|
|
|
assert.ok( parseFloat( inp.next( "img" ).css( "opacity" ) ) === 1, "Enable/disable image - image initially enabled" );
|
2015-08-24 13:00:11 +00:00
|
|
|
inp.datepicker( "disable" );
|
2016-04-03 15:11:33 +00:00
|
|
|
assert.ok( inp.datepicker( "isDisabled" ), "Enable/disable image - now marked as disabled" );
|
|
|
|
assert.ok( inp[ 0 ].disabled, "Enable/disable image - field now disabled" );
|
|
|
|
assert.ok( parseFloat( inp.next( "img" ).css( "opacity" ) ) !== 1, "Enable/disable image - image now disabled" );
|
2015-08-24 13:00:11 +00:00
|
|
|
inp.datepicker( "enable" );
|
2016-04-03 15:11:33 +00:00
|
|
|
assert.ok( !inp.datepicker( "isDisabled" ), "Enable/disable image - now marked as enabled" );
|
|
|
|
assert.ok( !inp[ 0 ].disabled, "Enable/disable image - field now enabled" );
|
|
|
|
assert.ok( parseFloat( inp.next( "img" ).css( "opacity" ) ) === 1, "Enable/disable image - image now enabled" );
|
2015-08-24 13:00:11 +00:00
|
|
|
inp.datepicker( "destroy" );
|
|
|
|
|
2009-02-04 04:27:14 +00:00
|
|
|
// Inline
|
2015-08-24 13:00:11 +00:00
|
|
|
inl = testHelper.init( "#inl", { changeYear: true } );
|
|
|
|
dp = $( ".ui-datepicker-inline", inl );
|
2016-04-03 15:11:33 +00:00
|
|
|
assert.ok( !inl.datepicker( "isDisabled" ), "Enable/disable inline - initially marked as enabled" );
|
|
|
|
assert.ok( !dp.children().is( ".ui-state-disabled" ), "Enable/disable inline - not visually disabled initially" );
|
|
|
|
assert.ok( !dp.find( "select" ).prop( "disabled" ), "Enable/disable inline - form element enabled initially" );
|
2015-08-24 13:00:11 +00:00
|
|
|
inl.datepicker( "disable" );
|
2016-04-03 15:11:33 +00:00
|
|
|
assert.ok( inl.datepicker( "isDisabled" ), "Enable/disable inline - now marked as disabled" );
|
|
|
|
assert.ok( dp.children().is( ".ui-state-disabled" ), "Enable/disable inline - visually disabled" );
|
|
|
|
assert.ok( dp.find( "select" ).prop( "disabled" ), "Enable/disable inline - form element disabled" );
|
2015-08-24 13:00:11 +00:00
|
|
|
inl.datepicker( "enable" );
|
2016-04-03 15:11:33 +00:00
|
|
|
assert.ok( !inl.datepicker( "isDisabled" ), "Enable/disable inline - now marked as enabled" );
|
|
|
|
assert.ok( !dp.children().is( ".ui-state-disabled" ), "Enable/disable inline - not visiually disabled" );
|
|
|
|
assert.ok( !dp.find( "select" ).prop( "disabled" ), "Enable/disable inline - form element enabled" );
|
2015-08-24 13:00:11 +00:00
|
|
|
inl.datepicker( "destroy" );
|
|
|
|
} );
|
2009-02-02 14:36:08 +00:00
|
|
|
|
2015-04-07 00:06:31 +00:00
|
|
|
} );
|