Skip to content

Commit 4356fe0

Browse files
authored
Add Snapshot Testing to TabList (#3000)
* Set up snapshot tests * Mock calls * Use fake timer * Change files * Add more cases * Add test comments * Split TabList and Tab snapshot tests * Remove fakeTimer call in Tab test
1 parent a94549d commit 4356fe0

File tree

9 files changed

+3521
-4
lines changed

9 files changed

+3521
-4
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Add snapshot testing to TabList",
4+
"packageName": "@fluentui-react-native/tablist",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const { configureReactNativeJest } = require('@fluentui-react-native/scripts');
2+
module.exports = configureReactNativeJest('win32');
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import * as React from 'react';
2+
3+
import { checkReRender } from '@fluentui-react-native/test-tools';
4+
import * as renderer from 'react-test-renderer';
5+
6+
import Tab from '../Tab';
7+
8+
describe('Tab component tests', () => {
9+
it('Tab default props', () => {
10+
const tree = renderer.create(<Tab tabKey="1">Tab 1</Tab>).toJSON();
11+
expect(tree).toMatchSnapshot();
12+
});
13+
14+
it('Tab disabled', () => {
15+
const tree = renderer
16+
.create(
17+
<Tab tabKey="1" disabled>
18+
Tab 1
19+
</Tab>,
20+
)
21+
.toJSON();
22+
expect(tree).toMatchSnapshot();
23+
});
24+
25+
it('Tab render icon only', () => {
26+
const tree = renderer
27+
.create(
28+
<Tab
29+
icon={{
30+
fontSource: {
31+
fontFamily: 'Arial',
32+
codepoint: 0x2663,
33+
},
34+
}}
35+
tabKey="1"
36+
/>,
37+
)
38+
.toJSON();
39+
expect(tree).toMatchSnapshot();
40+
});
41+
42+
it('Tab render icon + text', () => {
43+
const tree = renderer
44+
.create(
45+
<Tab
46+
icon={{
47+
fontSource: {
48+
fontFamily: 'Arial',
49+
codepoint: 0x2663,
50+
},
51+
}}
52+
tabKey="1"
53+
>
54+
Tab 1
55+
</Tab>,
56+
)
57+
.toJSON();
58+
expect(tree).toMatchSnapshot();
59+
});
60+
61+
it('Customized Tab', () => {
62+
const CustomTab = Tab.customize({
63+
variant: 'headerSemibold',
64+
stackMarginVertical: 16,
65+
stackMarginHorizontal: 16,
66+
indicatorThickness: 4,
67+
color: 'red',
68+
});
69+
const tree = renderer.create(<CustomTab tabKey="1">Tab 1</CustomTab>);
70+
expect(tree).toMatchSnapshot();
71+
});
72+
73+
it('Tab re-renders correctly', () => {
74+
checkReRender(
75+
() => (
76+
<Tab tabKey="1" accessibilityPositionInSet={1}>
77+
Tab 1
78+
</Tab>
79+
),
80+
2,
81+
);
82+
});
83+
});

0 commit comments

Comments
 (0)