This repository has been archived by the owner on Nov 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
date-picker-driver.ts
99 lines (76 loc) · 2.73 KB
/
date-picker-driver.ts
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
import {DriverBase, selectDom, simulate, trigger} from 'test-drive-react';
import {DatePicker} from '../../src';
import {getDayNames} from '../../src/utils';
const bodySelect = selectDom(document.body);
const datePickerDropdown = 'DATE_PICKER_DROPDOWN';
export class DatePickerTestDriver extends DriverBase {
public static ComponentClass = DatePicker;
public get input(): HTMLInputElement {
return this.select<HTMLInputElement>('DATE_PICKER_INPUT');
}
public get selectedDate(): string {
return this.select<HTMLInputElement>('DATE_PICKER_INPUT').value;
}
public changeDate(value: string): void {
trigger.change(this.input, value);
simulate.blur(this.input);
}
public focus(): void {
simulate.focus(this.input);
}
public clickOnDatePicker(): void {
simulate.mouseDown(this.input);
}
public clickOnDay(day: number): void {
simulate.mouseDown(this.getDay(day));
}
public clickOnNextMonth(): void {
simulate.mouseDown(this.nextMonthLabel);
}
public clickOnPrevMonth(): void {
simulate.mouseDown(this.prevMonthLabel);
}
public openCalender(): void {
simulate.click(this.select('CALENDAR_ICON'));
}
public isOpen(): boolean {
return !!this.dropDown;
}
public keyPress(keyCode: number): void {
simulate.keyDown(this.input, {keyCode});
}
public simulateInput(): void {
simulate.input(this.input);
}
public get nextMonthLabel(): HTMLSpanElement | null {
return bodySelect('NEXT_MONTH_BUTTON');
}
public get prevMonthLabel(): HTMLSpanElement | null {
return bodySelect('PREV_MONTH_BUTTON');
}
public get dropDown(): HTMLDivElement | null {
return bodySelect(datePickerDropdown);
}
public getDay(day: number | string): HTMLSpanElement | null {
return bodySelect(datePickerDropdown, `DAY_${day}`);
}
public getPrevDay(day: number | string): HTMLSpanElement | null {
return bodySelect(datePickerDropdown, `PREV_DAY_${day}`);
}
public getNextDay(day: number | string): HTMLSpanElement | null {
return bodySelect(datePickerDropdown, `NEXT_DAY_${day}`);
}
public getDayName(dayName: number): HTMLSpanElement | null {
if (dayName < 0 || dayName > 6) {
return null;
}
const dayNames: string[] = getDayNames();
return bodySelect(datePickerDropdown, `DAY_NAME_${dayNames[dayName].toUpperCase()}`);
}
public get yearLabel(): HTMLSpanElement | null {
return bodySelect(datePickerDropdown, 'YEAR');
}
public get monthLabel(): HTMLSpanElement | null {
return bodySelect(datePickerDropdown, 'MONTH_NAME');
}
}