Jest单元测试输出:

import React, { useState } from 'react';
import { View, Text, StyleSheet } from 'react-native';
import Iconfont from '@assets/iconfont';
import LColors from '@assets/Strings/LColors';
import { getStatusBarHeight, screenHeight, screenWidth } from '@utils/layout';
import { isBindPhone, getLoginState } from '@utils/auth';
import RouteHelper from '@common/Web/RouteHelper';
import { applyLoginPage } from '@utils/native';
import LTouchableOpacity from './TouchAble/LTouchableOpacity';
import LModal from 'imou-rn/dist/components/LModal';

export default (props) => {
  const iconMap = {
    home: {
      path: 'HomeScreen',
      icon: 'common_nav_home',
      label: '首页',
    },
    category: {
      path: 'SortScreen',
      icon: 'common__moreinfo_cat',
      label: '分类',
    },
    cart: {
      path: 'CartScreen',
      icon: 'common_nav__cart',
      label: '购物车',
      needLogin: true,
    },
    order: {
      path: 'OrderHomeScreen',
      icon: 'common__moreinfo_order',
      label: '商城订单',
      needLogin: true,
    },
    center: {
      path: 'MallCenter',
      icon: 'common__moreinfo_mallcenter',
      label: '我的商城',
      needLogin: true,
    },
    coupon: {
      path: 'MyCouponScreen',
      icon: 'common_moreinfo_coupon',
      label: '优惠券',
      needLogin: true,
    },
  };
  const arr = props.list.map((item) => iconMap[item]);
  const [visible, setVisible] = useState(false);
  const handleJump = async (item) => {
    setVisible(false);
    const isLogin = await getLoginState();
    if (item.needLogin && !isLogin) {
      applyLoginPage();
      return;
    }
    if (item.needLogin) {
      const isBind = await isBindPhone(true);
      if (!isBind) return;
    }
    RouteHelper.navigate(item.path, props.navigation, null);
  };
  return (
    <>
      <LTouchableOpacity
        testID={'m_home_more_lo0c901'}
        sensorsDataParams={{ $element_id: 'm_home_more_lo0c9' }}
        trackInfo={{
          screenName: 'HomeScreen',
          elementInfo: {
            $element_id: `navigation/click_nav_more`,
          },
        }}
        onPress={() => {
          setVisible(!visible);
        }}>
        <Iconfont name="common_nav_moreinfo" size={26} color={props.color} style={props.style} />
      </LTouchableOpacity>
      <LModal
        animationDuration={200}
        animateAppear
        onAnimationEnd={() => {}}
        animationType="slide-down"
        visible={visible}
        popup
        maskClosable
        wrapStyle={{ backgroundColor: 'red', zIndex: 999 }}
        maskStyle={{ width: screenWidth, height: screenHeight }}
        style={{ backgroundColor: 'transparent', zIndex: 999 }}
        bodyStyle={{
          backgroundColor: 'rgba(0, 0, 0, 0.8)',
          borderBottomLeftRadius: 15,
          borderBottomRightRadius: 15,
          paddingTop: props.top || 0,
        }}
        onClose={() => {
          setVisible(false);
        }}>
        <View style={[styles.contentWrapper, { paddingTop: props.top ? 0 : getStatusBarHeight() }]}>
          <View style={styles.titleWrapper}>
            <Text style={styles.titleText}>功能直达</Text>
            <LTouchableOpacity
              sensorsDataParams={{ $element_id: 'm_home_more_close_o0kj9' }}
              onPress={() => {
                setVisible(false);
              }}>
              <Iconfont name="common_nav_cancel" size={26} color={LColors.N7} />
            </LTouchableOpacity>
          </View>
          <View style={styles.wrapper}>
            {arr.map((item, index) => {
              return (
                <LTouchableOpacity
                  sensorsDataParams={{ $element_id: `m_home_more_${index}_vd7m0` }}
                  trackInfo={{
                    screenName: 'HomeScreen',
                    elementInfo: {
                      $element_id: `navigation/click_nav_${index}`,
                    },
                  }}
                  key={index}
                  style={[styles.itemWrapper, index === 0 ? styles.first : '']}
                  onPress={() => {
                    handleJump(item);
                  }}>
                  <Iconfont name={item.icon} size={26} color={LColors.N7} />
                  <Text style={styles.itemText}>{item.label}</Text>
                </LTouchableOpacity>
              );
            })}
          </View>
        </View>
      </LModal>
    </>
  );
};

注意:这是一个React组件,只能在支持React的环境中运行。


原文地址: https://www.cveoy.top/t/topic/hJdP 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录