-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsetComponents.test.js
133 lines (133 loc) · 5.61 KB
/
setComponents.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
/* eslint-disable react/prop-types */
import React from 'react';
import renderer from 'react-test-renderer';
import showMorePlugin, {
ShowMoreButton,
setMoreButtonPlugin,
setTablistOverflow,
setTablistView,
setDefaultOptions,
setSetting,
} from './setComponents.js';
beforeAll(() => {});
beforeEach(() => {});
afterEach(() => {});
afterAll(() => {
showMorePlugin.ShowMoreButton = ShowMoreButton;
showMorePlugin.setMoreButtonPlugin = setMoreButtonPlugin;
showMorePlugin.setTablistOverflow = setTablistOverflow;
showMorePlugin.setTablistView = setTablistView;
showMorePlugin.setDefaultOptions = setDefaultOptions;
});
describe('showMorePlugin ', () => {
test('MoreButtonPlugin : ', () => {
const ctx = {};
const components = {useForceUpdate: () => {}, useRootState: () => ({openTabIDs: ['1', '2'], selectedTabID: '1'})};
const ShowMoreTabs = (props) => <div {...props}>{props.children}</div>;
const memo = jest.fn((fn) => fn);
setMoreButtonPlugin(ctx, components, ShowMoreTabs, ShowMoreButton, memo);
const Com = <components.MoreButtonPlugin customProp="customProp">button children</components.MoreButtonPlugin>;
const tree = renderer.create(Com).toJSON();
expect(tree).toMatchSnapshot();
expect(memo.mock.calls.length).toBe(1);
expect(typeof memo.mock.calls[0][0]).toBe('function');
expect(memo.mock.calls[0][1]()).toBe(true);
});
test('setTablistOverflow only works if the OriginalTablistOverflow property is not existed : ', () => {
const components = {TablistOverflow: '', OriginalTablistOverflow: 1};
setTablistOverflow(components);
expect(components.TablistOverflow).toBe('');
});
test('TablistOverflow : ', () => {
const TablistOverflow = (props) => (
<div id="TablistOverflow" {...props}>
{props.children}
</div>
);
const MoreButtonPlugin = () => <div id="MoreButtonPlugin"></div>;
const components = {TablistOverflow, MoreButtonPlugin};
setTablistOverflow(components);
const Com = <components.TablistOverflow customProp="customProp">tablist</components.TablistOverflow>;
const tree = renderer.create(Com).toJSON();
expect(tree).toMatchSnapshot();
expect(components.OriginalTablistOverflow).toEqual(TablistOverflow);
});
test('TablistView : ', () => {
const components = {
tablistViewPropsManager: () => ({className: ''}),
TablistViewFactory: (getDeps, props) => {
const {tablistViewPropsManager} = getDeps();
return <div {...tablistViewPropsManager()}>{props.children}</div>;
},
};
setTablistView(components);
const Com = <components.TablistView>tablist view children</components.TablistView>;
const tree = renderer.create(Com).toJSON();
expect(tree).toMatchSnapshot();
});
test('setDefaultOptions : ', () => {
const ctx = {
optionsManager: {
options: {},
},
};
const components = {};
const moreButtonPlugin_buttonComponent = jest.fn((obj) =>
obj.components && obj.ctx ? 'moreButtonPlugin_buttonComponent' : '',
);
const moreButtonPlugin_iconComponent = 'moreButtonPlugin_iconComponent';
setDefaultOptions(ctx, components, moreButtonPlugin_buttonComponent, moreButtonPlugin_iconComponent);
expect(ctx.optionsManager.options.moreButtonPlugin_iconComponent).toBe('moreButtonPlugin_iconComponent');
expect(ctx.optionsManager.options.moreButtonPlugin_buttonComponent).toBe('moreButtonPlugin_buttonComponent');
expect(ctx.optionsManager.options.moreButtonPlugin_buttonTooltip).toBe('show more');
expect(moreButtonPlugin_buttonComponent.mock.calls.length).toBe(1);
expect(moreButtonPlugin_buttonComponent.mock.calls[0][0]).toEqual({ctx, components});
});
test('setSetting : ', () => {
const ctx = {
optionsManager: {
setting: {},
},
};
setSetting(ctx);
expect(ctx.optionsManager.setting.showMoreContainerClass).toBe('rc-dyn-tabs-showmorebutton-container');
expect(ctx.optionsManager.setting.showMoreButtonClass).toBe('rc-dyn-tabs-showmorebutton');
expect(ctx.optionsManager.setting.showMorePopperClass).toBe('rc-dyn-tabs-popper');
});
test('constructor : ', () => {
const executionOrder = [];
showMorePlugin.ShowMoreButton = jest.fn(() => {});
showMorePlugin.setMoreButtonPlugin = jest.fn(() => {
executionOrder.push('setMoreButtonPlugin');
});
showMorePlugin.setTablistOverflow = jest.fn(() => {
executionOrder.push('setTablistOverflow');
});
showMorePlugin.setTablistView = jest.fn(() => {
executionOrder.push('setTablistView');
});
showMorePlugin.setDefaultOptions = jest.fn(() => {
executionOrder.push('setDefaultOptions');
});
showMorePlugin.setSetting = jest.fn(() => {
executionOrder.push('setSetting');
});
const deps = {
moreButtonPlugin_buttonComponent: 'moreButtonPlugin_buttonComponent',
ShowMoreTabs: 'ShowMoreTabs',
moreButtonPlugin_iconComponent: 'moreButtonPlugin_iconComponent',
};
const ctx = {};
const components = {};
showMorePlugin(deps, ctx, components);
expect(showMorePlugin.setSetting.mock.calls.length).toBe(1);
expect(showMorePlugin.setDefaultOptions.mock.calls.length).toBe(1);
expect(showMorePlugin.setTablistView.mock.calls.length).toBe(1);
expect(showMorePlugin.setMoreButtonPlugin.mock.calls.length).toBe(1);
expect(showMorePlugin.setTablistOverflow.mock.calls.length).toBe(1);
expect(executionOrder.toString()).toBe(
'setSetting,setDefaultOptions,setTablistView,setMoreButtonPlugin,setTablistOverflow',
);
expect(showMorePlugin.setMoreButtonPlugin.mock.calls[0][3]).toEqual(showMorePlugin.ShowMoreButton);
});
});