-
Notifications
You must be signed in to change notification settings - Fork 357
/
spinbutton_datepicker.js
985 lines (829 loc) · 23.7 KB
/
spinbutton_datepicker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
const { ariaTest } = require('..');
const { By, Key } = require('selenium-webdriver');
const assertAttributeValues = require('../util/assertAttributeValues');
const assertAriaLabelledby = require('../util/assertAriaLabelledby');
const assertAriaRoles = require('../util/assertAriaRoles');
const exampleFile =
'content/patterns/spinbutton/examples/datepicker-spinbuttons.html';
const valuesDay = [
'',
'first',
'second',
'third',
'fourth',
'fifth',
'sixth',
'seventh',
'eighth',
'ninth',
'tenth',
'eleventh',
'twelfth',
'thirteenth',
'fourteenth',
'fifteenth',
'sixteenth',
'seventeenth',
'eighteenth',
'nineteenth',
'twentieth',
'twenty first',
'twenty second',
'twenty third',
'twenty fourth',
'twenty fifth',
'twenty sixth',
'twenty seventh',
'twenty eighth',
'twenty ninth',
'thirtieth',
'thirty first',
];
const valuesMonth = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
];
var getDaysInMonth = function (year, month) {
return new Date(year, month + 1, 0).getDate();
};
var d = new Date();
// The date picker uses the current day, month and year to setup
const ex = {
groupSelector: '#example [role="group"]',
spinbuttonSelector: '#example [role="spinbutton"]',
yearSelector: '#example .spinbutton.year [role="spinbutton"]',
yearMin: '2019',
yearMax: '2040',
yearNow: d.getFullYear().toString(),
monthSelector: '#example .spinbutton.month [role="spinbutton"]',
monthMin: '0',
monthMax: '11',
monthNow: d.getMonth().toString(),
monthText: valuesMonth[d.getMonth()],
daySelector: '#example .spinbutton.day [role="spinbutton"]',
dayMin: '1',
dayMax: getDaysInMonth(d.getFullYear(), d.getMonth()).toString(),
dayNow: d.getDate().toString(),
dayText: valuesDay[d.getDate()],
yearIncreaseSelector: '#example .spinbutton.year .increase',
yearDecreaseSelector: '#example .spinbutton.year .decrease',
yearHiddenPreviousSelector: '#example .spinbutton.year .previous',
yearHiddenNextSelector: '#example .spinbutton.year .next',
monthIncreaseSelector: '#example .spinbutton.month .increase',
monthDecreaseSelector: '#example .spinbutton.month .decrease',
monthHiddenPreviousSelector: '#example .spinbutton.month .previous',
monthHiddenNextSelector: '#example .spinbutton.month .next',
dayIncreaseSelector: '#example .spinbutton.day .increase',
dayDecreaseSelector: '#example .spinbutton.day .decrease',
dayHiddenPreviousSelector: '#example .spinbutton.day .previous',
dayHiddenNextSelector: '#example .spinbutton.day .next',
};
// Attributes
ariaTest(
'role="group" on div element',
exampleFile,
'group-role',
async (t) => {
await assertAriaRoles(t, 'example', 'group', '1', 'div');
}
);
ariaTest(
'"aria-labelledby" attribute on group',
exampleFile,
'group-aria-labelledby',
async (t) => {
await assertAriaLabelledby(t, ex.groupSelector);
}
);
ariaTest(
'role="spinbutton" on div element',
exampleFile,
'spinbutton-role',
async (t) => {
await assertAriaRoles(t, 'example', 'spinbutton', '3', 'div');
}
);
ariaTest(
'"aria-valuemax" represents the minimum value on spinbuttons',
exampleFile,
'spinbutton-aria-valuemax',
async (t) => {
await assertAttributeValues(t, ex.daySelector, 'aria-valuemax', ex.dayMax);
await assertAttributeValues(
t,
ex.monthSelector,
'aria-valuemax',
ex.monthMax
);
await assertAttributeValues(
t,
ex.yearSelector,
'aria-valuemax',
ex.yearMax
);
}
);
ariaTest(
'"aria-valuemin" represents the maximum value on spinbuttons',
exampleFile,
'spinbutton-aria-valuemin',
async (t) => {
await assertAttributeValues(t, ex.daySelector, 'aria-valuemin', ex.dayMin);
await assertAttributeValues(
t,
ex.monthSelector,
'aria-valuemin',
ex.monthMin
);
await assertAttributeValues(
t,
ex.yearSelector,
'aria-valuemin',
ex.yearMin
);
}
);
ariaTest(
'"aria-valuenow" reflects spinbutton value as a number',
exampleFile,
'spinbutton-aria-valuenow',
async (t) => {
await assertAttributeValues(t, ex.daySelector, 'aria-valuenow', ex.dayNow);
await assertAttributeValues(
t,
ex.monthSelector,
'aria-valuenow',
ex.monthNow
);
await assertAttributeValues(
t,
ex.yearSelector,
'aria-valuenow',
ex.yearNow
);
}
);
ariaTest(
'"aria-valuetext" reflects spin button value as a text string',
exampleFile,
'spinbutton-aria-valuetext',
async (t) => {
await assertAttributeValues(
t,
ex.daySelector,
'aria-valuetext',
ex.dayText
);
await assertAttributeValues(
t,
ex.monthSelector,
'aria-valuetext',
ex.monthText
);
}
);
ariaTest(
'"aria-label" provides accessible name for the spin buttons to screen reader users',
exampleFile,
'spinbutton-aria-label',
async (t) => {
await assertAttributeValues(t, ex.daySelector, 'aria-label', 'Day');
await assertAttributeValues(t, ex.monthSelector, 'aria-label', 'Month');
await assertAttributeValues(t, ex.yearSelector, 'aria-label', 'Year');
}
);
ariaTest(
'"tabindex=-1" removes previous and next from the tab order of the page',
exampleFile,
'button-tabindex',
async (t) => {
await assertAttributeValues(t, ex.dayIncreaseSelector, 'tabindex', '-1');
await assertAttributeValues(t, ex.dayDecreaseSelector, 'tabindex', '-1');
await assertAttributeValues(t, ex.monthIncreaseSelector, 'tabindex', '-1');
await assertAttributeValues(t, ex.monthDecreaseSelector, 'tabindex', '-1');
await assertAttributeValues(t, ex.yearIncreaseSelector, 'tabindex', '-1');
await assertAttributeValues(t, ex.yearDecreaseSelector, 'tabindex', '-1');
}
);
ariaTest(
'"aria-label" provides accessible name for the previous and next buttons to screen reader users',
exampleFile,
'button-aria-label',
async (t) => {
await assertAttributeValues(
t,
ex.dayIncreaseSelector,
'aria-label',
'next day'
);
await assertAttributeValues(
t,
ex.dayDecreaseSelector,
'aria-label',
'previous day'
);
await assertAttributeValues(
t,
ex.monthIncreaseSelector,
'aria-label',
'next month'
);
await assertAttributeValues(
t,
ex.monthDecreaseSelector,
'aria-label',
'previous month'
);
await assertAttributeValues(
t,
ex.yearIncreaseSelector,
'aria-label',
'next year'
);
await assertAttributeValues(
t,
ex.yearDecreaseSelector,
'aria-label',
'previous year'
);
}
);
ariaTest(
'"aria-hidden" hides decorative and redundant content form screen reader users',
exampleFile,
'spinbutton-aria-hidden',
async (t) => {
await assertAttributeValues(
t,
ex.dayHiddenPreviousSelector,
'aria-hidden',
'true'
);
await assertAttributeValues(
t,
ex.dayHiddenNextSelector,
'aria-hidden',
'true'
);
await assertAttributeValues(
t,
ex.monthHiddenPreviousSelector,
'aria-hidden',
'true'
);
await assertAttributeValues(
t,
ex.monthHiddenNextSelector,
'aria-hidden',
'true'
);
await assertAttributeValues(
t,
ex.yearHiddenPreviousSelector,
'aria-hidden',
'true'
);
await assertAttributeValues(
t,
ex.yearHiddenNextSelector,
'aria-hidden',
'true'
);
}
);
// keys
ariaTest('up arrow on day', exampleFile, 'spinbutton-up-arrow', async (t) => {
let control = parseInt(ex.dayNow);
let daysInMonth = parseInt(ex.dayMax);
// Send up arrow to day date spinner
let daySpinner = await t.context.session.findElement(By.css(ex.daySelector));
await daySpinner.sendKeys(Key.ARROW_UP);
// Add a day to the control
control = (control + 1) % daysInMonth;
t.is(
parseInt(await daySpinner.getText()),
control,
'After sending 1 up arrow to the day spinner, the day should be: ' + control
);
// Send up arrow 30 more times to date spinner
for (let i = 1; i <= 30; i++) {
await daySpinner.sendKeys(Key.ARROW_UP);
}
// Add 30 days to the control
control = (control + 30) % daysInMonth;
if (control === 0) {
control = parseInt(ex.dayMax);
}
t.is(
parseInt(await daySpinner.getText()),
control,
'After sending 31 up arrows to the day spinner, the day should be: ' +
control
);
});
ariaTest(
'down arrow on day',
exampleFile,
'spinbutton-down-arrow',
async (t) => {
let control = 31;
// Set to December for a 31 day month
let monthSpinner = await t.context.session.findElement(
By.css(ex.monthSelector)
);
await monthSpinner.sendKeys(Key.END);
// Send down arrow to day date spinner
let daySpinner = await t.context.session.findElement(
By.css(ex.daySelector)
);
// Set to first of month
await daySpinner.sendKeys(Key.HOME);
await daySpinner.sendKeys(Key.ARROW_DOWN);
t.is(
parseInt(await daySpinner.getText()),
control,
'After sending 1 down arrow to the day spinner, the day should be: ' +
control
);
// Send down arrow 30 more times to date spinner
for (let i = 1; i <= 30; i++) {
await daySpinner.sendKeys(Key.ARROW_DOWN);
}
// Subtract 30 days to the control
control -= 30;
t.is(
parseInt(await daySpinner.getText()),
control,
'After sending 31 down arrows to the day spinner, the day should be: ' +
control
);
}
);
ariaTest('up arrow on month', exampleFile, 'spinbutton-up-arrow', async (t) => {
let date = new Date();
date.setDate(1); // This is necessary to do the correct date math for months.
let monthSpinner = await t.context.session.findElement(
By.css(ex.monthSelector)
);
// Send up arrow 12 times to date spinner
for (let i = 1; i <= 12; i++) {
await monthSpinner.sendKeys(Key.ARROW_UP);
const index = new Date(date.setMonth(date.getMonth() + 1)).getMonth();
t.is(
await monthSpinner.getText(),
valuesMonth[index],
`After sending ${i} up arrows to the month spinner, the month should be: ${valuesMonth[index]}`
);
}
});
ariaTest(
'down arrow on month',
exampleFile,
'spinbutton-down-arrow',
async (t) => {
let control = 0;
// Send down arrow to month date spinner
let monthSpinner = await t.context.session.findElement(
By.css(ex.monthSelector)
);
// Set to January
await monthSpinner.sendKeys(Key.HOME);
await monthSpinner.sendKeys(Key.ARROW_DOWN);
// Subtract a month to the control
control = 11;
t.is(
await monthSpinner.getText(),
valuesMonth[control],
'After sending 1 down arrow to the month spinner, the month should be: ' +
valuesMonth[control]
);
// Send down arrow 30 more times to date spinner
for (let i = 1; i <= 30; i++) {
await monthSpinner.sendKeys(Key.ARROW_DOWN);
}
// Subtract 30 months to the control
control = 12 + ((control - 30) % 12);
t.is(
await monthSpinner.getText(),
valuesMonth[control],
'After sending 31 down arrows to the month spinner, the month should be: ' +
valuesMonth[control]
);
}
);
ariaTest('up arrow on year', exampleFile, 'spinbutton-up-arrow', async (t) => {
// Send up arrow to day date spinner
let yearSpinner = await t.context.session.findElement(
By.css(ex.yearSelector)
);
await yearSpinner.sendKeys(Key.ARROW_UP);
let nextYear = (parseInt(ex.yearNow) + 1).toString();
t.is(
await yearSpinner.getText(),
nextYear,
'After sending 1 up arrow to the year spinner, the year should be: ' +
nextYear
);
let manyYears = parseInt(ex.yearMax) - parseInt(ex.yearNow);
for (let i = 1; i <= manyYears; i++) {
await yearSpinner.sendKeys(Key.ARROW_UP);
}
t.is(
await yearSpinner.getText(),
ex.yearMax,
'After sending ' +
(manyYears + 1) +
' up arrows to the year spinner, the year should be: ' +
ex.yearMax
);
});
ariaTest(
'down arrow on year',
exampleFile,
'spinbutton-down-arrow',
async (t) => {
// Send down arrow to year date spinner
let yearSpinner = await t.context.session.findElement(
By.css(ex.yearSelector)
);
await yearSpinner.sendKeys(Key.ARROW_DOWN);
// Subtract a year to the control
let lastYear = (parseInt(ex.yearNow) - 1).toString();
t.is(
await yearSpinner.getText(),
lastYear,
'After sending 1 down arrow to the year spinner, the year should be: ' +
lastYear
);
let manyYears = parseInt(ex.yearNow) - parseInt(ex.yearMin);
for (let i = 1; i <= manyYears; i++) {
await yearSpinner.sendKeys(Key.ARROW_DOWN);
}
t.is(
await yearSpinner.getText(),
ex.yearMin,
'After sending ' +
manyYears +
' down arrows to the year spinner, the year should be: ' +
ex.yearMin
);
}
);
ariaTest('page up on day', exampleFile, 'spinbutton-page-up', async (t) => {
let control = parseInt(ex.dayNow);
// Set to December for a 31 day month
let monthSpinner = await t.context.session.findElement(
By.css(ex.monthSelector)
);
await monthSpinner.sendKeys(Key.END);
// Send page up to day date spinner
let daySpinner = await t.context.session.findElement(By.css(ex.daySelector));
// Set to first of month
await daySpinner.sendKeys(Key.HOME);
await daySpinner.sendKeys(Key.PAGE_UP);
// Add a day to the control
control = 6;
t.is(
parseInt(await daySpinner.getText()),
control,
'After sending 1 page up to the day spinner, the day should be: ' + control
);
// Send page up 5 more times to date spinner
for (let i = 1; i <= 5; i++) {
await daySpinner.sendKeys(Key.PAGE_UP);
}
// Add 25 days to the control
control = 31;
t.is(
parseInt(await daySpinner.getText()),
control,
'After sending 6 page ups to the day spinner, the day should be: ' + control
);
// Set to end of month
await daySpinner.sendKeys(Key.END);
// Rolls around to start of month
control = 1;
await daySpinner.sendKeys(Key.PAGE_UP);
t.is(
parseInt(await daySpinner.getText()),
control,
'After sending page up to the day spinner on the last day of the month, the day should be: ' +
control
);
// Set to end of month
await daySpinner.sendKeys(Key.END);
// Set to four days before
for (let i = 1; i <= 4; i++) {
await daySpinner.sendKeys(Key.DOWN);
}
await daySpinner.sendKeys(Key.PAGE_UP);
t.is(
parseInt(await daySpinner.getText()),
control,
'After sending page up to the day spinner on 4 days before the end of the month, the day should be: ' +
control
);
});
ariaTest('page down on day', exampleFile, 'spinbutton-page-down', async (t) => {
let control = parseInt(ex.dayNow);
// Set to December for a 31 day month
let monthSpinner = await t.context.session.findElement(
By.css(ex.monthSelector)
);
await monthSpinner.sendKeys(Key.END);
// Send page down to day date spinner
let daySpinner = await t.context.session.findElement(By.css(ex.daySelector));
// Set to 31st
await daySpinner.sendKeys(Key.END);
await daySpinner.sendKeys(Key.PAGE_DOWN);
// Subtract 5 days to the control
control = 26;
t.is(
parseInt(await daySpinner.getText()),
control,
'After sending 1 page down to the day spinner, the day should be: ' +
control
);
// Send page down 5 more times to date spinner
for (let i = 1; i <= 5; i++) {
await daySpinner.sendKeys(Key.PAGE_DOWN);
}
// Subtract 25 days to the control
control -= 25;
t.is(
parseInt(await daySpinner.getText()),
control,
'After sending 6 page downs to the day spinner, the day should be: ' +
control
);
await daySpinner.sendKeys(Key.PAGE_DOWN);
// End of month if hit when at first of month.
control = 31;
t.is(
parseInt(await daySpinner.getText()),
control,
'After sending page downs to the day spinner when set to 1, the day should be: ' +
control
);
// Set to first of month
await daySpinner.sendKeys(Key.HOME);
// Set to five
for (let i = 1; i <= 4; i++) {
await daySpinner.sendKeys(Key.UP);
}
await daySpinner.sendKeys(Key.PAGE_DOWN);
t.is(
parseInt(await daySpinner.getText()),
control,
'After sending page down to the day spinner when set to 5, the day should be: ' +
control
);
});
ariaTest('page up on month', exampleFile, 'spinbutton-page-up', async (t) => {
let control = 1;
// Send page up to day date spinner
let monthSpinner = await t.context.session.findElement(
By.css(ex.monthSelector)
);
// Set to January
await monthSpinner.sendKeys(Key.HOME);
await monthSpinner.sendKeys(Key.PAGE_UP);
// Add 5 month to the control
control += 5;
t.is(
await monthSpinner.getText(),
valuesMonth[control - 1],
'After sending 1 page up to the month spinner, the month should be: ' +
valuesMonth[control - 1]
);
// Send page up 2 more times to date spinner
for (let i = 1; i <= 2; i++) {
await monthSpinner.sendKeys(Key.PAGE_UP);
}
// Should roll around to January
control = 1;
t.is(
await monthSpinner.getText(),
valuesMonth[control - 1],
'After sending 3 page ups to the month spinner, the month should be: ' +
valuesMonth[control - 1]
);
// Set to December
await monthSpinner.sendKeys(Key.END);
// Should roll around to January
await monthSpinner.sendKeys(Key.PAGE_UP);
t.is(
await monthSpinner.getText(),
valuesMonth[control - 1],
'After sending page ups to the month spinner in December, the month should be: ' +
valuesMonth[control - 1]
);
// Set to December
await monthSpinner.sendKeys(Key.END);
// Set to August
for (let i = 1; i <= 4; i++) {
await monthSpinner.sendKeys(Key.DOWN);
}
await monthSpinner.sendKeys(Key.PAGE_UP);
t.is(
await monthSpinner.getText(),
valuesMonth[control - 1],
'After sending page up to the month spinner on August, the month should be: ' +
valuesMonth[control - 1]
);
});
ariaTest(
'page down on month',
exampleFile,
'spinbutton-page-down',
async (t) => {
let control = 12;
// Send page down to month date spinner
let monthSpinner = await t.context.session.findElement(
By.css(ex.monthSelector)
);
// Set spinner to December
await monthSpinner.sendKeys(Key.END);
await monthSpinner.sendKeys(Key.PAGE_DOWN);
// Subtract 5 month to the control
control -= 5;
t.is(
await monthSpinner.getText(),
valuesMonth[control - 1],
'After sending 1 page down to the month spinner, the month should be: ' +
valuesMonth[control - 1]
);
// Send page down 2 more times to date spinner
for (let i = 1; i <= 2; i++) {
await monthSpinner.sendKeys(Key.PAGE_DOWN);
}
// Roll around to December
control = 12;
t.is(
await monthSpinner.getText(),
valuesMonth[control - 1],
'After sending 3 page downs to the month spinner, the month should be: ' +
valuesMonth[control - 1]
);
// Set to January
await monthSpinner.sendKeys(Key.HOME);
// Roll around to December
await monthSpinner.sendKeys(Key.PAGE_DOWN);
t.is(
await monthSpinner.getText(),
valuesMonth[control - 1],
'After sending page down to the month spinner on January, the month should be: ' +
valuesMonth[control - 1]
);
// Set to January
await monthSpinner.sendKeys(Key.HOME);
// Set to May
for (let i = 1; i <= 4; i++) {
await monthSpinner.sendKeys(Key.ARROW_UP);
}
await monthSpinner.sendKeys(Key.PAGE_DOWN);
t.is(
await monthSpinner.getText(),
valuesMonth[control - 1],
'After sending page down to the month spinner on May, the month should be: ' +
valuesMonth[control - 1]
);
}
);
ariaTest('page up on year', exampleFile, 'spinbutton-page-up', async (t) => {
// Send page up to day date spinner
let yearSpinner = await t.context.session.findElement(
By.css(ex.yearSelector)
);
await yearSpinner.sendKeys(Key.PAGE_UP);
let nextYear = (parseInt(ex.yearNow) + 5).toString();
t.is(
await yearSpinner.getText(),
nextYear,
'After sending 1 page up to the year spinner, the year should be: ' +
nextYear
);
let manyYears = Math.ceil((parseInt(ex.yearMax) - parseInt(ex.yearNow)) / 5);
for (let i = 1; i <= manyYears; i++) {
await yearSpinner.sendKeys(Key.PAGE_UP);
}
t.is(
await yearSpinner.getText(),
ex.yearMax,
'After sending ' +
(manyYears + 1) +
' page ups to the year spinner, the year should be: ' +
ex.yearMax
);
});
ariaTest(
'down arrow on year',
exampleFile,
'spinbutton-page-down',
async (t) => {
// Send down arrow to year date spinner
let yearSpinner = await t.context.session.findElement(
By.css(ex.yearSelector)
);
await yearSpinner.sendKeys(Key.PAGE_UP);
await yearSpinner.sendKeys(Key.PAGE_DOWN);
t.is(
await yearSpinner.getText(),
ex.yearNow,
'After sending 1 up arrow, then 1 down arrow to the year spinner, the year should be: ' +
ex.yearNow
);
let manyYears = Math.ceil(
(parseInt(ex.yearNow) - parseInt(ex.yearMin)) / 5
);
for (let i = 1; i <= manyYears; i++) {
await yearSpinner.sendKeys(Key.PAGE_DOWN);
}
t.is(
await yearSpinner.getText(),
ex.yearMin,
'After sending ' +
manyYears +
' down arrows to the year spinner, the year should be: ' +
ex.yearMin
);
}
);
ariaTest('home on day', exampleFile, 'spinbutton-home', async (t) => {
// Send home to day date spinner
let daySpinner = await t.context.session.findElement(By.css(ex.daySelector));
await daySpinner.sendKeys(Key.HOME);
t.is(
await daySpinner.getText(),
'1',
'After sending home to the day spinner, the day should be: 1'
);
});
ariaTest('end on day', exampleFile, 'spinbutton-end', async (t) => {
// Send home to day date spinner
let daySpinner = await t.context.session.findElement(By.css(ex.daySelector));
await daySpinner.sendKeys(Key.END);
t.is(
await daySpinner.getText(),
ex.dayMax,
'After sending end to the day spinner, the day should be: ' + ex.dayMax
);
});
ariaTest('home on month', exampleFile, 'spinbutton-home', async (t) => {
// Send home to month date spinner
let monthSpinner = await t.context.session.findElement(
By.css(ex.monthSelector)
);
await monthSpinner.sendKeys(Key.HOME);
t.is(
await monthSpinner.getText(),
'January',
'After sending home to the month spinner, the month should be: January'
);
});
ariaTest('end on month', exampleFile, 'spinbutton-end', async (t) => {
// Send home to month date spinner
let monthSpinner = await t.context.session.findElement(
By.css(ex.monthSelector)
);
await monthSpinner.sendKeys(Key.END);
t.is(
await monthSpinner.getText(),
'December',
'After sending end to the month spinner, the month should be: December'
);
});
ariaTest('home on year', exampleFile, 'spinbutton-home', async (t) => {
// Send home to year date spinner
let yearSpinner = await t.context.session.findElement(
By.css(ex.yearSelector)
);
await yearSpinner.sendKeys(Key.HOME);
t.is(
await yearSpinner.getText(),
ex.yearMin,
'After sending home to the year spinner, the year should be: ' + ex.yearMin
);
});
ariaTest('end on year', exampleFile, 'spinbutton-end', async (t) => {
// Send home to year date spinner
let yearSpinner = await t.context.session.findElement(
By.css(ex.yearSelector)
);
await yearSpinner.sendKeys(Key.END);
t.is(
await yearSpinner.getText(),
ex.yearMax,
'After sending end to the year spinner, the year should be: ' + ex.yearMax
);
});