Skip to content

Commit 28c0cad

Browse files
add getData method and
replace getCopyData method with getData method
1 parent b8bc1f6 commit 28c0cad

File tree

5 files changed

+34
-15
lines changed

5 files changed

+34
-15
lines changed

src/index.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ describe('calling some action inside the events options', () => {
174174
this.select('2');
175175
});
176176
renderApp();
177-
expect(instance.getCopyData().selectedTabID === '2').toBe(true);
177+
expect(instance.getData().selectedTabID === '2').toBe(true);
178178
expect(op.onLoad.mock.calls.length === 1).toBe(true);
179179
expect(op.onInit.mock.calls.length === 2).toBe(true);
180180
expect(op.onChange.mock.calls.length === 1).toBe(true);
@@ -205,7 +205,7 @@ describe('select method : ', () => {
205205
renderApp();
206206
return act(() => {
207207
return instance.select('2').then((result) => {
208-
expect(result.currentData).toEqual(instance.getCopyData());
208+
expect(result.currentData).toEqual(instance.getData());
209209
expect(result.instance).toBe(instance);
210210
expect(document.querySelector('[tab-id="2"]').className.includes('rc-dyn-tabs-selected')).toBe(true);
211211
expect(op.onInit.mock.calls.length === 2).toBe(true);
@@ -230,7 +230,7 @@ describe('select method : ', () => {
230230
return act(() => {
231231
return instance.select('3').then(() => {
232232
expect(document.querySelector('.rc-dyn-tabs-selected') == null).toBe(true);
233-
expect(instance.getCopyData().selectedTabID === '3').toBe(true);
233+
expect(instance.getData().selectedTabID === '3').toBe(true);
234234
expect(op.onChange.mock.calls.length === 1).toBe(true);
235235
expect(op.onInit.mock.calls.length === 2).toBe(true);
236236
});
@@ -258,7 +258,7 @@ describe('close method : ', () => {
258258
renderApp();
259259
return act(() => {
260260
return instance.close('2').then((result) => {
261-
expect(result.currentData).toEqual(instance.getCopyData());
261+
expect(result.currentData).toEqual(instance.getData());
262262
expect(result.instance).toBe(instance);
263263
expect(document.querySelector('[tab-id="1"]').className.includes('rc-dyn-tabs-selected')).toBe(true);
264264
expect(op.onInit.mock.calls.length === 2).toBe(true);
@@ -311,7 +311,7 @@ describe('open method : ', () => {
311311
title: 'tab3',
312312
})
313313
.then((result) => {
314-
expect(result.currentData).toEqual(instance.getCopyData());
314+
expect(result.currentData).toEqual(instance.getData());
315315
expect(result.instance).toBe(instance);
316316
expect(op.onInit.mock.calls.length === 2).toBe(true);
317317
expect(op.onChange.mock.calls.length === 1).toBe(true);
@@ -326,7 +326,7 @@ describe('open method : ', () => {
326326
return instance.open(op.tabs[0]).then(() => {
327327
expect(op.onChange.mock.calls.length === 0).toBe(true);
328328
expect(op.onInit.mock.calls.length === 2).toBe(true);
329-
expect(instance.getCopyData().openTabIDs.length === 2).toBe(true);
329+
expect(instance.getData().openTabIDs.length === 2).toBe(true);
330330
});
331331
});
332332
});
@@ -345,7 +345,7 @@ describe('refresh method : ', () => {
345345
renderApp();
346346
return act(() => {
347347
return instance.refresh().then((result) => {
348-
expect(result.currentData).toEqual(instance.getCopyData());
348+
expect(result.currentData).toEqual(instance.getData());
349349
expect(result.instance).toBe(instance);
350350
expect(op.onInit.mock.calls.length === 2).toBe(true);
351351
expect(op.onChange.mock.calls.length === 0).toBe(true);
@@ -410,7 +410,7 @@ describe('onChange callback : ', () => {
410410
openedTabIDs: [],
411411
closedTabIDs: [],
412412
});
413-
expect(op.onChange.mock.calls[0][0].currentData).toEqual(instance.getCopyData());
413+
expect(op.onChange.mock.calls[0][0].currentData).toEqual(instance.getData());
414414
expect(op.onChange.mock.calls[0][0].previousData).toEqual(instance.getPreviousData());
415415
});
416416
});

src/useDynamicTabs/useDynamicTabs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function useDynamicTabs(getDeps, options = {}) {
3333
api.onChange({newState: state, oldState, closedTabIDs, openedTabIDs, isSwitched});
3434
}, [state]);
3535
useLayoutEffect(() => {
36-
api.trigger('_onFlushEffects', api.userProxy, {currentData: api.getCopyData(), instance: api.userProxy});
36+
api.trigger('_onFlushEffects', api.userProxy, {currentData: api.getData(), instance: api.userProxy});
3737
}, [flushState]);
3838
if (!_ref.TabListComponent)
3939
_ref.TabListComponent = function TabListComponent(props = {}) {

src/utils/api/api.factory.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,12 @@ const _apiProps = {
8383
getCopyPerviousData: function () {
8484
return this.getPreviousData();
8585
},
86-
getCopyData: function () {
86+
getData: function () {
8787
return this.helper.getCopyState(this.stateRef);
8888
},
89+
getCopyData: function () {
90+
return this.getData();
91+
},
8992
isSelected: function (id = missingParamEr('isSelected')) {
9093
return this.stateRef.selectedTabID == id;
9194
},

src/utils/api/api.factory.test.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,12 +420,12 @@ describe('Api.prototype.eventHandlerFactory : ', () => {
420420
}
421421
});
422422
});
423-
describe('Api.prototype.getPreviousData', () => {
423+
describe('Api.prototype.getPreviousData and Api.prototype.getData : ', () => {
424424
test('returned data should be equal to optionsManager.initialState in onLoad event', () => {
425425
expect.assertions(2);
426426
obj.setOption('onLoad', function () {
427427
const previousData = this.getPreviousData();
428-
const data = this.getCopyData();
428+
const data = this.getData();
429429
expect(previousData).toEqual(obj.optionsManager.initialState);
430430
expect(previousData).not.toEqual(data);
431431
});
@@ -435,24 +435,39 @@ describe('Api.prototype.getPreviousData', () => {
435435
test('returned data should be equal to currentData in onLoad event', () => {
436436
expect.assertions(1);
437437
obj.setOption('onLoad', function () {
438-
expect(this.getPreviousData()).toEqual(this.getCopyData());
438+
expect(this.getPreviousData()).toEqual(this.getData());
439439
});
440440
obj.updateStateRef({selectedTabID: 'tab1', openTabIDs: ['tab1', 'tab2']}, () => {});
441441
obj.trigger('onLoad', obj.userProxy);
442442
});
443-
test('In the onLoad event, return data is equal to getInitialState() and getCopyData()', () => {
443+
test('In the onLoad event, return data is equal to getInitialState() and getData()', () => {
444444
expect.assertions(3);
445445
const _state = {selectedTabID: 'tab1', openTabIDs: ['tab1', 'tab2']};
446446
obj.setOption('onLoad', function () {
447447
const previousData = this.getPreviousData();
448-
const data = this.getCopyData();
448+
const data = this.getData();
449449
expect(previousData).toEqual(_state);
450450
expect(previousData).toEqual(data);
451451
expect(previousData !== null).toBe(true);
452452
});
453453
obj.updateStateRef(_state, () => {});
454454
obj.trigger('onLoad', obj.userProxy);
455455
});
456+
test('getCopyData method should call getData internally and result of two method should be equal', () => {
457+
obj.updateStateRef({selectedTabID: 'tab1', openTabIDs: ['tab1', 'tab2']}, () => {});
458+
expect(obj.getData()).toEqual(obj.getCopyData());
459+
obj.getData = jest.fn(() => {});
460+
obj.getCopyData();
461+
expect(obj.getData.mock.calls.length).toBe(1);
462+
});
463+
test('getCopyPerviousData method should call getPreviousData internally and result of two method should be equal', () => {
464+
obj.updateStateRef({selectedTabID: 'tab1', openTabIDs: ['tab1', 'tab2']}, () => {});
465+
expect(obj.getPreviousData()).toEqual(obj.getCopyPerviousData());
466+
obj.getPreviousData = jest.fn(() => {});
467+
obj.getCopyPerviousData();
468+
expect(obj.getPreviousData.mock.calls.length).toBe(1);
469+
});
470+
//
456471
});
457472
describe('Api.prototype.setTab : ', () => {
458473
test('it should call optionsManager.validateObjectiveTabData and validatePanelComponent internally', () => {

src/utils/api/api.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ describe('user api : ', () => {
1313
'setOption',
1414
'getPreviousData',
1515
'getCopyPerviousData',
16+
'getData',
1617
'getCopyData',
1718
'isSelected',
1819
'isOpen',

0 commit comments

Comments
 (0)