ttdung11t2 / react-native-confirmation-code-input

A react-native component to input confirmation code for both Android and IOS
MIT License
411 stars 349 forks source link

How to test with detox? #60

Open oliviayizhang opened 5 years ago

oliviayizhang commented 5 years ago

Is there a way to do detox test with this library? I have no luck finding the element/type text because the code input component doesn't expose individual input and doesn't support testID too.

dillonchr commented 5 years ago

This might not be your blocker, but for me I just needed to input the code and get to the next screen to keep my test flow going. I just wound up targeting the parent view and sending the keystrokes there. Worked to get me past the screen but it doesn't give you any deep control with the CodeInput itself. Just a stop-gap.

//  component
import React from 'react'
import { View } from 'react-native'
const Screen = () => (
  <View testID={`parent-view-id`}>
    <CodeInput />
  </View>
)
//  spec
describe('component with code input', () => {
  it('should type in code', () => {
    await element(by.id(`parent-view-id`)).typeText('123456')
  })
})
maxkomarychev commented 4 years ago

@dillonchr this approach doesn't work for me. which version of library and detox are you trying?

dillonchr commented 4 years ago

@dillonchr this approach doesn't work for me. which version of library and detox are you trying?

@maxkomarychev we're using detox@^14.3.4 and react-native@0.59.10 oh and it turns out we're using a branch of react-native-confirmation-code-input@1.0.1. https://github.com/marketforces/react-native-confirmation-code-input so maybe in the changes we made to width being able to copy and paste helped us out along the way. Not sure on what would cause the difference.

retyui commented 4 years ago

@oliviayizhang You can use a fork without this problem https://github.com/retyui/react-native-confirmation-code-field

sebastianpaz commented 4 years ago

Hey @dillonchr @oliviayizhang Firstly, set testID={CODE_INPUT} in the code input component (the matcher will return n TextFields, being n your code length. Then use forEach to write one code character or number in each TextField individually per iteration.

const code = '123456';
const codeSplit = code.split('');
codeSplit.forEach(async (number, index) => {
  await element(by.id(CODE_INPUT)).atIndex(index).typeText(number);
 });
});
Moustafa-mahmaed commented 3 years ago

pass value one to one

 await element(by.id('CodeInput')).atIndex(0).typeText("1");
 await element(by.id('CodeInput')).atIndex(1).typeText("1");
 await element(by.id('CodeInput')).atIndex(2).typeText("1");
 await element(by.id('CodeInput')).atIndex(3).typeText("1");