2015-07-15 13:40:38 +00:00
|
|
|
define( [
|
|
|
|
"jquery",
|
2015-08-20 13:48:11 +00:00
|
|
|
"ui/widgets/calendar"
|
2016-05-22 19:12:10 +00:00
|
|
|
], function( $ ) {
|
2014-06-03 21:18:51 +00:00
|
|
|
|
2016-05-22 19:58:20 +00:00
|
|
|
module( "calendar: methods", {
|
|
|
|
setup: function() {
|
|
|
|
this.element = $( "#calendar" ).calendar();
|
|
|
|
this.widget = this.element.calendar( "widget" );
|
|
|
|
},
|
|
|
|
teardown: function() {
|
|
|
|
this.element.calendar( "destroy" );
|
|
|
|
}
|
|
|
|
} );
|
2014-06-03 21:18:51 +00:00
|
|
|
|
2015-07-15 13:40:38 +00:00
|
|
|
test( "destroy", function( assert ) {
|
2016-10-11 23:23:24 +00:00
|
|
|
assert.expect( 1 );
|
2014-06-03 21:18:51 +00:00
|
|
|
|
2016-05-22 19:58:20 +00:00
|
|
|
var div = $( "<div>" ).appendTo( "#qunit-fixture" );
|
|
|
|
|
|
|
|
assert.domEqual( div, function() {
|
|
|
|
div.calendar().calendar( "destroy" );
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
|
|
|
} );
|
2014-06-03 21:18:51 +00:00
|
|
|
|
2016-10-11 23:23:24 +00:00
|
|
|
test( "enable / disable", function( assert ) {
|
|
|
|
assert.expect( 8 );
|
2014-06-03 21:18:51 +00:00
|
|
|
|
2016-05-22 19:58:20 +00:00
|
|
|
this.element.calendar( "disable" );
|
|
|
|
ok( this.element.calendar( "option", "disabled" ), "disabled option is set" );
|
|
|
|
ok( this.element.hasClass( "ui-calendar-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" );
|
|
|
|
|
|
|
|
this.element.calendar( "enable" );
|
|
|
|
ok( !this.element.calendar( "option", "disabled" ), "enabled after enable() call" );
|
|
|
|
ok( !this.element.hasClass( "ui-calendar-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" );
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
2014-06-03 21:18:51 +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:58:20 +00:00
|
|
|
strictEqual( this.widget[ 0 ], this.element[ 0 ] );
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
2014-06-03 21:18:51 +00:00
|
|
|
|
2016-10-11 23:23:24 +00:00
|
|
|
test( "value", function( assert ) {
|
|
|
|
assert.expect( 3 );
|
2014-06-03 21:18:51 +00:00
|
|
|
|
2016-05-22 19:58:20 +00:00
|
|
|
this.element.calendar( "value", "1/1/14" );
|
2016-10-11 23:31:22 +00:00
|
|
|
ok( this.element.find( "button[data-ui-calendar-timestamp]:first" )
|
2015-01-20 17:23:49 +00:00
|
|
|
.hasClass( "ui-state-active" ),
|
|
|
|
"first day marked as selected"
|
|
|
|
);
|
2016-05-22 19:58:20 +00:00
|
|
|
equal( this.element.calendar( "value" ), "1/1/14", "getter" );
|
2014-06-03 21:18:51 +00:00
|
|
|
|
2016-05-22 19:58:20 +00:00
|
|
|
this.element.calendar( "value", "abc" );
|
|
|
|
equal( this.element.calendar( "value" ), "1/1/14", "Setting invalid values should be ignored." );
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
2014-06-03 21:18:51 +00:00
|
|
|
|
2016-05-22 19:12:10 +00:00
|
|
|
test( "valueAsDate", function( assert ) {
|
2016-10-11 23:23:24 +00:00
|
|
|
assert.expect( 11 );
|
2014-06-03 21:18:51 +00:00
|
|
|
|
2014-06-04 17:07:23 +00:00
|
|
|
var minDate, maxDate, dateAndTimeToSet, dateAndTimeClone,
|
2014-06-03 21:18:51 +00:00
|
|
|
date1 = new Date( 2008, 6 - 1, 4 ),
|
2014-11-07 17:10:31 +00:00
|
|
|
date2;
|
2014-06-03 21:18:51 +00:00
|
|
|
|
2016-05-22 19:58:20 +00:00
|
|
|
this.element.calendar( "valueAsDate", new Date( 2014, 0, 1 ) );
|
2016-10-11 23:31:22 +00:00
|
|
|
ok( this.element.find( "button[data-ui-calendar-timestamp]:first" )
|
2015-01-20 17:23:49 +00:00
|
|
|
.hasClass( "ui-state-active" ),
|
|
|
|
"First day marked as selected"
|
|
|
|
);
|
2016-05-22 19:58:20 +00:00
|
|
|
assert.dateEqual( this.element.calendar( "valueAsDate" ), new Date( 2014, 0, 1 ), "Getter" );
|
2014-06-03 21:18:51 +00:00
|
|
|
|
2016-05-22 19:58:20 +00:00
|
|
|
this.element.calendar( "destroy" );
|
|
|
|
this.element.calendar();
|
|
|
|
equal( this.element.calendar( "valueAsDate" ), null, "Set date - default" );
|
2014-06-03 21:18:51 +00:00
|
|
|
|
2016-05-22 19:58:20 +00:00
|
|
|
this.element.calendar( "valueAsDate", date1 );
|
|
|
|
assert.dateEqual( this.element.calendar( "valueAsDate" ), date1, "Set date - 2008-06-04" );
|
2014-06-04 17:07:23 +00:00
|
|
|
|
2016-05-22 19:58:20 +00:00
|
|
|
// With minimum / maximum
|
2014-06-04 17:07:23 +00:00
|
|
|
date1 = new Date( 2008, 1 - 1, 4 );
|
|
|
|
date2 = new Date( 2008, 6 - 1, 4 );
|
|
|
|
minDate = new Date( 2008, 2 - 1, 29 );
|
|
|
|
maxDate = new Date( 2008, 3 - 1, 28 );
|
|
|
|
|
2016-05-22 19:58:20 +00:00
|
|
|
this.element
|
2014-06-04 17:07:23 +00:00
|
|
|
.calendar( "option", { min: minDate } )
|
|
|
|
.calendar( "valueAsDate", date2 );
|
2016-05-22 19:12:10 +00:00
|
|
|
assert.dateEqual(
|
2016-05-22 19:58:20 +00:00
|
|
|
this.element.calendar( "valueAsDate" ),
|
2014-06-04 17:07:23 +00:00
|
|
|
date2, "Set date min/max - value > min"
|
|
|
|
);
|
|
|
|
|
2016-05-22 19:58:20 +00:00
|
|
|
this.element.calendar( "valueAsDate", date1 );
|
2016-05-22 19:12:10 +00:00
|
|
|
assert.dateEqual(
|
2016-05-22 19:58:20 +00:00
|
|
|
this.element.calendar( "valueAsDate" ),
|
2014-06-04 17:07:23 +00:00
|
|
|
date2,
|
|
|
|
"Set date min/max - value < min"
|
|
|
|
);
|
|
|
|
|
2016-05-22 19:58:20 +00:00
|
|
|
this.element
|
2014-06-04 17:07:23 +00:00
|
|
|
.calendar( "option", { max: maxDate, min: null } )
|
|
|
|
.calendar( "valueAsDate", date1 );
|
2016-05-22 19:12:10 +00:00
|
|
|
assert.dateEqual(
|
2016-05-22 19:58:20 +00:00
|
|
|
this.element.calendar( "valueAsDate" ),
|
2014-06-04 17:07:23 +00:00
|
|
|
date1,
|
|
|
|
"Set date min/max - value < max"
|
|
|
|
);
|
|
|
|
|
2016-05-22 19:58:20 +00:00
|
|
|
this.element.calendar( "valueAsDate", date2 );
|
2016-05-22 19:12:10 +00:00
|
|
|
assert.dateEqual(
|
2016-05-22 19:58:20 +00:00
|
|
|
this.element.calendar( "valueAsDate" ),
|
2014-06-04 17:07:23 +00:00
|
|
|
date1,
|
|
|
|
"Set date min/max - value > max"
|
|
|
|
);
|
|
|
|
|
2016-05-22 19:58:20 +00:00
|
|
|
this.element
|
2014-06-04 17:07:23 +00:00
|
|
|
.calendar( "option", { min: minDate } )
|
|
|
|
.calendar( "valueAsDate", date1 );
|
2016-05-22 19:12:10 +00:00
|
|
|
assert.dateEqual(
|
2016-05-22 19:58:20 +00:00
|
|
|
this.element.calendar( "valueAsDate" ),
|
2014-06-04 17:07:23 +00:00
|
|
|
date1,
|
|
|
|
"Set date min/max - value < min"
|
|
|
|
);
|
|
|
|
|
2016-05-22 19:58:20 +00:00
|
|
|
this.element.calendar( "valueAsDate", date2 );
|
2016-05-22 19:12:10 +00:00
|
|
|
assert.dateEqual(
|
2016-05-22 19:58:20 +00:00
|
|
|
this.element.calendar( "valueAsDate" ),
|
2014-06-04 17:07:23 +00:00
|
|
|
date1, "Set date min/max - value > max"
|
|
|
|
);
|
|
|
|
|
|
|
|
dateAndTimeToSet = new Date( 2008, 3 - 1, 28, 1, 11, 0 );
|
|
|
|
dateAndTimeClone = new Date( 2008, 3 - 1, 28, 1, 11, 0 );
|
2016-05-22 19:58:20 +00:00
|
|
|
this.element.calendar( "valueAsDate", dateAndTimeToSet );
|
2014-06-04 17:07:23 +00:00
|
|
|
equal(
|
|
|
|
dateAndTimeToSet.getTime(),
|
|
|
|
dateAndTimeClone.getTime(),
|
|
|
|
"Date object passed should not be changed by valueAsDate"
|
|
|
|
);
|
2015-10-08 13:06:55 +00:00
|
|
|
} );
|
2014-06-03 21:18:51 +00:00
|
|
|
|
2015-07-15 13:40:38 +00:00
|
|
|
} );
|