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,58 +1,42 @@
|
|
|
1
1
|
import {afterEach, beforeEach, describe, expect, jest, test} from "@jest/globals";
|
|
2
|
-
import {
|
|
2
|
+
import {DTComponent, DTError, DTMaster} from "../../src";
|
|
3
3
|
import {
|
|
4
4
|
checkMasterActions,
|
|
5
|
-
checkMasterManagers,
|
|
5
|
+
checkMasterManagers,
|
|
6
|
+
checkMasterModules,
|
|
6
7
|
DTMasterTest,
|
|
7
8
|
IDTest,
|
|
8
|
-
KeyTest
|
|
9
|
-
populateMaster
|
|
9
|
+
KeyTest
|
|
10
10
|
} from "./DTMaster.double";
|
|
11
|
-
import {mockOverriddenMethods} from "./DTComponent.double";
|
|
12
11
|
import {
|
|
13
|
-
DTManagerStub,
|
|
12
|
+
DTManagerStub,
|
|
14
13
|
IDTest as manager1IDTest,
|
|
15
14
|
manager1IDTest as manager2IDTest,
|
|
16
|
-
manager1KeyTest as manager2KeyTest,
|
|
15
|
+
manager1KeyTest as manager2KeyTest,
|
|
16
|
+
manager1ToObject
|
|
17
17
|
} from "./DTManager.double";
|
|
18
18
|
import {
|
|
19
|
+
action1IDTest as action2IDTest,
|
|
20
|
+
action1KeyTest as action2KeyTest,
|
|
21
|
+
action1ToObject,
|
|
19
22
|
DTActionStub,
|
|
20
23
|
IDTest as action1IDTest,
|
|
21
|
-
KeyTest as action1KeyTest
|
|
22
|
-
action1IDTest as action2IDTest,
|
|
23
|
-
action1KeyTest as action2KeyTest, action1ToObject
|
|
24
|
+
KeyTest as action1KeyTest
|
|
24
25
|
} from "./DTAction.double";
|
|
25
26
|
import {
|
|
26
27
|
DTModuleStub,
|
|
27
28
|
IDTest as module1IDTest,
|
|
28
|
-
KeyTest as module1KeyTest,
|
|
29
29
|
module1IDTest as module2IDTest,
|
|
30
|
-
module1KeyTest as module2KeyTest,
|
|
30
|
+
module1KeyTest as module2KeyTest,
|
|
31
|
+
module1ToObject
|
|
31
32
|
} from "./DTModule.double";
|
|
32
|
-
import DYOToolsError from "../../src/core/DTError";
|
|
33
|
-
import {checkCallForMockedDTError} from "./DTError.double";
|
|
34
|
-
import MockedFunction = jest.MockedFunction;
|
|
35
|
-
import {DTBunchStubLibrary} from "./DTBunch.double";
|
|
36
|
-
|
|
37
|
-
/** ****************** MOCK DEPENDENCIES
|
|
38
|
-
* Dependencies used by the component are mocked with Jest
|
|
39
|
-
* **** */
|
|
40
|
-
jest.mock('../../src/core/DTManager');
|
|
41
|
-
jest.mock('../../src/core/DTAction');
|
|
42
|
-
jest.mock('../../src/core/DTModule');
|
|
43
|
-
jest.mock('../../src/core/DTComponent');
|
|
44
|
-
jest.mock('../../src/core/DTError');
|
|
45
|
-
// Add specific mock for inherited methods to have a basic implementation
|
|
46
|
-
mockOverriddenMethods(DTComponent);
|
|
47
33
|
|
|
48
34
|
/** *********************** TESTS SUITES ****************************** */
|
|
49
|
-
describe('class
|
|
35
|
+
describe('class DTMaster', () => {
|
|
50
36
|
let masterTest: DTMasterTest;
|
|
51
37
|
|
|
52
38
|
beforeEach(() => {
|
|
53
39
|
masterTest = new DTMasterTest();
|
|
54
|
-
masterTest.th_set_id(IDTest);
|
|
55
|
-
masterTest.th_set_key(KeyTest);
|
|
56
40
|
});
|
|
57
41
|
|
|
58
42
|
afterEach(() => {
|
|
@@ -67,7 +51,7 @@ describe('class DYOToolsMaster', () => {
|
|
|
67
51
|
|
|
68
52
|
describe('_componentType', () => {
|
|
69
53
|
test('componentType must be "master"', () => {
|
|
70
|
-
expect(masterTest.
|
|
54
|
+
expect(masterTest.getComponentType()).toBe('master');
|
|
71
55
|
});
|
|
72
56
|
});
|
|
73
57
|
|
|
@@ -77,15 +61,11 @@ describe('class DYOToolsMaster', () => {
|
|
|
77
61
|
});
|
|
78
62
|
|
|
79
63
|
test('simple creation with key', () => {
|
|
80
|
-
const newMaster = new DTMasterTest(KeyTest);
|
|
81
|
-
const parentConstructorMock = (DTComponent.prototype.constructor as MockedFunction<(key: string, options: any) => void>).mock;
|
|
82
|
-
|
|
83
|
-
expect(parentConstructorMock.calls.length).toBe(1);
|
|
84
|
-
expect(parentConstructorMock.calls[0][0]).toBe(KeyTest);
|
|
64
|
+
const newMaster = new DTMasterTest(IDTest, KeyTest);
|
|
85
65
|
|
|
86
|
-
expect(newMaster.
|
|
87
|
-
expect(newMaster.
|
|
88
|
-
expect(newMaster.
|
|
66
|
+
expect(newMaster._getManagers()).toStrictEqual({});
|
|
67
|
+
expect(newMaster._getActions()).toStrictEqual({});
|
|
68
|
+
expect(newMaster._getModules()).toStrictEqual({});
|
|
89
69
|
});
|
|
90
70
|
|
|
91
71
|
});
|
|
@@ -95,8 +75,6 @@ describe('class DYOToolsMaster', () => {
|
|
|
95
75
|
|
|
96
76
|
beforeEach(() => {
|
|
97
77
|
managerToAdd = new DTManagerStub();
|
|
98
|
-
|
|
99
|
-
jest.spyOn(masterTest, 'getId').mockReturnValue(IDTest);
|
|
100
78
|
});
|
|
101
79
|
|
|
102
80
|
test('add a new manager - standard case', () => {
|
|
@@ -106,64 +84,72 @@ describe('class DYOToolsMaster', () => {
|
|
|
106
84
|
});
|
|
107
85
|
|
|
108
86
|
test('trigger error when adding two managers with same id', () => {
|
|
109
|
-
const mockedTriggerError: MockedFunction<(error: DYOToolsError) => void> = DTMaster.prototype.triggerError as MockedFunction<(error: DYOToolsError) => void>;
|
|
110
|
-
|
|
111
87
|
masterTest.addManager(managerToAdd);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
)
|
|
88
|
+
let errorThrown: DTError | undefined;
|
|
89
|
+
try {
|
|
90
|
+
masterTest.addManager(managerToAdd);
|
|
91
|
+
} catch(error) {
|
|
92
|
+
errorThrown = error;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
expect(errorThrown).toBeDefined();
|
|
96
|
+
expect(Object.keys(masterTest._getManagers()).length).toBe(1);
|
|
97
|
+
if (errorThrown) {
|
|
98
|
+
expect(errorThrown.getCode()).toBe('id_conflict');
|
|
99
|
+
expect(errorThrown.getMessage()).toBe('Manager with same id already exists in the Master instance');
|
|
100
|
+
expect(errorThrown.getInitiator().getId()).toBe(IDTest);
|
|
101
|
+
expect(errorThrown.getConvicted().getId()).toBe(managerToAdd.getId());
|
|
102
|
+
}
|
|
122
103
|
});
|
|
123
104
|
|
|
124
105
|
test('trigger error when adding two managers with same key', () => {
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
106
|
+
const firstManager = new DTManagerStub();
|
|
107
|
+
firstManager._setId(manager2IDTest);
|
|
108
|
+
masterTest.addManager(firstManager);
|
|
109
|
+
let errorThrown: DTError | undefined;
|
|
110
|
+
try {
|
|
111
|
+
masterTest.addManager(managerToAdd);
|
|
112
|
+
} catch(error) {
|
|
113
|
+
errorThrown = error;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
expect(errorThrown).toBeDefined();
|
|
117
|
+
expect(Object.keys(masterTest._getManagers()).length).toBe(1);
|
|
118
|
+
if (errorThrown) {
|
|
119
|
+
expect(errorThrown.getCode()).toBe('key_conflict');
|
|
120
|
+
expect(errorThrown.getMessage()).toBe('Manager with same key already exists in the Master instance');
|
|
121
|
+
expect(errorThrown.getInitiator().getId()).toBe(IDTest);
|
|
122
|
+
expect(errorThrown.getConvicted().getId()).toBe(managerToAdd.getId());
|
|
123
|
+
}
|
|
140
124
|
});
|
|
141
125
|
|
|
142
126
|
test('set context when adding a new manager', () => {
|
|
127
|
+
const setContextSpy = jest.spyOn(managerToAdd, 'setContext');
|
|
128
|
+
|
|
143
129
|
masterTest.addManager(managerToAdd);
|
|
144
130
|
|
|
145
|
-
expect(
|
|
146
|
-
expect(
|
|
131
|
+
expect(setContextSpy.mock.calls.length).toBe(1);
|
|
132
|
+
expect(setContextSpy.mock.calls[0][0].getId()).toBe(IDTest);
|
|
147
133
|
});
|
|
148
134
|
});
|
|
149
135
|
|
|
150
136
|
describe('getManager()', () => {
|
|
151
137
|
beforeEach(() => {
|
|
152
|
-
|
|
138
|
+
masterTest.populate();
|
|
153
139
|
});
|
|
154
140
|
|
|
155
141
|
test('return a manager by its id', () => {
|
|
156
|
-
const manager = masterTest.getManager(manager1IDTest)
|
|
142
|
+
const manager = masterTest.getManager(manager1IDTest);
|
|
157
143
|
|
|
158
144
|
expect(manager).toBeDefined();
|
|
159
|
-
expect(manager.
|
|
145
|
+
expect(manager.getId()).toBe(manager1IDTest);
|
|
160
146
|
});
|
|
161
147
|
|
|
162
148
|
test('return a manager by its key', () => {
|
|
163
|
-
const manager = masterTest.getManager(manager2KeyTest)
|
|
149
|
+
const manager = masterTest.getManager(manager2KeyTest);
|
|
164
150
|
|
|
165
151
|
expect(manager).toBeDefined();
|
|
166
|
-
expect(manager.
|
|
152
|
+
expect(manager.getKey()).toBe(manager2KeyTest);
|
|
167
153
|
});
|
|
168
154
|
|
|
169
155
|
test('return undefined if manager is not found', () => {
|
|
@@ -175,40 +161,29 @@ describe('class DYOToolsMaster', () => {
|
|
|
175
161
|
|
|
176
162
|
describe('removeManager()', () => {
|
|
177
163
|
beforeEach(() => {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const managers = masterTest.th_get_managers();
|
|
181
|
-
jest.spyOn(masterTest, 'getManager').mockImplementation(function(idOrKey: string): DTManager<any> | undefined {
|
|
182
|
-
if (idOrKey === manager2KeyTest) {
|
|
183
|
-
return managers[manager2IDTest];
|
|
184
|
-
} else if (idOrKey === 'unexisting-id') {
|
|
185
|
-
return undefined;
|
|
186
|
-
} else {
|
|
187
|
-
return managers[manager1IDTest];
|
|
188
|
-
}
|
|
189
|
-
});
|
|
164
|
+
masterTest.populate();
|
|
190
165
|
});
|
|
191
166
|
|
|
192
167
|
test('remove a manager by its id', () => {
|
|
193
168
|
masterTest.removeManager(manager1IDTest);
|
|
194
169
|
|
|
195
|
-
expect(Object.keys(masterTest.
|
|
196
|
-
expect(Object.keys(masterTest.
|
|
170
|
+
expect(Object.keys(masterTest._getManagers()).length).toBe(1);
|
|
171
|
+
expect(Object.keys(masterTest._getManagers())[0]).toBe(manager2IDTest);
|
|
197
172
|
});
|
|
198
173
|
|
|
199
174
|
test('remove a manager by its key', () => {
|
|
200
175
|
masterTest.removeManager(manager2KeyTest);
|
|
201
176
|
|
|
202
|
-
expect(Object.keys(masterTest.
|
|
203
|
-
expect(Object.keys(masterTest.
|
|
177
|
+
expect(Object.keys(masterTest._getManagers()).length).toBe(1);
|
|
178
|
+
expect(Object.keys(masterTest._getManagers())[0]).toBe(manager1IDTest);
|
|
204
179
|
});
|
|
205
180
|
|
|
206
181
|
test('no removal if manager is not found', () => {
|
|
207
182
|
masterTest.removeManager('unexisting-id');
|
|
208
183
|
|
|
209
|
-
expect(Object.keys(masterTest.
|
|
210
|
-
expect(Object.keys(masterTest.
|
|
211
|
-
expect(Object.keys(masterTest.
|
|
184
|
+
expect(Object.keys(masterTest._getManagers()).length).toBe(2);
|
|
185
|
+
expect(Object.keys(masterTest._getManagers())[0]).toBe(manager1IDTest);
|
|
186
|
+
expect(Object.keys(masterTest._getManagers())[1]).toBe(manager2IDTest);
|
|
212
187
|
});
|
|
213
188
|
});
|
|
214
189
|
|
|
@@ -217,8 +192,6 @@ describe('class DYOToolsMaster', () => {
|
|
|
217
192
|
|
|
218
193
|
beforeEach(() => {
|
|
219
194
|
actionToAdd = new DTActionStub();
|
|
220
|
-
|
|
221
|
-
jest.spyOn(masterTest, 'getId').mockReturnValue(IDTest);
|
|
222
195
|
});
|
|
223
196
|
|
|
224
197
|
test('add a new action - standard case', () => {
|
|
@@ -228,64 +201,72 @@ describe('class DYOToolsMaster', () => {
|
|
|
228
201
|
});
|
|
229
202
|
|
|
230
203
|
test('trigger error when adding two actions with same id', () => {
|
|
231
|
-
const mockedTriggerError: MockedFunction<(error: DYOToolsError) => void> = DTMaster.prototype.triggerError as MockedFunction<(error: DYOToolsError) => void>;
|
|
232
|
-
|
|
233
|
-
masterTest.addAction(actionToAdd);
|
|
234
204
|
masterTest.addAction(actionToAdd);
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
);
|
|
205
|
+
let errorThrown: DTError | undefined;
|
|
206
|
+
try {
|
|
207
|
+
masterTest.addAction(actionToAdd);
|
|
208
|
+
} catch(error) {
|
|
209
|
+
errorThrown = error;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
expect(errorThrown).toBeDefined();
|
|
213
|
+
expect(Object.keys(masterTest._getActions()).length).toBe(1);
|
|
214
|
+
if (errorThrown) {
|
|
215
|
+
expect(errorThrown.getCode()).toBe('id_conflict');
|
|
216
|
+
expect(errorThrown.getMessage()).toBe('Action with same id already exists in the Master instance');
|
|
217
|
+
expect(errorThrown.getInitiator().getId()).toBe(IDTest);
|
|
218
|
+
expect(errorThrown.getConvicted().getId()).toBe(actionToAdd.getId());
|
|
219
|
+
}
|
|
244
220
|
});
|
|
245
221
|
|
|
246
222
|
test('trigger error when adding two actions with same key', () => {
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
223
|
+
const firstAction = new DTActionStub();
|
|
224
|
+
firstAction._setId(action2IDTest);
|
|
225
|
+
masterTest.addAction(firstAction);
|
|
226
|
+
let errorThrown: DTError | undefined;
|
|
227
|
+
try {
|
|
228
|
+
masterTest.addAction(actionToAdd);
|
|
229
|
+
} catch(error) {
|
|
230
|
+
errorThrown = error;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
expect(errorThrown).toBeDefined();
|
|
234
|
+
expect(Object.keys(masterTest._getActions()).length).toBe(1);
|
|
235
|
+
if (errorThrown) {
|
|
236
|
+
expect(errorThrown.getCode()).toBe('key_conflict');
|
|
237
|
+
expect(errorThrown.getMessage()).toBe('Action with same key already exists in the Master instance');
|
|
238
|
+
expect(errorThrown.getInitiator().getId()).toBe(IDTest);
|
|
239
|
+
expect(errorThrown.getConvicted().getId()).toBe(actionToAdd.getId());
|
|
240
|
+
}
|
|
262
241
|
});
|
|
263
242
|
|
|
264
243
|
test('set context when adding a new action', () => {
|
|
244
|
+
const setContextSpy = jest.spyOn(actionToAdd, 'setContext');
|
|
245
|
+
|
|
265
246
|
masterTest.addAction(actionToAdd);
|
|
266
247
|
|
|
267
|
-
expect(
|
|
268
|
-
expect(
|
|
248
|
+
expect(setContextSpy.mock.calls.length).toBe(1);
|
|
249
|
+
expect(setContextSpy.mock.calls[0][0].getId()).toBe(IDTest);
|
|
269
250
|
});
|
|
270
251
|
});
|
|
271
252
|
|
|
272
253
|
describe('getAction()', () => {
|
|
273
254
|
beforeEach(() => {
|
|
274
|
-
|
|
255
|
+
masterTest.populate();
|
|
275
256
|
});
|
|
276
257
|
|
|
277
258
|
test('return an action by its id', () => {
|
|
278
|
-
const action = masterTest.getAction(action1IDTest)
|
|
259
|
+
const action = masterTest.getAction(action1IDTest);
|
|
279
260
|
|
|
280
261
|
expect(action).toBeDefined();
|
|
281
|
-
expect(action.
|
|
262
|
+
expect(action.getId()).toBe(action1IDTest);
|
|
282
263
|
});
|
|
283
264
|
|
|
284
265
|
test('return an action by its key', () => {
|
|
285
|
-
const action = masterTest.getAction(action2KeyTest)
|
|
266
|
+
const action = masterTest.getAction(action2KeyTest);
|
|
286
267
|
|
|
287
268
|
expect(action).toBeDefined();
|
|
288
|
-
expect(action.
|
|
269
|
+
expect(action.getId()).toBe(action2IDTest);
|
|
289
270
|
});
|
|
290
271
|
|
|
291
272
|
test('return undefined if action is not found', () => {
|
|
@@ -297,57 +278,35 @@ describe('class DYOToolsMaster', () => {
|
|
|
297
278
|
|
|
298
279
|
describe('removeAction()', () => {
|
|
299
280
|
beforeEach(() => {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
const actions = masterTest.th_get_actions();
|
|
303
|
-
jest.spyOn(masterTest, 'getAction').mockImplementation(function(idOrKey: string): DTAction | undefined {
|
|
304
|
-
if (idOrKey === action2KeyTest) {
|
|
305
|
-
return actions[action2IDTest];
|
|
306
|
-
} else if (idOrKey === 'unexisting-id') {
|
|
307
|
-
return undefined;
|
|
308
|
-
} else {
|
|
309
|
-
return actions[action1IDTest];
|
|
310
|
-
}
|
|
311
|
-
});
|
|
281
|
+
masterTest.populate();
|
|
312
282
|
});
|
|
313
283
|
|
|
314
284
|
test('remove an action by its id', () => {
|
|
315
285
|
masterTest.removeAction(action1IDTest);
|
|
316
286
|
|
|
317
|
-
expect(Object.keys(masterTest.
|
|
318
|
-
expect(Object.keys(masterTest.
|
|
287
|
+
expect(Object.keys(masterTest._getActions()).length).toBe(1);
|
|
288
|
+
expect(Object.keys(masterTest._getActions())[0]).toBe(action2IDTest);
|
|
319
289
|
});
|
|
320
290
|
|
|
321
291
|
test('remove an action by its key', () => {
|
|
322
292
|
masterTest.removeAction(action2KeyTest);
|
|
323
293
|
|
|
324
|
-
expect(Object.keys(masterTest.
|
|
325
|
-
expect(Object.keys(masterTest.
|
|
294
|
+
expect(Object.keys(masterTest._getActions()).length).toBe(1);
|
|
295
|
+
expect(Object.keys(masterTest._getActions())[0]).toBe(action1IDTest);
|
|
326
296
|
});
|
|
327
297
|
|
|
328
298
|
test('no removal if action is not found', () => {
|
|
329
299
|
masterTest.removeAction('unexisting-id');
|
|
330
300
|
|
|
331
|
-
expect(Object.keys(masterTest.
|
|
332
|
-
expect(Object.keys(masterTest.
|
|
333
|
-
expect(Object.keys(masterTest.
|
|
301
|
+
expect(Object.keys(masterTest._getActions()).length).toBe(2);
|
|
302
|
+
expect(Object.keys(masterTest._getActions())[0]).toBe(action1IDTest);
|
|
303
|
+
expect(Object.keys(masterTest._getActions())[1]).toBe(action2IDTest);
|
|
334
304
|
});
|
|
335
305
|
});
|
|
336
306
|
|
|
337
307
|
describe('executeAction()', () => {
|
|
338
308
|
beforeEach(() => {
|
|
339
|
-
|
|
340
|
-
const actions = masterTest.th_get_actions();
|
|
341
|
-
|
|
342
|
-
jest.spyOn(masterTest, 'getAction').mockImplementation(function(idOrKey: string): DTAction | undefined {
|
|
343
|
-
if (idOrKey === action2KeyTest) {
|
|
344
|
-
return actions[action2IDTest];
|
|
345
|
-
} else if (idOrKey === 'unexisting-id') {
|
|
346
|
-
return undefined;
|
|
347
|
-
} else {
|
|
348
|
-
return actions[action1IDTest];
|
|
349
|
-
}
|
|
350
|
-
});
|
|
309
|
+
masterTest.populate();
|
|
351
310
|
});
|
|
352
311
|
|
|
353
312
|
test('call execute method with payload for action by its id', async () => {
|
|
@@ -377,8 +336,6 @@ describe('class DYOToolsMaster', () => {
|
|
|
377
336
|
|
|
378
337
|
beforeEach(() => {
|
|
379
338
|
moduleToAdd = new DTModuleStub();
|
|
380
|
-
|
|
381
|
-
jest.spyOn(masterTest, 'getId').mockReturnValue(IDTest);
|
|
382
339
|
});
|
|
383
340
|
|
|
384
341
|
test('add a new module - standard case', () => {
|
|
@@ -388,64 +345,72 @@ describe('class DYOToolsMaster', () => {
|
|
|
388
345
|
});
|
|
389
346
|
|
|
390
347
|
test('trigger error when adding two modules with same id', () => {
|
|
391
|
-
const mockedTriggerError: MockedFunction<(error: DYOToolsError) => void> = DTMaster.prototype.triggerError as MockedFunction<(error: DYOToolsError) => void>;
|
|
392
|
-
|
|
393
348
|
masterTest.addModule(moduleToAdd);
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
)
|
|
349
|
+
let errorThrown: DTError | undefined;
|
|
350
|
+
try {
|
|
351
|
+
masterTest.addModule(moduleToAdd);
|
|
352
|
+
} catch(error) {
|
|
353
|
+
errorThrown = error;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
expect(errorThrown).toBeDefined();
|
|
357
|
+
expect(Object.keys(masterTest._getModules()).length).toBe(1);
|
|
358
|
+
if (errorThrown) {
|
|
359
|
+
expect(errorThrown.getCode()).toBe('id_conflict');
|
|
360
|
+
expect(errorThrown.getMessage()).toBe('Module with same id already exists in the Master instance');
|
|
361
|
+
expect(errorThrown.getInitiator().getId()).toBe(IDTest);
|
|
362
|
+
expect(errorThrown.getConvicted().getId()).toBe(moduleToAdd.getId());
|
|
363
|
+
}
|
|
404
364
|
});
|
|
405
365
|
|
|
406
366
|
test('trigger error when adding two modules with same key', () => {
|
|
407
|
-
const
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
367
|
+
const firstModule = new DTModuleStub();
|
|
368
|
+
firstModule._setId(module2IDTest);
|
|
369
|
+
masterTest.addModule(firstModule);
|
|
370
|
+
let errorThrown: DTError | undefined;
|
|
371
|
+
try {
|
|
372
|
+
masterTest.addModule(moduleToAdd);
|
|
373
|
+
} catch(error) {
|
|
374
|
+
errorThrown = error;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
expect(errorThrown).toBeDefined();
|
|
378
|
+
expect(Object.keys(masterTest._getModules()).length).toBe(1);
|
|
379
|
+
if (errorThrown) {
|
|
380
|
+
expect(errorThrown.getCode()).toBe('key_conflict');
|
|
381
|
+
expect(errorThrown.getMessage()).toBe('Module with same key already exists in the Master instance');
|
|
382
|
+
expect(errorThrown.getInitiator().getId()).toBe(IDTest);
|
|
383
|
+
expect(errorThrown.getConvicted().getId()).toBe(moduleToAdd.getId());
|
|
384
|
+
}
|
|
422
385
|
});
|
|
423
386
|
|
|
424
387
|
test('set context when adding a new module', () => {
|
|
388
|
+
const setContextSpy = jest.spyOn(moduleToAdd, 'setContext');
|
|
389
|
+
|
|
425
390
|
masterTest.addModule(moduleToAdd);
|
|
426
391
|
|
|
427
|
-
expect(
|
|
428
|
-
expect(
|
|
392
|
+
expect(setContextSpy.mock.calls.length).toBe(1);
|
|
393
|
+
expect(setContextSpy.mock.calls[0][0].getId()).toBe(IDTest);
|
|
429
394
|
});
|
|
430
395
|
});
|
|
431
396
|
|
|
432
397
|
describe('getModule()', () => {
|
|
433
398
|
beforeEach(() => {
|
|
434
|
-
|
|
399
|
+
masterTest.populate();
|
|
435
400
|
});
|
|
436
401
|
|
|
437
402
|
test('return a module by its id', () => {
|
|
438
|
-
const module = masterTest.getModule(module1IDTest)
|
|
403
|
+
const module = masterTest.getModule(module1IDTest);
|
|
439
404
|
|
|
440
405
|
expect(module).toBeDefined();
|
|
441
|
-
expect(module.
|
|
406
|
+
expect(module.getId()).toBe(module1IDTest);
|
|
442
407
|
});
|
|
443
408
|
|
|
444
409
|
test('return a module by its key', () => {
|
|
445
|
-
const module = masterTest.getModule(module2KeyTest)
|
|
410
|
+
const module = masterTest.getModule(module2KeyTest);
|
|
446
411
|
|
|
447
412
|
expect(module).toBeDefined();
|
|
448
|
-
expect(module.
|
|
413
|
+
expect(module.getId()).toBe(module2IDTest);
|
|
449
414
|
});
|
|
450
415
|
|
|
451
416
|
test('return undefined if module is not found', () => {
|
|
@@ -457,48 +422,33 @@ describe('class DYOToolsMaster', () => {
|
|
|
457
422
|
|
|
458
423
|
describe('removeModule()', () => {
|
|
459
424
|
beforeEach(() => {
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
const modules = masterTest.th_get_modules();
|
|
463
|
-
jest.spyOn(masterTest, 'getModule').mockImplementation(function(idOrKey: string): DTModule | undefined {
|
|
464
|
-
if (idOrKey === module2KeyTest) {
|
|
465
|
-
return modules[module2IDTest];
|
|
466
|
-
} else if (idOrKey === 'unexisting-id') {
|
|
467
|
-
return undefined;
|
|
468
|
-
} else {
|
|
469
|
-
return modules[module1IDTest];
|
|
470
|
-
}
|
|
471
|
-
});
|
|
425
|
+
masterTest.populate();
|
|
472
426
|
});
|
|
473
427
|
|
|
474
428
|
test('remove a module by its id', () => {
|
|
475
429
|
masterTest.removeModule(module1IDTest);
|
|
476
430
|
|
|
477
|
-
expect(Object.keys(masterTest.
|
|
478
|
-
expect(Object.keys(masterTest.
|
|
431
|
+
expect(Object.keys(masterTest._getModules()).length).toBe(1);
|
|
432
|
+
expect(Object.keys(masterTest._getModules())[0]).toBe(module2IDTest);
|
|
479
433
|
});
|
|
480
434
|
|
|
481
435
|
test('remove a module by its key', () => {
|
|
482
436
|
masterTest.removeModule(module2KeyTest);
|
|
483
437
|
|
|
484
|
-
expect(Object.keys(masterTest.
|
|
485
|
-
expect(Object.keys(masterTest.
|
|
438
|
+
expect(Object.keys(masterTest._getModules()).length).toBe(1);
|
|
439
|
+
expect(Object.keys(masterTest._getModules())[0]).toBe(module1IDTest);
|
|
486
440
|
});
|
|
487
441
|
|
|
488
442
|
test('no removal if module is not found', () => {
|
|
489
443
|
masterTest.removeModule('unexisting-id');
|
|
490
444
|
|
|
491
|
-
expect(Object.keys(masterTest.
|
|
492
|
-
expect(Object.keys(masterTest.
|
|
493
|
-
expect(Object.keys(masterTest.
|
|
445
|
+
expect(Object.keys(masterTest._getModules()).length).toBe(2);
|
|
446
|
+
expect(Object.keys(masterTest._getModules())[0]).toBe(module1IDTest);
|
|
447
|
+
expect(Object.keys(masterTest._getModules())[1]).toBe(module2IDTest);
|
|
494
448
|
});
|
|
495
449
|
});
|
|
496
450
|
|
|
497
451
|
describe('toString()', () => {
|
|
498
|
-
beforeEach(() => {
|
|
499
|
-
masterTest.th_set_key(KeyTest);
|
|
500
|
-
});
|
|
501
|
-
|
|
502
452
|
test('string output standard', () => {
|
|
503
453
|
const toStringMaster = masterTest.toString();
|
|
504
454
|
const expectedString = `Component ${KeyTest} - Type: Master - Managers: 0 - Actions: 0 - Modules: 0`;
|
|
@@ -507,7 +457,7 @@ describe('class DYOToolsMaster', () => {
|
|
|
507
457
|
});
|
|
508
458
|
|
|
509
459
|
test('string output standard with all components', () => {
|
|
510
|
-
|
|
460
|
+
masterTest.populate();
|
|
511
461
|
|
|
512
462
|
const toStringMaster = masterTest.toString();
|
|
513
463
|
const expectedString = `Component ${KeyTest} - Type: Master - Managers: 2 - Actions: 2 - Modules: 2`;
|
|
@@ -516,9 +466,10 @@ describe('class DYOToolsMaster', () => {
|
|
|
516
466
|
});
|
|
517
467
|
|
|
518
468
|
test('string output without actions and modules', () => {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
469
|
+
masterTest = new DTMasterTest(IDTest, KeyTest, {
|
|
470
|
+
[manager1IDTest]: new DTManagerStub(),
|
|
471
|
+
[manager2IDTest]: new DTManagerStub(),
|
|
472
|
+
});
|
|
522
473
|
|
|
523
474
|
const toStringMaster = masterTest.toString();
|
|
524
475
|
const expectedString = `Component ${KeyTest} - Type: Master - Managers: 2 - Actions: 0 - Modules: 0`;
|
|
@@ -528,10 +479,6 @@ describe('class DYOToolsMaster', () => {
|
|
|
528
479
|
});
|
|
529
480
|
|
|
530
481
|
describe('toObject()', () => {
|
|
531
|
-
beforeEach(() => {
|
|
532
|
-
masterTest.th_set_id(IDTest);
|
|
533
|
-
masterTest.th_set_key(KeyTest);
|
|
534
|
-
});
|
|
535
482
|
|
|
536
483
|
test('toObject output standard', () => {
|
|
537
484
|
const toObjectMaster = masterTest.toObject();
|
|
@@ -548,7 +495,9 @@ describe('class DYOToolsMaster', () => {
|
|
|
548
495
|
test('toObject output with managers', () => {
|
|
549
496
|
const manager1 = new DTManagerStub();
|
|
550
497
|
jest.spyOn(manager1, 'toObject').mockImplementation(() => manager1ToObject);
|
|
551
|
-
masterTest
|
|
498
|
+
masterTest = new DTMasterTest(IDTest, KeyTest, {
|
|
499
|
+
[manager1IDTest]: manager1,
|
|
500
|
+
});
|
|
552
501
|
|
|
553
502
|
const toObjectMaster = masterTest.toObject();
|
|
554
503
|
|
|
@@ -563,13 +512,17 @@ describe('class DYOToolsMaster', () => {
|
|
|
563
512
|
test('toObject output with managers, actions and modules', () => {
|
|
564
513
|
const manager1 = new DTManagerStub();
|
|
565
514
|
jest.spyOn(manager1, 'toObject').mockImplementation(() => manager1ToObject);
|
|
566
|
-
masterTest.th_set_managers({ [manager1IDTest]: manager1 });
|
|
567
515
|
const action1 = new DTActionStub();
|
|
568
516
|
jest.spyOn(action1, 'toObject').mockImplementation(() => action1ToObject);
|
|
569
|
-
masterTest.th_set_actions({ [action1IDTest]: action1 });
|
|
570
517
|
const module1 = new DTModuleStub();
|
|
571
518
|
jest.spyOn(module1, 'toObject').mockImplementation(() => module1ToObject);
|
|
572
|
-
masterTest
|
|
519
|
+
masterTest = new DTMasterTest(IDTest, KeyTest, {
|
|
520
|
+
[manager1IDTest]: manager1,
|
|
521
|
+
}, {
|
|
522
|
+
[action1IDTest]: action1,
|
|
523
|
+
}, {
|
|
524
|
+
[module1IDTest]: module1,
|
|
525
|
+
});
|
|
573
526
|
|
|
574
527
|
const toObjectMaster = masterTest.toObject();
|
|
575
528
|
|