8
8
toFormattedDateString ,
9
9
} from '../datepicker-helpers.js' ;
10
10
import {
11
+ getComputedStylePropertyValue ,
11
12
getShadowInnerHTML ,
12
13
shadowQuery ,
13
14
shadowQueryAll ,
@@ -28,6 +29,12 @@ const {
28
29
* of SauceLabs's configurations.
29
30
*/
30
31
const defaultLocale = 'en-US' ;
32
+ /**
33
+ * NOTE: This is not a random/ magic date selected for the testing. It's been selected for a reason
34
+ * which has explained in detail at https://github.com/motss/app-datepicker/issues/128.
35
+ */
36
+ const date13 = '2020-01-13' ;
37
+ const date15 = '2020-01-15' ;
31
38
32
39
describe ( 'app-datepicker' , ( ) => {
33
40
describe ( 'initial render (calendar view)' , ( ) => {
@@ -200,8 +207,8 @@ describe('app-datepicker', () => {
200
207
} ) ;
201
208
202
209
it ( `renders with correct 'min'` , async ( ) => {
203
- const minVal = '2020-01-03' ;
204
- const valueVal = '2020-01-05' ;
210
+ const minVal = date13 ;
211
+ const valueVal = date15 ;
205
212
206
213
el . min = minVal ;
207
214
el . value = valueVal ;
@@ -210,15 +217,15 @@ describe('app-datepicker', () => {
210
217
const firstSelectableDate =
211
218
shadowQuery (
212
219
el ,
213
- '.calendar-container:nth-child (2) .full-calendar__day[aria-label="Jan 3 , 2020"]' ) ;
220
+ '.calendar-container:nth-of-type (2) .full-calendar__day[aria-label="Jan 13 , 2020"]' ) ;
214
221
const allDisabledDates =
215
222
shadowQueryAll (
216
223
el ,
217
- '.calendar-container:nth-child (2) .full-calendar__day.day--disabled' ) ;
224
+ '.calendar-container:nth-of-type (2) .full-calendar__day.day--disabled' ) ;
218
225
const focusedDate =
219
226
shadowQuery (
220
227
el ,
221
- '.calendar-container:nth-child (2) .full-calendar__day.day--focused' ) ;
228
+ '.calendar-container:nth-of-type (2) .full-calendar__day.day--focused' ) ;
222
229
const lastDayBeforeMinDate = allDisabledDates [ allDisabledDates . length - 1 ] ;
223
230
224
231
isNotNull ( firstSelectableDate , 'First selectable date not found' ) ;
@@ -230,11 +237,11 @@ describe('app-datepicker', () => {
230
237
'First selectable is disabled day' ) ;
231
238
strictEqual (
232
239
lastDayBeforeMinDate . getAttribute ( 'aria-label' ) ,
233
- 'Jan 2 , 2020' ,
240
+ 'Jan 12 , 2020' ,
234
241
`Last day before 'min' not matched` ) ;
235
242
strictEqual (
236
243
focusedDate . getAttribute ( 'aria-label' ) ,
237
- 'Jan 5 , 2020' ,
244
+ 'Jan 15 , 2020' ,
238
245
'Focused date not matched' ) ;
239
246
240
247
strictEqual ( el . min , minVal , `'min' property not matched` ) ;
@@ -245,8 +252,8 @@ describe('app-datepicker', () => {
245
252
} ) ;
246
253
247
254
it ( `renders with correct 'max'` , async ( ) => {
248
- const maxVal = '2020-01-05' ;
249
- const valueVal = '2020-01-03' ;
255
+ const maxVal = date15 ;
256
+ const valueVal = date13 ;
250
257
251
258
el . max = maxVal ;
252
259
el . value = valueVal ;
@@ -255,15 +262,15 @@ describe('app-datepicker', () => {
255
262
const lastSelectableDate =
256
263
shadowQuery (
257
264
el ,
258
- '.calendar-container:nth-child (2) .full-calendar__day[aria-label="Jan 5 , 2020"]' ) ;
265
+ '.calendar-container:nth-of-type (2) .full-calendar__day[aria-label="Jan 15 , 2020"]' ) ;
259
266
const firstDayAfterMaxDate =
260
267
shadowQuery (
261
268
el ,
262
- '.calendar-container:nth-child (2) .full-calendar__day.day--disabled' ) ;
269
+ '.calendar-container:nth-of-type (2) .full-calendar__day.day--disabled' ) ;
263
270
const focusedDate =
264
271
shadowQuery (
265
272
el ,
266
- '.calendar-container:nth-child (2) .full-calendar__day.day--focused' ) ;
273
+ '.calendar-container:nth-of-type (2) .full-calendar__day.day--focused' ) ;
267
274
268
275
isNotNull ( lastSelectableDate , 'Last selectable date not found' ) ;
269
276
isNotNull ( firstDayAfterMaxDate , `Last day before 'min' not found` ) ;
@@ -274,11 +281,11 @@ describe('app-datepicker', () => {
274
281
'Last selectable is disabled day' ) ;
275
282
strictEqual (
276
283
firstDayAfterMaxDate . getAttribute ( 'aria-label' ) ,
277
- 'Jan 6 , 2020' ,
284
+ 'Jan 16 , 2020' ,
278
285
`First day after 'max' not matched` ) ;
279
286
strictEqual (
280
287
focusedDate . getAttribute ( 'aria-label' ) ,
281
- 'Jan 3 , 2020' ,
288
+ 'Jan 13 , 2020' ,
282
289
'Focused date not matched' ) ;
283
290
284
291
strictEqual ( el . max , maxVal , `'max' property not matched` ) ;
@@ -296,10 +303,10 @@ describe('app-datepicker', () => {
296
303
toFormattedDateString ( todayDate ) ,
297
304
`'value' does not match with today's date` ) ;
298
305
299
- const val = '2020-01-03' ;
306
+ const val = date15 ;
300
307
301
308
/** NOTE: To ensure 'min' is lesser than 'val' */
302
- el . min = '2020-01-01' ;
309
+ el . min = date13 ;
303
310
el . value = val ;
304
311
await el . updateComplete ;
305
312
@@ -328,8 +335,8 @@ describe('app-datepicker', () => {
328
335
strictEqual ( el . firstDayOfWeek , 0 , `'firstDayOfWeek' not matched` ) ;
329
336
330
337
/** NOTE: Ensure dates are not disabled during testings */
331
- el . min = '2020-01-03' ;
332
- el . value = '2020-01-05' ;
338
+ el . min = date13 ;
339
+ el . value = date15 ;
333
340
await el . updateComplete ;
334
341
335
342
const expectedFirstDayInMonthIdx = [
@@ -350,7 +357,7 @@ describe('app-datepicker', () => {
350
357
await el . updateComplete ;
351
358
352
359
const fullCalendarDays =
353
- shadowQueryAll ( el , '.calendar-container:nth-child (2) .full-calendar__day' ) ;
360
+ shadowQueryAll ( el , '.calendar-container:nth-of-type (2) .full-calendar__day' ) ;
354
361
const firstDayInMonthIdx =
355
362
fullCalendarDays . findIndex ( n => ! n . classList . contains ( 'day--empty' ) ) ;
356
363
@@ -382,8 +389,8 @@ describe('app-datepicker', () => {
382
389
} ) ;
383
390
384
391
it ( `renders with correct 'weekNumberType'` , async ( ) => {
385
- el . min = '2020-01-03' ;
386
- el . value = '2020-01-05' ;
392
+ el . min = date13 ;
393
+ el . value = date15 ;
387
394
el . showWeekNumber = true ;
388
395
await el . updateComplete ;
389
396
@@ -406,7 +413,7 @@ describe('app-datepicker', () => {
406
413
await el . updateComplete ;
407
414
408
415
const firstWeekdayLabel =
409
- getShadowInnerHTML ( shadowQuery ( el , '.calendar-container:nth-child (2) .weekday-label' ) ) ;
416
+ getShadowInnerHTML ( shadowQuery ( el , '.calendar-container:nth-of-type (2) .weekday-label' ) ) ;
410
417
411
418
strictEqual (
412
419
el . weekNumberType ,
@@ -419,6 +426,23 @@ describe('app-datepicker', () => {
419
426
}
420
427
} ) ;
421
428
429
+ it ( `renders with correct 'landscape'` , async ( ) => {
430
+ strictEqual ( el . landscape , false , `'landscape' not matched` ) ;
431
+ strictEqual (
432
+ getComputedStylePropertyValue ( el , 'display' ) ,
433
+ 'block' ,
434
+ `Element has no 'display: block'` ) ;
435
+
436
+ el . landscape = true ;
437
+ await el . updateComplete ;
438
+
439
+ isTrue ( el . hasAttribute ( 'landscape' ) , `Element has no 'landscape' attribute` ) ;
440
+ strictEqual (
441
+ getComputedStylePropertyValue ( el , 'display' ) ,
442
+ 'flex' ,
443
+ `Element has no 'display: flex` ) ;
444
+ } ) ;
445
+
422
446
} ) ;
423
447
424
448
// describe('updates via attributes', () => {});
0 commit comments