-
Notifications
You must be signed in to change notification settings - Fork 125
/
time-picker.e2e-spec.ts
231 lines (208 loc) · 7.92 KB
/
time-picker.e2e-spec.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
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
import { TimePickerPo } from '../pages/time-picker.po';
import {
click,
getText,
isElementDisplayed,
refreshPage,
getNextElementText,
clickNextElement,
getValue,
doesItExist,
getElementClass,
clearValue,
setValue,
sendKeys,
getPreviousElementText,
clickPreviousElement,
waitForElDisplayed,
browserIsSafari,
waitForPresent
} from '../../driver/wdio';
describe('Time-picker component test', () => {
const timePickerPage = new TimePickerPo();
const {
formExample,
nullExample,
localExample,
compactExamle,
defaultExample,
disabledExample,
formattingExample,
setToNullButton,
setValidTimeButton,
inputGroup,
timeInput,
clockIcon,
formatDropDown,
timePicker,
currentHour,
currentMinute,
hoursColumn,
minutesColumn,
thirdColumn,
customTimePicker,
amButton,
pmButton,
selectedTime,
formatList,
arFormat,
bgFormat,
bnFormat,
usFormat,
frFormat
} = timePickerPage;
beforeAll(() => {
timePickerPage.open();
}, 1);
beforeEach(() => {
refreshPage();
waitForPresent(timePickerPage.root);
waitForElDisplayed(timePickerPage.title);
}, 2);
it('should check default example', () => {
checkTimePickerFormat(defaultExample);
checkChoosingTime(defaultExample);
setValueByKeyboard(defaultExample);
});
it('should check formatting example', () => {
checkTimePickerFormat(formattingExample);
checkChoosingTime(formattingExample);
setValueByKeyboard(formattingExample);
});
it('should check disabled time-pickers', () => {
expect(getElementClass(disabledExample + inputGroup)).toContain('is-disabled', 'Input is not disabled');
expect(getElementClass(formExample + inputGroup, 1)).toContain('is-disabled', 'Input is not disabled');
});
it('should check compact example', () => {
checkTimePickerFormat(compactExamle);
checkChoosingTime(compactExamle);
setValueByKeyboard(compactExamle);
});
it('should check null validaty example', () => {
checkTimePickerFormat(nullExample);
click(setToNullButton);
expect(getElementClass(nullExample + customTimePicker)).toContain('ng-invalid', 'Valus is valid');
expect(getElementClass(nullExample + inputGroup)).toContain('is-error', 'No error message');
click(setValidTimeButton);
expect(getElementClass(nullExample + customTimePicker)).not.toContain('ng-invalid', 'Value is invalid');
expect(getElementClass(nullExample + inputGroup)).not.toContain('is-error', 'Error message is present');
checkChoosingTime(nullExample);
setValueByKeyboard(nullExample);
});
it('should check form example', () => {
checkTimePickerFormat(formExample);
click(formExample + clockIcon);
click(currentHour);
click(thirdColumn);
click(pmButton);
expect(getText(selectedTime).trim()).toEqual('12h 0m 0s');
click(amButton);
expect(getText(selectedTime).trim()).toEqual('0h 0m 0s');
click(formExample + clockIcon);
checkChoosingTime(formExample);
setValueByKeyboard(formExample);
});
it('should check local example', () => {
checkTimePickerFormat(localExample);
checkChoosingTime(localExample);
setValueByKeyboard(localExample);
});
it('should check countries formats in local example', () => {
const usInputValue = '3:30 PM';
const usAmValue = 'AM';
const usPmValue = 'PM';
checkCountryFormat(usFormat, usInputValue, usAmValue, usPmValue);
const frInputValue = '15:30';
checkCountryFormat(frFormat, frInputValue);
// skipped due to https://github.com/SAP/fundamental-ngx/issues/5751
// const bgInputValue = '15:30 ч.';
// checkCountryFormat(bgFormat, bgInputValue)
// skipping because correct format is not applied on CI
// const zhInputValue = '下午3:30';
// const zhAmValue = '上午';
// const zhPmValue = '下午';
// checkCountryFormat(zhFormat, zhInputValue, zhAmValue, zhPmValue);
const bnInputValue = '৩:৩০ PM';
const bnAmValue = 'AM';
const bnPmValue = 'PM';
checkCountryFormat(bnFormat, bnInputValue, bnAmValue, bnPmValue);
// skip due to for unknown issue it fails in Safari
if (!browserIsSafari()) {
const arInputValue = '٣:٣٠ م';
const arAmValue = 'ص';
const arPmValue = 'م';
checkCountryFormat(arFormat, arInputValue, arAmValue, arPmValue);
}
});
it('should check RTL and LTR orientation', () => {
timePickerPage.checkRtlSwitch();
});
xit('should check visual regression for all examples', () => {
timePickerPage.saveExampleBaselineScreenshot();
expect(timePickerPage.compareWithBaseline()).toBeLessThan(5);
});
function checkCountryFormat(format: string, inputValue?: string, amValue?: string, pmValue?: string): void {
refreshPage();
click(formatDropDown);
expect(isElementDisplayed(formatList)).toBe(true);
click(format);
expect(getValue(localExample + timeInput).trim()).toEqual(inputValue);
click(localExample + clockIcon);
if (format !== frFormat && format !== bgFormat) {
click(thirdColumn);
expect(getText(amButton).trim()).toEqual(amValue);
expect(getText(pmButton).trim()).toEqual(pmValue);
}
if (format === frFormat || format === bgFormat) {
expect(doesItExist(thirdColumn)).toBe(false);
}
}
function checkChoosingTime(section: string): void {
click(section + clockIcon);
expect(getElementClass(section + clockIcon)).toContain('is-expanded', 'Time picker is not expanded');
expect(isElementDisplayed(timePicker)).toBe(true);
const nextHour = getNextElementText(currentHour).trim();
clickNextElement(currentHour);
click(minutesColumn);
const prevMin = getPreviousElementText(currentMinute).trim();
clickPreviousElement(currentMinute);
const inputValue = getValue(section + timeInput);
if (section === formExample) {
expect(inputValue).toEqual(`${nextHour}:${prevMin} AM`);
}
if (section === formattingExample) {
expect(inputValue).toEqual(`${nextHour}:${prevMin}:00`);
}
if (section !== formattingExample && section !== formExample) {
expect(inputValue).toEqual(`${nextHour}:${prevMin} PM`);
}
click(section + clockIcon);
}
function setValueByKeyboard(section: string): void {
const value = '12:34 AM';
clearValue(section + timeInput);
setValue(section + timeInput, value);
sendKeys('Enter');
if (section === formattingExample) {
expect(getValue(section + timeInput)).toEqual(`${value}`);
}
if (section !== formattingExample) {
expect(getValue(section + timeInput)).toEqual(`${value}`);
}
}
function checkTimePickerFormat(section: string): void {
click(section + clockIcon);
expect(doesItExist(hoursColumn)).toBe(true, 'Hours column does not exist');
expect(doesItExist(minutesColumn)).toBe(true, 'Minutes column does not exist');
if (section === formattingExample) {
expect(getElementClass(thirdColumn)).not.toContain(
'fd-time__wrapper--meridian',
'It is not meridian column'
);
}
if (section !== formattingExample) {
expect(getElementClass(thirdColumn)).toContain('fd-time__wrapper--meridian', 'It is not meridian column');
}
click(section + clockIcon);
}
});