-
-
Notifications
You must be signed in to change notification settings - Fork 456
Expand file tree
/
Copy pathdetoxTest.spec.js
More file actions
499 lines (416 loc) · 15.7 KB
/
detoxTest.spec.js
File metadata and controls
499 lines (416 loc) · 15.7 KB
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
const {
elementById,
elementByText,
getDateTimePickerIOS,
getDatePickerAndroid,
getDateTimePickerControlIOS,
getInlineTimePickerIOS,
getDatePickerButtonIOS,
} = require('./utils/matchers');
const {
userChangesTimeValue,
userOpensPicker,
userTapsCancelButtonAndroid,
userTapsOkButtonAndroid,
userSelectsDayInCalendar,
userSwipesTimezoneListUntilDesiredIsVisible,
userDismissesCompactDatePicker,
} = require('./utils/actions');
const {isIOS, isAndroid, wait, Platform} = require('./utils/utils');
const {device} = require('detox');
const {describe} = require('jest-circus');
const {
assertTimeLabels,
assertInitialTimeLabels,
} = require('./utils/assertions');
describe.skip('e2e tests', () => {
const getPickerDisplay = () => {
return isIOS() ? 'spinner' : 'default';
};
beforeAll(async () => {
if (isIOS()) {
await device.launchApp({newInstance: true});
}
}, 300000);
beforeEach(async () => {
if (isIOS()) {
await device.reloadReactNative();
} else {
await device.launchApp({newInstance: true});
}
await waitFor(elementByText('Example DateTime Picker'))
.toBeVisible()
.withTimeout(5000);
});
it('timeInfo heading has expected content', async () => {
await assertInitialTimeLabels();
await expect(elementById('deviceTzName')).toHaveText('Europe/Prague');
await expect(elementById('overriddenTzName')).toHaveText('Europe/Prague');
});
it('should show date picker after tapping datePicker button', async () => {
await userOpensPicker({mode: 'date', display: getPickerDisplay()});
if (isIOS()) {
await expect(getDateTimePickerIOS()).toBeVisible();
} else {
await expect(getDatePickerAndroid()).toBeVisible();
}
});
it('nothing should happen if date picker is dismissed / cancelled', async () => {
await userOpensPicker({mode: 'date', display: 'default'});
if (isIOS()) {
await getDatePickerButtonIOS().tap();
// 'label' maps to 'description' in view hierarchy debugger
const nextMonthArrow = element(by.label('Next Month'));
await nextMonthArrow.tap();
await nextMonthArrow.tap();
await userDismissesCompactDatePicker();
} else {
const calendarHorizontalScrollView = element(
by
.type('android.widget.ScrollView')
.withAncestor(by.id('dateTimePicker')),
);
await calendarHorizontalScrollView.swipe('left', 'fast', 1);
await calendarHorizontalScrollView.tap({x: 50, y: 200});
await userTapsCancelButtonAndroid();
}
await elementByText('great').tap();
await assertInitialTimeLabels();
});
it('should update dateTimeText when date changes', async () => {
await userOpensPicker({mode: 'date', display: getPickerDisplay()});
const targetDate = '2021-11-02T01:00:00Z';
if (isIOS()) {
const testElement = getDateTimePickerControlIOS();
await testElement.setDatePickerDate(targetDate, 'ISO8601');
} else {
const uiDevice = device.getUiDevice();
const focusSecondOfNovemberInCalendar = async () => {
await uiDevice.pressDPadDown();
await uiDevice.pressDPadDown();
await uiDevice.pressDPadDown();
};
await focusSecondOfNovemberInCalendar();
await uiDevice.pressEnter();
await userTapsOkButtonAndroid();
}
await assertTimeLabels({
utcTime: targetDate,
deviceTime: '2021-11-02T02:00:00+01:00',
});
});
it('should show time picker after tapping timePicker button', async () => {
const display = Platform.select({
ios: 'inline',
android: 'default',
});
await userOpensPicker({mode: 'time', display});
if (isIOS()) {
await expect(getInlineTimePickerIOS()).toBeVisible();
} else {
await expect(element(by.type('android.widget.TimePicker'))).toBeVisible();
}
});
it('nothing should happen if time does not change', async () => {
await userOpensPicker({mode: 'time', display: getPickerDisplay()});
if (isIOS()) {
await expect(getDateTimePickerIOS()).toBeVisible();
} else {
await userChangesTimeValue({minutes: '22'});
await userTapsCancelButtonAndroid();
await elementByText('great').tap();
}
await assertInitialTimeLabels();
});
it('should change time text when time changes', async () => {
await userOpensPicker({mode: 'time', display: getPickerDisplay()});
if (isIOS()) {
const testElement = getDateTimePickerControlIOS();
// TODO
await testElement.setDatePickerDate('2021-11-13T14:44:00Z', 'ISO8601');
} else {
await userChangesTimeValue({hours: 15, minutes: 44});
await userTapsOkButtonAndroid();
}
await assertTimeLabels({
utcTime: '2021-11-13T14:44:00Z',
deviceTime: '2021-11-13T15:44:00+01:00',
});
});
describe.skip('IANA time zone', () => {
it('should show utcTime, deviceTime, overriddenTime correctly', async () => {
await assertInitialTimeLabels();
await expect(elementById('overriddenTzName')).toHaveText('Europe/Prague');
let timeZone = 'America/Vancouver';
await elementById('DateTimePickerScrollView').scrollTo('bottom');
await waitFor(elementById('timezone')).toBeVisible().withTimeout(1000);
await userSwipesTimezoneListUntilDesiredIsVisible(timeZone);
if (isAndroid()) {
timeZone = timeZone.toUpperCase();
}
await waitFor(elementByText(timeZone)).toBeVisible().withTimeout(1000);
await elementByText(timeZone).multiTap(2);
await assertTimeLabels({
utcTime: '2021-11-13T01:00:00Z',
deviceTime: '2021-11-13T02:00:00+01:00',
overriddenTime: '2021-11-12T17:00:00-08:00',
});
await expect(elementById('overriddenTzName')).toHaveText(
'America/Vancouver',
);
});
it('daylight saving should work properly', async () => {
let timeZone = 'America/Vancouver';
await elementById('DateTimePickerScrollView').scrollTo('bottom');
await waitFor(elementById('timezone')).toBeVisible().withTimeout(1000);
await userSwipesTimezoneListUntilDesiredIsVisible(timeZone);
if (isAndroid()) {
timeZone = timeZone.toUpperCase();
}
await waitFor(elementByText(timeZone)).toBeVisible().withTimeout(1000);
await elementByText(timeZone).multiTap(2);
await userOpensPicker({mode: 'date', display: getPickerDisplay()});
if (isIOS()) {
const testElement = getDateTimePickerControlIOS();
await testElement.setDatePickerDate('2021-03-14T10:00:00Z', 'ISO8601');
} else {
const uiDevice = device.getUiDevice();
// Ensure you can't select yesterday (Android)
const focusFourteenthOfMarchInCalendar = async () => {
for (let i = 0; i < 3; i++) {
await uiDevice.pressDPadDown();
}
await uiDevice.pressDPadUp();
for (let i = 0; i < 8; i++) {
await uiDevice.pressEnter();
}
for (let i = 0; i < 2; i++) {
await uiDevice.pressDPadDown();
}
};
await focusFourteenthOfMarchInCalendar();
await uiDevice.pressEnter();
await userTapsOkButtonAndroid();
await userOpensPicker({mode: 'time', display: getPickerDisplay()});
await userChangesTimeValue({hours: '2', minutes: '0'});
await userTapsOkButtonAndroid();
}
await assertTimeLabels({
utcTime: '2021-03-14T10:00:00Z',
deviceTime: '2021-03-14T11:00:00+01:00',
overriddenTime: '2021-03-14T03:00:00-07:00',
});
});
});
describe.skip('time zone offset', () => {
it('should update dateTimeText when date changes and set setTzOffsetInMinutes to 0', async () => {
await assertInitialTimeLabels();
let tzOffsetPreset = '0 mins';
if (isIOS()) {
await userOpensPicker({
mode: 'date',
display: 'spinner',
tzOffsetPreset,
});
} else {
tzOffsetPreset = tzOffsetPreset.toUpperCase();
await userOpensPicker({
mode: 'date',
display: 'default',
tzOffsetPreset,
});
await userTapsOkButtonAndroid();
}
await expect(elementById('overriddenTime')).toHaveText(
'2021-11-13T01:00:00Z',
);
});
it('setTz should change time text when setTzOffsetInMinutes is 120 minutes', async () => {
await elementById('DateTimePickerScrollView').scrollTo('bottom');
let tzOffsetPreset = '+120 mins';
if (isAndroid()) {
tzOffsetPreset = tzOffsetPreset.toUpperCase();
}
await userOpensPicker({
mode: 'time',
display: getPickerDisplay(),
tzOffsetPreset,
});
if (isIOS()) {
const testElement = getDateTimePickerIOS();
await testElement.setColumnToValue(0, '7');
await testElement.setColumnToValue(1, '30');
await testElement.setColumnToValue(2, 'AM');
} else {
await userChangesTimeValue({hours: '7', minutes: '30'});
await userTapsOkButtonAndroid();
}
await assertTimeLabels({
utcTime: '2021-11-13T05:30:00Z',
deviceTime: '2021-11-13T06:30:00+01:00',
overriddenTime: '2021-11-13T07:30:00+02:00',
});
});
it('should let you pick tomorrow but not yesterday when setting min/max', async () => {
await elementById('DateTimePickerScrollView').scrollTo('bottom');
await elementById('setMinMax').tap();
if (isIOS()) {
const testElement = getDateTimePickerControlIOS();
// Ensure you can't select yesterday (iOS)
await testElement.setDatePickerDate('2021-11-12T01:00:00Z', 'ISO8601');
await expect(elementById('utcTime')).toHaveText('2021-11-13T00:00:00Z');
// Ensure you can select tomorrow (iOS)
await userOpensPicker({mode: 'date', display: getPickerDisplay()});
await testElement.setDatePickerDate('2021-11-14T01:00:00Z', 'ISO8601');
} else {
const uiDevice = device.getUiDevice();
// Ensure you can't select yesterday (Android)
const focusTwelveOfNovemberInCalendar = async () => {
for (let i = 0; i < 4; i++) {
await uiDevice.pressDPadDown();
}
for (let i = 0; i < 3; i++) {
await uiDevice.pressDPadRight();
}
};
await focusTwelveOfNovemberInCalendar();
await uiDevice.pressEnter();
await userTapsOkButtonAndroid();
await assertTimeLabels({
utcTime: '2021-11-13T01:00:00Z',
deviceTime: '2021-11-13T02:00:00+01:00',
overriddenTime: '2021-11-13T01:00:00Z',
});
// Ensure you can select tomorrow (Android)
await userOpensPicker({mode: 'date', display: getPickerDisplay()});
const focusFourteenthOfNovemberInCalendar = async () => {
for (let i = 0; i < 5; i++) {
await uiDevice.pressDPadDown();
}
for (let i = 0; i < 2; i++) {
await uiDevice.pressDPadLeft();
}
};
await focusFourteenthOfNovemberInCalendar();
await uiDevice.pressEnter();
await userTapsOkButtonAndroid();
}
await assertTimeLabels({
utcTime: '2021-11-14T01:00:00Z',
deviceTime: '2021-11-14T02:00:00+01:00',
overriddenTime: '2021-11-14T01:00:00Z',
});
});
});
it.skip(':android: given we specify neutralButtonLabel, tapping the corresponding button sets date to the beginning of the unix time epoch', async () => {
await elementById('neutralButtonLabelTextInput').clearText();
await elementById('neutralButtonLabelTextInput').typeText('clear');
await userOpensPicker({mode: 'time', display: 'default'});
await elementByText('clear').tap();
await assertTimeLabels({
utcTime: '1970-01-01T00:00:00Z',
deviceTime: '1970-01-01T01:00:00+01:00',
});
});
it(':android: when component unmounts, dialog is dismissed', async () => {
await elementById('DateTimePickerScrollView').scrollTo('bottom');
await elementById('showAndDismissPickerButton').tap();
await waitFor(getDatePickerAndroid()).toExist().withTimeout(4000);
await wait(6000);
await expect(getDatePickerAndroid()).not.toExist();
});
describe.skip('given 5-minute interval', () => {
it(':android: clock picker should correct 18-minute selection to 20-minute one', async () => {
await userOpensPicker({mode: 'time', display: 'clock', interval: 5});
await userChangesTimeValue({hours: '23', minutes: '18'});
await userTapsOkButtonAndroid();
await assertTimeLabels({
utcTime: '2021-11-13T22:20:00Z',
deviceTime: '2021-11-13T23:20:00+01:00',
});
});
it(':android: when the picker is shown as "spinner", swiping it down changes selected time', async () => {
await assertTimeLabels({
utcTime: '2021-11-13T01:00:00Z',
deviceTime: '2021-11-13T02:00:00+01:00',
});
await userOpensPicker({mode: 'time', display: 'spinner', interval: 5});
const minutePicker = element(
by.type('android.widget.NumberPicker'),
).atIndex(1);
await minutePicker.swipe('up', 'slow', 0.33);
await userTapsOkButtonAndroid();
await assertTimeLabels({
utcTime: '2021-11-13T01:15:00Z',
deviceTime: '2021-11-13T02:15:00+01:00',
});
});
it(':ios: picker should offer only options divisible by 5 (0, 5, 10,...)', async () => {
await userOpensPicker({mode: 'time', display: 'spinner', interval: 5});
const testElement = getDateTimePickerIOS();
await testElement.setColumnToValue(0, '2');
await testElement.setColumnToValue(1, '15');
await testElement.setColumnToValue(2, 'PM');
await assertTimeLabels({
utcTime: '2021-11-13T13:15:00Z',
deviceTime: '2021-11-13T14:15:00+01:00',
});
const valueThatShouldNotBePresented = '18';
try {
await testElement.setColumnToValue(1, valueThatShouldNotBePresented);
} catch (err) {
if (err.message.includes('does not contain value')) {
await testElement.setColumnToValue(1, '45');
} else {
throw new Error(
'because time interval of 5 minutes was set, Picker should not contain value ' +
valueThatShouldNotBePresented +
' but it was displayed in the list.' +
err,
);
}
}
await assertTimeLabels({
utcTime: '2021-11-13T13:45:00Z',
deviceTime: '2021-11-13T14:45:00+01:00',
});
});
});
describe.skip(':android: firstDayOfWeek functionality', () => {
it.each([
{
firstDayOfWeekIn: 'Sunday',
selectDayPositions: {xPosIn: -2, yPosIn: 4},
},
{
firstDayOfWeekIn: 'Tuesday',
selectDayPositions: {xPosIn: 3, yPosIn: 3},
},
])(
':android: picker should have $firstDayOfWeekIn as firstDayOfWeek and select Sunday date',
async ({firstDayOfWeekIn, selectDayPositions}) => {
const targetDate = '2021-11-07T01:00:00Z';
const targetDateWithTZ = '2021-11-07T02:00:00+01:00';
await userOpensPicker({
mode: 'date',
display: getPickerDisplay(),
firstDayOfWeek: firstDayOfWeekIn,
});
await expect(getDatePickerAndroid()).toBeVisible();
const uiDevice = device.getUiDevice();
await userSelectsDayInCalendar(uiDevice, {
xPos: selectDayPositions.xPosIn,
yPos: selectDayPositions.yPosIn,
});
await userTapsOkButtonAndroid();
await expect(elementById('firstDayOfWeek')).toHaveText(
firstDayOfWeekIn,
);
await assertTimeLabels({
utcTime: targetDate,
deviceTime: targetDateWithTZ,
});
},
);
});
});