1
1
define ( [
2
+ "qunit" ,
2
3
"jquery" ,
3
4
"ui/widgets/datepicker"
4
- ] , function ( $ ) {
5
+ ] , function ( QUnit , $ ) {
5
6
6
- module ( "datepicker: core" , {
7
- setup : function ( ) {
7
+ QUnit . module ( "datepicker: core" , {
8
+ beforeEach : function ( ) {
8
9
this . element = $ ( "#datepicker" ) . datepicker ( { show : false , hide : false } ) ;
9
10
this . widget = this . element . datepicker ( "widget" ) ;
10
11
} ,
11
- teardown : function ( ) {
12
+ afterEach : function ( ) {
12
13
this . element . datepicker ( "destroy" ) . val ( "" ) ;
13
14
}
14
15
} ) ;
15
16
16
- test ( "input's value determines starting date" , function ( assert ) {
17
+ QUnit . test ( "input's value determines starting date" , function ( assert ) {
17
18
assert . expect ( 3 ) ;
18
19
19
20
this . element = $ ( "<input>" ) . appendTo ( "#qunit-fixture" ) ;
@@ -22,59 +23,62 @@ test( "input's value determines starting date", function( assert ) {
22
23
23
24
this . element . datepicker ( "open" ) ;
24
25
25
- equal ( this . widget . find ( ".ui-calendar-month" ) . html ( ) , "January" , "correct month displayed" ) ;
26
- equal ( this . widget . find ( ".ui-calendar-year" ) . html ( ) , "2014" , "correct year displayed" ) ;
27
- equal ( this . widget . find ( ".ui-state-active" ) . html ( ) , "1" , "correct day highlighted" ) ;
26
+ assert . equal ( this . widget . find ( ".ui-calendar-month" ) . html ( ) , "January" , "correct month displayed" ) ;
27
+ assert . equal ( this . widget . find ( ".ui-calendar-year" ) . html ( ) , "2014" , "correct year displayed" ) ;
28
+ assert . equal ( this . widget . find ( ".ui-state-active" ) . html ( ) , "1" , "correct day highlighted" ) ;
28
29
} ) ;
29
30
30
- asyncTest ( "base structure" , function ( assert ) {
31
+ QUnit . test ( "base structure" , function ( assert ) {
32
+ var ready = assert . async ( ) ;
31
33
assert . expect ( 5 ) ;
32
34
33
35
var that = this ;
34
36
35
37
this . element . focus ( ) ;
36
38
37
39
setTimeout ( function ( ) {
38
- ok ( that . widget . is ( ":visible" ) , "Datepicker visible" ) ;
39
- equal ( that . widget . children ( ) . length , 3 , "Child count" ) ;
40
- ok ( that . widget . is ( ".ui-calendar" ) , "Class ui-calendar" ) ;
41
- ok ( that . widget . is ( ".ui-datepicker" ) , "Class ui-datepicker" ) ;
42
- ok ( that . widget . is ( ".ui-front" ) , "Class ui-front" ) ;
40
+ assert . ok ( that . widget . is ( ":visible" ) , "Datepicker visible" ) ;
41
+ assert . equal ( that . widget . children ( ) . length , 3 , "Child count" ) ;
42
+ assert . ok ( that . widget . is ( ".ui-calendar" ) , "Class ui-calendar" ) ;
43
+ assert . ok ( that . widget . is ( ".ui-datepicker" ) , "Class ui-datepicker" ) ;
44
+ assert . ok ( that . widget . is ( ".ui-front" ) , "Class ui-front" ) ;
43
45
44
46
that . element . datepicker ( "close" ) ;
45
- start ( ) ;
47
+ ready ( ) ;
46
48
} , 50 ) ;
47
49
} ) ;
48
50
49
- asyncTest ( "Keyboard handling: focus" , function ( assert ) {
51
+ QUnit . test ( "Keyboard handling: focus" , function ( assert ) {
52
+ var ready = assert . async ( ) ;
50
53
assert . expect ( 2 ) ;
51
54
52
55
var that = this ;
53
56
54
- ok ( ! this . widget . is ( ":visible" ) , "datepicker closed" ) ;
57
+ assert . ok ( ! this . widget . is ( ":visible" ) , "datepicker closed" ) ;
55
58
56
59
this . element . focus ( ) ;
57
60
setTimeout ( function ( ) {
58
- ok ( that . widget . is ( ":visible" ) , "Datepicker opens when receiving focus" ) ;
59
- start ( ) ;
61
+ assert . ok ( that . widget . is ( ":visible" ) , "Datepicker opens when receiving focus" ) ;
62
+ ready ( ) ;
60
63
} , 100 ) ;
61
64
} ) ;
62
65
63
- asyncTest ( "Keyboard handling: keystroke up" , function ( assert ) {
66
+ QUnit . test ( "Keyboard handling: keystroke up" , function ( assert ) {
67
+ var ready = assert . async ( ) ;
64
68
assert . expect ( 2 ) ;
65
69
66
70
var that = this ;
67
71
68
- ok ( ! this . widget . is ( ":visible" ) , "datepicker closed" ) ;
72
+ assert . ok ( ! this . widget . is ( ":visible" ) , "datepicker closed" ) ;
69
73
70
74
this . element . simulate ( "keydown" , { keyCode : $ . ui . keyCode . UP } ) ;
71
75
setTimeout ( function ( ) {
72
- ok ( that . widget . is ( ":visible" ) , "Keystroke up opens datepicker" ) ;
73
- start ( ) ;
76
+ assert . ok ( that . widget . is ( ":visible" ) , "Keystroke up opens datepicker" ) ;
77
+ ready ( ) ;
74
78
} , 100 ) ;
75
79
} ) ;
76
80
77
- test ( "Keyboard handling: input" , function ( assert ) {
81
+ QUnit . test ( "Keyboard handling: input" , function ( assert ) {
78
82
assert . expect ( 6 ) ;
79
83
80
84
var that = this ,
@@ -92,10 +96,10 @@ test( "Keyboard handling: input", function( assert ) {
92
96
that . element
93
97
. val ( "" )
94
98
. datepicker ( "open" ) ;
95
- ok ( instance . isOpen , "datepicker is open before escape" ) ;
99
+ assert . ok ( instance . isOpen , "datepicker is open before escape" ) ;
96
100
97
101
that . element . simulate ( "keydown" , { keyCode : $ . ui . keyCode . ESCAPE } ) ;
98
- ok ( ! instance . isOpen , "escape closes the datepicker" ) ;
102
+ assert . ok ( ! instance . isOpen , "escape closes the datepicker" ) ;
99
103
100
104
that . element
101
105
. val ( "1/1/14" )
@@ -120,11 +124,12 @@ test( "Keyboard handling: input", function( assert ) {
120
124
} ) ;
121
125
122
126
// TODO: implement
123
- test ( "ARIA" , function ( ) {
124
- expect ( 0 ) ;
127
+ QUnit . test ( "ARIA" , function ( assert ) {
128
+ assert . expect ( 0 ) ;
125
129
} ) ;
126
130
127
- asyncTest ( "mouse" , function ( assert ) {
131
+ QUnit . test ( "mouse" , function ( assert ) {
132
+ var ready = assert . async ( ) ;
128
133
assert . expect ( 4 ) ;
129
134
130
135
var that = this ;
@@ -142,7 +147,7 @@ asyncTest( "mouse", function( assert ) {
142
147
143
148
that . element . val ( "" ) . datepicker ( "refresh" ) ;
144
149
that . element . simulate ( "click" ) ;
145
- strictEqual ( that . element . datepicker ( "valueAsDate" ) , null , "Mouse click - close" ) ;
150
+ assert . strictEqual ( that . element . datepicker ( "valueAsDate" ) , null , "Mouse click - close" ) ;
146
151
147
152
that . element . val ( "4/4/08" ) . datepicker ( "refresh" ) . datepicker ( "open" ) ;
148
153
that . element . simulate ( "click" ) ;
@@ -161,7 +166,7 @@ asyncTest( "mouse", function( assert ) {
161
166
"Mouse click - abandoned"
162
167
) ;
163
168
164
- start ( ) ;
169
+ ready ( ) ;
165
170
} , 100 ) ;
166
171
} ) ;
167
172
0 commit comments