import React from 'react'; import { View, Text } from 'react-native'; import { render, fireEvent } from '@testing-library/react-native'; import NavigationMore from '../NavigationMore';

test('renders NavigationMore component', () => { const list = ['home', 'category', 'cart', 'order', 'center', 'coupon']; const navigation = { navigate: jest.fn(), }; const { getByTestId } = render();

// Check if the component renders correctly const component = getByTestId('navigation-more'); expect(component).toBeTruthy();

// Check if the modal is initially hidden const modal = getByTestId('navigation-modal'); expect(modal.props.visible).toBeFalsy();

// Check if the TouchableOpacity for opening the modal is rendered const touchableOpacity = getByTestId('navigation-touchable-opacity'); expect(touchableOpacity).toBeTruthy();

// Check if pressing the TouchableOpacity toggles the visibility of the modal fireEvent.press(touchableOpacity); expect(modal.props.visible).toBeTruthy();

// Check if the TouchableOpacity for closing the modal is rendered const closeTouchableOpacity = getByTestId('navigation-close-touchable-opacity'); expect(closeTouchableOpacity).toBeTruthy();

// Check if pressing the close TouchableOpacity hides the modal fireEvent.press(closeTouchableOpacity); expect(modal.props.visible).toBeFalsy();

// Check if pressing an item TouchableOpacity triggers the handleJump function const itemTouchableOpacity = getByTestId('navigation-item-0-touchable-opacity'); fireEvent.press(itemTouchableOpacity); expect(navigation.navigate).toHaveBeenCalledTimes(1); });


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

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