forked from callstack/react-native-paper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBottomNavigation.test.js
168 lines (147 loc) · 4.12 KB
/
BottomNavigation.test.js
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import * as React from 'react';
import renderer from 'react-test-renderer';
import BottomNavigation from '../BottomNavigation.tsx';
// Make sure any animation finishes before checking the snapshot results
jest.mock('react-native', () => {
const RN = jest.requireActual('react-native');
RN.Animated.timing = (value, config) => ({
start: callback => {
value.setValue(config.toValue);
callback && callback({ finished: true });
},
});
return RN;
});
const icons = ['magnify', 'camera', 'inbox', 'heart', 'shopping-music'];
const createState = (index, length) => ({
index,
routes: Array.from({ length }, (_, i) => ({
key: `key-${i}`,
icon: icons[i],
title: `Route: ${i}`,
})),
});
it('renders shifting bottom navigation', () => {
const tree = renderer
.create(
<BottomNavigation
shifting
navigationState={createState(0, 5)}
onIndexChange={jest.fn()}
renderScene={({ route }) => route.title}
/>
)
.toJSON();
expect(tree).toMatchSnapshot();
});
it('renders non-shifting bottom navigation', () => {
const tree = renderer
.create(
<BottomNavigation
shifting={false}
navigationState={createState(0, 3)}
onIndexChange={jest.fn()}
renderScene={({ route }) => route.title}
/>
)
.toJSON();
expect(tree).toMatchSnapshot();
});
it('renders custom icon and label in shifting bottom navigation', () => {
const tree = renderer
.create(
<BottomNavigation
shifting
navigationState={createState(0, 5)}
onIndexChange={jest.fn()}
renderScene={({ route }) => route.title}
renderIcon={({ route, color }) => (
<icon color={color}>{route.icon}</icon>
)}
renderLabel={({ route, color }) => (
<text color={color}>{route.label}</text>
)}
/>
)
.toJSON();
expect(tree).toMatchSnapshot();
});
it('renders custom icon and label in non-shifting bottom navigation', () => {
const tree = renderer
.create(
<BottomNavigation
shifting={false}
navigationState={createState(0, 3)}
onIndexChange={jest.fn()}
renderScene={({ route }) => route.title}
renderIcon={({ route, color }) => (
<icon color={color}>{route.icon}</icon>
)}
renderLabel={({ route, color }) => (
<text color={color}>{route.label}</text>
)}
/>
)
.toJSON();
expect(tree).toMatchSnapshot();
});
it('renders custom icon and label with custom colors in shifting bottom navigation', () => {
const tree = renderer
.create(
<BottomNavigation
shifting
navigationState={createState(0, 3)}
onIndexChange={jest.fn()}
renderScene={({ route }) => route.title}
activeColor="#FBF7DB"
inactiveColor="#853D4B"
barStyle={{ backgroundColor: '#E96A82' }}
/>
)
.toJSON();
expect(tree).toMatchSnapshot();
});
it('renders custom icon and label with custom colors in non-shifting bottom navigation', () => {
const tree = renderer
.create(
<BottomNavigation
shifting={false}
navigationState={createState(0, 3)}
onIndexChange={jest.fn()}
renderScene={({ route }) => route.title}
activeColor="#FBF7DB"
inactiveColor="#853D4B"
barStyle={{ backgroundColor: '#E96A82' }}
/>
)
.toJSON();
expect(tree).toMatchSnapshot();
});
it('hides labels in shifting bottom navigation', () => {
const tree = renderer
.create(
<BottomNavigation
shifting
labeled={false}
navigationState={createState(0, 3)}
onIndexChange={jest.fn()}
renderScene={({ route }) => route.title}
/>
)
.toJSON();
expect(tree).toMatchSnapshot();
});
it('hides labels in non-shifting bottom navigation', () => {
const tree = renderer
.create(
<BottomNavigation
shifting={false}
labeled={false}
navigationState={createState(0, 3)}
onIndexChange={jest.fn()}
renderScene={({ route }) => route.title}
/>
)
.toJSON();
expect(tree).toMatchSnapshot();
});