2016-05-22 15:18:28 +00:00
|
|
|
define( [
|
2016-12-11 16:53:41 +00:00
|
|
|
"qunit",
|
2016-05-22 15:18:28 +00:00
|
|
|
"jquery",
|
|
|
|
"./helper",
|
|
|
|
"ui/widgets/calendar"
|
2016-12-11 16:53:41 +00:00
|
|
|
], function( QUnit, $, testHelper ) {
|
2016-05-22 15:18:28 +00:00
|
|
|
|
2016-12-11 16:53:41 +00:00
|
|
|
QUnit.module( "calendar: events", {
|
|
|
|
beforeEach: function() {
|
2016-05-22 19:58:20 +00:00
|
|
|
this.element = $( "#calendar" ).calendar();
|
|
|
|
}
|
|
|
|
} );
|
2016-05-22 15:18:28 +00:00
|
|
|
|
2016-12-11 16:53:41 +00:00
|
|
|
QUnit.test( "change", function( assert ) {
|
2016-12-11 22:10:26 +00:00
|
|
|
assert.expect( 8 );
|
2016-05-29 08:57:35 +00:00
|
|
|
|
|
|
|
var shouldFire, eventType;
|
|
|
|
|
|
|
|
this.element.calendar( {
|
2016-12-11 22:10:26 +00:00
|
|
|
change: function( event, ui ) {
|
2016-12-11 16:53:41 +00:00
|
|
|
assert.ok( shouldFire, "change event fired" );
|
|
|
|
assert.equal(
|
2016-05-29 08:57:35 +00:00
|
|
|
event.type,
|
|
|
|
"calendarchange",
|
|
|
|
"change event"
|
|
|
|
);
|
2016-12-11 16:53:41 +00:00
|
|
|
assert.equal(
|
2016-05-29 08:57:35 +00:00
|
|
|
event.originalEvent.type,
|
|
|
|
eventType,
|
|
|
|
"change originalEvent on calendar button " + eventType
|
|
|
|
);
|
2016-12-11 22:10:26 +00:00
|
|
|
assert.equal( $.type( ui.value ), "date", "value is a date object" );
|
2016-05-29 08:57:35 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
shouldFire = true;
|
|
|
|
eventType = "mousedown";
|
|
|
|
this.element.find( "tbody button" ).last().simulate( eventType );
|
|
|
|
|
|
|
|
shouldFire = true;
|
|
|
|
eventType = "keydown";
|
|
|
|
testHelper.focusGrid( this.element )
|
|
|
|
.simulate( eventType, { keyCode: $.ui.keyCode.HOME } )
|
|
|
|
.simulate( eventType, { keyCode: $.ui.keyCode.ENTER } );
|
|
|
|
|
|
|
|
shouldFire = false;
|
|
|
|
eventType = "mousedown";
|
|
|
|
this.element.find( "tbody button" ).first().simulate( eventType );
|
|
|
|
} );
|
|
|
|
|
2016-12-11 16:53:41 +00:00
|
|
|
QUnit.test( "select", function( assert ) {
|
2016-12-11 22:10:26 +00:00
|
|
|
assert.expect( 8 );
|
2016-05-22 15:18:28 +00:00
|
|
|
|
2016-12-11 16:53:41 +00:00
|
|
|
var ready = assert.async(),
|
|
|
|
that = this,
|
2016-05-22 19:58:20 +00:00
|
|
|
message, eventType;
|
|
|
|
|
|
|
|
this.element.calendar( {
|
2016-12-11 22:10:26 +00:00
|
|
|
select: function( event, ui ) {
|
2016-12-11 16:53:41 +00:00
|
|
|
assert.ok( true, "select event fired " + message );
|
|
|
|
assert.equal(
|
2016-05-22 19:58:20 +00:00
|
|
|
event.type,
|
|
|
|
"calendarselect",
|
|
|
|
"select event " + message
|
|
|
|
);
|
2016-12-11 16:53:41 +00:00
|
|
|
assert.equal(
|
2016-05-22 19:58:20 +00:00
|
|
|
event.originalEvent.type,
|
|
|
|
eventType,
|
|
|
|
"select originalEvent " + message
|
|
|
|
);
|
2016-12-11 22:10:26 +00:00
|
|
|
assert.equal( $.type( ui.value ), "date", "value is a date object" );
|
2016-05-22 19:58:20 +00:00
|
|
|
}
|
|
|
|
} );
|
2016-05-22 15:18:28 +00:00
|
|
|
|
|
|
|
function step1() {
|
2016-10-11 23:09:03 +00:00
|
|
|
eventType = "mousedown";
|
|
|
|
message = "on calendar button " + eventType;
|
|
|
|
that.element.find( "table button:eq(1)" ).simulate( eventType );
|
|
|
|
setTimeout( step2, 50 );
|
2016-05-22 15:18:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function step2() {
|
2016-10-11 23:09:03 +00:00
|
|
|
eventType = "keydown";
|
|
|
|
message = "on calendar button " + eventType;
|
|
|
|
testHelper.focusGrid( that.element )
|
|
|
|
.simulate( eventType, { keyCode: $.ui.keyCode.END } )
|
|
|
|
.simulate( eventType, { keyCode: $.ui.keyCode.ENTER } );
|
|
|
|
setTimeout( step3, 50 );
|
2016-05-22 15:18:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This should not trigger another event
|
|
|
|
function step3() {
|
2016-10-11 23:09:03 +00:00
|
|
|
that.element.calendar( "disable" );
|
|
|
|
that.element.find( "table button:eq(10)" ).simulate( "mousedown" );
|
2016-12-11 16:53:41 +00:00
|
|
|
setTimeout( ready, 50 );
|
2016-05-22 15:18:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
step1();
|
|
|
|
} );
|
|
|
|
|
2016-12-11 22:30:25 +00:00
|
|
|
QUnit.test( "refresh", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
|
|
|
|
|
|
|
var shouldFire;
|
|
|
|
|
|
|
|
this.element.calendar( {
|
|
|
|
refresh: function() {
|
|
|
|
assert.ok( shouldFire, "refresh event fired" );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
shouldFire = true;
|
|
|
|
this.element.find( "button.ui-calendar-next" ).simulate( "click" );
|
|
|
|
|
|
|
|
shouldFire = false;
|
|
|
|
this.element.find( "table button:eq(1)" ).simulate( "click" );
|
|
|
|
|
|
|
|
testHelper.focusGrid( this.element ).simulate( "keydown", { keyCode: $.ui.keyCode.END } );
|
|
|
|
shouldFire = true;
|
|
|
|
testHelper.focusGrid( this.element ).simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
|
|
|
} );
|
|
|
|
|
2016-05-22 15:18:28 +00:00
|
|
|
} );
|