1- const { getTimeText, getDateText} = require ( './utils/matchers' ) ;
2-
3- async function userChangesMinuteValue ( ) {
4- const keyboardIconButton = element (
5- by . type ( 'androidx.appcompat.widget.AppCompatImageButton' ) ,
6- ) ;
7-
8- await keyboardIconButton . tap ( ) ;
9-
10- const minuteTextinput = element (
11- by . type ( 'androidx.appcompat.widget.AppCompatEditText' ) ,
12- ) . atIndex ( 1 ) ;
13-
14- await minuteTextinput . replaceText ( '30' ) ;
15- }
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- }
1+ const {
2+ getTimeText,
3+ getDateText,
4+ elementById,
5+ elementByText,
6+ } = require ( './utils/matchers' ) ;
7+ const {
8+ userChangesMinuteValue,
9+ userOpensPicker,
10+ userTapsCancelButtonAndroid,
11+ userTapsOkButtonAndroid,
12+ } = require ( './utils/actions' ) ;
13+ const { isAndroid, isIOS} = require ( './utils/utils' ) ;
4614
4715describe ( 'Example' , ( ) => {
4816 beforeEach ( async ( ) => {
49- if ( global . device . getPlatform ( ) === 'ios' ) {
17+ if ( isIOS ( ) ) {
5018 await device . reloadReactNative ( ) ;
5119 } else {
5220 await device . launchApp ( { newInstance : true } ) ;
5321 }
54- await waitFor ( element ( by . text ( 'Example DateTime Picker' ) ) )
22+ await waitFor ( elementByText ( 'Example DateTime Picker' ) )
5523 . toBeVisible ( )
5624 . withTimeout ( 5000 ) ;
5725 } ) ;
5826
5927 it ( 'should have title and hermes indicator on android' , async ( ) => {
60- await expect ( element ( by . text ( 'Example DateTime Picker' ) ) ) . toBeVisible ( ) ;
61- if ( device . getPlatform ( ) === 'android' ) {
62- await expect ( element ( by . id ( 'hermesIndicator' ) ) ) . toExist ( ) ;
28+ await expect ( elementByText ( 'Example DateTime Picker' ) ) . toBeVisible ( ) ;
29+ if ( isAndroid ( ) ) {
30+ await expect ( elementById ( 'hermesIndicator' ) ) . toExist ( ) ;
6331 }
6432 } ) ;
6533
6634 it ( 'should show date picker after tapping datePicker button' , async ( ) => {
6735 await userOpensPicker ( { mode : 'date' , display : 'default' } ) ;
6836
69- if ( global . device . getPlatform ( ) === 'ios' ) {
37+ if ( isIOS ( ) ) {
7038 await expect (
7139 element ( by . type ( 'UIPickerView' ) . withAncestor ( by . id ( 'dateTimePicker' ) ) ) ,
7240 ) . toBeVisible ( ) ;
@@ -75,10 +43,10 @@ describe('Example', () => {
7543 }
7644 } ) ;
7745
78- it ( 'Nothing should happen if date does not change' , async ( ) => {
46+ it ( 'nothing should happen if date does not change' , async ( ) => {
7947 await userOpensPicker ( { mode : 'date' , display : 'default' } ) ;
8048
81- if ( global . device . getPlatform ( ) === 'ios' ) {
49+ if ( isIOS ( ) ) {
8250 await expect (
8351 element ( by . type ( 'UIPickerView' ) . withAncestor ( by . id ( 'dateTimePicker' ) ) ) ,
8452 ) . toBeVisible ( ) ;
@@ -101,7 +69,7 @@ describe('Example', () => {
10169 await userOpensPicker ( { mode : 'date' , display : 'default' } ) ;
10270 const dateText = getDateText ( ) ;
10371
104- if ( global . device . getPlatform ( ) === 'ios' ) {
72+ if ( isIOS ( ) ) {
10573 const testElement = element (
10674 by . type ( 'UIPickerView' ) . withAncestor ( by . id ( 'dateTimePicker' ) ) ,
10775 ) ;
@@ -127,7 +95,7 @@ describe('Example', () => {
12795 it ( 'should show time picker after tapping timePicker button' , async ( ) => {
12896 await userOpensPicker ( { mode : 'time' , display : 'default' } ) ;
12997
130- if ( global . device . getPlatform ( ) === 'ios' ) {
98+ if ( isIOS ( ) ) {
13199 await expect (
132100 element ( by . type ( 'UIPickerView' ) . withAncestor ( by . id ( 'dateTimePicker' ) ) ) ,
133101 ) . toBeVisible ( ) ;
@@ -136,10 +104,10 @@ describe('Example', () => {
136104 }
137105 } ) ;
138106
139- it ( 'Nothing should happen if time does not change' , async ( ) => {
107+ it ( 'nothing should happen if time does not change' , async ( ) => {
140108 await userOpensPicker ( { mode : 'time' , display : 'default' } ) ;
141109
142- if ( global . device . getPlatform ( ) === 'ios' ) {
110+ if ( isIOS ( ) ) {
143111 await expect (
144112 element ( by . type ( 'UIPickerView' ) . withAncestor ( by . id ( 'dateTimePicker' ) ) ) ,
145113 ) . toBeVisible ( ) ;
@@ -155,7 +123,7 @@ describe('Example', () => {
155123 await userOpensPicker ( { mode : 'time' , display : 'default' } ) ;
156124 const timeText = getTimeText ( ) ;
157125
158- if ( global . device . getPlatform ( ) === 'ios' ) {
126+ if ( isIOS ( ) ) {
159127 const testElement = element (
160128 by . type ( 'UIPickerView' ) . withAncestor ( by . id ( 'dateTimePicker' ) ) ,
161129 ) ;
@@ -172,6 +140,15 @@ describe('Example', () => {
172140 }
173141 } ) ;
174142
143+ it ( ':android: given we specify neutralButtonLabel, tapping the corresponding button sets date to the beginning of the unix time epoch' , async ( ) => {
144+ await elementById ( 'neutralButtonLabelTextInput' ) . typeText ( 'clear' ) ;
145+ await userOpensPicker ( { mode : 'time' , display : 'default' } ) ;
146+ await elementByText ( 'clear' ) . tap ( ) ;
147+
148+ const dateText = getDateText ( ) ;
149+ await expect ( dateText ) . toHaveText ( '01/01/1970' ) ;
150+ } ) ;
151+
175152 describe ( 'given 5-minute interval' , ( ) => {
176153 it ( ':android: clock picker should correct 18-minute selection to 20-minute one' , async ( ) => {
177154 try {
@@ -195,7 +172,7 @@ describe('Example', () => {
195172 }
196173 } ) ;
197174
198- it ( ':android: given picker is shown as a spinner, swiping it down changes selected time' , async ( ) => {
175+ it ( ':android: when the picker is shown as " spinner" , swiping it down changes selected time' , async ( ) => {
199176 try {
200177 const timeText = getTimeText ( ) ;
201178
0 commit comments