@@ -14,6 +14,36 @@ async function userChangesMinuteValue() {
14
14
await minuteTextinput . replaceText ( '30' ) ;
15
15
}
16
16
17
+ async function userOpensPicker ( { mode, display, interval} ) {
18
+ await element ( by . text ( mode ) ) . tap ( ) ;
19
+ await element ( by . text ( display ) ) . tap ( ) ;
20
+ if ( interval ) {
21
+ await element ( by . text ( String ( interval ) ) ) . tap ( ) ;
22
+ }
23
+ await element ( by . id ( 'showPickerButton' ) ) . tap ( ) ;
24
+ }
25
+
26
+ async function userTapsCancelButtonAndroid ( ) {
27
+ // selecting element by text does not work consistently :/
28
+ // const cancelButton = element(by.text('Cancel'));
29
+ const cancelButton = element (
30
+ by
31
+ . type ( 'androidx.appcompat.widget.AppCompatButton' )
32
+ . withAncestor ( by . type ( 'android.widget.ScrollView' ) ) ,
33
+ ) . atIndex ( 0 ) ;
34
+ await cancelButton . tap ( ) ;
35
+ }
36
+ async function userTapsOkButtonAndroid ( ) {
37
+ // selecting element by text does not work consistently :/
38
+ // const okButton = element(by.text('OK'));
39
+ const okButton = element (
40
+ by
41
+ . type ( 'androidx.appcompat.widget.AppCompatButton' )
42
+ . withAncestor ( by . type ( 'android.widget.ScrollView' ) ) ,
43
+ ) . atIndex ( 1 ) ;
44
+ await okButton . tap ( ) ;
45
+ }
46
+
17
47
describe ( 'Example' , ( ) => {
18
48
beforeEach ( async ( ) => {
19
49
if ( global . device . getPlatform ( ) === 'ios' ) {
@@ -34,7 +64,7 @@ describe('Example', () => {
34
64
} ) ;
35
65
36
66
it ( 'should show date picker after tapping datePicker button' , async ( ) => {
37
- await element ( by . id ( 'datePickerButton' ) ) . tap ( ) ;
67
+ await userOpensPicker ( { mode : 'date' , display : 'default' } ) ;
38
68
39
69
if ( global . device . getPlatform ( ) === 'ios' ) {
40
70
await expect (
@@ -46,7 +76,7 @@ describe('Example', () => {
46
76
} ) ;
47
77
48
78
it ( 'Nothing should happen if date does not change' , async ( ) => {
49
- await element ( by . id ( 'datePickerButton' ) ) . tap ( ) ;
79
+ await userOpensPicker ( { mode : 'date' , display : 'default' } ) ;
50
80
51
81
if ( global . device . getPlatform ( ) === 'ios' ) {
52
82
await expect (
@@ -60,15 +90,15 @@ describe('Example', () => {
60
90
) ;
61
91
await testElement . swipe ( 'left' , 'fast' , '100' ) ;
62
92
await testElement . tapAtPoint ( { x : 50 , y : 200 } ) ;
63
- await element ( by . text ( 'CANCEL' ) ) . tap ( ) ;
93
+ await userTapsCancelButtonAndroid ( ) ;
64
94
}
65
95
66
96
const dateText = getDateText ( ) ;
67
97
await expect ( dateText ) . toHaveText ( '08/21/2020' ) ;
68
98
} ) ;
69
99
70
100
it ( 'should update dateTimeText when date changes' , async ( ) => {
71
- await element ( by . id ( 'datePickerButton' ) ) . tap ( ) ;
101
+ await userOpensPicker ( { mode : 'date' , display : 'default' } ) ;
72
102
const dateText = getDateText ( ) ;
73
103
74
104
if ( global . device . getPlatform ( ) === 'ios' ) {
@@ -88,14 +118,14 @@ describe('Example', () => {
88
118
) ;
89
119
await testElement . swipe ( 'left' , 'fast' , '100' ) ;
90
120
await testElement . tapAtPoint ( { x : 50 , y : 200 } ) ;
91
- await element ( by . text ( 'OK' ) ) . tap ( ) ;
121
+ await userTapsOkButtonAndroid ( ) ;
92
122
93
123
await expect ( dateText ) . toHaveText ( '09/13/2020' ) ;
94
124
}
95
125
} ) ;
96
126
97
127
it ( 'should show time picker after tapping timePicker button' , async ( ) => {
98
- await element ( by . id ( 'timePickerButton' ) ) . tap ( ) ;
128
+ await userOpensPicker ( { mode : 'time' , display : 'default' } ) ;
99
129
100
130
if ( global . device . getPlatform ( ) === 'ios' ) {
101
131
await expect (
@@ -107,22 +137,22 @@ describe('Example', () => {
107
137
} ) ;
108
138
109
139
it ( 'Nothing should happen if time does not change' , async ( ) => {
110
- await element ( by . id ( 'timePickerButton' ) ) . tap ( ) ;
140
+ await userOpensPicker ( { mode : 'time' , display : 'default' } ) ;
111
141
112
142
if ( global . device . getPlatform ( ) === 'ios' ) {
113
143
await expect (
114
144
element ( by . type ( 'UIPickerView' ) . withAncestor ( by . id ( 'dateTimePicker' ) ) ) ,
115
145
) . toBeVisible ( ) ;
116
146
} else {
117
147
await userChangesMinuteValue ( ) ;
118
- await element ( by . text ( 'CANCEL' ) ) . tap ( ) ;
148
+ await userTapsCancelButtonAndroid ( ) ;
119
149
}
120
150
const timeText = getTimeText ( ) ;
121
151
await expect ( timeText ) . toHaveText ( '23:15' ) ;
122
152
} ) ;
123
153
124
154
it ( 'should change time text when time changes' , async ( ) => {
125
- await element ( by . id ( 'timePickerButton' ) ) . tap ( ) ;
155
+ await userOpensPicker ( { mode : 'time' , display : 'default' } ) ;
126
156
const timeText = getTimeText ( ) ;
127
157
128
158
if ( global . device . getPlatform ( ) === 'ios' ) {
@@ -136,7 +166,7 @@ describe('Example', () => {
136
166
await expect ( timeText ) . toHaveText ( '14:44' ) ;
137
167
} else {
138
168
await userChangesMinuteValue ( ) ;
139
- await element ( by . text ( 'OK' ) ) . tap ( ) ;
169
+ await userTapsOkButtonAndroid ( ) ;
140
170
141
171
await expect ( timeText ) . toHaveText ( '23:30' ) ;
142
172
}
@@ -145,7 +175,7 @@ describe('Example', () => {
145
175
describe ( 'given 5-minute interval' , ( ) => {
146
176
it ( ':android: clock picker should correct 18-minute selection to 20-minute one' , async ( ) => {
147
177
try {
148
- await element ( by . id ( 'timePickerDefaultIntervalButton' ) ) . tap ( ) ;
178
+ await userOpensPicker ( { mode : 'time' , display : 'clock' , interval : 5 } ) ;
149
179
150
180
const keyboardButton = element (
151
181
by . type ( 'androidx.appcompat.widget.AppCompatImageButton' ) ,
@@ -156,7 +186,7 @@ describe('Example', () => {
156
186
) . atIndex ( 1 ) ;
157
187
await testElement . tap ( ) ;
158
188
await testElement . replaceText ( '18' ) ;
159
- await element ( by . text ( 'OK' ) ) . tap ( ) ;
189
+ await userTapsOkButtonAndroid ( ) ;
160
190
161
191
const timeText = getTimeText ( ) ;
162
192
await expect ( timeText ) . toHaveText ( '23:20' ) ;
@@ -171,13 +201,13 @@ describe('Example', () => {
171
201
172
202
await expect ( timeText ) . toHaveText ( '23:15' ) ;
173
203
174
- await element ( by . id ( 'timePickerSpinnerIntervalButton' ) ) . tap ( ) ;
204
+ await userOpensPicker ( { mode : 'time' , display : 'spinner' , interval : 5 } ) ;
175
205
176
206
const minutePicker = element (
177
207
by . type ( 'android.widget.NumberPicker' ) ,
178
208
) . atIndex ( 1 ) ;
179
209
await minutePicker . swipe ( 'up' , 'slow' , '33' ) ;
180
- await element ( by . text ( 'OK' ) ) . tap ( ) ;
210
+ await userTapsOkButtonAndroid ( ) ;
181
211
182
212
await expect ( timeText ) . toHaveText ( '23:25' ) ;
183
213
} catch ( err ) {
@@ -186,7 +216,7 @@ describe('Example', () => {
186
216
} ) ;
187
217
188
218
it ( ':ios: picker should offer only options divisible by 5 (0, 5, 10,...)' , async ( ) => {
189
- await element ( by . id ( 'timePickerDefaultIntervalButton' ) ) . tap ( ) ;
219
+ await userOpensPicker ( { mode : 'time' , display : 'spinner' , interval : 5 } ) ;
190
220
191
221
const testElement = element (
192
222
by . type ( 'UIPickerView' ) . withAncestor ( by . id ( 'dateTimePicker' ) ) ,
0 commit comments