-
-
Notifications
You must be signed in to change notification settings - Fork 456
Expand file tree
/
Copy pathactions.js
More file actions
116 lines (104 loc) · 3.59 KB
/
actions.js
File metadata and controls
116 lines (104 loc) · 3.59 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
const {elementById} = require('./matchers');
async function userChangesTimeValue(
{hours, minutes} = {hours: undefined, minutes: undefined},
) {
const keyboardIconButton = element(
by.type('androidx.appcompat.widget.AppCompatImageButton'),
);
await keyboardIconButton.tap();
if (minutes !== undefined) {
const minuteTextinput = element(
by.type('androidx.appcompat.widget.AppCompatEditText'),
).atIndex(1);
await minuteTextinput.replaceText(String(minutes));
}
if (hours !== undefined) {
const hourTextinput = element(
by.type('androidx.appcompat.widget.AppCompatEditText'),
).atIndex(0);
await hourTextinput.replaceText(String(hours));
}
}
async function userOpensPicker({
mode,
display,
interval,
tzOffsetPreset,
firstDayOfWeek,
}) {
await elementById('DateTimePickerScrollView').scrollTo('top');
await element(by.text(mode)).tap();
await element(by.text(display)).atIndex(0).tap();
if (interval) {
await element(by.text(String(interval))).tap();
}
if (tzOffsetPreset) {
await elementById('DateTimePickerScrollView').scrollTo('bottom');
await element(by.text(tzOffsetPreset)).tap();
await elementById('DateTimePickerScrollView').scrollTo('top');
}
if (firstDayOfWeek) {
// Scroll to make firstDayOfWeekSelector visible in viewport first
await elementById('DateTimePickerScrollView').scrollTo('bottom');
await waitFor(elementById('firstDayOfWeekSelector'))
.toBeVisible()
.withTimeout(1000);
// Scroll the horizontal FlatList to make the button visible
await elementById('firstDayOfWeekSelector').scroll(200, 'right');
await element(by.id(firstDayOfWeek)).tap();
}
await elementById('DateTimePickerScrollView').scrollTo('bottom');
await element(by.id('showPickerButton')).tap();
}
async function userTapsCancelButtonAndroid() {
// selecting element by text does not work consistently :/
const cancelButton = element(by.text('Cancel'));
// const cancelButton = element(
// by
// .type('androidx.appcompat.widget.AppCompatButton')
// .withAncestor(by.type('android.widget.ScrollView')),
// ).atIndex(0);
await cancelButton.tap();
}
async function userTapsOkButtonAndroid() {
// selecting element by text does not work consistently :/
const okButton = element(by.text('OK'));
// const okButton = element(
// by
// .type('androidx.appcompat.widget.AppCompatButton')
// .withAncestor(by.type('android.widget.ScrollView')),
// ).atIndex(1);
await okButton.tap();
}
async function userSwipesTimezoneListUntilDesiredIsVisible(timeZone) {
await waitFor(elementById(timeZone))
.toBeVisible()
.whileElement(by.id('timezone'))
.scroll(200, 'right');
}
// Helper function to select a day in the calendar
// A negative number xPos and yPos means we go left and up respectively
// A positive number xPos and yPos means we go right and down respectively
async function userSelectsDayInCalendar(uiDevice, {xPos, yPos}) {
for (let i = 0; i < Math.abs(yPos); i++) {
yPos < 0 ? await uiDevice.pressDPadUp(i) : await uiDevice.pressDPadDown(i);
}
for (let j = 0; j < Math.abs(xPos); j++) {
xPos < 0
? await uiDevice.pressDPadLeft(j)
: await uiDevice.pressDPadRight(j);
}
await uiDevice.pressEnter();
}
async function userDismissesCompactDatePicker() {
await element(by.type('_UIDatePickerContainerView')).tap();
}
module.exports = {
userOpensPicker,
userTapsCancelButtonAndroid,
userTapsOkButtonAndroid,
userChangesTimeValue,
userSelectsDayInCalendar,
userSwipesTimezoneListUntilDesiredIsVisible,
userDismissesCompactDatePicker,
};