dyo-tools 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.c8rc.json +4 -4
- package/.eslintignore +1 -1
- package/.eslintrc.json +47 -47
- package/Makefile +34 -34
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +24 -20
- package/dist/constants.js.map +1 -1
- package/dist/core/DTAction.d.ts +6 -4
- package/dist/core/DTAction.d.ts.map +1 -0
- package/dist/core/DTAction.js +3 -6
- package/dist/core/DTAction.js.map +1 -1
- package/dist/core/DTBunch.d.ts +8 -5
- package/dist/core/DTBunch.d.ts.map +1 -0
- package/dist/core/DTBunch.js +53 -19
- package/dist/core/DTBunch.js.map +1 -1
- package/dist/core/DTComponent.d.ts +13 -10
- package/dist/core/DTComponent.d.ts.map +1 -0
- package/dist/core/DTComponent.js +23 -10
- package/dist/core/DTComponent.js.map +1 -1
- package/dist/core/DTComponentPhysical.d.ts +11 -8
- package/dist/core/DTComponentPhysical.d.ts.map +1 -0
- package/dist/core/DTComponentPhysical.js +21 -6
- package/dist/core/DTComponentPhysical.js.map +1 -1
- package/dist/core/DTComponentWithMeta.d.ts +6 -3
- package/dist/core/DTComponentWithMeta.d.ts.map +1 -0
- package/dist/core/DTComponentWithMeta.js +21 -7
- package/dist/core/DTComponentWithMeta.js.map +1 -1
- package/dist/core/DTElement.d.ts +10 -8
- package/dist/core/DTElement.d.ts.map +1 -0
- package/dist/core/DTElement.js +8 -9
- package/dist/core/DTElement.js.map +1 -1
- package/dist/core/DTError.d.ts +8 -7
- package/dist/core/DTError.d.ts.map +1 -0
- package/dist/core/DTError.js +1 -5
- package/dist/core/DTError.js.map +1 -1
- package/dist/core/DTManager.d.ts +17 -14
- package/dist/core/DTManager.d.ts.map +1 -0
- package/dist/core/DTManager.js +84 -26
- package/dist/core/DTManager.js.map +1 -1
- package/dist/core/DTMaster.d.ts +19 -16
- package/dist/core/DTMaster.d.ts.map +1 -0
- package/dist/core/DTMaster.js +48 -31
- package/dist/core/DTMaster.js.map +1 -1
- package/dist/core/DTModule.d.ts +8 -5
- package/dist/core/DTModule.d.ts.map +1 -0
- package/dist/core/DTModule.js +6 -6
- package/dist/core/DTModule.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -28
- package/dist/index.js.map +1 -1
- package/dist/libs/DYOFinder.d.ts +1 -0
- package/dist/libs/DYOFinder.d.ts.map +1 -0
- package/dist/libs/DYOFinder.js +10 -14
- package/dist/libs/DYOFinder.js.map +1 -1
- package/dist/libs/dix/DIXModule.module.d.ts +8 -0
- package/dist/libs/dix/DIXModule.module.d.ts.map +1 -0
- package/dist/libs/dix/DIXModule.module.js +73 -0
- package/dist/libs/player/DTPlayer.element.d.ts +3 -2
- package/dist/libs/player/DTPlayer.element.d.ts.map +1 -0
- package/dist/libs/player/DTPlayer.element.js +2 -6
- package/dist/libs/player/DTPlayer.element.js.map +1 -1
- package/dist/libs/player/DTPlayer.manager.d.ts +8 -7
- package/dist/libs/player/DTPlayer.manager.d.ts.map +1 -0
- package/dist/libs/player/DTPlayer.manager.js +13 -20
- package/dist/libs/player/DTPlayer.manager.js.map +1 -1
- package/dist/tsconfig.dev.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/core.d.ts +40 -12
- package/dist/types/core.d.ts.map +1 -0
- package/dist/types/core.js +2 -6
- package/dist/types/core.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -19
- package/dist/types/index.js.map +1 -1
- package/dist/types/player.d.ts +1 -1
- package/dist/types/player.d.ts.map +1 -0
- package/dist/types/player.js +1 -3
- package/integration/data/components/DTHero.ts +42 -0
- package/integration/data/components/DTHeroManager.ts +11 -0
- package/integration/data/components/DTHeroPlayZone.ts +6 -0
- package/integration/data/components/DTHeroPlayerHand.ts +11 -0
- package/integration/data/components/index.ts +5 -0
- package/integration/data/in/heroIn.helper.ts +8 -0
- package/integration/data/in/playerIn.helper.ts +13 -0
- package/integration/data/out/heroOut.helper.ts +48 -0
- package/integration/endings/synchronisation.ending.ts +25 -0
- package/integration/scenes/drawCard.scene.ts +31 -0
- package/integration/scenes/empty.scene.ts +6 -0
- package/integration/scenes/playCard.scene.ts +23 -0
- package/integration/scenes/playerLeave.scene.ts +33 -0
- package/integration/stages/baseDix.stage.ts +137 -0
- package/integration/stages/syncDix.stage.ts +36 -0
- package/integration/tests/scenario1.spec.ts +55 -0
- package/integration/types/index.ts +24 -0
- package/jest-integration.config.ts +25 -0
- package/jest.config.ts +26 -0
- package/package.json +31 -19
- package/src/constants.ts +2 -0
- package/src/core/DTAction.ts +7 -5
- package/src/core/DTBunch.ts +78 -14
- package/src/core/DTComponent.ts +48 -15
- package/src/core/DTComponentPhysical.ts +45 -11
- package/src/core/DTComponentWithMeta.ts +37 -4
- package/src/core/DTElement.ts +19 -10
- package/src/core/DTError.ts +7 -7
- package/src/core/DTManager.ts +120 -30
- package/src/core/DTMaster.ts +76 -28
- package/src/core/DTModule.ts +12 -6
- package/src/index.ts +17 -17
- package/src/libs/DYOFinder.ts +175 -175
- package/src/libs/dix/DIXModule.module.ts +98 -0
- package/src/libs/player/DTPlayer.element.ts +2 -2
- package/src/libs/player/DTPlayer.manager.ts +20 -34
- package/src/types/core.ts +39 -4
- package/src/types/index.ts +2 -2
- package/src/types/player.ts +0 -1
- package/test/core/DTAction.double.ts +12 -28
- package/test/core/DTAction.spec.ts +8 -16
- package/test/core/DTBunch.double.ts +49 -135
- package/test/core/DTBunch.spec.ts +157 -245
- package/test/core/DTComponent.double.ts +17 -2
- package/test/core/DTComponent.spec.ts +6 -4
- package/test/core/DTComponentPhysical.double.ts +29 -43
- package/test/core/DTComponentPhysical.spec.ts +22 -19
- package/test/core/DTComponentWithMeta.double.ts +38 -31
- package/test/core/DTComponentWithMeta.spec.ts +23 -18
- package/test/core/DTElement.double.ts +32 -53
- package/test/core/DTElement.spec.ts +15 -38
- package/test/core/DTError.double.ts +18 -53
- package/test/core/DTError.spec.ts +21 -32
- package/test/core/DTManager.double.ts +74 -141
- package/test/core/DTManager.spec.ts +289 -380
- package/test/core/DTMaster.double.ts +56 -80
- package/test/core/DTMaster.spec.ts +185 -232
- package/test/core/DTModule.double.ts +12 -25
- package/test/core/DTModule.spec.ts +14 -28
- package/test/core/copy.spec.ts +9 -30
- package/tsconfig.dev.json +5 -8
- package/tsconfig.json +5 -8
- package/cucumber-report.html +0 -48
- package/docs/assets/navigation.js +0 -1
- package/docs/classes/core_DTAction.DYOToolsAction.html +0 -89
- package/docs/classes/core_DTBunch.DYOToolsBunch.html +0 -254
- package/docs/classes/core_DTComponent.DYOToolsComponent.html +0 -76
- package/docs/classes/core_DTComponentPhysical.DYOToolsComponentPhysical.html +0 -110
- package/docs/classes/core_DTComponentWithMeta.DYOToolsComponentWithMeta.html +0 -96
- package/docs/classes/core_DTElement.DYOToolsElement.html +0 -135
- package/docs/classes/core_DTError.DYOToolsError.html +0 -37
- package/docs/classes/core_DTManager.DYOToolsManager.html +0 -237
- package/docs/classes/core_DTMaster.DYOToolsMaster.html +0 -150
- package/docs/classes/core_DTModule.DYOToolsModule.html +0 -92
- package/docs/classes/libs_DYOFinder.DYOFinder.html +0 -34
- package/docs/classes/libs_player_DTPlayer_element.DYOToolsPlayer.html +0 -134
- package/docs/classes/libs_player_DTPlayer_manager.DYOToolsPlayerManager.html +0 -243
- package/docs/enums/types_core.FilterOperatorType.html +0 -10
- package/docs/hierarchy.html +0 -1
- package/docs/interfaces/types_core.DTBunchFilters.html +0 -6
- package/docs/interfaces/types_core.DTBunchOptions.html +0 -19
- package/docs/interfaces/types_core.DTBunchToObject.html +0 -7
- package/docs/interfaces/types_core.DTComponentOptions.html +0 -5
- package/docs/interfaces/types_core.DTComponentToObject.html +0 -4
- package/docs/interfaces/types_core.DTElementToObject.html +0 -7
- package/docs/interfaces/types_core.DTManagerFilters.html +0 -6
- package/docs/interfaces/types_core.DTManagerOptions.html +0 -8
- package/docs/interfaces/types_core.DTManagerToObject.html +0 -5
- package/docs/interfaces/types_core.DTMasterToObject.html +0 -8
- package/docs/interfaces/types_core.DTModuleToObject.html +0 -6
- package/docs/interfaces/types_core.DYOFinderConfigurationPropDefault.html +0 -4
- package/docs/interfaces/types_core.DYOFinderConfigurationPropObjectSearch.html +0 -4
- package/docs/interfaces/types_core.DYOFinderFilterOperatorAdvanced.html +0 -5
- package/docs/interfaces/types_core.DYOFinderFilterOperatorBase.html +0 -5
- package/docs/interfaces/types_player.DTPlayerManagerSimpleConfiguration.html +0 -3
- package/docs/modules/constants.html +0 -6
- package/docs/modules/core_DTAction.html +0 -2
- package/docs/modules/core_DTBunch.html +0 -2
- package/docs/modules/core_DTComponent.html +0 -2
- package/docs/modules/core_DTComponentPhysical.html +0 -2
- package/docs/modules/core_DTComponentWithMeta.html +0 -2
- package/docs/modules/core_DTElement.html +0 -2
- package/docs/modules/core_DTError.html +0 -2
- package/docs/modules/core_DTManager.html +0 -2
- package/docs/modules/core_DTMaster.html +0 -2
- package/docs/modules/core_DTModule.html +0 -2
- package/docs/modules/libs_DYOFinder.html +0 -2
- package/docs/modules/libs_player_DTPlayer_element.html +0 -2
- package/docs/modules/libs_player_DTPlayer_manager.html +0 -2
- package/docs/modules/types.html +0 -29
- package/docs/modules/types_core.html +0 -28
- package/docs/modules/types_player.html +0 -2
- package/docs/types/types_core.DTAcceptedMetaData.html +0 -2
- package/docs/types/types_core.DTManagerItemType.html +0 -1
- package/docs/types/types_core.DTManagerItemsType.html +0 -2
- package/docs/types/types_core.DYOFinderComponentType.html +0 -1
- package/docs/types/types_core.DYOFinderConfiguration.html +0 -2
- package/docs/types/types_core.DYOFinderConfigurationProp.html +0 -1
- package/docs/types/types_core.DYOFinderFilterOperator.html +0 -1
- package/docs/types/types_core.DYOFinderFilterOperatorArgument.html +0 -1
- package/docs/types/types_core.DYOFinderFilters.html +0 -1
- package/docs/types/types_core.StandardPrimitiveType.html +0 -2
- package/docs/types/types_core.StandardPrimitiveTypeWithArray.html +0 -1
- package/docs/variables/constants.bunchDefaultOptions.html +0 -2
- package/docs/variables/constants.componentBunchDefaultFinderConfiguration.html +0 -1
- package/docs/variables/constants.componentManagerDefaultFinderConfiguration.html +0 -1
- package/docs/variables/constants.componentPhysicalDefaultFinderConfiguration.html +0 -1
- package/docs/variables/constants.managerDefaultOptions.html +0 -2
- package/jest.config.js +0 -6
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import {afterEach, beforeEach, describe, expect, jest, test,} from '@jest/globals';
|
|
2
|
+
import {DTBunchStub, DTBunchTest, generateStubElements, IDTest, KeyTest} from './DTBunch.double';
|
|
3
3
|
import {
|
|
4
4
|
DTElementStub,
|
|
5
5
|
HaileiIdTest,
|
|
@@ -20,38 +20,19 @@ import {
|
|
|
20
20
|
YssaliaKeyTest,
|
|
21
21
|
YssaliaToObjectTest,
|
|
22
22
|
} from './DTElement.double';
|
|
23
|
-
import {
|
|
24
|
-
import
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import
|
|
29
|
-
import { mockOverriddenMethods, OwnerTest } from './DTComponentPhysical.double';
|
|
30
|
-
import { DTManagerStub, IDTest as managerIDTest } from './DTManager.double';
|
|
31
|
-
import { componentBunchDefaultFinderConfiguration } from '../../src/constants';
|
|
32
|
-
import Mocked = jest.Mocked;
|
|
33
|
-
import MockedFunction = jest.MockedFunction;
|
|
34
|
-
|
|
35
|
-
/** ****************** MOCK DEPENDENCIES
|
|
36
|
-
* All Dependencies used by the component are mocked with Jest
|
|
37
|
-
* **** */
|
|
38
|
-
jest.mock('../../src/core/DTElement');
|
|
39
|
-
jest.mock('../../src/core/DTManager');
|
|
40
|
-
jest.mock('../../src/core/DTError');
|
|
41
|
-
jest.mock('../../src/core/DTComponent');
|
|
42
|
-
jest.mock('../../src/core/DTComponentWithMeta');
|
|
43
|
-
jest.mock('../../src/core/DTComponentPhysical');
|
|
44
|
-
jest.mock('../../src/libs/DYOFinder');
|
|
45
|
-
// Add specific mock for inherited methods to have a basic implementation
|
|
46
|
-
mockOverriddenMethods(DTComponentPhysical);
|
|
23
|
+
import {DTBunch, DTComponentPhysical, DTError} from '../../src';
|
|
24
|
+
import {BunchMetaData, HaileiMetaData} from './DTComponentWithMeta.double';
|
|
25
|
+
import {DTBunchOptions, FilterOperatorType} from '../../src/types';
|
|
26
|
+
import {CodeTest as DTErrorCodeTest, DTErrorStub} from './DTError.double';
|
|
27
|
+
import {OwnerTest} from './DTComponentPhysical.double';
|
|
28
|
+
import {DTManagerStub, IDTest as managerIDTest} from './DTManager.double';
|
|
47
29
|
|
|
48
30
|
/** *********************** TESTS SUITES ****************************** */
|
|
49
|
-
describe('class
|
|
31
|
+
describe('class DTBunch', () => {
|
|
50
32
|
let bunchTest: DTBunchTest;
|
|
51
33
|
|
|
52
34
|
beforeEach(() => {
|
|
53
35
|
bunchTest = new DTBunchTest();
|
|
54
|
-
bunchTest.th_set_options(defaultOptions);
|
|
55
36
|
});
|
|
56
37
|
|
|
57
38
|
afterEach(() => {
|
|
@@ -78,22 +59,15 @@ describe('class DYOToolsBunch', () => {
|
|
|
78
59
|
});
|
|
79
60
|
|
|
80
61
|
test('creation simple with key', () => {
|
|
81
|
-
const newBunch = new DTBunchTest(
|
|
82
|
-
const parentConstructorMock = (DTComponentPhysical.prototype.constructor as MockedFunction<(key: string, options: any) => void>).mock;
|
|
62
|
+
const newBunch = new DTBunchTest();
|
|
83
63
|
|
|
84
|
-
expect(
|
|
85
|
-
expect(parentConstructorMock.calls[0][1]).toStrictEqual(defaultOptions);
|
|
86
|
-
expect(newBunch.th_get_items()).toStrictEqual([]);
|
|
87
|
-
|
|
88
|
-
// Finder initialization
|
|
89
|
-
expect((newBunch.th_get_finder() as any).constructor.mock.calls.length).toBe(1);
|
|
90
|
-
expect((newBunch.th_get_finder() as any).constructor.mock.calls[0][0]).toStrictEqual(newBunch);
|
|
91
|
-
expect((newBunch.th_get_finder() as any).constructor.mock.calls[0][1]).toStrictEqual(componentBunchDefaultFinderConfiguration);
|
|
64
|
+
expect(newBunch.getAll()).toStrictEqual([]);
|
|
92
65
|
});
|
|
93
66
|
|
|
94
67
|
test('creation with items', () => {
|
|
95
|
-
|
|
96
|
-
const
|
|
68
|
+
const elements: DTElementStub[] = generateStubElements(3);
|
|
69
|
+
const newBunch = new DTBunchTest(IDTest, KeyTest, elements);
|
|
70
|
+
const mockedAddMany = DTBunch.prototype.addMany as any;
|
|
97
71
|
|
|
98
72
|
expect(mockedAddMany.mock.calls.length).toBe(1);
|
|
99
73
|
expect(mockedAddMany.mock.calls[0][0].length).toBe(3);
|
|
@@ -108,24 +82,23 @@ describe('class DYOToolsBunch', () => {
|
|
|
108
82
|
uniqueKey: true,
|
|
109
83
|
inheritOwner: true,
|
|
110
84
|
};
|
|
111
|
-
const newBunch = new DTBunchTest(KeyTest, [], testOptions);
|
|
112
|
-
const parentConstructorMock = (DTComponentPhysical.prototype.constructor as MockedFunction<(key: string, options: any) => void>).mock;
|
|
85
|
+
const newBunch = new DTBunchTest(IDTest, KeyTest, [], testOptions);
|
|
113
86
|
|
|
114
|
-
expect(
|
|
115
|
-
expect(parentConstructorMock.calls[0][1]).toStrictEqual({
|
|
87
|
+
expect(newBunch.getOptions()).toStrictEqual({
|
|
116
88
|
errors: true,
|
|
89
|
+
syncId: undefined,
|
|
117
90
|
uniqueKey: true,
|
|
118
91
|
inheritOwner: true,
|
|
119
92
|
replaceIndex: false,
|
|
120
93
|
virtualContainer: false,
|
|
121
94
|
});
|
|
122
|
-
expect(newBunch.
|
|
95
|
+
expect(newBunch.getAll()).toStrictEqual([]);
|
|
123
96
|
});
|
|
124
97
|
});
|
|
125
98
|
|
|
126
99
|
describe('_componentType', () => {
|
|
127
100
|
test('componentType must be "bunch"', () => {
|
|
128
|
-
expect(bunchTest.
|
|
101
|
+
expect(bunchTest.getComponentType()).toBe('bunch');
|
|
129
102
|
});
|
|
130
103
|
});
|
|
131
104
|
|
|
@@ -224,57 +197,41 @@ describe('class DYOToolsBunch', () => {
|
|
|
224
197
|
});
|
|
225
198
|
|
|
226
199
|
test('add a new owner - not updating elements owner when inheritOwner = false', () => {
|
|
227
|
-
|
|
228
|
-
bunchTest.th_set_items(generateMockedElements(3));
|
|
200
|
+
const newBunch = new DTBunchTest(IDTest, KeyTest, generateStubElements(1), { inheritOwner: false});
|
|
229
201
|
|
|
230
|
-
|
|
202
|
+
newBunch.setOwner(OwnerTest);
|
|
231
203
|
|
|
232
|
-
expect(
|
|
233
|
-
expect(bunchTest.th_get_items()[1].setOwner.mock.calls.length).toBe(0);
|
|
234
|
-
expect(bunchTest.th_get_items()[2].setOwner.mock.calls.length).toBe(0);
|
|
204
|
+
expect(newBunch.get(0).getOwner()).toBeUndefined();
|
|
235
205
|
});
|
|
236
206
|
|
|
237
207
|
test('add a new owner - updating elements owner when inheritOwner = true', () => {
|
|
238
|
-
|
|
239
|
-
bunchTest.th_set_items(generateMockedElements(3));
|
|
208
|
+
const newBunch = new DTBunchTest(IDTest, KeyTest, generateStubElements(1), { inheritOwner: true});
|
|
240
209
|
|
|
241
|
-
|
|
210
|
+
newBunch.setOwner(OwnerTest);
|
|
242
211
|
|
|
243
|
-
expect(
|
|
244
|
-
expect(bunchTest.th_get_items()[0].setOwner.mock.calls[0][0]).toBe(OwnerTest);
|
|
245
|
-
expect(bunchTest.th_get_items()[1].setOwner.mock.calls.length).toBe(1);
|
|
246
|
-
expect(bunchTest.th_get_items()[1].setOwner.mock.calls[0][0]).toBe(OwnerTest);
|
|
247
|
-
expect(bunchTest.th_get_items()[2].setOwner.mock.calls.length).toBe(1);
|
|
248
|
-
expect(bunchTest.th_get_items()[2].setOwner.mock.calls[0][0]).toBe(OwnerTest);
|
|
212
|
+
expect(newBunch.get(0).getOwner()).toBe(OwnerTest);
|
|
249
213
|
});
|
|
250
214
|
});
|
|
251
215
|
|
|
252
216
|
describe('removeOwner()', () => {
|
|
253
217
|
test('remove current Owner - not updating elements owner when inheritOwner = false', () => {
|
|
254
|
-
|
|
255
|
-
|
|
218
|
+
const newBunch = new DTBunchTest(IDTest, KeyTest, generateStubElements(1, OwnerTest), { inheritOwner: false}, OwnerTest);
|
|
219
|
+
newBunch.removeOwner();
|
|
256
220
|
|
|
257
|
-
|
|
258
|
-
bunchTest.removeOwner();
|
|
259
|
-
|
|
260
|
-
expect(bunchTest.th_get_items()[0].removeOwner.mock.calls.length).toBe(0);
|
|
261
|
-
expect(bunchTest.th_get_items()[1].removeOwner.mock.calls.length).toBe(0);
|
|
221
|
+
expect(newBunch.get(0).getOwner()).toBe(OwnerTest);
|
|
262
222
|
});
|
|
263
223
|
|
|
264
224
|
test('remove current Owner - updating elements owner when inheritOwner = true', () => {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
bunchTest.removeOwner();
|
|
225
|
+
const newBunch = new DTBunchTest(IDTest, KeyTest, generateStubElements(1, OwnerTest), { inheritOwner: true}, OwnerTest);
|
|
226
|
+
newBunch.removeOwner();
|
|
269
227
|
|
|
270
|
-
expect(
|
|
271
|
-
expect(bunchTest.th_get_items()[1].removeOwner.mock.calls.length).toBe(1);
|
|
228
|
+
expect(newBunch.get(0).getOwner()).toBeUndefined();
|
|
272
229
|
});
|
|
273
230
|
});
|
|
274
231
|
|
|
275
232
|
describe('get()', () => {
|
|
276
233
|
beforeEach(() => {
|
|
277
|
-
bunchTest
|
|
234
|
+
bunchTest = new DTBunchTest(IDTest, KeyTest, generateStubElements(5))
|
|
278
235
|
});
|
|
279
236
|
|
|
280
237
|
test('return an item by its id', () => {
|
|
@@ -306,7 +263,7 @@ describe('class DYOToolsBunch', () => {
|
|
|
306
263
|
});
|
|
307
264
|
|
|
308
265
|
test('return all items array', () => {
|
|
309
|
-
bunchTest
|
|
266
|
+
bunchTest = new DTBunchTest(IDTest, KeyTest, generateStubElements(5));
|
|
310
267
|
|
|
311
268
|
expect(bunchTest.getAll()[0].getKey()).toBe(HaileiKeyTest);
|
|
312
269
|
expect(bunchTest.getAll()[1].getKey()).toBe(MeldrineKeyTest);
|
|
@@ -318,7 +275,7 @@ describe('class DYOToolsBunch', () => {
|
|
|
318
275
|
|
|
319
276
|
describe('indexOf()', () => {
|
|
320
277
|
beforeEach(() => {
|
|
321
|
-
bunchTest
|
|
278
|
+
bunchTest = new DTBunchTest(IDTest, KeyTest, generateStubElements(5))
|
|
322
279
|
});
|
|
323
280
|
|
|
324
281
|
test('return index of an item by id', () => {
|
|
@@ -336,214 +293,191 @@ describe('class DYOToolsBunch', () => {
|
|
|
336
293
|
let objectsToAdd;
|
|
337
294
|
|
|
338
295
|
beforeEach(() => {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
bunchTest.th_set_items(generateMockedElements(5));
|
|
296
|
+
bunchTest = new DTBunchTest(IDTest, KeyTest, generateStubElements(5))
|
|
342
297
|
|
|
343
|
-
objectsToAdd =
|
|
298
|
+
objectsToAdd = generateStubElements(6);
|
|
344
299
|
objectToAdd = objectsToAdd[5];
|
|
345
|
-
jest.spyOn(bunchTest, 'find').mockReturnValue([objectToAdd]);
|
|
346
300
|
});
|
|
347
301
|
|
|
348
302
|
test('add a new item at last index - simple case', () => {
|
|
349
303
|
bunchTest.addAtIndex(objectToAdd, 5);
|
|
350
304
|
|
|
351
|
-
expect(bunchTest.
|
|
305
|
+
expect(bunchTest.get(5).getId()).toBe(objectToAdd.getId());
|
|
352
306
|
});
|
|
353
307
|
|
|
354
308
|
test('add a new item at specified index and reindex - default case', () => {
|
|
355
309
|
bunchTest.addAtIndex(objectToAdd, 2);
|
|
356
310
|
|
|
357
|
-
expect(bunchTest.
|
|
358
|
-
expect(bunchTest.
|
|
359
|
-
expect(bunchTest.
|
|
360
|
-
expect(bunchTest.
|
|
311
|
+
expect(bunchTest.get(2).getId()).toBe(objectToAdd.getId());
|
|
312
|
+
expect(bunchTest.get(3).getId()).toBe(`${MaydenaIdTest}-2`);
|
|
313
|
+
expect(bunchTest.get(4).getId()).toBe(`${IldressIdTest}-3`);
|
|
314
|
+
expect(bunchTest.get(5).getId()).toBe(`${YssaliaIdTest}-4`);
|
|
361
315
|
});
|
|
362
316
|
|
|
363
317
|
test('add a new item at specified index and replace - replace option', () => {
|
|
364
318
|
bunchTest.addAtIndex(objectToAdd, 2, { replaceIndex: true });
|
|
365
319
|
|
|
366
|
-
expect(bunchTest.
|
|
367
|
-
expect(bunchTest.
|
|
368
|
-
expect(bunchTest.
|
|
369
|
-
expect(bunchTest.
|
|
320
|
+
expect(bunchTest.get(2).getId()).toBe(objectToAdd.getId());
|
|
321
|
+
expect(bunchTest.get(3).getId()).toBe(`${IldressIdTest}-3`);
|
|
322
|
+
expect(bunchTest.get(4).getId()).toBe(`${YssaliaIdTest}-4`);
|
|
323
|
+
expect(bunchTest.get(5)).toBeUndefined();
|
|
370
324
|
});
|
|
371
325
|
|
|
372
326
|
test('add a new item at lower index', () => {
|
|
373
327
|
bunchTest.addAtIndex(objectToAdd, -11);
|
|
374
328
|
|
|
375
|
-
expect(bunchTest.
|
|
376
|
-
expect(bunchTest.
|
|
329
|
+
expect(bunchTest.get(0).getId()).toBe(objectToAdd.getId());
|
|
330
|
+
expect(bunchTest.get(1).getId()).toBe(`${HaileiIdTest}-0`);
|
|
377
331
|
});
|
|
378
332
|
|
|
379
333
|
test('add a new item at greater index', () => {
|
|
380
334
|
bunchTest.addAtIndex(objectToAdd, 11);
|
|
381
335
|
|
|
382
|
-
expect(bunchTest.
|
|
383
|
-
expect(bunchTest.
|
|
336
|
+
expect(bunchTest.get(5).getId()).toBe(objectToAdd.getId());
|
|
337
|
+
expect(bunchTest.get(6)).toBeUndefined();
|
|
384
338
|
});
|
|
385
339
|
|
|
386
340
|
test('trigger conflict when adding two same ids - parent triggerError', () => {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
341
|
+
let errorThrown: DTError | undefined;
|
|
342
|
+
try {
|
|
343
|
+
bunchTest.addAtIndex(objectsToAdd[0], 2);
|
|
344
|
+
} catch(error) {
|
|
345
|
+
errorThrown = error;
|
|
346
|
+
}
|
|
390
347
|
|
|
391
|
-
expect(
|
|
392
|
-
|
|
393
|
-
'id_conflict'
|
|
394
|
-
'Element with same id already exists in the bunch'
|
|
395
|
-
IDTest
|
|
396
|
-
objectsToAdd[0].getId()
|
|
397
|
-
|
|
348
|
+
expect(errorThrown).toBeDefined();
|
|
349
|
+
if (errorThrown) {
|
|
350
|
+
expect(errorThrown.getCode()).toBe('id_conflict');
|
|
351
|
+
expect(errorThrown.getMessage()).toBe('Element with same id already exists in the bunch');
|
|
352
|
+
expect(errorThrown.getInitiator().getId()).toBe(IDTest);
|
|
353
|
+
expect(errorThrown.getConvicted().getId()).toBe(objectsToAdd[0].getId());
|
|
354
|
+
}
|
|
398
355
|
});
|
|
399
356
|
|
|
400
357
|
test('no conflict when adding two same keys - default case', () => {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
358
|
+
let errorThrown: DTError | undefined;
|
|
359
|
+
try {
|
|
360
|
+
bunchTest.addAtIndex(objectToAdd, 2);
|
|
361
|
+
} catch(error) {
|
|
362
|
+
errorThrown = error;
|
|
363
|
+
}
|
|
404
364
|
|
|
405
|
-
expect(
|
|
406
|
-
expect(
|
|
407
|
-
expect(bunchTest.
|
|
408
|
-
expect(bunchTest.th_get_items()[2].getKey()).toBe(HaileiKeyTest);
|
|
365
|
+
expect(errorThrown).toBeUndefined();
|
|
366
|
+
expect(bunchTest.get(0).getKey()).toBe(HaileiKeyTest);
|
|
367
|
+
expect(bunchTest.get(2).getKey()).toBe(HaileiKeyTest);
|
|
409
368
|
});
|
|
410
369
|
|
|
411
370
|
test('trigger conflict when adding two same keys - uniqueKey option and parent triggerError', () => {
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
371
|
+
let errorThrown: DTError | undefined;
|
|
372
|
+
try {
|
|
373
|
+
bunchTest.addAtIndex(objectToAdd, 2, { uniqueKey: true });
|
|
374
|
+
} catch(error) {
|
|
375
|
+
errorThrown = error;
|
|
376
|
+
}
|
|
415
377
|
|
|
416
|
-
expect(
|
|
417
|
-
|
|
418
|
-
'key_conflict'
|
|
419
|
-
'Element with same key already exists in the bunch'
|
|
420
|
-
|
|
421
|
-
objectToAdd.getId()
|
|
422
|
-
|
|
423
|
-
expect((bunchTest.find as any).mock.calls.length).toBe(1);
|
|
424
|
-
expect((bunchTest.find as any).mock.calls[0][0]).toStrictEqual({ key: { $eq: objectToAdd.getKey() } });
|
|
425
|
-
expect(bunchTest.th_get_items()[2].getId()).toBe(`${MaydenaIdTest}-2`);
|
|
378
|
+
expect(errorThrown).toBeDefined();
|
|
379
|
+
if (errorThrown) {
|
|
380
|
+
expect(errorThrown.getCode()).toBe('key_conflict');
|
|
381
|
+
expect(errorThrown.getMessage()).toBe('Element with same key already exists in the bunch');
|
|
382
|
+
expect(errorThrown.getInitiator().getKey()).toBe(KeyTest);
|
|
383
|
+
expect(errorThrown.getConvicted().getId()).toBe(objectToAdd.getId());
|
|
384
|
+
}
|
|
426
385
|
});
|
|
427
386
|
|
|
428
387
|
test('not inherit owner when adding an item - default case', () => {
|
|
429
|
-
bunchTest.
|
|
388
|
+
bunchTest.setOwner(OwnerTest);
|
|
430
389
|
|
|
431
390
|
bunchTest.addAtIndex(objectToAdd, 2);
|
|
432
391
|
|
|
433
|
-
expect(bunchTest.
|
|
434
|
-
expect(objectToAdd.
|
|
392
|
+
expect(bunchTest.getOwner()).toBe(OwnerTest);
|
|
393
|
+
expect(objectToAdd.getOwner()).toBeUndefined();
|
|
435
394
|
});
|
|
436
395
|
|
|
437
396
|
test('inherit owner when adding an item - inheritOwner option', () => {
|
|
438
|
-
bunchTest.
|
|
397
|
+
bunchTest.setOwner(OwnerTest);
|
|
439
398
|
|
|
440
399
|
bunchTest.addAtIndex(objectToAdd, 2, { inheritOwner: true });
|
|
441
400
|
|
|
442
|
-
expect(bunchTest.
|
|
443
|
-
expect(objectToAdd.
|
|
444
|
-
expect(objectToAdd.setOwner.mock.calls[0][0]).toBe(OwnerTest);
|
|
401
|
+
expect(bunchTest.getOwner()).toBe(OwnerTest);
|
|
402
|
+
expect(objectToAdd.getOwner()).toBe(OwnerTest);
|
|
445
403
|
});
|
|
446
404
|
|
|
447
405
|
test('not set context if undefined when adding an item', () => {
|
|
448
406
|
bunchTest.addAtIndex(objectToAdd, 2);
|
|
449
407
|
|
|
450
|
-
expect(bunchTest.
|
|
408
|
+
expect(bunchTest.get(2).getContext()).toBeUndefined();
|
|
451
409
|
});
|
|
452
410
|
|
|
453
411
|
test('set context with parent manager when adding an item', () => {
|
|
454
412
|
const manager = new DTManagerStub();
|
|
455
|
-
bunchTest.
|
|
413
|
+
bunchTest.setContext(manager);
|
|
456
414
|
|
|
457
415
|
bunchTest.addAtIndex(objectToAdd, 2);
|
|
458
416
|
|
|
459
|
-
expect(bunchTest.
|
|
460
|
-
expect(bunchTest.th_get_items()[2].setContext.mock.calls[0][0].getId()).toBe(managerIDTest);
|
|
417
|
+
expect(bunchTest.get(2).getContext()?.getId()).toBe(managerIDTest);
|
|
461
418
|
});
|
|
462
419
|
|
|
463
420
|
test('set container when adding an item', () => {
|
|
464
421
|
bunchTest.addAtIndex(objectToAdd, 2);
|
|
465
422
|
|
|
466
|
-
expect(bunchTest.
|
|
467
|
-
expect(bunchTest.th_get_items()[2].setContainer.mock.calls[0][0].getId()).toBe(IDTest);
|
|
423
|
+
expect(bunchTest.get(2).getContainer()?.getId()).toBe(IDTest);
|
|
468
424
|
});
|
|
469
425
|
|
|
470
426
|
test('not set container when adding an item - virtualContainer option', () => {
|
|
471
|
-
bunchTest
|
|
427
|
+
bunchTest = new DTBunchTest(IDTest, KeyTest, generateStubElements(5), { virtualContainer: true });
|
|
472
428
|
|
|
473
429
|
bunchTest.addAtIndex(objectToAdd, 2);
|
|
474
430
|
|
|
475
|
-
expect(bunchTest.
|
|
431
|
+
expect(bunchTest.get(2).getContainer()).toBeUndefined();
|
|
476
432
|
});
|
|
477
433
|
|
|
478
434
|
test('set container when adding an item - remove from old bunch', () => {
|
|
479
|
-
const bunchTestOld = new DTBunchTest();
|
|
480
|
-
bunchTestOld.
|
|
481
|
-
objectToAdd = bunchTestOld.th_get_items()[5];
|
|
435
|
+
const bunchTestOld = new DTBunchTest(IDTest + "_old", KeyTest, generateStubElements(6));
|
|
436
|
+
objectToAdd = bunchTestOld.get(5);
|
|
482
437
|
objectToAdd.setContainer(bunchTestOld);
|
|
483
|
-
objectToAdd.setContainer.mockClear();
|
|
484
|
-
jest.spyOn(bunchTestOld, 'remove').mockImplementation(() => {});
|
|
485
|
-
jest.spyOn(bunchTestOld, 'getComponentType').mockImplementation(() => 'bunch');
|
|
486
438
|
|
|
487
439
|
bunchTest.addAtIndex(objectToAdd, 2);
|
|
488
440
|
|
|
489
|
-
expect(
|
|
490
|
-
expect(
|
|
491
|
-
expect((bunchTestOld.remove as any).mock.calls.length).toBe(1);
|
|
492
|
-
expect((bunchTestOld.remove as any).mock.calls[0][0]).toBe(objectToAdd.getId());
|
|
441
|
+
expect(objectToAdd.getContainer()?.getId()).toBe(IDTest);
|
|
442
|
+
expect(bunchTestOld.get(5)).toBeUndefined();
|
|
493
443
|
});
|
|
494
444
|
|
|
495
445
|
test('set container when adding an item - dont remove if virtualContainer option', () => {
|
|
496
|
-
const bunchTestOld = new DTBunchTest();
|
|
497
|
-
bunchTestOld.
|
|
498
|
-
objectToAdd = bunchTestOld.th_get_items()[5];
|
|
499
|
-
jest.spyOn(bunchTestOld, 'remove').mockImplementation(() => {});
|
|
446
|
+
const bunchTestOld = new DTBunchTest(IDTest + "_old", KeyTest, generateStubElements(6), { virtualContainer: true });
|
|
447
|
+
objectToAdd = bunchTestOld.get(5);
|
|
500
448
|
|
|
501
|
-
bunchTest.th_set_options({ virtualContainer: true });
|
|
502
449
|
bunchTest.addAtIndex(objectToAdd, 2);
|
|
503
450
|
|
|
504
|
-
expect(
|
|
505
|
-
expect(
|
|
451
|
+
expect(objectToAdd.getContainer()?.getId()).toBe(IDTest);
|
|
452
|
+
expect(bunchTestOld.get(5)?.getId()).toBe(objectToAdd.getId());
|
|
506
453
|
});
|
|
507
454
|
|
|
508
455
|
test('manager context - add item into the manager library', () => {
|
|
509
456
|
const managerTest = new DTManagerStub();
|
|
510
|
-
|
|
511
|
-
(contextType) => contextType === 'manager' && managerTest,
|
|
512
|
-
);
|
|
513
|
-
jest.spyOn(managerTest, 'getLibrary').mockImplementation(() => managerTest.th_get_library());
|
|
514
|
-
jest.spyOn(managerTest.th_get_library(), 'add');
|
|
457
|
+
bunchTest.setContext(managerTest);
|
|
515
458
|
|
|
516
459
|
bunchTest.addAtIndex(objectToAdd, 5);
|
|
517
460
|
|
|
518
|
-
expect(
|
|
519
|
-
expect((managerTest.th_get_library().add as any).mock.calls[0][0]).toStrictEqual(objectToAdd);
|
|
461
|
+
expect(managerTest.getLibrary().get(objectToAdd.getId())).toBeDefined();
|
|
520
462
|
});
|
|
521
463
|
|
|
522
464
|
test('manager context - not add existing item into the manager library', () => {
|
|
523
465
|
const managerTest = new DTManagerStub();
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
);
|
|
527
|
-
jest.spyOn(managerTest, 'getLibrary').mockImplementation(() => managerTest.th_get_library());
|
|
528
|
-
jest.spyOn(managerTest.th_get_library(), 'add');
|
|
529
|
-
managerTest.th_get_library().th_set_items([objectToAdd]);
|
|
466
|
+
bunchTest.setContext(managerTest);
|
|
467
|
+
managerTest.getLibrary().add(objectToAdd);
|
|
530
468
|
|
|
531
469
|
bunchTest.addAtIndex(objectToAdd, 5);
|
|
532
470
|
|
|
533
|
-
expect(
|
|
471
|
+
expect(managerTest.getLibrary().getAll().length).toBe(1);
|
|
534
472
|
});
|
|
535
473
|
|
|
536
474
|
test('manager context - not add item into the manager if the caller is the library', () => {
|
|
537
475
|
const managerTest = new DTManagerStub();
|
|
538
|
-
|
|
539
|
-
(contextType) => contextType === 'manager' && managerTest,
|
|
540
|
-
);
|
|
541
|
-
jest.spyOn(managerTest, 'getLibrary').mockImplementation(() => managerTest.th_get_library());
|
|
542
|
-
jest.spyOn(managerTest.th_get_library(), 'add');
|
|
476
|
+
bunchTest.setContext(managerTest);
|
|
543
477
|
|
|
544
|
-
managerTest.
|
|
478
|
+
managerTest.getLibrary().addAtIndex(objectToAdd, 5);
|
|
545
479
|
|
|
546
|
-
expect(
|
|
480
|
+
expect(managerTest.getLibrary().getAll().length).toBe(1);
|
|
547
481
|
});
|
|
548
482
|
});
|
|
549
483
|
|
|
@@ -552,11 +486,10 @@ describe('class DYOToolsBunch', () => {
|
|
|
552
486
|
let objectToAdd;
|
|
553
487
|
|
|
554
488
|
beforeEach(() => {
|
|
489
|
+
bunchTest = new DTBunchTest(IDTest, KeyTest, generateStubElements(5));
|
|
555
490
|
jest.spyOn(bunchTest, 'addAtIndex').mockImplementation(() => {});
|
|
556
491
|
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
objectsToAdd = generateMockedElements(6);
|
|
492
|
+
objectsToAdd = generateStubElements(6);
|
|
560
493
|
objectToAdd = objectsToAdd[5];
|
|
561
494
|
});
|
|
562
495
|
|
|
@@ -579,11 +512,10 @@ describe('class DYOToolsBunch', () => {
|
|
|
579
512
|
let itemLibrary;
|
|
580
513
|
|
|
581
514
|
beforeEach(() => {
|
|
515
|
+
bunchTest = new DTBunchTest(IDTest, KeyTest, generateStubElements(5));
|
|
582
516
|
jest.spyOn(bunchTest, 'addAtIndex').mockImplementation(() => {});
|
|
583
517
|
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
itemLibrary = generateMockedElements(8);
|
|
518
|
+
itemLibrary = generateStubElements(8);
|
|
587
519
|
itemsToAdd = [itemLibrary[5], itemLibrary[6], itemLibrary[7]];
|
|
588
520
|
});
|
|
589
521
|
|
|
@@ -628,7 +560,6 @@ describe('class DYOToolsBunch', () => {
|
|
|
628
560
|
}
|
|
629
561
|
|
|
630
562
|
expect(errorThrown).toBeDefined();
|
|
631
|
-
expect(DTErrorStub).toHaveBeenCalled();
|
|
632
563
|
expect(errorThrown.getCode()).toBe(DTErrorCodeTest);
|
|
633
564
|
expect((bunchTest.addAtIndex as any).mock.calls.length).toBe(1);
|
|
634
565
|
expect((bunchTest.addAtIndex as any).mock.calls[0][0].getId()).toBe(itemsToAdd[0].getId());
|
|
@@ -649,7 +580,6 @@ describe('class DYOToolsBunch', () => {
|
|
|
649
580
|
bunchTest.addManyAtIndex(itemsToAdd, indexToAdd, { errors: true });
|
|
650
581
|
|
|
651
582
|
expect(errors.length).toBe(2);
|
|
652
|
-
expect(DTErrorStub).toHaveBeenCalled();
|
|
653
583
|
expect((bunchTest.addAtIndex as any).mock.calls.length).toBe(3);
|
|
654
584
|
expect((bunchTest.addAtIndex as any).mock.calls[0][0].getId()).toBe(itemsToAdd[0].getId());
|
|
655
585
|
expect((bunchTest.addAtIndex as any).mock.calls[1][0].getId()).toBe(itemsToAdd[1].getId());
|
|
@@ -662,11 +592,10 @@ describe('class DYOToolsBunch', () => {
|
|
|
662
592
|
let itemLibrary;
|
|
663
593
|
|
|
664
594
|
beforeEach(() => {
|
|
595
|
+
bunchTest = new DTBunchTest(IDTest, KeyTest, generateStubElements(5));
|
|
665
596
|
jest.spyOn(bunchTest, 'addManyAtIndex').mockImplementation(() => {});
|
|
666
597
|
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
itemLibrary = generateMockedElements(8);
|
|
598
|
+
itemLibrary = generateStubElements(8);
|
|
670
599
|
itemsToAdd = [itemLibrary[5], itemLibrary[6], itemLibrary[7]];
|
|
671
600
|
});
|
|
672
601
|
|
|
@@ -692,15 +621,15 @@ describe('class DYOToolsBunch', () => {
|
|
|
692
621
|
const checkAllItemsInBunch = (bunch: DTBunchTest, itemRemoved = 3) => {
|
|
693
622
|
const sup = itemRemoved;
|
|
694
623
|
expect(bunchTest.getAll().length).toBe(5 - sup);
|
|
695
|
-
expect(bunchTest.
|
|
696
|
-
itemRemoved < 1 && expect(bunchTest.
|
|
697
|
-
itemRemoved < 2 && expect(bunchTest.
|
|
698
|
-
itemRemoved < 3 && expect(bunchTest.
|
|
699
|
-
expect(bunchTest.
|
|
624
|
+
expect(bunchTest.get(0).getId()).toBe(`${HaileiIdTest}-0`);
|
|
625
|
+
itemRemoved < 1 && expect(bunchTest.get(1 - sup).getId()).toBe(`${MeldrineIdTest}-1`);
|
|
626
|
+
itemRemoved < 2 && expect(bunchTest.get(2 - sup).getId()).toBe(`${MaydenaIdTest}-2`);
|
|
627
|
+
itemRemoved < 3 && expect(bunchTest.get(3 - sup).getId()).toBe(`${IldressIdTest}-3`);
|
|
628
|
+
expect(bunchTest.get(4 - sup).getId()).toBe(`${YssaliaIdTest}-4`);
|
|
700
629
|
};
|
|
701
630
|
|
|
702
631
|
beforeEach(() => {
|
|
703
|
-
bunchTest
|
|
632
|
+
bunchTest = new DTBunchTest(IDTest, KeyTest, generateStubElements(5));
|
|
704
633
|
});
|
|
705
634
|
|
|
706
635
|
test('remove many items by ids', () => {
|
|
@@ -735,45 +664,36 @@ describe('class DYOToolsBunch', () => {
|
|
|
735
664
|
|
|
736
665
|
test('define container at undefined for removed items - default case', () => {
|
|
737
666
|
const items = [
|
|
738
|
-
bunchTest.
|
|
739
|
-
bunchTest.
|
|
667
|
+
bunchTest.get(1),
|
|
668
|
+
bunchTest.get(2),
|
|
740
669
|
];
|
|
741
670
|
|
|
742
671
|
bunchTest.removeMany([`${MeldrineIdTest}-1`, `${MaydenaIdTest}-2`]);
|
|
743
|
-
items.push(bunchTest.th_get_items()[0]);
|
|
744
|
-
items.push(bunchTest.th_get_items()[1]);
|
|
745
|
-
bunchTest.removeMany([0, 1]);
|
|
746
672
|
|
|
747
|
-
expect(items[0].
|
|
748
|
-
expect(items[1].
|
|
749
|
-
expect(items[2].removeContainer.mock.calls.length).toBe(1);
|
|
750
|
-
expect(items[3].removeContainer.mock.calls.length).toBe(1);
|
|
673
|
+
expect(items[0].getContainer()).toBeUndefined();
|
|
674
|
+
expect(items[1].getContainer()).toBeUndefined();
|
|
751
675
|
});
|
|
752
676
|
|
|
753
677
|
test('not change container for removed items - virtual container option', () => {
|
|
678
|
+
bunchTest = new DTBunchTest(IDTest, KeyTest, generateStubElements(5), { virtualContainer: true });
|
|
679
|
+
let bunchTestPhysical = new DTBunchTest(IDTest + "_physical", KeyTest);
|
|
754
680
|
const items = [
|
|
755
|
-
bunchTest.
|
|
756
|
-
bunchTest.
|
|
681
|
+
bunchTest.get(1),
|
|
682
|
+
bunchTest.get(2),
|
|
757
683
|
];
|
|
758
|
-
|
|
684
|
+
bunchTestPhysical.addMany(items);
|
|
685
|
+
|
|
759
686
|
bunchTest.removeMany([`${MeldrineIdTest}-1`, `${MaydenaIdTest}-2`]);
|
|
760
|
-
items.push(bunchTest.th_get_items()[0]);
|
|
761
|
-
items.push(bunchTest.th_get_items()[1]);
|
|
762
|
-
bunchTest.removeMany([0, 1]);
|
|
763
687
|
|
|
764
|
-
expect(items[0].
|
|
765
|
-
expect(items[1].
|
|
766
|
-
expect(items[2].removeContainer.mock.calls.length).toBe(0);
|
|
767
|
-
expect(items[3].removeContainer.mock.calls.length).toBe(0);
|
|
688
|
+
expect(items[0].getContainer().getId()).toBe(IDTest + "_physical");
|
|
689
|
+
expect(items[1].getContainer().getId()).toBe(IDTest + "_physical");
|
|
768
690
|
});
|
|
769
691
|
});
|
|
770
692
|
|
|
771
693
|
describe('remove()', () => {
|
|
772
694
|
beforeEach(() => {
|
|
773
|
-
|
|
774
|
-
});
|
|
775
|
-
|
|
776
|
-
bunchTest.th_set_items(generateMockedElements(5));
|
|
695
|
+
bunchTest = new DTBunchTest(IDTest, KeyTest, generateStubElements(5));
|
|
696
|
+
jest.spyOn(bunchTest, 'removeMany').mockImplementation(() => {});
|
|
777
697
|
});
|
|
778
698
|
|
|
779
699
|
test('remove one item by id using removeMany', () => {
|
|
@@ -793,10 +713,8 @@ describe('class DYOToolsBunch', () => {
|
|
|
793
713
|
|
|
794
714
|
describe('removeAll()', () => {
|
|
795
715
|
beforeEach(() => {
|
|
796
|
-
|
|
797
|
-
});
|
|
798
|
-
|
|
799
|
-
bunchTest.th_set_items(generateMockedElements(5));
|
|
716
|
+
bunchTest = new DTBunchTest(IDTest, KeyTest, generateStubElements(5));
|
|
717
|
+
jest.spyOn(bunchTest, 'removeMany').mockImplementation(() => {});
|
|
800
718
|
});
|
|
801
719
|
|
|
802
720
|
test('remove all items using removeMany', () => {
|
|
@@ -812,27 +730,29 @@ describe('class DYOToolsBunch', () => {
|
|
|
812
730
|
});
|
|
813
731
|
|
|
814
732
|
describe('find()', () => {
|
|
733
|
+
let findSpy;
|
|
734
|
+
|
|
735
|
+
beforeEach(() => {
|
|
736
|
+
findSpy = jest.spyOn(bunchTest._getFinder(), 'execute');
|
|
737
|
+
})
|
|
738
|
+
|
|
815
739
|
test('find items using DYOFinder - empty case', () => {
|
|
816
740
|
bunchTest.find({});
|
|
817
741
|
|
|
818
|
-
expect((
|
|
819
|
-
expect((
|
|
742
|
+
expect((findSpy as any).mock.calls.length).toBe(1);
|
|
743
|
+
expect((findSpy as any).mock.calls[0][0]).toStrictEqual({});
|
|
820
744
|
});
|
|
821
745
|
|
|
822
746
|
test('find items using DYOFinder', () => {
|
|
823
747
|
const testFilters = { id: { $eq: 'id_bunch' }, key: { $ne: 'key_test' } };
|
|
824
748
|
bunchTest.find(testFilters);
|
|
825
749
|
|
|
826
|
-
expect((
|
|
827
|
-
expect((
|
|
750
|
+
expect((findSpy as any).mock.calls.length).toBe(1);
|
|
751
|
+
expect((findSpy as any).mock.calls[0][0]).toStrictEqual(testFilters);
|
|
828
752
|
});
|
|
829
753
|
});
|
|
830
754
|
|
|
831
755
|
describe('toObject()', () => {
|
|
832
|
-
beforeEach(() => {
|
|
833
|
-
bunchTest.th_set_id(IDTest);
|
|
834
|
-
bunchTest.th_set_key(KeyTest);
|
|
835
|
-
});
|
|
836
756
|
|
|
837
757
|
test('toObject output standard', () => {
|
|
838
758
|
const toObjectBunch = bunchTest.toObject();
|
|
@@ -845,7 +765,7 @@ describe('class DYOToolsBunch', () => {
|
|
|
845
765
|
});
|
|
846
766
|
|
|
847
767
|
test('toObject output standard with owner', () => {
|
|
848
|
-
bunchTest.
|
|
768
|
+
bunchTest.setOwner(OwnerTest);
|
|
849
769
|
|
|
850
770
|
const toObjectBunch = bunchTest.toObject();
|
|
851
771
|
expect(Object.keys(toObjectBunch)).toStrictEqual(['id', 'key', 'type', 'items', 'owner']);
|
|
@@ -853,12 +773,8 @@ describe('class DYOToolsBunch', () => {
|
|
|
853
773
|
});
|
|
854
774
|
|
|
855
775
|
test('toObject output standard with owner and meta', () => {
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
});
|
|
859
|
-
|
|
860
|
-
bunchTest.th_set_owner(OwnerTest);
|
|
861
|
-
bunchTest.th_set_meta(BunchMetaData);
|
|
776
|
+
bunchTest.setOwner(OwnerTest);
|
|
777
|
+
bunchTest.setManyMeta(BunchMetaData);
|
|
862
778
|
|
|
863
779
|
const toObjectBunch = bunchTest.toObject();
|
|
864
780
|
expect(Object.keys(toObjectBunch)).toStrictEqual(['id', 'key', 'type', 'items', 'owner', 'meta']);
|
|
@@ -866,7 +782,7 @@ describe('class DYOToolsBunch', () => {
|
|
|
866
782
|
});
|
|
867
783
|
|
|
868
784
|
test('toObject output standard with items', () => {
|
|
869
|
-
bunchTest
|
|
785
|
+
bunchTest = new DTBunchTest(IDTest, KeyTest, generateStubElements(5));
|
|
870
786
|
const toObjectBunch = bunchTest.toObject();
|
|
871
787
|
|
|
872
788
|
expect(Object.keys(toObjectBunch)).toStrictEqual(['id', 'key', 'type', 'items']);
|
|
@@ -882,10 +798,6 @@ describe('class DYOToolsBunch', () => {
|
|
|
882
798
|
});
|
|
883
799
|
|
|
884
800
|
describe('toString()', () => {
|
|
885
|
-
beforeEach(() => {
|
|
886
|
-
bunchTest.th_set_key(KeyTest);
|
|
887
|
-
});
|
|
888
|
-
|
|
889
801
|
test('string output standard', () => {
|
|
890
802
|
const toStringBunch = bunchTest.toString();
|
|
891
803
|
|
|
@@ -893,15 +805,15 @@ describe('class DYOToolsBunch', () => {
|
|
|
893
805
|
});
|
|
894
806
|
|
|
895
807
|
test('string output standard with items', () => {
|
|
896
|
-
bunchTest
|
|
808
|
+
bunchTest = new DTBunchTest(IDTest, KeyTest, generateStubElements(5));
|
|
897
809
|
const toStringBunch = bunchTest.toString();
|
|
898
810
|
|
|
899
811
|
expect(toStringBunch).toBe(`Component ${KeyTest} - Type: Bunch - Items: 5`);
|
|
900
812
|
});
|
|
901
813
|
|
|
902
814
|
test('string output standard with items and owner', () => {
|
|
903
|
-
bunchTest
|
|
904
|
-
bunchTest.
|
|
815
|
+
bunchTest = new DTBunchTest(IDTest, KeyTest, generateStubElements(5));
|
|
816
|
+
bunchTest.setOwner(OwnerTest);
|
|
905
817
|
|
|
906
818
|
const toStringBunch = bunchTest.toString();
|
|
907
819
|
expect(toStringBunch).toBe(`Component ${KeyTest} - Type: Bunch - Owner: ${OwnerTest} - Items: 5`);
|