dyo-tools 0.3.0 → 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 +54 -20
- 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 -7
- 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/docs/assets/main.js +59 -59
- package/docs/assets/style.css +1414 -1414
- 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 +87 -85
- package/src/core/DTAction.ts +54 -52
- package/src/core/DTBunch.ts +531 -467
- package/src/core/DTComponent.ts +258 -225
- package/src/core/DTComponentPhysical.ts +88 -53
- package/src/core/DTComponentWithMeta.ts +98 -65
- package/src/core/DTElement.ts +111 -102
- package/src/core/DTError.ts +78 -78
- package/src/core/DTManager.ts +555 -465
- package/src/core/DTMaster.ts +366 -318
- package/src/core/DTModule.ts +96 -90
- package/src/libs/dix/DIXModule.module.ts +98 -0
- package/src/libs/player/DTPlayer.element.ts +9 -9
- package/src/libs/player/DTPlayer.manager.ts +70 -84
- package/src/types/core.ts +204 -169
- package/src/types/player.ts +5 -6
- 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 +163 -238
- 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,201 +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);
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
test('manager context - not add item into the manager if the caller is the library', () => {
|
|
475
|
+
const managerTest = new DTManagerStub();
|
|
476
|
+
bunchTest.setContext(managerTest);
|
|
477
|
+
|
|
478
|
+
managerTest.getLibrary().addAtIndex(objectToAdd, 5);
|
|
479
|
+
|
|
480
|
+
expect(managerTest.getLibrary().getAll().length).toBe(1);
|
|
534
481
|
});
|
|
535
482
|
});
|
|
536
483
|
|
|
@@ -539,11 +486,10 @@ describe('class DYOToolsBunch', () => {
|
|
|
539
486
|
let objectToAdd;
|
|
540
487
|
|
|
541
488
|
beforeEach(() => {
|
|
489
|
+
bunchTest = new DTBunchTest(IDTest, KeyTest, generateStubElements(5));
|
|
542
490
|
jest.spyOn(bunchTest, 'addAtIndex').mockImplementation(() => {});
|
|
543
491
|
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
objectsToAdd = generateMockedElements(6);
|
|
492
|
+
objectsToAdd = generateStubElements(6);
|
|
547
493
|
objectToAdd = objectsToAdd[5];
|
|
548
494
|
});
|
|
549
495
|
|
|
@@ -566,11 +512,10 @@ describe('class DYOToolsBunch', () => {
|
|
|
566
512
|
let itemLibrary;
|
|
567
513
|
|
|
568
514
|
beforeEach(() => {
|
|
515
|
+
bunchTest = new DTBunchTest(IDTest, KeyTest, generateStubElements(5));
|
|
569
516
|
jest.spyOn(bunchTest, 'addAtIndex').mockImplementation(() => {});
|
|
570
517
|
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
itemLibrary = generateMockedElements(8);
|
|
518
|
+
itemLibrary = generateStubElements(8);
|
|
574
519
|
itemsToAdd = [itemLibrary[5], itemLibrary[6], itemLibrary[7]];
|
|
575
520
|
});
|
|
576
521
|
|
|
@@ -615,7 +560,6 @@ describe('class DYOToolsBunch', () => {
|
|
|
615
560
|
}
|
|
616
561
|
|
|
617
562
|
expect(errorThrown).toBeDefined();
|
|
618
|
-
expect(DTErrorStub).toHaveBeenCalled();
|
|
619
563
|
expect(errorThrown.getCode()).toBe(DTErrorCodeTest);
|
|
620
564
|
expect((bunchTest.addAtIndex as any).mock.calls.length).toBe(1);
|
|
621
565
|
expect((bunchTest.addAtIndex as any).mock.calls[0][0].getId()).toBe(itemsToAdd[0].getId());
|
|
@@ -636,7 +580,6 @@ describe('class DYOToolsBunch', () => {
|
|
|
636
580
|
bunchTest.addManyAtIndex(itemsToAdd, indexToAdd, { errors: true });
|
|
637
581
|
|
|
638
582
|
expect(errors.length).toBe(2);
|
|
639
|
-
expect(DTErrorStub).toHaveBeenCalled();
|
|
640
583
|
expect((bunchTest.addAtIndex as any).mock.calls.length).toBe(3);
|
|
641
584
|
expect((bunchTest.addAtIndex as any).mock.calls[0][0].getId()).toBe(itemsToAdd[0].getId());
|
|
642
585
|
expect((bunchTest.addAtIndex as any).mock.calls[1][0].getId()).toBe(itemsToAdd[1].getId());
|
|
@@ -649,11 +592,10 @@ describe('class DYOToolsBunch', () => {
|
|
|
649
592
|
let itemLibrary;
|
|
650
593
|
|
|
651
594
|
beforeEach(() => {
|
|
595
|
+
bunchTest = new DTBunchTest(IDTest, KeyTest, generateStubElements(5));
|
|
652
596
|
jest.spyOn(bunchTest, 'addManyAtIndex').mockImplementation(() => {});
|
|
653
597
|
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
itemLibrary = generateMockedElements(8);
|
|
598
|
+
itemLibrary = generateStubElements(8);
|
|
657
599
|
itemsToAdd = [itemLibrary[5], itemLibrary[6], itemLibrary[7]];
|
|
658
600
|
});
|
|
659
601
|
|
|
@@ -679,15 +621,15 @@ describe('class DYOToolsBunch', () => {
|
|
|
679
621
|
const checkAllItemsInBunch = (bunch: DTBunchTest, itemRemoved = 3) => {
|
|
680
622
|
const sup = itemRemoved;
|
|
681
623
|
expect(bunchTest.getAll().length).toBe(5 - sup);
|
|
682
|
-
expect(bunchTest.
|
|
683
|
-
itemRemoved < 1 && expect(bunchTest.
|
|
684
|
-
itemRemoved < 2 && expect(bunchTest.
|
|
685
|
-
itemRemoved < 3 && expect(bunchTest.
|
|
686
|
-
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`);
|
|
687
629
|
};
|
|
688
630
|
|
|
689
631
|
beforeEach(() => {
|
|
690
|
-
bunchTest
|
|
632
|
+
bunchTest = new DTBunchTest(IDTest, KeyTest, generateStubElements(5));
|
|
691
633
|
});
|
|
692
634
|
|
|
693
635
|
test('remove many items by ids', () => {
|
|
@@ -722,45 +664,36 @@ describe('class DYOToolsBunch', () => {
|
|
|
722
664
|
|
|
723
665
|
test('define container at undefined for removed items - default case', () => {
|
|
724
666
|
const items = [
|
|
725
|
-
bunchTest.
|
|
726
|
-
bunchTest.
|
|
667
|
+
bunchTest.get(1),
|
|
668
|
+
bunchTest.get(2),
|
|
727
669
|
];
|
|
728
670
|
|
|
729
671
|
bunchTest.removeMany([`${MeldrineIdTest}-1`, `${MaydenaIdTest}-2`]);
|
|
730
|
-
items.push(bunchTest.th_get_items()[0]);
|
|
731
|
-
items.push(bunchTest.th_get_items()[1]);
|
|
732
|
-
bunchTest.removeMany([0, 1]);
|
|
733
672
|
|
|
734
|
-
expect(items[0].
|
|
735
|
-
expect(items[1].
|
|
736
|
-
expect(items[2].removeContainer.mock.calls.length).toBe(1);
|
|
737
|
-
expect(items[3].removeContainer.mock.calls.length).toBe(1);
|
|
673
|
+
expect(items[0].getContainer()).toBeUndefined();
|
|
674
|
+
expect(items[1].getContainer()).toBeUndefined();
|
|
738
675
|
});
|
|
739
676
|
|
|
740
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);
|
|
741
680
|
const items = [
|
|
742
|
-
bunchTest.
|
|
743
|
-
bunchTest.
|
|
681
|
+
bunchTest.get(1),
|
|
682
|
+
bunchTest.get(2),
|
|
744
683
|
];
|
|
745
|
-
|
|
684
|
+
bunchTestPhysical.addMany(items);
|
|
685
|
+
|
|
746
686
|
bunchTest.removeMany([`${MeldrineIdTest}-1`, `${MaydenaIdTest}-2`]);
|
|
747
|
-
items.push(bunchTest.th_get_items()[0]);
|
|
748
|
-
items.push(bunchTest.th_get_items()[1]);
|
|
749
|
-
bunchTest.removeMany([0, 1]);
|
|
750
687
|
|
|
751
|
-
expect(items[0].
|
|
752
|
-
expect(items[1].
|
|
753
|
-
expect(items[2].removeContainer.mock.calls.length).toBe(0);
|
|
754
|
-
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");
|
|
755
690
|
});
|
|
756
691
|
});
|
|
757
692
|
|
|
758
693
|
describe('remove()', () => {
|
|
759
694
|
beforeEach(() => {
|
|
760
|
-
|
|
761
|
-
});
|
|
762
|
-
|
|
763
|
-
bunchTest.th_set_items(generateMockedElements(5));
|
|
695
|
+
bunchTest = new DTBunchTest(IDTest, KeyTest, generateStubElements(5));
|
|
696
|
+
jest.spyOn(bunchTest, 'removeMany').mockImplementation(() => {});
|
|
764
697
|
});
|
|
765
698
|
|
|
766
699
|
test('remove one item by id using removeMany', () => {
|
|
@@ -780,10 +713,8 @@ describe('class DYOToolsBunch', () => {
|
|
|
780
713
|
|
|
781
714
|
describe('removeAll()', () => {
|
|
782
715
|
beforeEach(() => {
|
|
783
|
-
|
|
784
|
-
});
|
|
785
|
-
|
|
786
|
-
bunchTest.th_set_items(generateMockedElements(5));
|
|
716
|
+
bunchTest = new DTBunchTest(IDTest, KeyTest, generateStubElements(5));
|
|
717
|
+
jest.spyOn(bunchTest, 'removeMany').mockImplementation(() => {});
|
|
787
718
|
});
|
|
788
719
|
|
|
789
720
|
test('remove all items using removeMany', () => {
|
|
@@ -799,27 +730,29 @@ describe('class DYOToolsBunch', () => {
|
|
|
799
730
|
});
|
|
800
731
|
|
|
801
732
|
describe('find()', () => {
|
|
733
|
+
let findSpy;
|
|
734
|
+
|
|
735
|
+
beforeEach(() => {
|
|
736
|
+
findSpy = jest.spyOn(bunchTest._getFinder(), 'execute');
|
|
737
|
+
})
|
|
738
|
+
|
|
802
739
|
test('find items using DYOFinder - empty case', () => {
|
|
803
740
|
bunchTest.find({});
|
|
804
741
|
|
|
805
|
-
expect((
|
|
806
|
-
expect((
|
|
742
|
+
expect((findSpy as any).mock.calls.length).toBe(1);
|
|
743
|
+
expect((findSpy as any).mock.calls[0][0]).toStrictEqual({});
|
|
807
744
|
});
|
|
808
745
|
|
|
809
746
|
test('find items using DYOFinder', () => {
|
|
810
747
|
const testFilters = { id: { $eq: 'id_bunch' }, key: { $ne: 'key_test' } };
|
|
811
748
|
bunchTest.find(testFilters);
|
|
812
749
|
|
|
813
|
-
expect((
|
|
814
|
-
expect((
|
|
750
|
+
expect((findSpy as any).mock.calls.length).toBe(1);
|
|
751
|
+
expect((findSpy as any).mock.calls[0][0]).toStrictEqual(testFilters);
|
|
815
752
|
});
|
|
816
753
|
});
|
|
817
754
|
|
|
818
755
|
describe('toObject()', () => {
|
|
819
|
-
beforeEach(() => {
|
|
820
|
-
bunchTest.th_set_id(IDTest);
|
|
821
|
-
bunchTest.th_set_key(KeyTest);
|
|
822
|
-
});
|
|
823
756
|
|
|
824
757
|
test('toObject output standard', () => {
|
|
825
758
|
const toObjectBunch = bunchTest.toObject();
|
|
@@ -832,7 +765,7 @@ describe('class DYOToolsBunch', () => {
|
|
|
832
765
|
});
|
|
833
766
|
|
|
834
767
|
test('toObject output standard with owner', () => {
|
|
835
|
-
bunchTest.
|
|
768
|
+
bunchTest.setOwner(OwnerTest);
|
|
836
769
|
|
|
837
770
|
const toObjectBunch = bunchTest.toObject();
|
|
838
771
|
expect(Object.keys(toObjectBunch)).toStrictEqual(['id', 'key', 'type', 'items', 'owner']);
|
|
@@ -840,12 +773,8 @@ describe('class DYOToolsBunch', () => {
|
|
|
840
773
|
});
|
|
841
774
|
|
|
842
775
|
test('toObject output standard with owner and meta', () => {
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
});
|
|
846
|
-
|
|
847
|
-
bunchTest.th_set_owner(OwnerTest);
|
|
848
|
-
bunchTest.th_set_meta(BunchMetaData);
|
|
776
|
+
bunchTest.setOwner(OwnerTest);
|
|
777
|
+
bunchTest.setManyMeta(BunchMetaData);
|
|
849
778
|
|
|
850
779
|
const toObjectBunch = bunchTest.toObject();
|
|
851
780
|
expect(Object.keys(toObjectBunch)).toStrictEqual(['id', 'key', 'type', 'items', 'owner', 'meta']);
|
|
@@ -853,7 +782,7 @@ describe('class DYOToolsBunch', () => {
|
|
|
853
782
|
});
|
|
854
783
|
|
|
855
784
|
test('toObject output standard with items', () => {
|
|
856
|
-
bunchTest
|
|
785
|
+
bunchTest = new DTBunchTest(IDTest, KeyTest, generateStubElements(5));
|
|
857
786
|
const toObjectBunch = bunchTest.toObject();
|
|
858
787
|
|
|
859
788
|
expect(Object.keys(toObjectBunch)).toStrictEqual(['id', 'key', 'type', 'items']);
|
|
@@ -869,10 +798,6 @@ describe('class DYOToolsBunch', () => {
|
|
|
869
798
|
});
|
|
870
799
|
|
|
871
800
|
describe('toString()', () => {
|
|
872
|
-
beforeEach(() => {
|
|
873
|
-
bunchTest.th_set_key(KeyTest);
|
|
874
|
-
});
|
|
875
|
-
|
|
876
801
|
test('string output standard', () => {
|
|
877
802
|
const toStringBunch = bunchTest.toString();
|
|
878
803
|
|
|
@@ -880,15 +805,15 @@ describe('class DYOToolsBunch', () => {
|
|
|
880
805
|
});
|
|
881
806
|
|
|
882
807
|
test('string output standard with items', () => {
|
|
883
|
-
bunchTest
|
|
808
|
+
bunchTest = new DTBunchTest(IDTest, KeyTest, generateStubElements(5));
|
|
884
809
|
const toStringBunch = bunchTest.toString();
|
|
885
810
|
|
|
886
811
|
expect(toStringBunch).toBe(`Component ${KeyTest} - Type: Bunch - Items: 5`);
|
|
887
812
|
});
|
|
888
813
|
|
|
889
814
|
test('string output standard with items and owner', () => {
|
|
890
|
-
bunchTest
|
|
891
|
-
bunchTest.
|
|
815
|
+
bunchTest = new DTBunchTest(IDTest, KeyTest, generateStubElements(5));
|
|
816
|
+
bunchTest.setOwner(OwnerTest);
|
|
892
817
|
|
|
893
818
|
const toStringBunch = bunchTest.toString();
|
|
894
819
|
expect(toStringBunch).toBe(`Component ${KeyTest} - Type: Bunch - Owner: ${OwnerTest} - Items: 5`);
|