1
1
define ( [
2
+ "qunit" ,
2
3
"jquery" ,
3
4
"./helper" ,
4
5
"ui/widgets/calendar"
5
- ] , function ( $ , testHelper ) {
6
+ ] , function ( QUnit , $ , testHelper ) {
6
7
7
- module ( "calendar: core" , {
8
- setup : function ( ) {
8
+ QUnit . module ( "calendar: core" , {
9
+ beforeEach : function ( ) {
9
10
this . element = $ ( "#calendar" ) . calendar ( ) ;
10
11
this . widget = this . element . calendar ( "widget" ) ;
11
12
} ,
12
- teardown : function ( ) {
13
+ afterEach : function ( ) {
13
14
this . element . calendar ( "destroy" ) ;
14
15
}
15
16
} ) ;
16
17
17
- test ( "base structure" , function ( assert ) {
18
+ QUnit . test ( "base structure" , function ( assert ) {
18
19
assert . expect ( 28 ) ;
19
20
20
21
var that = this ,
21
22
buttons , header , title , table , thead , week , child , buttonpane ;
22
23
23
24
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)" ) ;
27
28
28
29
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" ) ;
33
34
34
35
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" ) ;
37
38
38
39
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" ) ;
43
44
44
45
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" ) ;
47
48
48
49
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" ) ;
53
54
54
55
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" ) ;
57
58
58
59
step2 ( ) ;
59
60
}
@@ -64,12 +65,12 @@ test( "base structure", function( assert ) {
64
65
"test button" : function ( ) { }
65
66
} ) ;
66
67
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)" ) ;
68
69
69
70
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" ) ;
73
74
74
75
that . element . calendar ( "destroy" ) ;
75
76
step3 ( ) ;
@@ -80,17 +81,17 @@ test( "base structure", function( assert ) {
80
81
// Multi-month 2
81
82
that . element . calendar ( { numberOfMonths : 2 } ) ;
82
83
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" ) ;
85
86
86
87
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" ) ;
88
89
}
89
90
90
91
step1 ( ) ;
91
92
} ) ;
92
93
93
- test ( "Localization" , function ( assert ) {
94
+ QUnit . test ( "Localization" , function ( assert ) {
94
95
assert . expect ( 10 ) ;
95
96
96
97
var that = this ,
@@ -108,23 +109,23 @@ test( "Localization", function( assert ) {
108
109
. calendar ( "valueAsDate" , date ) ;
109
110
} ,
110
111
testLocalization = function ( message ) {
111
- equal (
112
+ assert . equal (
112
113
that . element . find ( ".ui-calendar-month" ) . text ( ) ,
113
114
"Januar" , message + "titlebar year"
114
115
) ;
115
- equal (
116
+ assert . equal (
116
117
that . element . find ( "thead th:first" ) . text ( ) ,
117
118
"Mo." , message + "teader first day"
118
119
) ;
119
- equal (
120
+ assert . equal (
120
121
that . element . find ( "thead th:last" ) . text ( ) ,
121
122
"So." , message + "header last day"
122
123
) ;
123
- equal (
124
+ assert . equal (
124
125
that . element . find ( ".ui-calendar-prev" ) . text ( ) ,
125
126
"Zurück" , message + "header prev"
126
127
) ;
127
- equal (
128
+ assert . equal (
128
129
that . element . find ( ".ui-calendar-next" ) . text ( ) ,
129
130
"Vor" , message + "header next"
130
131
) ;
@@ -141,10 +142,11 @@ test( "Localization", function( assert ) {
141
142
testLocalization ( "After init: " ) ;
142
143
} ) ;
143
144
144
- asyncTest ( "keyboard handling" , function ( assert ) {
145
+ QUnit . test ( "keyboard handling" , function ( assert ) {
145
146
assert . expect ( 10 ) ;
146
147
147
- var that = this ;
148
+ var ready = assert . async ( ) ,
149
+ that = this ;
148
150
149
151
function step1 ( ) {
150
152
that . element . calendar ( { value : new Date ( 2014 , 1 - 1 , 1 ) } ) ;
@@ -305,17 +307,18 @@ asyncTest( "keyboard handling", function( assert ) {
305
307
new Date ( 2016 , 2 - 1 , 29 ) ,
306
308
"Keystroke Page Down and leap years"
307
309
) ;
308
- start ( ) ;
310
+ ready ( ) ;
309
311
} , 50 ) ;
310
312
}
311
313
312
314
step1 ( ) ;
313
315
} ) ;
314
316
315
- asyncTest ( "mouse" , function ( assert ) {
317
+ QUnit . test ( "mouse" , function ( assert ) {
316
318
assert . expect ( 6 ) ;
317
319
318
- var that = this ,
320
+ var ready = assert . async ( ) ,
321
+ that = this ,
319
322
date = new Date ( ) ;
320
323
321
324
function step1 ( ) {
@@ -391,7 +394,7 @@ asyncTest( "mouse", function( assert ) {
391
394
new Date ( 2008 , 2 - 1 , 18 ) ,
392
395
"Mouse click - next + min/max"
393
396
) ;
394
- start ( ) ;
397
+ ready ( ) ;
395
398
}
396
399
397
400
step1 ( ) ;
0 commit comments