1
1
define ( [
2
+ "qunit" ,
2
3
"jquery" ,
3
4
"./helper" ,
4
5
"ui/date"
5
- ] , function ( $ , testHelper ) {
6
+ ] , function ( QUnit , $ , testHelper ) {
6
7
7
- module ( "date: core" ) ;
8
+ QUnit . module ( "date: core" ) ;
8
9
9
10
var attributes = testHelper . getAttributes ( "en" ) ;
10
11
11
- test ( "Instantiation" , function ( ) {
12
- expect ( 2 ) ;
13
- ok ( new $ . ui . date ( null , attributes ) instanceof $ . ui . date , "constructor function" ) ;
14
- ok ( $ . ui . date ( null , attributes ) instanceof $ . ui . date , "instantiation without new" ) ;
12
+ QUnit . test ( "Instantiation" , function ( assert ) {
13
+ assert . expect ( 2 ) ;
14
+ assert . ok ( new $ . ui . date ( null , attributes ) instanceof $ . ui . date , "constructor function" ) ;
15
+ assert . ok ( $ . ui . date ( null , attributes ) instanceof $ . ui . date , "instantiation without new" ) ;
15
16
} ) ;
16
17
17
- test ( "Check Sets and Gets" , 4 , function ( ) {
18
- var date = $ . ui . date ( null , attributes ) ;
19
- equal ( date . setDay ( 15 ) . day ( ) , 15 , "Set day and retrieve" ) ;
20
- equal ( date . setFullDate ( 2012 , 9 , 15 ) . year ( ) , 2012 , "Set full date and retrieve year" ) ;
21
- equal ( date . month ( ) , 9 , "Set full date and retrieve month" ) ;
22
- equal ( date . day ( ) , 15 , "Set full date and retrieve day" ) ;
18
+ QUnit . test ( "Check Sets and Gets" , 4 , function ( assert ) {
19
+ var date = $ . ui . date ( null , attributes ) ;
20
+ assert . equal ( date . setDay ( 15 ) . day ( ) , 15 , "Set day and retrieve" ) ;
21
+ assert . equal ( date . setFullDate ( 2012 , 9 , 15 ) . year ( ) , 2012 , "Set full date and retrieve year" ) ;
22
+ assert . equal ( date . month ( ) , 9 , "Set full date and retrieve month" ) ;
23
+ assert . equal ( date . day ( ) , 15 , "Set full date and retrieve day" ) ;
23
24
24
25
// TODO Add setTime test
25
26
} ) ;
26
27
27
- test ( "Date Adjustments - Normal Use Cases" , 10 , function ( ) {
28
+ QUnit . test ( "Date Adjustments - Normal Use Cases" , 10 , function ( assert ) {
28
29
var date = $ . ui . date ( null , attributes ) ;
29
30
30
31
// Use October 15, 2012
31
32
date . setFullDate ( 2012 , 9 , 15 ) ;
32
- equal ( date . adjust ( "D" , 1 ) . day ( ) , 16 , "Add 1 day" ) ;
33
- equal ( date . adjust ( "D" , - 1 ) . day ( ) , 15 , "Subtract 1 day" ) ;
34
- equal ( date . adjust ( "M" , 1 ) . month ( ) , 10 , "Add 1 month" ) ;
35
- equal ( date . adjust ( "M" , - 1 ) . month ( ) , 9 , "Subtract 1 month" ) ;
36
- equal ( date . adjust ( "Y" , 1 ) . year ( ) , 2013 , "Add 1 year" ) ;
37
- equal ( date . adjust ( "Y" , - 1 ) . year ( ) , 2012 , "Subtract 1 year" ) ;
33
+ assert . equal ( date . adjust ( "D" , 1 ) . day ( ) , 16 , "Add 1 day" ) ;
34
+ assert . equal ( date . adjust ( "D" , - 1 ) . day ( ) , 15 , "Subtract 1 day" ) ;
35
+ assert . equal ( date . adjust ( "M" , 1 ) . month ( ) , 10 , "Add 1 month" ) ;
36
+ assert . equal ( date . adjust ( "M" , - 1 ) . month ( ) , 9 , "Subtract 1 month" ) ;
37
+ assert . equal ( date . adjust ( "Y" , 1 ) . year ( ) , 2013 , "Add 1 year" ) ;
38
+ assert . equal ( date . adjust ( "Y" , - 1 ) . year ( ) , 2012 , "Subtract 1 year" ) ;
38
39
39
40
// Check changing one value impact another. Ex: Day impacts month
40
41
// Use April 30th 2012
41
42
date . setFullDate ( 2012 , 3 , 30 ) ;
42
- equal ( date . adjust ( "D" , 1 ) . month ( ) , 4 , "Add 1 day to change month from April to May" ) ;
43
- equal ( date . adjust ( "D" , - 1 ) . month ( ) , 3 , "Subtract 1 day to change month from May to April" ) ;
43
+ assert . equal ( date . adjust ( "D" , 1 ) . month ( ) , 4 , "Add 1 day to change month from April to May" ) ;
44
+ assert . equal ( date . adjust ( "D" , - 1 ) . month ( ) , 3 , "Subtract 1 day to change month from May to April" ) ;
44
45
45
46
// Use December 31st 2012
46
47
date . setFullDate ( 2012 , 11 , 31 ) ;
47
- equal ( date . adjust ( "D" , 1 ) . year ( ) , 2013 , "Add 1 day to change year from 2012 to 2013" ) ;
48
- equal ( date . adjust ( "D" , - 1 ) . year ( ) , 2012 ,
48
+ assert . equal ( date . adjust ( "D" , 1 ) . year ( ) , 2013 , "Add 1 day to change year from 2012 to 2013" ) ;
49
+ assert . equal ( date . adjust ( "D" , - 1 ) . year ( ) , 2012 ,
49
50
"Subtract 1 day to change month from 2013 to 2012" ) ;
50
51
} ) ;
51
52
52
- test ( "Date Adjustments - Month Overflow Edge Cases" , 2 , function ( ) {
53
+ QUnit . test ( "Date Adjustments - Month Overflow Edge Cases" , 2 , function ( assert ) {
53
54
var date = $ . ui . date ( null , attributes ) ;
54
55
55
56
// Use May 31 2012
56
57
date . setFullDate ( 2012 , 4 , 31 ) ;
57
- equal ( date . adjust ( "M" , 1 ) . day ( ) , 30 ,
58
+ assert . equal ( date . adjust ( "M" , 1 ) . day ( ) , 30 ,
58
59
"Add 1 month from May to June sets days to 30, last day in June (prevent Overflow)" ) ;
59
- equal ( date . adjust ( "M" , - 1 ) . day ( ) , 30 ,
60
+ assert . equal ( date . adjust ( "M" , - 1 ) . day ( ) , 30 ,
60
61
"Subtract 1 month from June to May sets days to 30 in May" ) ;
61
62
} ) ;
62
63
63
- test ( "Date Adjustments - Leap Year Edge Cases" , 1 , function ( ) {
64
+ QUnit . test ( "Date Adjustments - Leap Year Edge Cases" , 1 , function ( assert ) {
64
65
var date = $ . ui . date ( null , attributes ) ;
65
66
66
67
// Use February 29 2012 a Leap year
67
68
date . setFullDate ( 2012 , 1 , 29 ) ;
68
- equal ( date . adjust ( "Y" , 1 ) . day ( ) , 28 ,
69
+ assert . equal ( date . adjust ( "Y" , 1 ) . day ( ) , 28 ,
69
70
"Feb 29 2012, add a year to convert to Feb 28, 2013" ) ;
70
71
} ) ;
71
72
72
- test ( "List days of Week" , 2 , function ( ) {
73
+ QUnit . test ( "List days of Week" , 2 , function ( assert ) {
73
74
var date = $ . ui . date ( null , attributes ) ,
74
75
offset0 = [
75
76
{ "fullname" : "Sunday" , "shortname" : "Su" } ,
@@ -90,34 +91,34 @@ test( "List days of Week", 2, function() {
90
91
{ "fullname" : "Sonntag" , "shortname" : "So." }
91
92
] ;
92
93
93
- deepEqual ( date . weekdays ( ) , offset0 , "Get weekdays with start of day on 0 (English)" ) ;
94
+ assert . deepEqual ( date . weekdays ( ) , offset0 , "Get weekdays with start of day on 0 (English)" ) ;
94
95
date = $ . ui . date ( null , testHelper . getAttributes ( "de" ) ) ;
95
- deepEqual ( date . weekdays ( ) , offset1 , "Get weekdays with start of day on 1 (Germany)" ) ;
96
+ assert . deepEqual ( date . weekdays ( ) , offset1 , "Get weekdays with start of day on 1 (Germany)" ) ;
96
97
} ) ;
97
98
98
- test ( "Days in Month" , 3 , function ( ) {
99
+ QUnit . test ( "Days in Month" , 3 , function ( assert ) {
99
100
var date = $ . ui . date ( null , attributes ) ;
100
101
date . setFullDate ( 2012 , 1 , 1 ) ;
101
- equal ( date . daysInMonth ( ) , 29 , "Leap Year implicit check for 29 days" ) ;
102
- equal ( date . daysInMonth ( 2012 , 1 ) , 29 , "Leap Year explicit check for 29 days" ) ;
103
- equal ( date . daysInMonth ( 2011 , 3 ) , 30 , "April has 30 days" ) ;
102
+ assert . equal ( date . daysInMonth ( ) , 29 , "Leap Year implicit check for 29 days" ) ;
103
+ assert . equal ( date . daysInMonth ( 2012 , 1 ) , 29 , "Leap Year explicit check for 29 days" ) ;
104
+ assert . equal ( date . daysInMonth ( 2011 , 3 ) , 30 , "April has 30 days" ) ;
104
105
} ) ;
105
106
106
- test ( "Month Name" , 2 , function ( ) {
107
+ QUnit . test ( "Month Name" , 2 , function ( assert ) {
107
108
var date = $ . ui . date ( null , attributes ) ;
108
- equal ( date . setFullDate ( 2012 , 3 , 1 ) . monthName ( ) , "April" , "Month name return April (English)" ) ;
109
+ assert . equal ( date . setFullDate ( 2012 , 3 , 1 ) . monthName ( ) , "April" , "Month name return April (English)" ) ;
109
110
date = $ . ui . date ( null , testHelper . getAttributes ( "de" ) ) ;
110
- equal ( date . setFullDate ( 2012 , 2 , 1 ) . monthName ( ) , "März" , "Month name return March (German)" ) ;
111
+ assert . equal ( date . setFullDate ( 2012 , 2 , 1 ) . monthName ( ) , "März" , "Month name return March (German)" ) ;
111
112
} ) ;
112
113
113
- test ( "Clone" , 2 , function ( ) {
114
+ QUnit . test ( "Clone" , 2 , function ( assert ) {
114
115
var date = $ . ui . date ( null , attributes ) ,
115
116
date2 = date . clone ( ) ;
116
- ok ( date2 , "Created cloned object" ) ;
117
- notEqual ( date . adjust ( "Y" , 1 ) . year ( ) , date2 . year ( ) , "Object manipulated independently" ) ;
117
+ assert . ok ( date2 , "Created cloned object" ) ;
118
+ assert . notEqual ( date . adjust ( "Y" , 1 ) . year ( ) , date2 . year ( ) , "Object manipulated independently" ) ;
118
119
} ) ;
119
120
120
- test ( "Days" , 1 , function ( ) {
121
+ QUnit . test ( "Days" , 1 , function ( assert ) {
121
122
122
123
// TODO Needs work
123
124
var date = $ . ui . date ( null , attributes ) ;
@@ -141,34 +142,34 @@ test( "Days", 1, function() {
141
142
day . title = "A good day!" ;
142
143
}
143
144
} ;
144
- ok ( date . days ( ) , "Date days() returns" ) ;
145
+ assert . ok ( date . days ( ) , "Date days() returns" ) ;
145
146
} ) ;
146
147
147
- test ( "Months" , 5 , function ( ) {
148
+ QUnit . test ( "Months" , 5 , function ( assert ) {
148
149
var date = $ . ui . date ( new Date ( 2015 , 11 - 1 , 15 ) , attributes ) ,
149
150
currentMonth = date . months ( 1 ) [ 0 ] ,
150
151
nextMonth = date . months ( 1 ) [ 1 ] ;
151
152
152
- ok ( currentMonth . first , "Current month marked as first" ) ;
153
- ok ( ! nextMonth . first , "Next month not marked as first" ) ;
154
- ok ( nextMonth . last , "Next month marked as last" ) ;
153
+ assert . ok ( currentMonth . first , "Current month marked as first" ) ;
154
+ assert . ok ( ! nextMonth . first , "Next month not marked as first" ) ;
155
+ assert . ok ( nextMonth . last , "Next month marked as last" ) ;
155
156
156
- equal ( currentMonth . month ( ) , 10 , "Current month index is November" ) ;
157
- equal ( nextMonth . month ( ) , 11 , "Next month index is December" ) ;
157
+ assert . equal ( currentMonth . month ( ) , 10 , "Current month index is November" ) ;
158
+ assert . equal ( nextMonth . month ( ) , 11 , "Next month index is December" ) ;
158
159
} ) ;
159
160
160
- test ( "Equal" , 4 , function ( ) {
161
+ QUnit . test ( "Equal" , 4 , function ( assert ) {
161
162
var date = $ . ui . date ( null , attributes ) ;
162
163
date . setFullDate ( 2012 , 9 , 16 ) ;
163
- ok ( date . equal ( new Date ( 2012 , 9 , 16 ) ) , "Does date equal provide date" ) ;
164
- ok ( ! date . equal ( new Date ( 2011 , 9 , 16 ) ) , "Does date year not equal provide date" ) ;
165
- ok ( ! date . equal ( new Date ( 2012 , 8 , 16 ) ) , "Does date month not equal provide date" ) ;
166
- ok ( ! date . equal ( new Date ( 2012 , 9 , 15 ) ) , "Does date day not equal provide date" ) ;
164
+ assert . ok ( date . equal ( new Date ( 2012 , 9 , 16 ) ) , "Does date equal provide date" ) ;
165
+ assert . ok ( ! date . equal ( new Date ( 2011 , 9 , 16 ) ) , "Does date year not equal provide date" ) ;
166
+ assert . ok ( ! date . equal ( new Date ( 2012 , 8 , 16 ) ) , "Does date month not equal provide date" ) ;
167
+ assert . ok ( ! date . equal ( new Date ( 2012 , 9 , 15 ) ) , "Does date day not equal provide date" ) ;
167
168
} ) ;
168
169
169
- test ( "Date" , 1 , function ( ) {
170
+ QUnit . test ( "Date" , 1 , function ( assert ) {
170
171
var date = $ . ui . date ( null , attributes ) ;
171
- ok ( date . date ( ) instanceof Date , "Date returned" ) ;
172
+ assert . ok ( date . date ( ) instanceof Date , "Date returned" ) ;
172
173
} ) ;
173
174
174
175
} ) ;
0 commit comments