Skip to content

Commit c0f1bd6

Browse files
committed
Calendar tests: Update to QUnit 2.x, shift to use no globals
1 parent 55b01ab commit c0f1bd6

File tree

4 files changed

+170
-163
lines changed

4 files changed

+170
-163
lines changed

tests/unit/calendar/core.js

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,60 @@
11
define( [
2+
"qunit",
23
"jquery",
34
"./helper",
45
"ui/widgets/calendar"
5-
], function( $, testHelper ) {
6+
], function( QUnit, $, testHelper ) {
67

7-
module( "calendar: core", {
8-
setup: function() {
8+
QUnit.module( "calendar: core", {
9+
beforeEach: function() {
910
this.element = $( "#calendar" ).calendar();
1011
this.widget = this.element.calendar( "widget" );
1112
},
12-
teardown: function() {
13+
afterEach: function() {
1314
this.element.calendar( "destroy" );
1415
}
1516
} );
1617

17-
test( "base structure", function( assert ) {
18+
QUnit.test( "base structure", function( assert ) {
1819
assert.expect( 28 );
1920

2021
var that = this,
2122
buttons, header, title, table, thead, week, child, buttonpane;
2223

2324
function step1() {
24-
ok( !that.widget.is( ".ui-calendar-rtl" ), "Structure - not right-to-left" );
25-
ok( !that.widget.is( ".ui-calendar-multi" ), "Structure - not multi-month" );
26-
equal( that.widget.children().length, 3, "Structure - child count (header, calendar)" );
25+
assert.ok( !that.widget.is( ".ui-calendar-rtl" ), "Structure - not right-to-left" );
26+
assert.ok( !that.widget.is( ".ui-calendar-multi" ), "Structure - not multi-month" );
27+
assert.equal( that.widget.children().length, 3, "Structure - child count (header, calendar)" );
2728

2829
buttons = that.widget.children( ":first" );
29-
ok( buttons.is( "div.ui-calendar-header-buttons" ), "Structure - header button division" );
30-
equal( buttons.children().length, 2, "Structure - header buttons child count" );
31-
ok( buttons.children( ":first" ).is( ".ui-calendar-prev" ) && buttons.children( ":first" ).html() !== "", "Structure - prev link" );
32-
ok( buttons.children( ":last" ).is( ".ui-calendar-next" ) && buttons.children( ":last" ).html() !== "", "Structure - next link" );
30+
assert.ok( buttons.is( "div.ui-calendar-header-buttons" ), "Structure - header button division" );
31+
assert.equal( buttons.children().length, 2, "Structure - header buttons child count" );
32+
assert.ok( buttons.children( ":first" ).is( ".ui-calendar-prev" ) && buttons.children( ":first" ).html() !== "", "Structure - prev link" );
33+
assert.ok( buttons.children( ":last" ).is( ".ui-calendar-next" ) && buttons.children( ":last" ).html() !== "", "Structure - next link" );
3334

3435
header = that.widget.children( ":eq(1)" );
35-
ok( header.is( "div.ui-calendar-header" ), "Structure - header division" );
36-
equal( header.children().length, 1, "Structure - header child count" );
36+
assert.ok( header.is( "div.ui-calendar-header" ), "Structure - header division" );
37+
assert.equal( header.children().length, 1, "Structure - header child count" );
3738

3839
title = header.children( ":last" ).children( ":first" );
39-
ok( title.is( "div.ui-calendar-title" ) && title.html() !== "", "Structure - title division" );
40-
equal( title.children().length, 2, "Structure - title child count" );
41-
ok( title.children( ":first" ).is( "span.ui-calendar-month" ) && title.children( ":first" ).text() !== "", "Structure - month text" );
42-
ok( title.children( ":last" ).is( "span.ui-calendar-year" ) && title.children( ":last" ).text() !== "", "Structure - year text" );
40+
assert.ok( title.is( "div.ui-calendar-title" ) && title.html() !== "", "Structure - title division" );
41+
assert.equal( title.children().length, 2, "Structure - title child count" );
42+
assert.ok( title.children( ":first" ).is( "span.ui-calendar-month" ) && title.children( ":first" ).text() !== "", "Structure - month text" );
43+
assert.ok( title.children( ":last" ).is( "span.ui-calendar-year" ) && title.children( ":last" ).text() !== "", "Structure - year text" );
4344

4445
table = that.widget.children( ":eq(2)" );
45-
ok( table.is( "table.ui-calendar-calendar" ), "Structure - month table" );
46-
ok( table.children( ":first" ).is( "thead" ), "Structure - month table thead" );
46+
assert.ok( table.is( "table.ui-calendar-calendar" ), "Structure - month table" );
47+
assert.ok( table.children( ":first" ).is( "thead" ), "Structure - month table thead" );
4748

4849
thead = table.children( ":first" ).children( ":first" );
49-
ok( thead.is( "tr" ), "Structure - month table title row" );
50-
equal( thead.find( "th" ).length, 7, "Structure - month table title cells" );
51-
ok( table.children( ":eq(1)" ).is( "tbody" ), "Structure - month table body" );
52-
ok( table.children( ":eq(1)" ).children( "tr" ).length >= 4, "Structure - month table week count" );
50+
assert.ok( thead.is( "tr" ), "Structure - month table title row" );
51+
assert.equal( thead.find( "th" ).length, 7, "Structure - month table title cells" );
52+
assert.ok( table.children( ":eq(1)" ).is( "tbody" ), "Structure - month table body" );
53+
assert.ok( table.children( ":eq(1)" ).children( "tr" ).length >= 4, "Structure - month table week count" );
5354

5455
week = table.children( ":eq(1)" ).children( ":first" );
55-
ok( week.is( "tr" ), "Structure - month table week row" );
56-
equal( week.children().length, 7, "Structure - week child count" );
56+
assert.ok( week.is( "tr" ), "Structure - month table week row" );
57+
assert.equal( week.children().length, 7, "Structure - week child count" );
5758

5859
step2();
5960
}
@@ -64,12 +65,12 @@ test( "base structure", function( assert ) {
6465
"test button": function() {}
6566
} );
6667

67-
equal( that.widget.children().length, 4, "Structure buttons - child count (header buttons, header, calendar, buttonpane)" );
68+
assert.equal( that.widget.children().length, 4, "Structure buttons - child count (header buttons, header, calendar, buttonpane)" );
6869

6970
buttonpane = that.widget.children( ".ui-calendar-buttonpane" );
70-
equal( buttonpane.children( "div.ui-calendar-buttonset" ).length, 1, "Structure buttons - buttonset" );
71-
equal( buttonpane.find( "button.ui-button:first" ).text(), "test", "Structure buttons - buttonset" );
72-
equal( buttonpane.find( "button.ui-button:eq(1)" ).text(), "test button", "Structure buttons - buttonset" );
71+
assert.equal( buttonpane.children( "div.ui-calendar-buttonset" ).length, 1, "Structure buttons - buttonset" );
72+
assert.equal( buttonpane.find( "button.ui-button:first" ).text(), "test", "Structure buttons - buttonset" );
73+
assert.equal( buttonpane.find( "button.ui-button:eq(1)" ).text(), "test button", "Structure buttons - buttonset" );
7374

7475
that.element.calendar( "destroy" );
7576
step3();
@@ -80,17 +81,17 @@ test( "base structure", function( assert ) {
8081
// Multi-month 2
8182
that.element.calendar( { numberOfMonths: 2 } );
8283

83-
ok( that.widget.is( ".ui-calendar-multi" ), "Structure multi [2] - multi-month" );
84-
equal( that.widget.children().length, 4, "Structure multi [2] - child count" );
84+
assert.ok( that.widget.is( ".ui-calendar-multi" ), "Structure multi [2] - multi-month" );
85+
assert.equal( that.widget.children().length, 4, "Structure multi [2] - child count" );
8586

8687
child = that.widget.children( ":eq(3)" );
87-
ok( child.is( "div.ui-calendar-row-break" ), "Structure multi [2] - row break" );
88+
assert.ok( child.is( "div.ui-calendar-row-break" ), "Structure multi [2] - row break" );
8889
}
8990

9091
step1();
9192
} );
9293

93-
test( "Localization", function( assert ) {
94+
QUnit.test( "Localization", function( assert ) {
9495
assert.expect( 10 );
9596

9697
var that = this,
@@ -108,23 +109,23 @@ test( "Localization", function( assert ) {
108109
.calendar( "valueAsDate", date );
109110
},
110111
testLocalization = function( message ) {
111-
equal(
112+
assert.equal(
112113
that.element.find( ".ui-calendar-month" ).text(),
113114
"Januar", message + "titlebar year"
114115
);
115-
equal(
116+
assert.equal(
116117
that.element.find( "thead th:first" ).text(),
117118
"Mo.", message + "teader first day"
118119
);
119-
equal(
120+
assert.equal(
120121
that.element.find( "thead th:last" ).text(),
121122
"So.", message + "header last day"
122123
);
123-
equal(
124+
assert.equal(
124125
that.element.find( ".ui-calendar-prev" ).text(),
125126
"Zurück", message + "header prev"
126127
);
127-
equal(
128+
assert.equal(
128129
that.element.find( ".ui-calendar-next" ).text(),
129130
"Vor", message + "header next"
130131
);
@@ -141,10 +142,11 @@ test( "Localization", function( assert ) {
141142
testLocalization( "After init: " );
142143
} );
143144

144-
asyncTest( "keyboard handling", function( assert ) {
145+
QUnit.test( "keyboard handling", function( assert ) {
145146
assert.expect( 10 );
146147

147-
var that = this;
148+
var ready = assert.async(),
149+
that = this;
148150

149151
function step1() {
150152
that.element.calendar( { value: new Date( 2014, 1 - 1, 1 ) } );
@@ -305,17 +307,18 @@ asyncTest( "keyboard handling", function( assert ) {
305307
new Date( 2016, 2 - 1, 29 ),
306308
"Keystroke Page Down and leap years"
307309
);
308-
start();
310+
ready();
309311
}, 50 );
310312
}
311313

312314
step1();
313315
} );
314316

315-
asyncTest( "mouse", function( assert ) {
317+
QUnit.test( "mouse", function( assert ) {
316318
assert.expect( 6 );
317319

318-
var that = this,
320+
var ready = assert.async(),
321+
that = this,
319322
date = new Date();
320323

321324
function step1() {
@@ -391,7 +394,7 @@ asyncTest( "mouse", function( assert ) {
391394
new Date( 2008, 2 - 1, 18 ),
392395
"Mouse click - next + min/max"
393396
);
394-
start();
397+
ready();
395398
}
396399

397400
step1();

tests/unit/calendar/events.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
define( [
2+
"qunit",
23
"jquery",
34
"./helper",
45
"ui/widgets/calendar"
5-
], function( $, testHelper ) {
6+
], function( QUnit, $, testHelper ) {
67

7-
module( "calendar: events", {
8-
setup: function() {
8+
QUnit.module( "calendar: events", {
9+
beforeEach: function() {
910
this.element = $( "#calendar" ).calendar();
1011
}
1112
} );
1213

13-
test( "change", function( assert ) {
14+
QUnit.test( "change", function( assert ) {
1415
assert.expect( 6 );
1516

1617
var shouldFire, eventType;
1718

1819
this.element.calendar( {
1920
change: function( event ) {
20-
ok( shouldFire, "change event fired" );
21-
equal(
21+
assert.ok( shouldFire, "change event fired" );
22+
assert.equal(
2223
event.type,
2324
"calendarchange",
2425
"change event"
2526
);
26-
equal(
27+
assert.equal(
2728
event.originalEvent.type,
2829
eventType,
2930
"change originalEvent on calendar button " + eventType
@@ -46,21 +47,22 @@ test( "change", function( assert ) {
4647
this.element.find( "tbody button" ).first().simulate( eventType );
4748
} );
4849

49-
asyncTest( "select", function( assert ) {
50+
QUnit.test( "select", function( assert ) {
5051
assert.expect( 6 );
5152

52-
var that = this,
53+
var ready = assert.async(),
54+
that = this,
5355
message, eventType;
5456

5557
this.element.calendar( {
5658
select: function( event ) {
57-
ok( true, "select event fired " + message );
58-
equal(
59+
assert.ok( true, "select event fired " + message );
60+
assert.equal(
5961
event.type,
6062
"calendarselect",
6163
"select event " + message
6264
);
63-
equal(
65+
assert.equal(
6466
event.originalEvent.type,
6567
eventType,
6668
"select originalEvent " + message
@@ -88,7 +90,7 @@ asyncTest( "select", function( assert ) {
8890
function step3() {
8991
that.element.calendar( "disable" );
9092
that.element.find( "table button:eq(10)" ).simulate( "mousedown" );
91-
setTimeout( start, 50 );
93+
setTimeout( ready, 50 );
9294
}
9395

9496
step1();

0 commit comments

Comments
 (0)