react-native-ui-lib
Version:
<p align="center"> <img src="https://user-images.githubusercontent.com/1780255/105469025-56759000-5ca0-11eb-993d-3568c1fd54f4.png" height="250px" style="display:block"/> </p> <p align="center">UI Toolset & Components Library for React Native</p> <p a
89 lines (85 loc) • 3.07 kB
JavaScript
import { fireEvent } from '@testing-library/react-native';
import TextDriver from "../../components/text/Text.driver";
import _ from 'lodash';
const TextFieldDriverFactory = async ({
wrapperComponent,
testID
}) => {
const textInput = await wrapperComponent.queryByTestId(testID);
const label = await TextDriver({
wrapperComponent,
testID: `${testID}.label`
});
const validationMsg = await TextDriver({
wrapperComponent,
testID: `${testID}.validationMessage`
});
const floatingPlaceholder = await TextDriver({
wrapperComponent,
testID: `${testID}.floatingPlaceholder`
});
const charCounter = await TextDriver({
wrapperComponent,
testID: `${testID}.charCounter`
});
function isPlaceholderVisible() {
if (textInput) {
const hasPlaceholderProp = !!_.get(textInput, 'props.placeholder');
const hasInputText = !!_.get(textInput, 'props.value');
return hasPlaceholderProp && (!hasInputText || hasInputText && floatingPlaceholder.exists());
} else {
console.warn(`TextField component with testId:${testID}, is not found. So you can't get his placeholder`);
}
}
return {
exists: () => !!textInput,
getRootElement: () => textInput,
content: () => {
if (textInput) {
return textInput.props.value;
} else {
console.warn(`TextField component with testId:${testID}, is not found. So you can't get the content`);
return null;
}
},
isDisabled: () => {
if (textInput) {
return _.get(textInput, 'props.accessibilityState.disabled');
} else {
console.warn(`TextField component with testId:${testID}, is not found. So you can't get the content`);
return null;
}
},
changeText: text => {
if (textInput) {
fireEvent.changeText(textInput, text);
} else {
console.warn(`TextFieldDriverFactory: cannot change text because testID:${testID} were not found`);
}
},
// placeholder
isPlaceholderVisible,
getPlaceholderContent: () => {
if (isPlaceholderVisible()) {
return _.get(textInput, 'props.placeholder');
} else {
console.warn(`You cant get placeholder content, cause placeholder is not visible.`);
return null;
}
},
// label
getLabelRootElement: () => label.getRootElement(),
isLabelExists: () => label.exists() && !floatingPlaceholder.exists(),
getLabelContent: () => label.getTextContent(),
// validation message
getValidationMsgRootElement: () => validationMsg.getRootElement(),
isValidationMsgExists: () => validationMsg.exists() && !_.isEmpty(validationMsg.getTextContent()),
getValidationMsgContent: () => validationMsg.getTextContent(),
//leadingAccessory, trailingAccessory, bottomAccessory
// char counter
getCharCounterRootElement: () => charCounter.getRootElement(),
isCharCounterExists: () => charCounter.exists(),
getCharCounterContent: () => charCounter.getTextContent()
};
};
export default TextFieldDriverFactory;