Skip to content

Commit ee8a35a

Browse files
committed
Add tests for MUI tabs
1 parent 5794348 commit ee8a35a

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React from 'react';
2+
import { mount } from 'enzyme';
3+
import AppBar from '@material-ui/core/AppBar';
4+
import Tabs from '@material-ui/core/Tabs';
5+
import Tab from '@material-ui/core/Tab';
6+
7+
import FormTabs from '../form-fields/tabs';
8+
9+
describe('tabs', () => {
10+
const props = {
11+
fields: [
12+
{
13+
key: 'cosiKey',
14+
title: 'cosiTitle',
15+
name: 'cosiName',
16+
fields: [],
17+
},
18+
{
19+
key: 'cosiKey2',
20+
title: 'cosiTitle2',
21+
name: 'cosiName2',
22+
fields: [],
23+
},
24+
],
25+
formOptions: {
26+
renderForm: jest.fn().mockImplementation(() => <h1>Content</h1>),
27+
},
28+
};
29+
30+
it('should render tabs correctly', () => {
31+
const wrapper = mount(<FormTabs { ...props } />);
32+
33+
expect(wrapper.find(AppBar)).toHaveLength(1);
34+
expect(wrapper.find(Tabs)).toHaveLength(1);
35+
expect(wrapper.find(Tab)).toHaveLength(2);
36+
expect(wrapper.find('h1')).toHaveLength(1);
37+
});
38+
39+
it('should switch tabs correctly', () => {
40+
const wrapper = mount(<FormTabs { ...props } />);
41+
expect(wrapper.instance().state.activeTab).toEqual(0);
42+
43+
const secondTabButton = wrapper.find('button').last();
44+
secondTabButton.simulate('click');
45+
46+
expect(wrapper.instance().state.activeTab).toEqual(1);
47+
});
48+
});

0 commit comments

Comments
 (0)