-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathTabsIconTab.test.tsx
More file actions
124 lines (112 loc) · 3.54 KB
/
TabsIconTab.test.tsx
File metadata and controls
124 lines (112 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Third party dependencies.
import React from 'react';
import { render, fireEvent } from '@testing-library/react-native';
// Internal dependencies.
import TabsIconTab from './TabsIconTab';
import { IconName } from '../../../components/Icons/Icon/Icon.types';
describe('TabsIconTab', () => {
const defaultProps = {
label: 'Portfolio',
iconName: IconName.PieChart,
isActive: false,
onPress: jest.fn(),
};
beforeEach(() => {
jest.clearAllMocks();
});
describe('Rendering', () => {
it('renders with testID', () => {
const { getByTestId } = render(
<TabsIconTab {...defaultProps} testID="tab" />,
);
expect(getByTestId('tab')).toBeOnTheScreen();
});
it('displays the label text', () => {
const { getByText } = render(<TabsIconTab {...defaultProps} />);
expect(getByText('Portfolio')).toBeOnTheScreen();
});
});
describe('Active State', () => {
it('renders enabled when isActive is true', () => {
const { getByTestId } = render(
<TabsIconTab {...defaultProps} isActive testID="active-tab" />,
);
expect(
getByTestId('active-tab').props.accessibilityState?.disabled,
).toBeFalsy();
});
it('renders enabled when isActive is false', () => {
const { getByTestId } = render(
<TabsIconTab
{...defaultProps}
isActive={false}
testID="inactive-tab"
/>,
);
expect(
getByTestId('inactive-tab').props.accessibilityState?.disabled,
).toBeFalsy();
});
});
describe('Disabled State', () => {
it('sets disabled accessibility state when isDisabled is true', () => {
const { getByTestId } = render(
<TabsIconTab {...defaultProps} isDisabled testID="disabled-tab" />,
);
expect(
getByTestId('disabled-tab').props.accessibilityState?.disabled,
).toBe(true);
});
it('does not call onPress when disabled', () => {
const mockOnPress = jest.fn();
const { getByText } = render(
<TabsIconTab {...defaultProps} onPress={mockOnPress} isDisabled />,
);
fireEvent.press(getByText('Portfolio'));
expect(mockOnPress).not.toHaveBeenCalled();
});
});
describe('Interaction', () => {
it('calls onPress when pressed and not disabled', () => {
const mockOnPress = jest.fn();
const { getByTestId } = render(
<TabsIconTab {...defaultProps} onPress={mockOnPress} testID="tab" />,
);
fireEvent.press(getByTestId('tab'));
expect(mockOnPress).toHaveBeenCalledTimes(1);
});
});
describe('Layout and Callbacks', () => {
it('calls onLayout callback when layout changes', () => {
const mockOnLayout = jest.fn();
const layoutEvent = {
nativeEvent: { layout: { x: 0, y: 0, width: 100, height: 60 } },
};
const { getByTestId } = render(
<TabsIconTab
{...defaultProps}
onLayout={mockOnLayout}
testID="layout-tab"
/>,
);
fireEvent(getByTestId('layout-tab'), 'onLayout', layoutEvent);
expect(mockOnLayout).toHaveBeenCalledWith(layoutEvent);
});
});
describe('Icon', () => {
it('renders all supported icon names without throwing', () => {
const icons: IconName[] = [
IconName.PieChart,
IconName.Candlestick,
IconName.Predictions,
];
icons.forEach((icon) => {
expect(() =>
render(
<TabsIconTab {...defaultProps} iconName={icon} testID="icon-tab" />,
),
).not.toThrow();
});
});
});
});