@@ -13,6 +13,7 @@ import * as helper from "../helper";
1313export function test_recycling ( ) {
1414 helper . nativeView_recycling_test ( ( ) => new datePickerModule . DatePicker ( ) ) ;
1515}
16+ const currentDate = new Date ( ) ;
1617
1718function assertDate ( datePicker : datePickerModule . DatePicker , expectedYear : number , expectedMonth : number , expectedDay : number ) {
1819 TKUnit . assertEqual ( datePicker . year , expectedYear , "datePicker.year" ) ;
@@ -43,7 +44,7 @@ function assertDate(datePicker: datePickerModule.DatePicker, expectedYear: numbe
4344
4445export class DatePickerTest extends testModule . UITest < datePickerModule . DatePicker > {
4546 public create ( ) {
46- let datePicker = new datePickerModule . DatePicker ( ) ;
47+ const datePicker = new datePickerModule . DatePicker ( ) ;
4748 datePicker . id = "DatePicker" ;
4849 return datePicker ;
4950 }
@@ -63,7 +64,7 @@ export class DatePickerTest extends testModule.UITest<datePickerModule.DatePicke
6364 }
6465
6566 public test_DummyForCodeSnippet ( ) {
66- let datePicker = new datePickerModule . DatePicker ( ) ;
67+ const datePicker = new datePickerModule . DatePicker ( ) ;
6768 // >> date-picker-configure
6869 datePicker . year = 1980 ;
6970 datePicker . month = 2 ;
@@ -80,189 +81,189 @@ export class DatePickerTest extends testModule.UITest<datePickerModule.DatePicke
8081 }
8182 }
8283
83- public test_WhenCreated_YearIsUndefined ( ) {
84- let actualValue = this . testView . year ;
85- let expectedValue = undefined ;
84+ public test_WhenCreated_YearIsCurrentYear ( ) {
85+ const actualValue = this . testView . year ;
86+ const expectedValue = currentDate . getFullYear ( ) ;
8687 TKUnit . assertEqual ( actualValue , expectedValue ) ;
8788 }
8889
89- public test_WhenCreated_MonthIsUndefined ( ) {
90- let actualValue = this . testView . month ;
91- let expectedValue = undefined ;
90+ public test_WhenCreated_MonthIsCurrentMonth ( ) {
91+ const actualValue = this . testView . month ;
92+ const expectedValue = currentDate . getMonth ( ) ;
9293 TKUnit . assertEqual ( actualValue , expectedValue ) ;
9394 }
9495
95- public test_WhenCreated_DayIsUndefined ( ) {
96- let actualValue = this . testView . day ;
97- let expectedValue = undefined ;
96+ public test_WhenCreated_DayIsCurrentDay ( ) {
97+ const actualValue = this . testView . day ;
98+ const expectedValue = currentDate . getDate ( ) ;
9899 TKUnit . assertEqual ( actualValue , expectedValue ) ;
99100 }
100101
101- public test_WhenCreated_DateIsUndefined ( ) {
102- let actualValue = this . testView . date ;
103- let expectedValue = undefined ;
104- TKUnit . assertEqual ( actualValue , expectedValue ) ;
102+ public test_WhenCreated_DateIsCurrentDate ( ) {
103+ const expectedValue = currentDate ;
104+ assertDate ( this . testView , expectedValue . getFullYear ( ) , expectedValue . getMonth ( ) , expectedValue . getDate ( ) ) ;
105105 }
106106
107107 public testYearFromLocalToNative ( ) {
108- let expectedValue = 1980 ;
108+ const expectedValue = 1980 ;
109109 this . testView . year = expectedValue ;
110- let actualValue = datePickerTestsNative . getNativeYear ( this . testView ) ;
110+ const actualValue = datePickerTestsNative . getNativeYear ( this . testView ) ;
111111 TKUnit . assertEqual ( actualValue , expectedValue ) ;
112112 }
113113
114114 public testMonthFromLocalToNative ( ) {
115- let expectedValue = 5 ;
115+ const expectedValue = 5 ;
116116 this . testView . month = expectedValue ;
117- let actualValue = datePickerTestsNative . getNativeMonth ( this . testView ) ;
117+ const actualValue = datePickerTestsNative . getNativeMonth ( this . testView ) ;
118118 TKUnit . assertEqual ( actualValue , expectedValue ) ;
119119 }
120120
121121 public testDayFromLocalToNative ( ) {
122- let expectedValue = 19 ;
122+ const expectedValue = 19 ;
123123 this . testView . day = expectedValue ;
124- let actualValue = datePickerTestsNative . getNativeDay ( this . testView ) ;
124+ const actualValue = datePickerTestsNative . getNativeDay ( this . testView ) ;
125125 TKUnit . assertEqual ( actualValue , expectedValue ) ;
126126 }
127127
128128 public test_DateIsSetCorrectlyWhenDayIsSet ( ) {
129- let today = new Date ( 2016 , 3 , 15 ) ;
129+ const today = new Date ( 2016 , 3 , 15 ) ;
130130 this . testView . year = today . getFullYear ( ) ;
131131 this . testView . month = today . getMonth ( ) ;
132- let expectedValue = today . getDate ( ) ;
132+
133+ const expectedValue = today . getDate ( ) ;
133134 this . testView . day = expectedValue ;
134135
135- let expectedDate = new Date ( today . getFullYear ( ) , today . getMonth ( ) - 1 , expectedValue ) ;
136+ const expectedDate = new Date ( today . getFullYear ( ) , today . getMonth ( ) , expectedValue ) ;
136137 TKUnit . assertEqual ( this . testView . date . getDate ( ) , expectedDate . getDate ( ) , "Getting Day from date property failed." ) ;
137138 TKUnit . assertEqual ( this . testView . date . getMonth ( ) , expectedDate . getMonth ( ) , "Getting Month from date property failed." ) ;
138139 TKUnit . assertEqual ( this . testView . date . getFullYear ( ) , expectedDate . getFullYear ( ) , "Getting Year from date property failed." ) ;
139140 }
140141
141142 public test_DateIsSetCorrectlyWhenMonthIsSet ( ) {
142- let today = new Date ( 2016 , 3 , 15 ) ;
143+ const today = new Date ( 2016 , 3 , 15 ) ;
143144 this . testView . year = today . getFullYear ( ) ;
144145 this . testView . day = today . getDate ( ) ;
145146
146- let expectedValue = today . getMonth ( ) ;
147+ const expectedValue = today . getMonth ( ) ;
147148 this . testView . month = expectedValue ;
148- let expectedDate = new Date ( today . getFullYear ( ) , expectedValue - 1 , today . getDate ( ) ) ;
149+ const expectedDate = new Date ( today . getFullYear ( ) , expectedValue , today . getDate ( ) ) ;
149150
150151 TKUnit . assertEqual ( this . testView . date . getDate ( ) , expectedDate . getDate ( ) , "Getting Day from date property failed." ) ;
151152 TKUnit . assertEqual ( this . testView . date . getMonth ( ) , expectedDate . getMonth ( ) , "Getting Month from date property failed." ) ;
152153 TKUnit . assertEqual ( this . testView . date . getFullYear ( ) , expectedDate . getFullYear ( ) , "Getting Year from date property failed." ) ;
153154 }
154155
155156 public test_DateIsSetCorrectlyWhenYearIsSet ( ) {
156- let current = new Date ( 2016 , 3 , 15 ) ;
157+ const current = new Date ( 2016 , 3 , 15 ) ;
157158 this . testView . month = current . getMonth ( ) ;
158159 this . testView . day = current . getDate ( ) ;
159160
160- let expectedValue = 1980 ;
161+ const expectedValue = 1980 ;
161162 this . testView . year = expectedValue ;
162- let expectedDate = new Date ( 1980 , current . getMonth ( ) - 1 , current . getDate ( ) ) ;
163+ const expectedDate = new Date ( 1980 , current . getMonth ( ) , current . getDate ( ) ) ;
163164
164165 TKUnit . assertEqual ( this . testView . date . getDate ( ) , expectedDate . getDate ( ) , "Getting Day from date property failed." ) ;
165166 TKUnit . assertEqual ( this . testView . date . getMonth ( ) , expectedDate . getMonth ( ) , "Getting Month from date property failed." ) ;
166167 TKUnit . assertEqual ( this . testView . date . getFullYear ( ) , expectedDate . getFullYear ( ) , "Getting Year from date property failed." ) ;
167168 }
168169
169170 public testMaxDateFromLocalToNative ( ) {
170- let expectedValue = new Date ( 1980 , 1 , 9 ) ;
171+ const expectedValue = new Date ( 1980 , 1 , 9 ) ;
171172 this . testView . maxDate = expectedValue ;
172- let actualValue = datePickerTestsNative . getNativeMaxDate ( this . testView ) ;
173+ const actualValue = datePickerTestsNative . getNativeMaxDate ( this . testView ) ;
173174 TKUnit . assertEqual ( actualValue . getTime ( ) , expectedValue . getTime ( ) ) ;
174175 }
175176
176177 public testMinDateFromLocalToNative ( ) {
177- let expectedValue = new Date ( 1980 , 1 , 9 ) ;
178+ const expectedValue = new Date ( 1980 , 1 , 9 ) ;
178179 this . testView . minDate = expectedValue ;
179- let actualValue = datePickerTestsNative . getNativeMinDate ( this . testView ) ;
180+ const actualValue = datePickerTestsNative . getNativeMinDate ( this . testView ) ;
180181 TKUnit . assertEqual ( actualValue . getTime ( ) , expectedValue . getTime ( ) ) ;
181182 }
182183
183184 public testYearFromNativeToLocal ( ) {
184- let expectedValue = 1981 ;
185+ const expectedValue = 1981 ;
185186 datePickerTestsNative . setNativeYear ( this . testView , expectedValue ) ;
186- let actualValue = this . testView . year ;
187+ const actualValue = this . testView . year ;
187188 TKUnit . assertEqual ( actualValue , expectedValue ) ;
188189 }
189190
190191 public testMonthFromNativeToLocal ( ) {
191- //Use July as it has 31 days
192- var expectedValue = 7 ;
192+ // Use July as it has 31 days
193+ const expectedValue = 7 ;
193194 datePickerTestsNative . setNativeMonth ( this . testView , expectedValue ) ;
194- var actualValue = this . testView . month ;
195+ const actualValue = this . testView . month ;
195196 TKUnit . assertEqual ( actualValue , expectedValue ) ;
196197 }
197198
198199 public testYearMonthDayFromNativeToLocal ( ) {
199- var testYear = 2000 ;
200- var testMonth = 3 ;
201- var testDay = 24 ;
200+ const testYear = 2000 ;
201+ const testMonth = 3 ;
202+ const testDay = 24 ;
202203
203204 datePickerTestsNative . setNativeDate ( this . testView , testYear , testMonth , testDay ) ;
204205 assertDate ( this . testView , testYear , testMonth , testDay ) ;
205206 }
206207
207208 public testDayFromNativeToLocal ( ) {
208- let expectedValue = 20 ;
209+ const expectedValue = 20 ;
209210 datePickerTestsNative . setNativeDay ( this . testView , expectedValue ) ;
210- let actualValue = this . testView . day ;
211+ const actualValue = this . testView . day ;
211212 TKUnit . assert ( actualValue === expectedValue , "Actual: " + actualValue + "; Expected: " + expectedValue ) ;
212213 }
213214
214215 public test_DateFromNativeToLocalWithDay ( ) {
215- let today = new Date ( ) ;
216- let expectedValue = 20 ;
216+ const today = new Date ( ) ;
217+ const expectedValue = 20 ;
217218
218219 datePickerTestsNative . setNativeDate ( this . testView , today . getFullYear ( ) , today . getMonth ( ) , expectedValue ) ;
219220
220- let expectedDate = new Date ( today . getFullYear ( ) , today . getMonth ( ) - 1 , expectedValue ) ;
221+ const expectedDate = new Date ( today . getFullYear ( ) , today . getMonth ( ) , expectedValue ) ;
221222 TKUnit . assertEqual ( this . testView . date . getDate ( ) , expectedDate . getDate ( ) , "Getting Day from date property failed." ) ;
222223 TKUnit . assertEqual ( this . testView . date . getMonth ( ) , expectedDate . getMonth ( ) , "Getting Month from date property failed." ) ;
223224 TKUnit . assertEqual ( this . testView . date . getFullYear ( ) , expectedDate . getFullYear ( ) , "Getting Year from date property failed." ) ;
224225 }
225226
226227 public test_DateFromNativeToLocalWithMonth ( ) {
227- let today = new Date ( ) ;
228- let expectedValue = 7 ;
228+ const today = new Date ( ) ;
229+ const expectedValue = 7 ;
229230
230231 datePickerTestsNative . setNativeDate ( this . testView , today . getFullYear ( ) , expectedValue , today . getDate ( ) ) ;
231232
232- let expectedDate = new Date ( today . getFullYear ( ) , expectedValue - 1 , today . getDate ( ) ) ;
233+ const expectedDate = new Date ( today . getFullYear ( ) , expectedValue , today . getDate ( ) ) ;
233234 TKUnit . assertEqual ( this . testView . date . getDate ( ) , expectedDate . getDate ( ) , "Getting Day from date property failed." ) ;
234235 TKUnit . assertEqual ( this . testView . date . getMonth ( ) , expectedDate . getMonth ( ) , "Getting Month from date property failed." ) ;
235236 TKUnit . assertEqual ( this . testView . date . getFullYear ( ) , expectedDate . getFullYear ( ) , "Getting Year from date property failed." ) ;
236237 }
237238
238239 public test_DateFromNativeToLocalWithYear ( ) {
239- let today = new Date ( ) ;
240+ const today = new Date ( ) ;
240241
241- var expectedValue = 1981 ;
242+ const expectedValue = 1981 ;
242243 datePickerTestsNative . setNativeDate ( this . testView , expectedValue , today . getMonth ( ) , today . getDate ( ) ) ;
243244
244- let expectedDate = new Date ( expectedValue , today . getMonth ( ) - 1 , today . getDate ( ) ) ;
245+ const expectedDate = new Date ( expectedValue , today . getMonth ( ) , today . getDate ( ) ) ;
245246 TKUnit . assertEqual ( this . testView . date . getDate ( ) , expectedDate . getDate ( ) , "Getting Day from date property failed." ) ;
246247 TKUnit . assertEqual ( this . testView . date . getMonth ( ) , expectedDate . getMonth ( ) , "Getting Month from date property failed." ) ;
247248 TKUnit . assertEqual ( this . testView . date . getFullYear ( ) , expectedDate . getFullYear ( ) , "Getting Year from date property failed." ) ;
248249 }
249250
250251 public test_DateFromNativeToLocalWithAll ( ) {
251- var testYear = 2000 ;
252- var testMonth = 3 ;
253- var testDay = 24 ;
252+ const testYear = 2000 ;
253+ const testMonth = 3 ;
254+ const testDay = 24 ;
254255
255256 datePickerTestsNative . setNativeDate ( this . testView , testYear , testMonth , testDay ) ;
256- let expectedDate = new Date ( testYear , testMonth - 1 , testDay ) ;
257+ const expectedDate = new Date ( testYear , testMonth , testDay ) ;
257258 TKUnit . assertEqual ( this . testView . date . getDate ( ) , expectedDate . getDate ( ) , "Getting Day from date property failed." ) ;
258259 TKUnit . assertEqual ( this . testView . date . getMonth ( ) , expectedDate . getMonth ( ) , "Getting Month from date property failed." ) ;
259260 TKUnit . assertEqual ( this . testView . date . getFullYear ( ) , expectedDate . getFullYear ( ) , "Getting Year from date property failed." ) ;
260261 }
261262
262263 public testSetYearMonthDay_BeforeLoaded ( ) {
263- var testYear = 2000 ;
264- var testMonth = 3 ;
265- var testDay = 24 ;
264+ const testYear = 2000 ;
265+ const testMonth = 3 ;
266+ const testDay = 24 ;
266267
267268 this . setUpDatePicker ( testYear , testMonth , testDay ) ;
268269
@@ -276,9 +277,9 @@ export class DatePickerTest extends testModule.UITest<datePickerModule.DatePicke
276277 }
277278
278279 public testSetYearMonthDay_AfterLoaded ( ) {
279- var testYear = 2000 ;
280- var testMonth = 3 ;
281- var testDay = 24 ;
280+ const testYear = 2000 ;
281+ const testMonth = 3 ;
282+ const testDay = 24 ;
282283
283284 this . testView . year = testYear ;
284285 this . testView . month = testMonth ;
0 commit comments