var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");var _interopRequireWildcard=require("@babel/runtime/helpers/interopRequireWildcard");Object.defineProperty(exports,"__esModule",{value:true});exports.getByAPI=exports.getAllByProps=exports.getAllByText=exports.getAllByType=exports.getAllByName=exports.getByTestId=exports.getByProps=exports.getByText=exports.getByType=exports.getByName=void 0;var React=_interopRequireWildcard(require("react"));var _prettyFormat=_interopRequireDefault(require("pretty-format"));var _errors=require("./errors");var filterNodeByType=function filterNodeByType(node,type){return node.type===type;};var filterNodeByName=function filterNodeByName(node,name){return typeof node.type!=='string'&&(node.type.displayName===name||node.type.name===name);};var getNodeByText=function getNodeByText(node,text){try{var _require=require('react-native'),Text=_require.Text,TextInput=_require.TextInput;return(filterNodeByType(node,Text)||filterNodeByType(node,TextInput))&&(typeof text==='string'?text===node.props.children:text.test(node.props.children));}catch(error){throw(0,_errors.createLibraryNotSupportedError)(error);}};var prepareErrorMessage=function prepareErrorMessage(error){return error.message.replace(/ matching custom predicate[^]*/gm,'');};var getByName=function getByName(instance){return function getByNameFn(name){(0,_errors.logDeprecationWarning)('getByName','getByType');try{return typeof name==='string'?instance.find(function(node){return filterNodeByName(node,name);}):instance.findByType(name);}catch(error){throw new _errors.ErrorWithStack(prepareErrorMessage(error),getByNameFn);}};};exports.getByName=getByName;var getByType=function getByType(instance){return function getByTypeFn(type){try{return instance.findByType(type);}catch(error){throw new _errors.ErrorWithStack(prepareErrorMessage(error),getByTypeFn);}};};exports.getByType=getByType;var getByText=function getByText(instance){return function getByTextFn(text){try{return instance.find(function(node){return getNodeByText(node,text);});}catch(error){throw new _errors.ErrorWithStack(prepareErrorMessage(error),getByTextFn);}};};exports.getByText=getByText;var getByProps=function getByProps(instance){return function getByPropsFn(props){try{return instance.findByProps(props);}catch(error){throw new _errors.ErrorWithStack(prepareErrorMessage(error),getByPropsFn);}};};exports.getByProps=getByProps;var getByTestId=function getByTestId(instance){return function getByTestIdFn(testID){try{return instance.findByProps({testID:testID});}catch(error){throw new _errors.ErrorWithStack(prepareErrorMessage(error),getByTestIdFn);}};};exports.getByTestId=getByTestId;var getAllByName=function getAllByName(instance){return function getAllByNameFn(name){(0,_errors.logDeprecationWarning)('getAllByName','getAllByType');var results=typeof name==='string'?instance.findAll(function(node){return filterNodeByName(node,name);}):instance.findAllByType(name);if(results.length===0){throw new _errors.ErrorWithStack('No instances found',getAllByNameFn);}return results;};};exports.getAllByName=getAllByName;var getAllByType=function getAllByType(instance){return function getAllByTypeFn(type){var results=instance.findAllByType(type);if(results.length===0){throw new _errors.ErrorWithStack('No instances found',getAllByTypeFn);}return results;};};exports.getAllByType=getAllByType;var getAllByText=function getAllByText(instance){return function getAllByTextFn(text){var results=instance.findAll(function(node){return getNodeByText(node,text);});if(results.length===0){throw new _errors.ErrorWithStack("No instances found with text: "+String(text),getAllByTextFn);}return results;};};exports.getAllByText=getAllByText;var getAllByProps=function getAllByProps(instance){return function getAllByPropsFn(props){var results=instance.findAllByProps(props);if(results.length===0){throw new _errors.ErrorWithStack("No instances found with props:\n"+(0,_prettyFormat.default)(props),getAllByPropsFn);}return results;};};exports.getAllByProps=getAllByProps;var getByAPI=function getByAPI(instance){return{getByTestId:getByTestId(instance),getByName:getByName(instance),getByType:getByType(instance),getByText:getByText(instance),getByProps:getByProps(instance),getAllByName:getAllByName(instance),getAllByType:getAllByType(instance),getAllByText:getAllByText(instance),getAllByProps:getAllByProps(instance)};};exports.getByAPI=getByAPI;