Skip to content

Commit 5f2e364

Browse files
remove setting related to moreButton plugin from default
setting and set them at moreButton plugin
1 parent 67cbbfc commit 5f2e364

File tree

6 files changed

+40
-17
lines changed

6 files changed

+40
-17
lines changed

src/plugins/moreButtonPlugin/button/button.test.js

+17-11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ import components from '../../../components/index.js';
88
import CTx from '../../../utils/api/index.js';
99
import Api from './api.js';
1010
import {ApiContext, StateContext} from '../../../context.js';
11+
import {setSetting} from '../setComponents.js';
12+
const getIns = (op) => {
13+
const ins = new CTx(op);
14+
setSetting(ins);
15+
return ins;
16+
};
1117
let container = document.createElement('div');
1218
const getButton = (ctx) =>
1319
memo(
@@ -29,7 +35,7 @@ beforeAll(() => {
2935
});
3036
let userProxy = {};
3137
beforeEach(() => {
32-
const ins = new CTx({
38+
const ins = getIns({
3339
options: {},
3440
});
3541
userProxy = ins.userProxy;
@@ -45,7 +51,7 @@ afterAll(() => {
4551
describe('Enable Accesibility : ', () => {
4652
test('DEFAULT:', () => {
4753
const Button = getButton(
48-
new CTx({
54+
getIns({
4955
options: {
5056
moreButtonPlugin_iconComponent,
5157
},
@@ -62,7 +68,7 @@ describe('Enable Accesibility : ', () => {
6268
});
6369
test('MULTIPLE BUTTON SHOULD NOT HAVE SAME ID:', () => {
6470
const Button = getButton(
65-
new CTx({
71+
getIns({
6672
options: {
6773
moreButtonPlugin_iconComponent,
6874
},
@@ -82,7 +88,7 @@ describe('Enable Accesibility : ', () => {
8288
describe('DISABLE ACCESIBILITY : ', () => {
8389
test('DEFAULT:', () => {
8490
const Button = getButton(
85-
new CTx({
91+
getIns({
8692
options: {
8793
moreButtonPlugin_iconComponent,
8894
accessibility: false,
@@ -102,7 +108,7 @@ describe('DISABLE ACCESIBILITY : ', () => {
102108
describe('OPEN AND CLOSE POPPER:', () => {
103109
test('BUTTON CLICK:', () => {
104110
const Button = getButton(
105-
new CTx({
111+
getIns({
106112
options: {
107113
moreButtonPlugin_iconComponent,
108114
//accessibility: false,
@@ -130,7 +136,7 @@ describe('OPEN AND CLOSE POPPER:', () => {
130136
});
131137
test('document click:', () => {
132138
const Button = getButton(
133-
new CTx({
139+
getIns({
134140
options: {
135141
moreButtonPlugin_iconComponent,
136142
},
@@ -156,7 +162,7 @@ describe('OPEN AND CLOSE POPPER:', () => {
156162
expect(getBtn().getAttribute('aria-expanded') == 'true').toBe(false);
157163
});
158164
test('select tab:', () => {
159-
const ins = new CTx({
165+
const ins = getIns({
160166
options: {
161167
moreButtonPlugin_iconComponent,
162168
},
@@ -189,7 +195,7 @@ describe('OPEN AND CLOSE POPPER:', () => {
189195
ref._cleanSelectEvent = jest.fn(() => {});
190196
return ref;
191197
};
192-
const ins = new CTx({
198+
const ins = getIns({
193199
options: {
194200
moreButtonPlugin_iconComponent,
195201
},
@@ -231,7 +237,7 @@ describe('TABS COMPONENT:', () => {
231237
buttonApi = (Api.default || Api).call(this, components, setOpen);
232238
return buttonApi;
233239
};
234-
const ins = new CTx({
240+
const ins = getIns({
235241
options: {
236242
moreButtonPlugin_iconComponent,
237243
selectedTabID: '1',
@@ -279,7 +285,7 @@ describe('TABS COMPONENT:', () => {
279285
buttonApi = (Api.default || Api).call(this, components, setOpen);
280286
return buttonApi;
281287
};
282-
const ins = new CTx({
288+
const ins = getIns({
283289
options: {
284290
moreButtonPlugin_iconComponent,
285291
selectedTabID: '1',
@@ -327,7 +333,7 @@ describe('TABS COMPONENT:', () => {
327333
buttonApi = (Api.default || Api).call(this, components, setOpen);
328334
return buttonApi;
329335
};
330-
const ins = new CTx({
336+
const ins = getIns({
331337
options: {
332338
moreButtonPlugin_iconComponent,
333339
selectedTabID: '1',

src/plugins/moreButtonPlugin/setComponents.js

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, {memo} from 'react';
22
import PropTypes from 'prop-types';
33
export default function setComponents(deps, ctx, components) {
44
const {moreButtonPlugin_buttonComponent, ShowMoreTabs, moreButtonPlugin_iconComponent} = deps;
5+
setComponents.setSetting(ctx);
56
setComponents.setDefaultOptions(ctx, components, moreButtonPlugin_buttonComponent, moreButtonPlugin_iconComponent);
67
setComponents.setTablistView(components);
78
setComponents.setMoreButtonPlugin(ctx, components, ShowMoreTabs, setComponents.ShowMoreButton, memo);
@@ -71,3 +72,8 @@ export const setDefaultOptions = (setComponents.setDefaultOptions = function (
7172
ctx.optionsManager.options,
7273
);
7374
});
75+
export const setSetting = (setComponents.setSetting = function (ctx) {
76+
ctx.optionsManager.setting.showMoreContainerClass = 'rc-dyn-tabs-showmorebutton-container';
77+
ctx.optionsManager.setting.showMoreButtonClass = 'rc-dyn-tabs-showmorebutton';
78+
ctx.optionsManager.setting.showMorePopperClass = 'rc-dyn-tabs-popper';
79+
});

src/plugins/moreButtonPlugin/setComponents.test.js

+15
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import showMorePlugin, {
77
setTablistOverflow,
88
setTablistView,
99
setDefaultOptions,
10+
setSetting,
1011
} from './setComponents.js';
1112
beforeAll(() => {});
1213
beforeEach(() => {});
@@ -82,12 +83,24 @@ describe('showMorePlugin ', () => {
8283
expect(moreButtonPlugin_buttonComponent.mock.calls.length).toBe(1);
8384
expect(moreButtonPlugin_buttonComponent.mock.calls[0][0]).toEqual({ctx, components});
8485
});
86+
test('setSetting : ', () => {
87+
const ctx = {
88+
optionsManager: {
89+
setting: {},
90+
},
91+
};
92+
setSetting(ctx);
93+
expect(ctx.optionsManager.setting.showMoreContainerClass).toBe('rc-dyn-tabs-showmorebutton-container');
94+
expect(ctx.optionsManager.setting.showMoreButtonClass).toBe('rc-dyn-tabs-showmorebutton');
95+
expect(ctx.optionsManager.setting.showMorePopperClass).toBe('rc-dyn-tabs-popper');
96+
});
8597
test('constructor : ', () => {
8698
showMorePlugin.ShowMoreButton = jest.fn(() => {});
8799
showMorePlugin.setMoreButtonPlugin = jest.fn(() => {});
88100
showMorePlugin.setTablistOverflow = jest.fn(() => {});
89101
showMorePlugin.setTablistView = jest.fn(() => {});
90102
showMorePlugin.setDefaultOptions = jest.fn(() => {});
103+
showMorePlugin.setSetting = jest.fn(() => {});
91104
const deps = {
92105
moreButtonPlugin_buttonComponent: 'moreButtonPlugin_buttonComponent',
93106
ShowMoreTabs: 'ShowMoreTabs',
@@ -96,10 +109,12 @@ describe('showMorePlugin ', () => {
96109
const ctx = {};
97110
const components = {};
98111
showMorePlugin(deps, ctx, components);
112+
expect(showMorePlugin.setSetting.mock.calls.length).toBe(1);
99113
expect(showMorePlugin.setDefaultOptions.mock.calls.length).toBe(1);
100114
expect(showMorePlugin.setTablistView.mock.calls.length).toBe(1);
101115
expect(showMorePlugin.setMoreButtonPlugin.mock.calls.length).toBe(1);
102116
expect(showMorePlugin.setTablistOverflow.mock.calls.length).toBe(1);
117+
expect(showMorePlugin.setSetting).toHaveBeenCalledBefore(showMorePlugin.setDefaultOptions);
103118
expect(showMorePlugin.setDefaultOptions).toHaveBeenCalledBefore(showMorePlugin.setTablistView);
104119
expect(showMorePlugin.setTablistView).toHaveBeenCalledBefore(showMorePlugin.setMoreButtonPlugin);
105120
expect(showMorePlugin.setMoreButtonPlugin).toHaveBeenCalledBefore(showMorePlugin.setTablistOverflow);

src/plugins/moreButtonPlugin/show-more-tabs/show-more-tabs.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import renderer from 'react-test-renderer';
77
import Api from './api.js';
88
import tabsMoreButton from 'tabs-more-button';
99
import Ctx from '../../../utils/api/index.js';
10+
import {setSetting} from '../setComponents.js';
1011
let container = document.createElement('div');
1112
const moreButtonPlugin_buttonComponent = (props) => <div {...props}>{props.children}</div>;
1213
const ctx = new Ctx({
@@ -19,6 +20,7 @@ const ctx = new Ctx({
1920
],
2021
},
2122
});
23+
setSetting(ctx);
2224
/**
2325
* render the app
2426
* @param {boolean} snapshot - if true then returns the element

src/utils/api/optionManager/optionManager.factory.js

-3
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ export default Helper.module(
9292
tablistContainerClass: 'rc-dyn-tabs-tablist-container',
9393
tablistOverflowClass: 'rc-dyn-tabs-tablist-overflow',
9494
tablistClass: 'rc-dyn-tabs-tablist',
95-
showMoreContainerClass: 'rc-dyn-tabs-showmorebutton-container',
96-
showMoreButtonClass: 'rc-dyn-tabs-showmorebutton',
97-
showMorePopperClass: 'rc-dyn-tabs-popper',
9895
panelIdTemplate: (id) => `rc-dyn-tabs-p-${id}`,
9996
ariaLabelledbyIdTemplate: (id) => `rc-dyn-tabs-l-${id}`,
10097
getDefaultTabData: () => {

src/utils/api/optionManager/optionManager.test.js

-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ describe('OptionManager constructor : ', () => {
6161
tablistContainerClass: 'rc-dyn-tabs-tablist-container',
6262
tablistOverflowClass: 'rc-dyn-tabs-tablist-overflow',
6363
tablistClass: 'rc-dyn-tabs-tablist',
64-
showMoreContainerClass: 'rc-dyn-tabs-showmorebutton-container',
65-
showMoreButtonClass: 'rc-dyn-tabs-showmorebutton',
66-
showMorePopperClass: 'rc-dyn-tabs-popper',
6764
panelIdTemplate: function () {},
6865
ariaLabelledbyIdTemplate: function () {},
6966
getDefaultTabData: function () {},

0 commit comments

Comments
 (0)