Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit c4488ad

Browse files
committed
add: create tests for BottomTabBar and TabBarButton components to verify rendering and interaction
1 parent 675e36f commit c4488ad

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { render } from '@testing-library/react-native';
2+
import BottomTabBar from '@/components/tabbar/BottomTabBar';
3+
import { BottomTabBarProps } from '@react-navigation/bottom-tabs';
4+
5+
describe('BottomTabBar Component', () => {
6+
it('should render all tabs', () => {
7+
const mockProps: BottomTabBarProps = {
8+
state: {
9+
index: 0,
10+
routes: [
11+
{ key: 'home', name: 'Home', params: undefined },
12+
{ key: 'recipients', name: 'Recipients', params: undefined },
13+
{ key: 'settings', name: 'Settings', params: undefined },
14+
],
15+
type: 'tab',
16+
stale: false,
17+
key: 'tab-key',
18+
routeNames: ['Home', 'Recipients', 'Settings'],
19+
history: [],
20+
preloadedRouteKeys: [],
21+
},
22+
descriptors: {
23+
home: {
24+
options: { title: 'Home', tabBarIcon: undefined },
25+
render: jest.fn(),
26+
route: { key: 'home', name: 'Home', params: undefined },
27+
navigation: jest.fn() as any,
28+
},
29+
recipients: {
30+
options: { title: 'Recipients', tabBarIcon: undefined },
31+
render: jest.fn(),
32+
route: { key: 'recipients', name: 'Recipients', params: undefined },
33+
navigation: jest.fn() as any,
34+
},
35+
settings: {
36+
options: { title: 'Settings', tabBarIcon: undefined },
37+
render: jest.fn(),
38+
route: { key: 'settings', name: 'Settings', params: undefined },
39+
navigation: jest.fn() as any,
40+
},
41+
},
42+
navigation: {
43+
emit: jest.fn(),
44+
navigate: jest.fn(),
45+
reset: jest.fn(),
46+
goBack: jest.fn(),
47+
isFocused: jest.fn(),
48+
canGoBack: jest.fn(),
49+
getParent: jest.fn(),
50+
setParams: jest.fn(),
51+
getState: jest.fn(),
52+
dispatch: jest.fn(),
53+
navigateDeprecated: jest.fn(),
54+
preload: jest.fn(),
55+
getId: jest.fn(),
56+
setStateForNextRouteNamesChange: jest.fn(),
57+
} as any,
58+
insets: {
59+
top: 0,
60+
left: 0,
61+
right: 0,
62+
bottom: 0,
63+
},
64+
};
65+
66+
const { getByText } = render(<BottomTabBar {...mockProps} />);
67+
expect(getByText('Home')).toBeTruthy();
68+
expect(getByText('Recipients')).toBeTruthy();
69+
expect(getByText('Settings')).toBeTruthy();
70+
});
71+
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { fireEvent, render } from '@testing-library/react-native';
2+
3+
import TabBarButton from '@/components/tabbar/TabBarButton';
4+
5+
describe('TabBarButton Component', () => {
6+
it('should render the button with the correct label', () => {
7+
const mockProps = {
8+
label: 'Home',
9+
isFocused: false,
10+
onPress: jest.fn(),
11+
tabBarActiveTintColor: '#4B6BFB',
12+
tabBarInactiveTintColor: '#666',
13+
};
14+
15+
const { getByText } = render(<TabBarButton {...mockProps} />);
16+
expect(getByText('Home')).toBeTruthy();
17+
});
18+
19+
it('should trigger onPress when the button is clicked', () => {
20+
const mockOnPress = jest.fn();
21+
const mockProps = {
22+
label: 'Home',
23+
isFocused: false,
24+
onPress: mockOnPress,
25+
tabBarActiveTintColor: '#4B6BFB',
26+
tabBarInactiveTintColor: '#666',
27+
};
28+
29+
const { getByText } = render(<TabBarButton {...mockProps} />);
30+
fireEvent.press(getByText('Home'));
31+
expect(mockOnPress).toHaveBeenCalled();
32+
});
33+
});

0 commit comments

Comments
 (0)