-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathtabListTest.js
107 lines (97 loc) · 3.43 KB
/
tabListTest.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
import React from 'react';
import { TabListStyle } from '../src/TabList';
import { mount } from 'enzyme';
import toJson from 'enzyme-to-json';
import 'jest-styled-components';
import styled from 'styled-components';
import {BulletIcon, RightIcon} from '../src/IconSvg';
const tabListTest = (type, TabListComponent, TabComponent) => {
const shareComponent = props => (
<TabListComponent {...props} customStyle={{}}>
<TabComponent>Tab1</TabComponent>
<TabComponent>Tab2</TabComponent>
</TabListComponent>
);
test(`render ${type} List`, () => {
const component = mount(
<TabListComponent customStyle={{}}>
<TabComponent>Tab1</TabComponent>
</TabListComponent>
);
expect(toJson(component)).toMatchSnapshot();
})
test('custom ListStyle style', () => {
const CustomListStyle = styled(TabListStyle)`
background-color: red;
`;
const component = mount(
<TabListComponent customStyle={{CustomTabList: CustomListStyle}}>
<TabComponent>Tab1</TabComponent>
</TabListComponent>
);
expect(toJson(component)).toMatchSnapshot();
})
describe('showModalButton', () => {
const returnMountedButton = showModalButton => {
const component = mount(shareComponent({showModalButton}));
return component.find(BulletIcon);
}
it('default: true => show', () => {
expect(returnMountedButton(true)).toHaveLength(1);
})
it('false', () => {
expect(returnMountedButton(false)).toHaveLength(0);
})
describe('number', () => {
it('2', () => {
expect(returnMountedButton(2)).toHaveLength(1);
})
it('100', () => {
expect(returnMountedButton(100)).toHaveLength(0);
})
it('show modal button when new tab is added', () => {
const component = mount(shareComponent({showModalButton: 4}));
expect(component.html().includes('svg')).toEqual(false);
component.setProps({children: [
<TabComponent key={1}>Tab1</TabComponent>,
<TabComponent key={2}>Tab2</TabComponent>,
<TabComponent key={3}>Tab3</TabComponent>,
<TabComponent key={4}>Tab4</TabComponent>
]});
expect(component.html().includes('svg')).toEqual(true);
})
})
})
describe('showArrowButton', () => {
const returnMountedButton = showArrowButton => {
const component = mount(shareComponent({showArrowButton}));
return component.find(RightIcon);
}
// because in test env it's containerWidth = 0, it always show arrow
it('auto', () => {
expect(returnMountedButton('auto')).toHaveLength(1);
})
it('true', () => {
expect(returnMountedButton(true)).toHaveLength(1);
})
it('false', () => {
expect(returnMountedButton(false)).toHaveLength(0);
})
})
// the reason to test closable button at TabList not at Tab component
// is because `DragTab` need to be wrapped by `DragTabList`
it('click close button', () => {
const mockTabChange = jest.fn();
const component = mount(
<TabListComponent handleEdit={mockTabChange} customStyle={{}}>
<TabComponent closable>Tab1</TabComponent>
<TabComponent closable>Tab2</TabComponent>
</TabListComponent>
);
const btn1 = component.find('CloseButton').at(1);
btn1.simulate('click');
expect(mockTabChange).toBeCalled();
expect(mockTabChange.mock.calls[0][0]).toEqual({type: 'delete', index: 1});
})
}
export default tabListTest;