--- /dev/null
+/*
+ * Assertion for comparing Date objects by day, month and year.
+ */
+define( [
+ "qunit"
+], function( QUnit ) {
+
+QUnit.assert.dateEqual = function( value, expected, message ) {
+
+ if ( !value || !expected ) {
+ this.push( false, value, expected,
+ "dateEqual failed, missing date object, message was: " + message );
+ return;
+ }
+
+ var newValue = new Date( value.getFullYear(), value.getMonth(), value.getDate() ),
+ newExpected = new Date( expected.getFullYear(), expected.getMonth(), expected.getDate() );
+
+ this.push( ( newValue.toString() === newExpected.toString() ), value, expected, message );
+};
+
+} );
"qunit-assert-classes",
"qunit-assert-close",
"lib/qunit-assert-domequal",
+ "lib/qunit-assert-dateequal",
"phantom-bridge"
], function( QUnit, $ ) {
testLocalization( "After init: " );
} );
-asyncTest( "keyboard handling", function() {
+asyncTest( "keyboard handling", function( assert ) {
expect( 10 );
var element = $( "#calendar" );
.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
setTimeout( function() {
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
- testHelper.equalsDate(
+ assert.dateEqual(
element.calendar( "valueAsDate" ),
new Date( 2013, 12 - 1, 31 ),
"Keystroke left to switch to previous day"
.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } )
.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
- testHelper.equalsDate(
+ assert.dateEqual(
element.calendar( "valueAsDate" ),
new Date( 2014, 1 - 1, 2 ),
"Keystroke right to switch to next day"
testHelper.focusGrid( element ).simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
setTimeout( function() {
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
- testHelper.equalsDate(
+ assert.dateEqual(
element.calendar( "valueAsDate" ),
new Date( 2013, 12 - 1, 25 ),
"Keystroke up to move to the previous week"
testHelper.focusGrid( element ).simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
setTimeout( function() {
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
- testHelper.equalsDate(
+ assert.dateEqual(
element.calendar( "valueAsDate" ),
new Date( 2014, 1 - 1, 8 ),
"Keystroke down to move to the next week"
testHelper.focusGrid( element ).simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
setTimeout( function() {
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
- testHelper.equalsDate(
+ assert.dateEqual(
element.calendar( "valueAsDate" ),
new Date( 2013, 12 - 1, 1 ),
"Keystroke Page Up moves date to previous month"
.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP, altKey: true } );
setTimeout( function() {
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
- testHelper.equalsDate(
+ assert.dateEqual(
element.calendar( "valueAsDate" ),
new Date( 2013, 1 - 1, 1 ),
"Keystroke Page Up + ALT moves date to previous year"
testHelper.focusGrid( element ).simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
setTimeout( function() {
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
- testHelper.equalsDate(
+ assert.dateEqual(
element.calendar( "valueAsDate" ),
new Date( 2014, 2 - 1, 1 ),
"Keystroke Page Down moves date to next month"
.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN, altKey: true } );
setTimeout( function() {
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
- testHelper.equalsDate(
+ assert.dateEqual(
element.calendar( "valueAsDate" ),
new Date( 2015, 1 - 1, 1 ),
"Keystroke Page Down + ALT moves date to next year"
testHelper.focusGrid( element ).simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
setTimeout( function() {
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
- testHelper.equalsDate(
+ assert.dateEqual(
element.calendar( "valueAsDate" ),
new Date( 2014, 2 - 1, 28 ),
"Keystroke Page Up and short months"
testHelper.focusGrid( element ).simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
setTimeout( function() {
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
- testHelper.equalsDate(
+ assert.dateEqual(
element.calendar( "valueAsDate" ),
new Date( 2016, 2 - 1, 29 ),
"Keystroke Page Down and leap years"
step1();
} );
-asyncTest( "mouse", function() {
+asyncTest( "mouse", function( assert ) {
expect( 6 );
var element = $( "#calendar" ).calendar(),
function step1() {
$( "tbody button:contains(10)", element ).simulate( "mousedown" );
date.setDate( 10 );
- testHelper.equalsDate(
+ assert.dateEqual(
element.calendar( "valueAsDate" ),
date,
"Mouse click"
element.calendar( "option", "value", new Date( 2008, 2 - 1, 4 ) );
$( ".ui-calendar-calendar tbody button:contains(12)", element ).simulate( "mousedown" );
- testHelper.equalsDate(
+ assert.dateEqual(
element.calendar( "valueAsDate" ),
new Date( 2008, 2 - 1, 12 ),
"Mouse click - preset"
element.calendar( "option", "value", new Date( 2008, 2 - 1, 4 ) );
$( ".ui-calendar-prev", element ).simulate( "click" );
$( ".ui-calendar-calendar tbody button:contains(16)", element ).simulate( "mousedown" );
- testHelper.equalsDate(
+ assert.dateEqual(
element.calendar( "valueAsDate" ),
new Date( 2008, 1 - 1, 16 ),
"Mouse click - previous"
element.calendar( "option", "value", new Date( 2008, 2 - 1, 4 ) );
$( ".ui-calendar-next", element ).simulate( "click" );
$( ".ui-calendar-calendar tbody button:contains(18)", element ).simulate( "mousedown" );
- testHelper.equalsDate(
+ assert.dateEqual(
element.calendar( "valueAsDate" ),
new Date( 2008, 3 - 1, 18 ),
"Mouse click - next"
$( ".ui-calendar-prev", element ).simulate( "click" );
$( "tbody button:contains(16)", element ).simulate( "mousedown" );
- testHelper.equalsDate(
+ assert.dateEqual(
element.calendar( "valueAsDate" ),
new Date( 2008, 2 - 1, 16 ),
"Mouse click - previous + min/max"
$( ".ui-calendar-next", element ).simulate( "click" );
$( "tbody button:contains(18)", element ).simulate( "mousedown" );
- testHelper.equalsDate(
+ assert.dateEqual(
element.calendar( "valueAsDate" ),
new Date( 2008, 2 - 1, 18 ),
"Mouse click - next + min/max"
], function( $, helper ) {
return $.extend( helper, {
- addMonths: function( date, offset ) {
- var maxDay = 32 - new Date( date.getFullYear(), date.getMonth() + offset, 32 ).getDate();
- date.setDate( Math.min( date.getDate(), maxDay ) );
- date.setMonth( date.getMonth() + offset );
- return date;
- },
- equalsDate: function( d1, d2, message ) {
- if ( !d1 || !d2 ) {
- ok( false, message + " - missing date" );
- return;
- }
- d1 = new Date( d1.getFullYear(), d1.getMonth(), d1.getDate() );
- d2 = new Date( d2.getFullYear(), d2.getMonth(), d2.getDate() );
- equal( d1.toString(), d2.toString(), message );
- },
focusGrid: function( element ) {
element.find( ":tabbable" ).last().simulate( "focus" );
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.TAB } );
define( [
"jquery",
- "./helper",
"ui/widgets/calendar"
-], function( $, testHelper ) {
+], function( $ ) {
module( "calendar: methods" );
equal( element.calendar( "value" ), "1/1/14", "Setting invalid values should be ignored." );
} );
-test( "valueAsDate", function() {
+test( "valueAsDate", function( assert ) {
expect( 11 );
var minDate, maxDate, dateAndTimeToSet, dateAndTimeClone,
.hasClass( "ui-state-active" ),
"First day marked as selected"
);
- testHelper.equalsDate( element.calendar( "valueAsDate" ), new Date( 2014, 0, 1 ), "Getter" );
+ assert.dateEqual( element.calendar( "valueAsDate" ), new Date( 2014, 0, 1 ), "Getter" );
element.calendar( "destroy" );
equal( element.calendar( "valueAsDate" ), null, "Set date - default" );
element.calendar( "valueAsDate", date1 );
- testHelper.equalsDate( element.calendar( "valueAsDate" ), date1, "Set date - 2008-06-04" );
+ assert.dateEqual( element.calendar( "valueAsDate" ), date1, "Set date - 2008-06-04" );
// With minimum/maximum
element = $( "#calendar" ).calendar();
element
.calendar( "option", { min: minDate } )
.calendar( "valueAsDate", date2 );
- testHelper.equalsDate(
+ assert.dateEqual(
element.calendar( "valueAsDate" ),
date2, "Set date min/max - value > min"
);
element.calendar( "valueAsDate", date1 );
- testHelper.equalsDate(
+ assert.dateEqual(
element.calendar( "valueAsDate" ),
date2,
"Set date min/max - value < min"
element
.calendar( "option", { max: maxDate, min: null } )
.calendar( "valueAsDate", date1 );
- testHelper.equalsDate(
+ assert.dateEqual(
element.calendar( "valueAsDate" ),
date1,
"Set date min/max - value < max"
);
element.calendar( "valueAsDate", date2 );
- testHelper.equalsDate(
+ assert.dateEqual(
element.calendar( "valueAsDate" ),
date1,
"Set date min/max - value > max"
element
.calendar( "option", { min: minDate } )
.calendar( "valueAsDate", date1 );
- testHelper.equalsDate(
+ assert.dateEqual(
element.calendar( "valueAsDate" ),
date1,
"Set date min/max - value < min"
);
element.calendar( "valueAsDate", date2 );
- testHelper.equalsDate(
+ assert.dateEqual(
element.calendar( "valueAsDate" ),
date1, "Set date min/max - value > max"
);
define( [
"jquery",
- "./helper",
"ui/widgets/calendar"
-], function( $, testHelper ) {
+], function( $ ) {
module( "calendar: options" );
equal( container.find( "thead th" ).length, 8, "supports changing option after init" );
} );
-test( "min / max", function() {
+test( "min / max", function( assert ) {
expect( 17 );
// With existing date
element
.calendar( "option", { min: minDate } )
.calendar( "value", "6/4/08" );
- testHelper.equalsDate( element.calendar( "valueAsDate" ), new Date( 2008, 6 - 1, 4 ), "Min/max - value > min" );
+ assert.dateEqual( element.calendar( "valueAsDate" ), new Date( 2008, 6 - 1, 4 ), "Min/max - value > min" );
element
.calendar( "option", { min: minDate } )
.calendar( "value", "1/4/08" );
- testHelper.equalsDate( element.calendar( "valueAsDate" ), new Date( 2008, 6 - 1, 4 ), "Min/max - value < min" );
+ assert.dateEqual( element.calendar( "valueAsDate" ), new Date( 2008, 6 - 1, 4 ), "Min/max - value < min" );
element
.calendar( "option", { min: null } )
.calendar( "value", "6/4/08" )
.calendar( "option", { max: maxDate } );
- testHelper.equalsDate( element.calendar( "valueAsDate" ), new Date( 2008, 6 - 1, 4 ), "Min/max - value < max" );
+ assert.dateEqual( element.calendar( "valueAsDate" ), new Date( 2008, 6 - 1, 4 ), "Min/max - value < max" );
element
.calendar( "option", { max: maxDate } )
.calendar( "value", "1/4/09" );
- testHelper.equalsDate( element.calendar( "valueAsDate" ), new Date( 2008, 6 - 1, 4 ), "Min/max - setDate > max" );
+ assert.dateEqual( element.calendar( "valueAsDate" ), new Date( 2008, 6 - 1, 4 ), "Min/max - setDate > max" );
element
.calendar( "option", { min: minDate, max: maxDate } )
.calendar( "value", "1/4/08" );
- testHelper.equalsDate( element.calendar( "valueAsDate" ), new Date( 2008, 6 - 1, 4 ), "Min/max - value < min" );
+ assert.dateEqual( element.calendar( "valueAsDate" ), new Date( 2008, 6 - 1, 4 ), "Min/max - value < min" );
element
.calendar( "option", { min: minDate, max: maxDate } )
.calendar( "value", "6/4/08" );
- testHelper.equalsDate( element.calendar( "valueAsDate" ), new Date( 2008, 6 - 1, 4 ), "Min/max - value > min, < max" );
+ assert.dateEqual( element.calendar( "valueAsDate" ), new Date( 2008, 6 - 1, 4 ), "Min/max - value > min, < max" );
element
.calendar( "option", { min: minDate, max: maxDate } )
.calendar( "value", "1/4/09" );
- testHelper.equalsDate( element.calendar( "valueAsDate" ), new Date( 2008, 6 - 1, 4 ), "Min/max - value > max" );
+ assert.dateEqual( element.calendar( "valueAsDate" ), new Date( 2008, 6 - 1, 4 ), "Min/max - value > max" );
element
.calendar( "option", { min: minDate, max: maxDate } )
}, 50 );
} );
-asyncTest( "Keyboard handling: input", function() {
+asyncTest( "Keyboard handling: input", function( assert ) {
expect( 10 );
var picker, instance,
input = $( "#datepicker" ).datepicker();
.datepicker( "refresh" )
.datepicker( "open" )
.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
- testHelper.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2014, 0, 1 ),
+ assert.dateEqual( input.datepicker( "valueAsDate" ), new Date( 2014, 0, 1 ),
"Keystroke enter - preset" );
input
.val( "1/1/14" )
.datepicker( "open" )
.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
- testHelper.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2014, 0, 1 ),
+ assert.dateEqual( input.datepicker( "valueAsDate" ), new Date( 2014, 0, 1 ),
"Keystroke esc - preset" );
input
.datepicker( "open" )
.simulate( "keydown", { ctrlKey: true, keyCode: $.ui.keyCode.PAGE_UP } )
.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
- testHelper.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2014, 0, 1 ),
+ assert.dateEqual( input.datepicker( "valueAsDate" ), new Date( 2014, 0, 1 ),
"Keystroke esc - abandoned" );
input
.val( "1/2/14" )
.simulate( "keyup" );
- testHelper.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2014, 0, 2 ),
+ assert.dateEqual( input.datepicker( "valueAsDate" ), new Date( 2014, 0, 2 ),
"Picker updated as user types into input" );
input.datepicker( "destroy" );
expect( 0 );
} );
-asyncTest( "mouse", function() {
+asyncTest( "mouse", function( assert ) {
expect( 4 );
var input = testHelper.init( $( "#datepicker" ).val( "" ) ),
setTimeout( function() {
input.val( "4/4/08" ).datepicker( "refresh" ).datepicker( "open" );
$( ".ui-calendar-calendar tbody button:contains(12)", picker ).simulate( "mousedown", {} );
- testHelper.equalsDate(
+ assert.dateEqual(
input.datepicker( "valueAsDate" ),
new Date( 2008, 4 - 1, 12 ),
"Mouse click - preset"
input.val( "4/4/08" ).datepicker( "refresh" ).datepicker( "open" );
input.simulate( "click" );
- testHelper.equalsDate(
+ assert.dateEqual(
input.datepicker( "valueAsDate" ),
new Date( 2008, 4 - 1, 4 ),
"Mouse click - close + preset"
input.val( "4/4/08" ).datepicker( "refresh" ).datepicker( "open" );
picker.find( "a.ui-calendar-prev" ).simulate( "click" );
input.simulate( "click" );
- testHelper.equalsDate(
+ assert.dateEqual(
input.datepicker( "valueAsDate" ),
new Date( 2008, 4 - 1, 4 ),
"Mouse click - abandoned"
], function( $, helper ) {
return $.extend( helper, {
- addMonths: function( date, offset ) {
- var maxDay = 32 - new Date( date.getFullYear(), date.getMonth() + offset, 32 ).getDate();
- date.setDate( Math.min( date.getDate(), maxDay ) );
- date.setMonth( date.getMonth() + offset );
- return date;
- },
- equalsDate: function( d1, d2, message ) {
- if ( !d1 || !d2 ) {
- ok( false, message + " - missing date" );
- return;
- }
- d1 = new Date( d1.getFullYear(), d1.getMonth(), d1.getDate() );
- d2 = new Date( d2.getFullYear(), d2.getMonth(), d2.getDate() );
- equal( d1.toString(), d2.toString(), message );
- },
init: function( id, options ) {
options = $.extend( { show: false, hide: false }, options || {} );
return $( id ).datepicker( options );
strictEqual( input.datepicker( "value" ), null, "Invalid values should return null." );
} );
-test( "valueAsDate", function() {
+test( "valueAsDate", function( assert ) {
expect( 6 );
var input = testHelper.init( "#datepicker" ),
picker.find( "button[data-timestamp]" ).eq( 0 ).hasClass( "ui-state-active" ),
"First day marked as selected"
);
- testHelper.equalsDate( input.datepicker( "valueAsDate" ), new Date( 2014, 0, 1 ), "Getter" );
+ assert.dateEqual( input.datepicker( "valueAsDate" ), new Date( 2014, 0, 1 ), "Getter" );
input.val( "a/b/c" );
equal( input.datepicker( "valueAsDate" ), null, "Invalid dates return null" );
strictEqual( input.datepicker( "valueAsDate" ), null, "Set date - default" );
input.datepicker( "valueAsDate", date1 );
- testHelper.equalsDate( input.datepicker( "valueAsDate" ), date1, "Set date - 2008-06-04" );
+ assert.dateEqual( input.datepicker( "valueAsDate" ), date1, "Set date - 2008-06-04" );
} );
test( "isValid", function() {