mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Calendar tests: Update to QUnit 2.x, shift to use no globals
This commit is contained in:
parent
55b01ab1de
commit
c0f1bd6526
@ -1,59 +1,60 @@
|
||||
define( [
|
||||
"qunit",
|
||||
"jquery",
|
||||
"./helper",
|
||||
"ui/widgets/calendar"
|
||||
], function( $, testHelper ) {
|
||||
], function( QUnit, $, testHelper ) {
|
||||
|
||||
module( "calendar: core", {
|
||||
setup: function() {
|
||||
QUnit.module( "calendar: core", {
|
||||
beforeEach: function() {
|
||||
this.element = $( "#calendar" ).calendar();
|
||||
this.widget = this.element.calendar( "widget" );
|
||||
},
|
||||
teardown: function() {
|
||||
afterEach: function() {
|
||||
this.element.calendar( "destroy" );
|
||||
}
|
||||
} );
|
||||
|
||||
test( "base structure", function( assert ) {
|
||||
QUnit.test( "base structure", function( assert ) {
|
||||
assert.expect( 28 );
|
||||
|
||||
var that = this,
|
||||
buttons, header, title, table, thead, week, child, buttonpane;
|
||||
|
||||
function step1() {
|
||||
ok( !that.widget.is( ".ui-calendar-rtl" ), "Structure - not right-to-left" );
|
||||
ok( !that.widget.is( ".ui-calendar-multi" ), "Structure - not multi-month" );
|
||||
equal( that.widget.children().length, 3, "Structure - child count (header, calendar)" );
|
||||
assert.ok( !that.widget.is( ".ui-calendar-rtl" ), "Structure - not right-to-left" );
|
||||
assert.ok( !that.widget.is( ".ui-calendar-multi" ), "Structure - not multi-month" );
|
||||
assert.equal( that.widget.children().length, 3, "Structure - child count (header, calendar)" );
|
||||
|
||||
buttons = that.widget.children( ":first" );
|
||||
ok( buttons.is( "div.ui-calendar-header-buttons" ), "Structure - header button division" );
|
||||
equal( buttons.children().length, 2, "Structure - header buttons child count" );
|
||||
ok( buttons.children( ":first" ).is( ".ui-calendar-prev" ) && buttons.children( ":first" ).html() !== "", "Structure - prev link" );
|
||||
ok( buttons.children( ":last" ).is( ".ui-calendar-next" ) && buttons.children( ":last" ).html() !== "", "Structure - next link" );
|
||||
assert.ok( buttons.is( "div.ui-calendar-header-buttons" ), "Structure - header button division" );
|
||||
assert.equal( buttons.children().length, 2, "Structure - header buttons child count" );
|
||||
assert.ok( buttons.children( ":first" ).is( ".ui-calendar-prev" ) && buttons.children( ":first" ).html() !== "", "Structure - prev link" );
|
||||
assert.ok( buttons.children( ":last" ).is( ".ui-calendar-next" ) && buttons.children( ":last" ).html() !== "", "Structure - next link" );
|
||||
|
||||
header = that.widget.children( ":eq(1)" );
|
||||
ok( header.is( "div.ui-calendar-header" ), "Structure - header division" );
|
||||
equal( header.children().length, 1, "Structure - header child count" );
|
||||
assert.ok( header.is( "div.ui-calendar-header" ), "Structure - header division" );
|
||||
assert.equal( header.children().length, 1, "Structure - header child count" );
|
||||
|
||||
title = header.children( ":last" ).children( ":first" );
|
||||
ok( title.is( "div.ui-calendar-title" ) && title.html() !== "", "Structure - title division" );
|
||||
equal( title.children().length, 2, "Structure - title child count" );
|
||||
ok( title.children( ":first" ).is( "span.ui-calendar-month" ) && title.children( ":first" ).text() !== "", "Structure - month text" );
|
||||
ok( title.children( ":last" ).is( "span.ui-calendar-year" ) && title.children( ":last" ).text() !== "", "Structure - year text" );
|
||||
assert.ok( title.is( "div.ui-calendar-title" ) && title.html() !== "", "Structure - title division" );
|
||||
assert.equal( title.children().length, 2, "Structure - title child count" );
|
||||
assert.ok( title.children( ":first" ).is( "span.ui-calendar-month" ) && title.children( ":first" ).text() !== "", "Structure - month text" );
|
||||
assert.ok( title.children( ":last" ).is( "span.ui-calendar-year" ) && title.children( ":last" ).text() !== "", "Structure - year text" );
|
||||
|
||||
table = that.widget.children( ":eq(2)" );
|
||||
ok( table.is( "table.ui-calendar-calendar" ), "Structure - month table" );
|
||||
ok( table.children( ":first" ).is( "thead" ), "Structure - month table thead" );
|
||||
assert.ok( table.is( "table.ui-calendar-calendar" ), "Structure - month table" );
|
||||
assert.ok( table.children( ":first" ).is( "thead" ), "Structure - month table thead" );
|
||||
|
||||
thead = table.children( ":first" ).children( ":first" );
|
||||
ok( thead.is( "tr" ), "Structure - month table title row" );
|
||||
equal( thead.find( "th" ).length, 7, "Structure - month table title cells" );
|
||||
ok( table.children( ":eq(1)" ).is( "tbody" ), "Structure - month table body" );
|
||||
ok( table.children( ":eq(1)" ).children( "tr" ).length >= 4, "Structure - month table week count" );
|
||||
assert.ok( thead.is( "tr" ), "Structure - month table title row" );
|
||||
assert.equal( thead.find( "th" ).length, 7, "Structure - month table title cells" );
|
||||
assert.ok( table.children( ":eq(1)" ).is( "tbody" ), "Structure - month table body" );
|
||||
assert.ok( table.children( ":eq(1)" ).children( "tr" ).length >= 4, "Structure - month table week count" );
|
||||
|
||||
week = table.children( ":eq(1)" ).children( ":first" );
|
||||
ok( week.is( "tr" ), "Structure - month table week row" );
|
||||
equal( week.children().length, 7, "Structure - week child count" );
|
||||
assert.ok( week.is( "tr" ), "Structure - month table week row" );
|
||||
assert.equal( week.children().length, 7, "Structure - week child count" );
|
||||
|
||||
step2();
|
||||
}
|
||||
@ -64,12 +65,12 @@ test( "base structure", function( assert ) {
|
||||
"test button": function() {}
|
||||
} );
|
||||
|
||||
equal( that.widget.children().length, 4, "Structure buttons - child count (header buttons, header, calendar, buttonpane)" );
|
||||
assert.equal( that.widget.children().length, 4, "Structure buttons - child count (header buttons, header, calendar, buttonpane)" );
|
||||
|
||||
buttonpane = that.widget.children( ".ui-calendar-buttonpane" );
|
||||
equal( buttonpane.children( "div.ui-calendar-buttonset" ).length, 1, "Structure buttons - buttonset" );
|
||||
equal( buttonpane.find( "button.ui-button:first" ).text(), "test", "Structure buttons - buttonset" );
|
||||
equal( buttonpane.find( "button.ui-button:eq(1)" ).text(), "test button", "Structure buttons - buttonset" );
|
||||
assert.equal( buttonpane.children( "div.ui-calendar-buttonset" ).length, 1, "Structure buttons - buttonset" );
|
||||
assert.equal( buttonpane.find( "button.ui-button:first" ).text(), "test", "Structure buttons - buttonset" );
|
||||
assert.equal( buttonpane.find( "button.ui-button:eq(1)" ).text(), "test button", "Structure buttons - buttonset" );
|
||||
|
||||
that.element.calendar( "destroy" );
|
||||
step3();
|
||||
@ -80,17 +81,17 @@ test( "base structure", function( assert ) {
|
||||
// Multi-month 2
|
||||
that.element.calendar( { numberOfMonths: 2 } );
|
||||
|
||||
ok( that.widget.is( ".ui-calendar-multi" ), "Structure multi [2] - multi-month" );
|
||||
equal( that.widget.children().length, 4, "Structure multi [2] - child count" );
|
||||
assert.ok( that.widget.is( ".ui-calendar-multi" ), "Structure multi [2] - multi-month" );
|
||||
assert.equal( that.widget.children().length, 4, "Structure multi [2] - child count" );
|
||||
|
||||
child = that.widget.children( ":eq(3)" );
|
||||
ok( child.is( "div.ui-calendar-row-break" ), "Structure multi [2] - row break" );
|
||||
assert.ok( child.is( "div.ui-calendar-row-break" ), "Structure multi [2] - row break" );
|
||||
}
|
||||
|
||||
step1();
|
||||
} );
|
||||
|
||||
test( "Localization", function( assert ) {
|
||||
QUnit.test( "Localization", function( assert ) {
|
||||
assert.expect( 10 );
|
||||
|
||||
var that = this,
|
||||
@ -108,23 +109,23 @@ test( "Localization", function( assert ) {
|
||||
.calendar( "valueAsDate", date );
|
||||
},
|
||||
testLocalization = function( message ) {
|
||||
equal(
|
||||
assert.equal(
|
||||
that.element.find( ".ui-calendar-month" ).text(),
|
||||
"Januar", message + "titlebar year"
|
||||
);
|
||||
equal(
|
||||
assert.equal(
|
||||
that.element.find( "thead th:first" ).text(),
|
||||
"Mo.", message + "teader first day"
|
||||
);
|
||||
equal(
|
||||
assert.equal(
|
||||
that.element.find( "thead th:last" ).text(),
|
||||
"So.", message + "header last day"
|
||||
);
|
||||
equal(
|
||||
assert.equal(
|
||||
that.element.find( ".ui-calendar-prev" ).text(),
|
||||
"Zurück", message + "header prev"
|
||||
);
|
||||
equal(
|
||||
assert.equal(
|
||||
that.element.find( ".ui-calendar-next" ).text(),
|
||||
"Vor", message + "header next"
|
||||
);
|
||||
@ -141,10 +142,11 @@ test( "Localization", function( assert ) {
|
||||
testLocalization( "After init: " );
|
||||
} );
|
||||
|
||||
asyncTest( "keyboard handling", function( assert ) {
|
||||
QUnit.test( "keyboard handling", function( assert ) {
|
||||
assert.expect( 10 );
|
||||
|
||||
var that = this;
|
||||
var ready = assert.async(),
|
||||
that = this;
|
||||
|
||||
function step1() {
|
||||
that.element.calendar( { value: new Date( 2014, 1 - 1, 1 ) } );
|
||||
@ -305,17 +307,18 @@ asyncTest( "keyboard handling", function( assert ) {
|
||||
new Date( 2016, 2 - 1, 29 ),
|
||||
"Keystroke Page Down and leap years"
|
||||
);
|
||||
start();
|
||||
ready();
|
||||
}, 50 );
|
||||
}
|
||||
|
||||
step1();
|
||||
} );
|
||||
|
||||
asyncTest( "mouse", function( assert ) {
|
||||
QUnit.test( "mouse", function( assert ) {
|
||||
assert.expect( 6 );
|
||||
|
||||
var that = this,
|
||||
var ready = assert.async(),
|
||||
that = this,
|
||||
date = new Date();
|
||||
|
||||
function step1() {
|
||||
@ -391,7 +394,7 @@ asyncTest( "mouse", function( assert ) {
|
||||
new Date( 2008, 2 - 1, 18 ),
|
||||
"Mouse click - next + min/max"
|
||||
);
|
||||
start();
|
||||
ready();
|
||||
}
|
||||
|
||||
step1();
|
||||
|
@ -1,29 +1,30 @@
|
||||
define( [
|
||||
"qunit",
|
||||
"jquery",
|
||||
"./helper",
|
||||
"ui/widgets/calendar"
|
||||
], function( $, testHelper ) {
|
||||
], function( QUnit, $, testHelper ) {
|
||||
|
||||
module( "calendar: events", {
|
||||
setup: function() {
|
||||
QUnit.module( "calendar: events", {
|
||||
beforeEach: function() {
|
||||
this.element = $( "#calendar" ).calendar();
|
||||
}
|
||||
} );
|
||||
|
||||
test( "change", function( assert ) {
|
||||
QUnit.test( "change", function( assert ) {
|
||||
assert.expect( 6 );
|
||||
|
||||
var shouldFire, eventType;
|
||||
|
||||
this.element.calendar( {
|
||||
change: function( event ) {
|
||||
ok( shouldFire, "change event fired" );
|
||||
equal(
|
||||
assert.ok( shouldFire, "change event fired" );
|
||||
assert.equal(
|
||||
event.type,
|
||||
"calendarchange",
|
||||
"change event"
|
||||
);
|
||||
equal(
|
||||
assert.equal(
|
||||
event.originalEvent.type,
|
||||
eventType,
|
||||
"change originalEvent on calendar button " + eventType
|
||||
@ -46,21 +47,22 @@ test( "change", function( assert ) {
|
||||
this.element.find( "tbody button" ).first().simulate( eventType );
|
||||
} );
|
||||
|
||||
asyncTest( "select", function( assert ) {
|
||||
QUnit.test( "select", function( assert ) {
|
||||
assert.expect( 6 );
|
||||
|
||||
var that = this,
|
||||
var ready = assert.async(),
|
||||
that = this,
|
||||
message, eventType;
|
||||
|
||||
this.element.calendar( {
|
||||
select: function( event ) {
|
||||
ok( true, "select event fired " + message );
|
||||
equal(
|
||||
assert.ok( true, "select event fired " + message );
|
||||
assert.equal(
|
||||
event.type,
|
||||
"calendarselect",
|
||||
"select event " + message
|
||||
);
|
||||
equal(
|
||||
assert.equal(
|
||||
event.originalEvent.type,
|
||||
eventType,
|
||||
"select originalEvent " + message
|
||||
@ -88,7 +90,7 @@ asyncTest( "select", function( assert ) {
|
||||
function step3() {
|
||||
that.element.calendar( "disable" );
|
||||
that.element.find( "table button:eq(10)" ).simulate( "mousedown" );
|
||||
setTimeout( start, 50 );
|
||||
setTimeout( ready, 50 );
|
||||
}
|
||||
|
||||
step1();
|
||||
|
@ -1,19 +1,20 @@
|
||||
define( [
|
||||
"qunit",
|
||||
"jquery",
|
||||
"ui/widgets/calendar"
|
||||
], function( $ ) {
|
||||
], function( QUnit, $ ) {
|
||||
|
||||
module( "calendar: methods", {
|
||||
setup: function() {
|
||||
QUnit.module( "calendar: methods", {
|
||||
beforeEach: function() {
|
||||
this.element = $( "#calendar" ).calendar();
|
||||
this.widget = this.element.calendar( "widget" );
|
||||
},
|
||||
teardown: function() {
|
||||
afterEach: function() {
|
||||
this.element.calendar( "destroy" );
|
||||
}
|
||||
} );
|
||||
|
||||
test( "destroy", function( assert ) {
|
||||
QUnit.test( "destroy", function( assert ) {
|
||||
assert.expect( 1 );
|
||||
|
||||
var div = $( "<div>" ).appendTo( "#qunit-fixture" );
|
||||
@ -23,43 +24,43 @@ test( "destroy", function( assert ) {
|
||||
} );
|
||||
} );
|
||||
|
||||
test( "enable / disable", function( assert ) {
|
||||
QUnit.test( "enable / disable", function( assert ) {
|
||||
assert.expect( 8 );
|
||||
|
||||
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" );
|
||||
assert.ok( this.element.calendar( "option", "disabled" ), "disabled option is set" );
|
||||
assert.ok( this.element.hasClass( "ui-calendar-disabled" ), "has disabled widget class name" );
|
||||
assert.ok( this.element.hasClass( "ui-state-disabled" ), "has disabled state class name" );
|
||||
assert.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" );
|
||||
assert.ok( !this.element.calendar( "option", "disabled" ), "enabled after enable() call" );
|
||||
assert.ok( !this.element.hasClass( "ui-calendar-disabled" ), "no longer has disabled widget class name" );
|
||||
assert.ok( !this.element.hasClass( "ui-state-disabled" ), "no longer has disabled state class name" );
|
||||
assert.equal( this.element.attr( "aria-disabled" ), "false", "no longer has ARIA disabled" );
|
||||
} );
|
||||
|
||||
test( "widget", function( assert ) {
|
||||
QUnit.test( "widget", function( assert ) {
|
||||
assert.expect( 1 );
|
||||
|
||||
strictEqual( this.widget[ 0 ], this.element[ 0 ] );
|
||||
assert.strictEqual( this.widget[ 0 ], this.element[ 0 ] );
|
||||
} );
|
||||
|
||||
test( "value", function( assert ) {
|
||||
QUnit.test( "value", function( assert ) {
|
||||
assert.expect( 3 );
|
||||
|
||||
this.element.calendar( "value", "1/1/14" );
|
||||
ok( this.element.find( "button[data-ui-calendar-timestamp]:first" )
|
||||
assert.ok( this.element.find( "button[data-ui-calendar-timestamp]:first" )
|
||||
.hasClass( "ui-state-active" ),
|
||||
"first day marked as selected"
|
||||
);
|
||||
equal( this.element.calendar( "value" ), "1/1/14", "getter" );
|
||||
assert.equal( this.element.calendar( "value" ), "1/1/14", "getter" );
|
||||
|
||||
this.element.calendar( "value", "abc" );
|
||||
equal( this.element.calendar( "value" ), null, "Setting invalid values." );
|
||||
assert.equal( this.element.calendar( "value" ), null, "Setting invalid values." );
|
||||
} );
|
||||
|
||||
test( "valueAsDate", function( assert ) {
|
||||
QUnit.test( "valueAsDate", function( assert ) {
|
||||
assert.expect( 11 );
|
||||
|
||||
var minDate, maxDate, dateAndTimeToSet, dateAndTimeClone,
|
||||
@ -67,7 +68,7 @@ test( "valueAsDate", function( assert ) {
|
||||
date2;
|
||||
|
||||
this.element.calendar( "valueAsDate", new Date( 2014, 0, 1 ) );
|
||||
ok( this.element.find( "button[data-ui-calendar-timestamp]:first" )
|
||||
assert.ok( this.element.find( "button[data-ui-calendar-timestamp]:first" )
|
||||
.hasClass( "ui-state-active" ),
|
||||
"First day marked as selected"
|
||||
);
|
||||
@ -75,7 +76,7 @@ test( "valueAsDate", function( assert ) {
|
||||
|
||||
this.element.calendar( "destroy" );
|
||||
this.element.calendar();
|
||||
equal( this.element.calendar( "valueAsDate" ), null, "Set date - default" );
|
||||
assert.equal( this.element.calendar( "valueAsDate" ), null, "Set date - default" );
|
||||
|
||||
this.element.calendar( "valueAsDate", date1 );
|
||||
assert.dateEqual( this.element.calendar( "valueAsDate" ), date1, "Set date - 2008-06-04" );
|
||||
@ -95,7 +96,7 @@ test( "valueAsDate", function( assert ) {
|
||||
);
|
||||
|
||||
this.element.calendar( "valueAsDate", date1 );
|
||||
equal(
|
||||
assert.equal(
|
||||
this.element.calendar( "valueAsDate" ),
|
||||
null,
|
||||
"Set date min/max - value < min"
|
||||
@ -111,7 +112,7 @@ test( "valueAsDate", function( assert ) {
|
||||
);
|
||||
|
||||
this.element.calendar( "valueAsDate", date2 );
|
||||
equal(
|
||||
assert.equal(
|
||||
this.element.calendar( "valueAsDate" ),
|
||||
null,
|
||||
"Set date min/max - value > max"
|
||||
@ -120,14 +121,14 @@ test( "valueAsDate", function( assert ) {
|
||||
this.element
|
||||
.calendar( "option", { min: minDate } )
|
||||
.calendar( "valueAsDate", date1 );
|
||||
equal(
|
||||
assert.equal(
|
||||
this.element.calendar( "valueAsDate" ),
|
||||
null,
|
||||
"Set date min/max - value < min"
|
||||
);
|
||||
|
||||
this.element.calendar( "valueAsDate", date2 );
|
||||
equal(
|
||||
assert.equal(
|
||||
this.element.calendar( "valueAsDate" ),
|
||||
null, "Set date min/max - value > max"
|
||||
);
|
||||
@ -135,7 +136,7 @@ test( "valueAsDate", function( assert ) {
|
||||
dateAndTimeToSet = new Date( 2008, 3 - 1, 28, 1, 11, 0 );
|
||||
dateAndTimeClone = new Date( 2008, 3 - 1, 28, 1, 11, 0 );
|
||||
this.element.calendar( "valueAsDate", dateAndTimeToSet );
|
||||
equal(
|
||||
assert.equal(
|
||||
dateAndTimeToSet.getTime(),
|
||||
dateAndTimeClone.getTime(),
|
||||
"Date object passed should not be changed by valueAsDate"
|
||||
|
@ -1,48 +1,49 @@
|
||||
define( [
|
||||
"qunit",
|
||||
"jquery",
|
||||
"ui/widgets/calendar"
|
||||
], function( $ ) {
|
||||
], function( QUnit, $ ) {
|
||||
|
||||
module( "calendar: options", {
|
||||
setup: function() {
|
||||
QUnit.module( "calendar: options", {
|
||||
beforeEach: function() {
|
||||
this.element = $( "#calendar" ).calendar();
|
||||
this.widget = this.element.calendar( "widget" );
|
||||
},
|
||||
teardown: function() {
|
||||
afterEach: function() {
|
||||
this.element.calendar( "destroy" );
|
||||
}
|
||||
} );
|
||||
|
||||
test( "buttons", function( assert ) {
|
||||
QUnit.test( "buttons", function( assert ) {
|
||||
assert.expect( 21 );
|
||||
|
||||
var button, i, newButtons,
|
||||
that = this,
|
||||
buttons = {
|
||||
"Ok": function( event ) {
|
||||
ok( true, "button click fires callback" );
|
||||
equal( this, that.element[ 0 ], "context of callback" );
|
||||
equal( event.target, button[ 0 ], "event target" );
|
||||
assert.ok( true, "button click fires callback" );
|
||||
assert.equal( this, that.element[ 0 ], "context of callback" );
|
||||
assert.equal( event.target, button[ 0 ], "event target" );
|
||||
},
|
||||
"Cancel": function( event ) {
|
||||
ok( true, "button click fires callback" );
|
||||
equal( this, that.element[ 0 ], "context of callback" );
|
||||
equal( event.target, button[ 1 ], "event target" );
|
||||
assert.ok( true, "button click fires callback" );
|
||||
assert.equal( this, that.element[ 0 ], "context of callback" );
|
||||
assert.equal( event.target, button[ 1 ], "event target" );
|
||||
}
|
||||
};
|
||||
|
||||
this.element.calendar( { buttons: buttons } );
|
||||
button = this.widget.find( ".ui-calendar-buttonpane button" );
|
||||
equal( button.length, 2, "number of buttons" );
|
||||
assert.equal( button.length, 2, "number of buttons" );
|
||||
|
||||
i = 0;
|
||||
$.each( buttons, function( key ) {
|
||||
equal( button.eq( i ).text(), key, "text of button " + ( i + 1 ) );
|
||||
assert.equal( button.eq( i ).text(), key, "text of button " + ( i + 1 ) );
|
||||
i++;
|
||||
} );
|
||||
|
||||
ok( button.parent().hasClass( "ui-calendar-buttonset" ), "buttons in container" );
|
||||
ok(
|
||||
assert.ok( button.parent().hasClass( "ui-calendar-buttonset" ), "buttons in container" );
|
||||
assert.ok(
|
||||
this.element.calendar( "widget" ).hasClass( "ui-calendar-buttons" ),
|
||||
"calendar wrapper adds class about having buttons"
|
||||
);
|
||||
@ -51,42 +52,42 @@ test( "buttons", function( assert ) {
|
||||
|
||||
newButtons = {
|
||||
"Close": function( event ) {
|
||||
ok( true, "button click fires callback" );
|
||||
equal( this, that.element[ 0 ], "context of callback" );
|
||||
equal( event.target, button[ 0 ], "event target" );
|
||||
assert.ok( true, "button click fires callback" );
|
||||
assert.equal( this, that.element[ 0 ], "context of callback" );
|
||||
assert.equal( event.target, button[ 0 ], "event target" );
|
||||
}
|
||||
};
|
||||
|
||||
deepEqual(
|
||||
assert.deepEqual(
|
||||
this.element.calendar( "option", "buttons" ),
|
||||
buttons,
|
||||
".calendar('option', 'buttons') getter"
|
||||
);
|
||||
this.element.calendar( "option", "buttons", newButtons );
|
||||
deepEqual(
|
||||
assert.deepEqual(
|
||||
this.element.calendar( "option", "buttons" ),
|
||||
newButtons,
|
||||
".calendar('option', 'buttons', ...) setter"
|
||||
);
|
||||
|
||||
button = this.element.calendar( "widget" ).find( ".ui-calendar-buttonpane button" );
|
||||
equal( button.length, 1, "number of buttons after setter" );
|
||||
assert.equal( button.length, 1, "number of buttons after setter" );
|
||||
button.trigger( "click" );
|
||||
|
||||
i = 0;
|
||||
$.each( newButtons, function( key ) {
|
||||
equal( button.eq( i ).text(), key, "text of button " + ( i + 1 ) );
|
||||
assert.equal( button.eq( i ).text(), key, "text of button " + ( i + 1 ) );
|
||||
i += 1;
|
||||
} );
|
||||
|
||||
this.element.calendar( "option", "buttons", null );
|
||||
button = this.widget.find( ".ui-calendar-buttonpane button" );
|
||||
equal( button.length, 0, "all buttons have been removed" );
|
||||
equal( this.element.find( ".ui-calendar-buttonset" ).length, 0, "buttonset has been removed" );
|
||||
equal( this.element.hasClass( "ui-calendar-buttons" ), false, "calendar element removes class about having buttons" );
|
||||
assert.equal( button.length, 0, "all buttons have been removed" );
|
||||
assert.equal( this.element.find( ".ui-calendar-buttonset" ).length, 0, "buttonset has been removed" );
|
||||
assert.equal( this.element.hasClass( "ui-calendar-buttons" ), false, "calendar element removes class about having buttons" );
|
||||
} );
|
||||
|
||||
test( "buttons - advanced", function( assert ) {
|
||||
QUnit.test( "buttons - advanced", function( assert ) {
|
||||
assert.expect( 7 );
|
||||
|
||||
var that = this,
|
||||
@ -98,7 +99,7 @@ test( "buttons - advanced", function( assert ) {
|
||||
"class": "additional-class",
|
||||
id: "my-button-id",
|
||||
click: function() {
|
||||
equal( this, that.element[ 0 ], "correct context" );
|
||||
assert.equal( this, that.element[ 0 ], "correct context" );
|
||||
},
|
||||
icon: "ui-icon-cancel",
|
||||
showLabel: false
|
||||
@ -106,36 +107,36 @@ test( "buttons - advanced", function( assert ) {
|
||||
} );
|
||||
|
||||
buttons = this.widget.find( ".ui-calendar-buttonpane button" );
|
||||
equal( buttons.length, 1, "correct number of buttons" );
|
||||
equal( buttons.attr( "id" ), "my-button-id", "correct id" );
|
||||
equal ( $.trim( buttons.text() ), "a button", "correct label" );
|
||||
ok( buttons.hasClass( "additional-class" ), "additional classes added" );
|
||||
equal( buttons.button( "option", "icon" ), "ui-icon-cancel" );
|
||||
equal( buttons.button( "option", "showLabel" ), false );
|
||||
assert.equal( buttons.length, 1, "correct number of buttons" );
|
||||
assert.equal( buttons.attr( "id" ), "my-button-id", "correct id" );
|
||||
assert.equal( $.trim( buttons.text() ), "a button", "correct label" );
|
||||
assert.ok( buttons.hasClass( "additional-class" ), "additional classes added" );
|
||||
assert.equal( buttons.button( "option", "icon" ), "ui-icon-cancel" );
|
||||
assert.equal( buttons.button( "option", "showLabel" ), false );
|
||||
buttons.click();
|
||||
} );
|
||||
|
||||
test( "dateFormat", function( assert ) {
|
||||
QUnit.test( "dateFormat", function( assert ) {
|
||||
assert.expect( 2 );
|
||||
|
||||
this.element.calendar( "value", "1/1/14" );
|
||||
|
||||
this.widget.find( "td[id]:first button" ).trigger( "mousedown" );
|
||||
equal( this.element.calendar( "value" ), "1/1/14", "default formatting" );
|
||||
assert.equal( this.element.calendar( "value" ), "1/1/14", "default formatting" );
|
||||
|
||||
this.element.calendar( "option", "dateFormat", { date: "full" } );
|
||||
equal( this.element.calendar( "value" ), "Wednesday, January 1, 2014", "updated formatting" );
|
||||
assert.equal( this.element.calendar( "value" ), "Wednesday, January 1, 2014", "updated formatting" );
|
||||
} );
|
||||
|
||||
test( "eachDay", function( assert ) {
|
||||
QUnit.test( "eachDay", function( assert ) {
|
||||
assert.expect( 5 );
|
||||
|
||||
var timestamp,
|
||||
firstCell = this.widget.find( "td[id]:first" );
|
||||
|
||||
equal( firstCell.find( "button" ).length, 1, "days are selectable by default" );
|
||||
assert.equal( firstCell.find( "button" ).length, 1, "days are selectable by default" );
|
||||
timestamp = parseInt( firstCell.find( "button" ).attr( "data-ui-calendar-timestamp" ), 10 );
|
||||
equal( new Date( timestamp ).getDate(), 1, "first available day is the 1st by default" );
|
||||
assert.equal( new Date( timestamp ).getDate(), 1, "first available day is the 1st by default" );
|
||||
|
||||
// Do not render the 1st of the month
|
||||
this.element.calendar( "option", "eachDay", function( day ) {
|
||||
@ -145,7 +146,7 @@ test( "eachDay", function( assert ) {
|
||||
} );
|
||||
firstCell = this.widget.find( "td[id]:first" );
|
||||
timestamp = parseInt( firstCell.find( "button" ).attr( "data-ui-calendar-timestamp" ), 10 );
|
||||
equal( new Date( timestamp ).getDate(), 2, "first available day is the 2nd" );
|
||||
assert.equal( new Date( timestamp ).getDate(), 2, "first available day is the 2nd" );
|
||||
|
||||
// Display the 1st of the month but make it not selectable.
|
||||
this.element.calendar( "option", "eachDay", function( day ) {
|
||||
@ -154,39 +155,39 @@ test( "eachDay", function( assert ) {
|
||||
}
|
||||
} );
|
||||
firstCell = this.widget.find( "td[id]:first" );
|
||||
ok( firstCell.find( "button" ).prop( "disabled" ), "the 1st is not selectable" );
|
||||
assert.ok( firstCell.find( "button" ).prop( "disabled" ), "the 1st is not selectable" );
|
||||
|
||||
this.element.calendar( "option", "eachDay", function( day ) {
|
||||
if ( day.date === 1 ) {
|
||||
day.extraClasses = "ui-custom";
|
||||
}
|
||||
} );
|
||||
ok( this.widget.find( "td[id]:first button" ).hasClass( "ui-custom" ), "extraClasses applied" );
|
||||
assert.ok( this.widget.find( "td[id]:first button" ).hasClass( "ui-custom" ), "extraClasses applied" );
|
||||
} );
|
||||
|
||||
test( "showWeek", function() {
|
||||
expect( 7 );
|
||||
QUnit.test( "showWeek", function( assert ) {
|
||||
assert.expect( 7 );
|
||||
|
||||
equal( this.widget.find( "thead th" ).length, 7, "just 7 days, no column cell" );
|
||||
equal( this.widget.find( ".ui-calendar-week-col" ).length, 0,
|
||||
assert.equal( this.widget.find( "thead th" ).length, 7, "just 7 days, no column cell" );
|
||||
assert.equal( this.widget.find( ".ui-calendar-week-col" ).length, 0,
|
||||
"no week column cells present" );
|
||||
this.element.calendar( "destroy" );
|
||||
|
||||
this.element.calendar( { showWeek: true } );
|
||||
equal( this.widget.find( "thead th" ).length, 8, "7 days + a column cell" );
|
||||
ok( this.widget.find( "thead th:first" ).is( ".ui-calendar-week-col" ),
|
||||
assert.equal( this.widget.find( "thead th" ).length, 8, "7 days + a column cell" );
|
||||
assert.ok( this.widget.find( "thead th:first" ).is( ".ui-calendar-week-col" ),
|
||||
"first cell should have ui-datepicker-week-col class name" );
|
||||
equal( this.widget.find( ".ui-calendar-week-col" ).length,
|
||||
assert.equal( this.widget.find( ".ui-calendar-week-col" ).length,
|
||||
this.widget.find( "tr" ).length, "one week cell for each week" );
|
||||
this.element.calendar( "destroy" );
|
||||
|
||||
this.element.calendar();
|
||||
equal( this.widget.find( "thead th" ).length, 7, "no week column" );
|
||||
assert.equal( this.widget.find( "thead th" ).length, 7, "no week column" );
|
||||
this.element.calendar( "option", "showWeek", true );
|
||||
equal( this.widget.find( "thead th" ).length, 8, "supports changing option after init" );
|
||||
assert.equal( this.widget.find( "thead th" ).length, 8, "supports changing option after init" );
|
||||
} );
|
||||
|
||||
test( "min / max", function( assert ) {
|
||||
QUnit.test( "min / max", function( assert ) {
|
||||
assert.expect( 19 );
|
||||
|
||||
// With existing date
|
||||
@ -203,7 +204,7 @@ test( "min / max", function( assert ) {
|
||||
this.element
|
||||
.calendar( "option", { min: minDate } )
|
||||
.calendar( "value", "1/4/08" );
|
||||
equal( this.element.calendar( "valueAsDate" ), null, "Min/max - value < min" );
|
||||
assert.equal( this.element.calendar( "valueAsDate" ), null, "Min/max - value < min" );
|
||||
|
||||
this.element
|
||||
.calendar( "option", { min: null } )
|
||||
@ -214,12 +215,12 @@ test( "min / max", function( assert ) {
|
||||
this.element
|
||||
.calendar( "option", { max: maxDate } )
|
||||
.calendar( "value", "1/4/09" );
|
||||
equal( this.element.calendar( "valueAsDate" ), null, "Min/max - setDate > max" );
|
||||
assert.equal( this.element.calendar( "valueAsDate" ), null, "Min/max - setDate > max" );
|
||||
|
||||
this.element
|
||||
.calendar( "option", { min: minDate, max: maxDate } )
|
||||
.calendar( "value", "1/4/08" );
|
||||
equal( this.element.calendar( "valueAsDate" ), null, "Min/max - value < min" );
|
||||
assert.equal( this.element.calendar( "valueAsDate" ), null, "Min/max - value < min" );
|
||||
|
||||
this.element
|
||||
.calendar( "option", { min: minDate, max: maxDate } )
|
||||
@ -229,50 +230,50 @@ test( "min / max", function( assert ) {
|
||||
this.element
|
||||
.calendar( "option", { min: minDate, max: maxDate } )
|
||||
.calendar( "value", "1/4/09" );
|
||||
equal( this.element.calendar( "valueAsDate" ), null, "Min/max - value > max" );
|
||||
assert.equal( this.element.calendar( "valueAsDate" ), null, "Min/max - value > max" );
|
||||
|
||||
this.element.calendar( "option", { min: minDate } );
|
||||
this.element.calendar( "option", { min: "invalid" } );
|
||||
equal( this.element.calendar( "option", "min" ), null, "Min/max - invalid" );
|
||||
assert.equal( this.element.calendar( "option", "min" ), null, "Min/max - invalid" );
|
||||
|
||||
this.element.calendar( "option", { min: maxDate } );
|
||||
this.element.calendar( "option", { max: null } );
|
||||
equal( this.element.calendar( "option", "max" ), null, "Min/max - null" );
|
||||
assert.equal( this.element.calendar( "option", "max" ), null, "Min/max - null" );
|
||||
|
||||
this.element
|
||||
.calendar( "option", { min: minDate, max: maxDate } )
|
||||
.calendar( "value", "3/4/08" );
|
||||
ok( !prevButton.hasClass( "ui-state-disabled" ), "Prev button enabled" );
|
||||
assert.ok( !prevButton.hasClass( "ui-state-disabled" ), "Prev button enabled" );
|
||||
prevButton.simulate( "click" );
|
||||
ok( prevButton.hasClass( "ui-state-disabled" ), "Prev button disabled" );
|
||||
assert.ok( prevButton.hasClass( "ui-state-disabled" ), "Prev button disabled" );
|
||||
|
||||
this.element.calendar( "value", "11/4/08" );
|
||||
ok( !nextButton.hasClass( "ui-state-disabled" ), "Next button enabled" );
|
||||
assert.ok( !nextButton.hasClass( "ui-state-disabled" ), "Next button enabled" );
|
||||
nextButton.simulate( "click" );
|
||||
ok( nextButton.hasClass( "ui-state-disabled" ), "Next button disabled" );
|
||||
assert.ok( nextButton.hasClass( "ui-state-disabled" ), "Next button disabled" );
|
||||
|
||||
this.element
|
||||
.calendar( "option", { max: null } )
|
||||
.calendar( "value", "1/4/09" )
|
||||
.calendar( "option", { min: minDate, max: maxDate } );
|
||||
ok( nextButton.hasClass( "ui-state-disabled" ), "Other year above max: Next button disabled" );
|
||||
assert.ok( nextButton.hasClass( "ui-state-disabled" ), "Other year above max: Next button disabled" );
|
||||
prevButton.simulate( "click" );
|
||||
ok( nextButton.hasClass( "ui-state-disabled" ), "Other year above max: Next button disabled after click" );
|
||||
assert.ok( nextButton.hasClass( "ui-state-disabled" ), "Other year above max: Next button disabled after click" );
|
||||
prevButton.simulate( "click" );
|
||||
ok( !nextButton.hasClass( "ui-state-disabled" ), "Other year above max: Next button enabled after click" );
|
||||
assert.ok( !nextButton.hasClass( "ui-state-disabled" ), "Other year above max: Next button enabled after click" );
|
||||
|
||||
this.element
|
||||
.calendar( "option", { min: null } )
|
||||
.calendar( "value", "1/4/08" )
|
||||
.calendar( "option", { min: minDate, max: maxDate } );
|
||||
ok( prevButton.hasClass( "ui-state-disabled" ), "Other year below min: Prev button disabled" );
|
||||
assert.ok( prevButton.hasClass( "ui-state-disabled" ), "Other year below min: Prev button disabled" );
|
||||
nextButton.simulate( "click" );
|
||||
ok( prevButton.hasClass( "ui-state-disabled" ), "Other year below min: Prev button disabled after click" );
|
||||
assert.ok( prevButton.hasClass( "ui-state-disabled" ), "Other year below min: Prev button disabled after click" );
|
||||
nextButton.simulate( "click" );
|
||||
ok( !prevButton.hasClass( "ui-state-disabled" ), "Other year below min: Prev button enabled after click" );
|
||||
assert.ok( !prevButton.hasClass( "ui-state-disabled" ), "Other year below min: Prev button enabled after click" );
|
||||
} );
|
||||
|
||||
test( "numberOfMonths", function( assert ) {
|
||||
QUnit.test( "numberOfMonths", function( assert ) {
|
||||
assert.expect( 6 );
|
||||
|
||||
var date = new Date( 2015, 8 - 1, 1 );
|
||||
@ -285,13 +286,13 @@ test( "numberOfMonths", function( assert ) {
|
||||
value: date
|
||||
} );
|
||||
|
||||
equal( this.widget.find( ".ui-calendar-group" ).length, 3, "3 calendar grids" );
|
||||
equal(
|
||||
assert.equal( this.widget.find( ".ui-calendar-group" ).length, 3, "3 calendar grids" );
|
||||
assert.equal(
|
||||
this.widget.find( "tbody:first td[id]:first" ).attr( "id" ),
|
||||
"calendar-2015-7-1",
|
||||
"Correct id set for first day of first grid"
|
||||
);
|
||||
equal(
|
||||
assert.equal(
|
||||
this.widget.find( "tbody:last td[id]:last" ).attr( "id" ),
|
||||
"calendar-2015-9-31",
|
||||
"Correct id set for last day of third grid"
|
||||
@ -299,7 +300,7 @@ test( "numberOfMonths", function( assert ) {
|
||||
|
||||
// Test for jumping in weekday rendering after click on last day of last grid
|
||||
this.widget.find( "tbody:last td[id]:last button" ).trigger( "mousedown" );
|
||||
equal( this.widget.find( "thead:last th:last" ).text(), "Sa",
|
||||
assert.equal( this.widget.find( "thead:last th:last" ).text(), "Sa",
|
||||
"After mousedown last month: Last day is Saturday"
|
||||
);
|
||||
|
||||
@ -307,18 +308,18 @@ test( "numberOfMonths", function( assert ) {
|
||||
// Focus doesn't work here so we use an additional mouse down event
|
||||
this.widget.find( "tbody:first td[id]:first button" ).trigger( "mousedown" );
|
||||
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
|
||||
equal( this.widget.find( ".ui-calendar-month:first" ).text(), "May",
|
||||
assert.equal( this.widget.find( ".ui-calendar-month:first" ).text(), "May",
|
||||
"After move to previous month: First month is May"
|
||||
);
|
||||
|
||||
this.widget.find( "tbody:last td[id]:last button" ).trigger( "mousedown" );
|
||||
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
|
||||
equal( this.widget.find( ".ui-calendar-month:last" ).text(), "October",
|
||||
assert.equal( this.widget.find( ".ui-calendar-month:last" ).text(), "October",
|
||||
"After move to next month: Last month is October"
|
||||
);
|
||||
} );
|
||||
|
||||
test( "value", function( assert ) {
|
||||
QUnit.test( "value", function( assert ) {
|
||||
assert.expect( 4 );
|
||||
|
||||
var date = new Date( 2016, 5 - 1, 23 );
|
||||
@ -334,7 +335,7 @@ test( "value", function( assert ) {
|
||||
);
|
||||
|
||||
this.element.calendar( "option", "value", "invalid" );
|
||||
equal( this.element.calendar( "option", "value" ), null, "Value after invalid parameter" );
|
||||
assert.equal( this.element.calendar( "option", "value" ), null, "Value after invalid parameter" );
|
||||
} );
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user