dyo-tools 0.1.0 → 0.3.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 -0
- package/.eslintignore +2 -0
- package/.eslintrc.json +47 -0
- package/Makefile +34 -0
- package/README.md +0 -7
- package/babel.config.js +1 -0
- package/cucumber-report.html +48 -0
- package/dist/constants.d.ts +6 -0
- package/dist/constants.js +63 -0
- package/dist/constants.js.map +1 -0
- package/dist/core/DTAction.d.ts +10 -0
- package/dist/core/DTAction.js +24 -0
- package/dist/core/DTAction.js.map +1 -0
- package/dist/core/DTBunch.d.ts +12 -17
- package/dist/core/DTBunch.js +39 -115
- package/dist/core/DTBunch.js.map +1 -1
- package/dist/core/DTComponent.d.ts +13 -5
- package/dist/core/DTComponent.js +39 -1
- package/dist/core/DTComponent.js.map +1 -1
- package/dist/core/DTComponentPhysical.d.ts +12 -0
- package/dist/core/DTComponentPhysical.js +22 -0
- package/dist/core/DTComponentPhysical.js.map +1 -0
- package/dist/core/DTComponentWithMeta.d.ts +2 -2
- package/dist/core/DTComponentWithMeta.js.map +1 -1
- package/dist/core/DTElement.d.ts +7 -7
- package/dist/core/DTElement.js +12 -11
- package/dist/core/DTElement.js.map +1 -1
- package/dist/core/DTManager.d.ts +33 -0
- package/dist/core/DTManager.js +190 -0
- package/dist/core/DTManager.js.map +1 -0
- package/dist/core/DTMaster.d.ts +24 -0
- package/dist/core/DTMaster.js +133 -0
- package/dist/core/DTMaster.js.map +1 -0
- package/dist/core/DTModule.d.ts +14 -0
- package/dist/core/DTModule.js +39 -0
- package/dist/core/DTModule.js.map +1 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +15 -3
- package/dist/index.js.map +1 -1
- package/dist/libs/DYOFinder.d.ts +10 -0
- package/dist/libs/DYOFinder.js +96 -0
- package/dist/libs/DYOFinder.js.map +1 -0
- package/dist/libs/player/DTPlayer.element.d.ts +5 -0
- package/dist/libs/player/DTPlayer.element.js +11 -0
- package/dist/libs/player/DTPlayer.element.js.map +1 -0
- package/dist/libs/player/DTPlayer.manager.d.ts +11 -0
- package/dist/libs/player/DTPlayer.manager.js +42 -0
- package/dist/libs/player/DTPlayer.manager.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1321
- package/dist/types/core.d.ts +103 -0
- package/dist/types/core.js +15 -0
- package/dist/types/core.js.map +1 -0
- package/dist/types/index.d.ts +2 -58
- package/dist/types/index.js +16 -12
- package/dist/types/index.js.map +1 -1
- package/dist/types/player.d.ts +5 -0
- package/dist/types/player.js +3 -0
- package/dist/types/player.js.map +1 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +29 -0
- package/docs/assets/main.js +59 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1414 -0
- package/docs/classes/core_DTAction.DYOToolsAction.html +89 -0
- package/docs/classes/core_DTBunch.DYOToolsBunch.html +254 -0
- package/docs/classes/core_DTComponent.DYOToolsComponent.html +76 -0
- package/docs/classes/core_DTComponentPhysical.DYOToolsComponentPhysical.html +110 -0
- package/docs/classes/core_DTComponentWithMeta.DYOToolsComponentWithMeta.html +96 -0
- package/docs/classes/core_DTElement.DYOToolsElement.html +135 -0
- package/docs/classes/core_DTError.DYOToolsError.html +37 -0
- package/docs/classes/core_DTManager.DYOToolsManager.html +237 -0
- package/docs/classes/core_DTMaster.DYOToolsMaster.html +150 -0
- package/docs/classes/core_DTModule.DYOToolsModule.html +92 -0
- package/docs/classes/libs_DYOFinder.DYOFinder.html +34 -0
- package/docs/classes/libs_player_DTPlayer_element.DYOToolsPlayer.html +134 -0
- package/docs/classes/libs_player_DTPlayer_manager.DYOToolsPlayerManager.html +243 -0
- package/docs/enums/types_core.FilterOperatorType.html +10 -0
- package/docs/hierarchy.html +1 -0
- package/docs/index.html +1 -0
- package/docs/interfaces/types_core.DTBunchFilters.html +6 -0
- package/docs/interfaces/types_core.DTBunchOptions.html +19 -0
- package/docs/interfaces/types_core.DTBunchToObject.html +7 -0
- package/docs/interfaces/types_core.DTComponentOptions.html +5 -0
- package/docs/interfaces/types_core.DTComponentToObject.html +4 -0
- package/docs/interfaces/types_core.DTElementToObject.html +7 -0
- package/docs/interfaces/types_core.DTManagerFilters.html +6 -0
- package/docs/interfaces/types_core.DTManagerOptions.html +8 -0
- package/docs/interfaces/types_core.DTManagerToObject.html +5 -0
- package/docs/interfaces/types_core.DTMasterToObject.html +8 -0
- package/docs/interfaces/types_core.DTModuleToObject.html +6 -0
- package/docs/interfaces/types_core.DYOFinderConfigurationPropDefault.html +4 -0
- package/docs/interfaces/types_core.DYOFinderConfigurationPropObjectSearch.html +4 -0
- package/docs/interfaces/types_core.DYOFinderFilterOperatorAdvanced.html +5 -0
- package/docs/interfaces/types_core.DYOFinderFilterOperatorBase.html +5 -0
- package/docs/interfaces/types_player.DTPlayerManagerSimpleConfiguration.html +3 -0
- package/docs/modules/constants.html +6 -0
- package/docs/modules/core_DTAction.html +2 -0
- package/docs/modules/core_DTBunch.html +2 -0
- package/docs/modules/core_DTComponent.html +2 -0
- package/docs/modules/core_DTComponentPhysical.html +2 -0
- package/docs/modules/core_DTComponentWithMeta.html +2 -0
- package/docs/modules/core_DTElement.html +2 -0
- package/docs/modules/core_DTError.html +2 -0
- package/docs/modules/core_DTManager.html +2 -0
- package/docs/modules/core_DTMaster.html +2 -0
- package/docs/modules/core_DTModule.html +2 -0
- package/docs/modules/libs_DYOFinder.html +2 -0
- package/docs/modules/libs_player_DTPlayer_element.html +2 -0
- package/docs/modules/libs_player_DTPlayer_manager.html +2 -0
- package/docs/modules/types.html +29 -0
- package/docs/modules/types_core.html +28 -0
- package/docs/modules/types_player.html +2 -0
- package/docs/types/types_core.DTAcceptedMetaData.html +2 -0
- package/docs/types/types_core.DTManagerItemType.html +1 -0
- package/docs/types/types_core.DTManagerItemsType.html +2 -0
- package/docs/types/types_core.DYOFinderComponentType.html +1 -0
- package/docs/types/types_core.DYOFinderConfiguration.html +2 -0
- package/docs/types/types_core.DYOFinderConfigurationProp.html +1 -0
- package/docs/types/types_core.DYOFinderFilterOperator.html +1 -0
- package/docs/types/types_core.DYOFinderFilterOperatorArgument.html +1 -0
- package/docs/types/types_core.DYOFinderFilters.html +1 -0
- package/docs/types/types_core.StandardPrimitiveType.html +2 -0
- package/docs/types/types_core.StandardPrimitiveTypeWithArray.html +1 -0
- package/docs/variables/constants.bunchDefaultOptions.html +2 -0
- package/docs/variables/constants.componentBunchDefaultFinderConfiguration.html +1 -0
- package/docs/variables/constants.componentManagerDefaultFinderConfiguration.html +1 -0
- package/docs/variables/constants.componentPhysicalDefaultFinderConfiguration.html +1 -0
- package/docs/variables/constants.managerDefaultOptions.html +2 -0
- package/jest.config.js +6 -0
- package/package.json +32 -23
- package/src/constants.ts +85 -0
- package/src/core/DTAction.ts +52 -0
- package/src/core/DTBunch.ts +467 -0
- package/src/core/DTComponent.ts +225 -0
- package/src/core/DTComponentPhysical.ts +53 -0
- package/src/core/DTComponentWithMeta.ts +65 -0
- package/src/core/DTElement.ts +102 -0
- package/src/core/DTError.ts +78 -0
- package/src/core/DTManager.ts +465 -0
- package/src/core/DTMaster.ts +318 -0
- package/src/core/DTModule.ts +90 -0
- package/src/index.ts +17 -0
- package/src/libs/DYOFinder.ts +175 -0
- package/src/libs/player/DTPlayer.element.ts +9 -0
- package/src/libs/player/DTPlayer.manager.ts +84 -0
- package/src/types/core.ts +169 -0
- package/src/types/index.ts +2 -0
- package/src/types/player.ts +6 -0
- package/test/core/DTAction.double.ts +78 -0
- package/test/core/DTAction.spec.ts +76 -0
- package/test/core/DTBunch.double.ts +261 -0
- package/test/core/DTBunch.spec.ts +897 -0
- package/test/core/DTComponent.double.ts +164 -0
- package/test/core/DTComponent.spec.ts +295 -0
- package/test/core/DTComponentPhysical.double.ts +76 -0
- package/test/core/DTComponentPhysical.spec.ts +78 -0
- package/test/core/DTComponentWithMeta.double.ts +115 -0
- package/test/core/DTComponentWithMeta.spec.ts +124 -0
- package/test/core/DTElement.double.ts +163 -0
- package/test/core/DTElement.spec.ts +146 -0
- package/test/core/DTError.double.ts +92 -0
- package/test/core/DTError.spec.ts +89 -0
- package/test/core/DTManager.double.ts +216 -0
- package/test/core/DTManager.spec.ts +965 -0
- package/test/core/DTMaster.double.ts +141 -0
- package/test/core/DTMaster.spec.ts +584 -0
- package/test/core/DTModule.double.ts +80 -0
- package/test/core/DTModule.spec.ts +138 -0
- package/test/core/copy.spec.ts +243 -0
- package/test/libs/DYOFinder.double.ts +152 -0
- package/test/libs/DYOFinder.spec.ts +194 -0
- package/test/libs/player/DTPlayer.element.double.ts +55 -0
- package/test/libs/player/DTPlayer.element.spec.ts +28 -0
- package/test/libs/player/DTPlayer.manager.double.ts +92 -0
- package/test/libs/player/DTPlayer.manager.spec.ts +178 -0
- package/tsconfig.dev.json +22 -0
- package/tsconfig.json +21 -0
- package/dist/core/DTPlayer.d.ts +0 -8
- package/dist/core/DTPlayer.js +0 -30
- package/dist/core/DTPlayer.js.map +0 -1
- package/dist/utils/filters.d.ts +0 -6
- package/dist/utils/filters.js +0 -39
- package/dist/utils/filters.js.map +0 -1
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import {DTComponentWithMeta} from '../../src';
|
|
2
|
+
import {DTAcceptedMetaData} from "../../src/types";
|
|
3
|
+
|
|
4
|
+
/******************** STUB PROPERTIES CONSTANTS
|
|
5
|
+
* Fixed properties to use with double classes, avoid auto generated and easy checking on test
|
|
6
|
+
* *****/
|
|
7
|
+
// Test meta data interface
|
|
8
|
+
export interface IMetaDataTest extends DTAcceptedMetaData {
|
|
9
|
+
name: string,
|
|
10
|
+
queen: boolean,
|
|
11
|
+
kd: number[],
|
|
12
|
+
rank?: number,
|
|
13
|
+
tribes?: string[]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Global properties
|
|
17
|
+
export const IDTest = "DTComponentWithMeta-id-1234567";
|
|
18
|
+
export const KeyTest = "DTComponentWithMeta-key-1234567";
|
|
19
|
+
export const ComponentTypeTest = 'DTComponentWithMeta-componentType-test';
|
|
20
|
+
export const ToObjectTest = { type: "DTComponentWithMeta-test-toObject" };
|
|
21
|
+
export const ToStringTest = "DTComponentWithMeta-test-toString";
|
|
22
|
+
|
|
23
|
+
// Specific components tests meta-data
|
|
24
|
+
export const HaileiMetaData: IMetaDataTest = {
|
|
25
|
+
name: 'Hailei Dorcan Kazan',
|
|
26
|
+
queen: true,
|
|
27
|
+
kd: [47, 1],
|
|
28
|
+
rank: 1,
|
|
29
|
+
tribes: ['Peuple de Salta', 'Fils de Salta', 'Peuple Kanti'],
|
|
30
|
+
};
|
|
31
|
+
export const MeldrineMetaData: IMetaDataTest = {
|
|
32
|
+
name: 'Meldrine Goldmane',
|
|
33
|
+
queen: false,
|
|
34
|
+
kd: [53, 0],
|
|
35
|
+
rank: 2,
|
|
36
|
+
tribes: ['Lodaniens'],
|
|
37
|
+
};
|
|
38
|
+
export const MaydenaMetaData: IMetaDataTest = {
|
|
39
|
+
name: "Maydena 'Intan Kazan",
|
|
40
|
+
queen: true,
|
|
41
|
+
kd: [29, 0],
|
|
42
|
+
tribes: ['Exil rouge', 'Désolation'],
|
|
43
|
+
};
|
|
44
|
+
export const IldressMetaData: IMetaDataTest = {
|
|
45
|
+
name: 'Electel Ildress',
|
|
46
|
+
queen: false,
|
|
47
|
+
kd: [19, 1],
|
|
48
|
+
rank: 3,
|
|
49
|
+
};
|
|
50
|
+
export const YssaliaMetaData: IMetaDataTest = {
|
|
51
|
+
name: 'Yssalia du Gillit',
|
|
52
|
+
queen: true,
|
|
53
|
+
kd: [23, 0],
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// Player default value
|
|
57
|
+
export const PlayerMetaData: IMetaDataTest = {
|
|
58
|
+
name: 'Llhôonn',
|
|
59
|
+
queen: true,
|
|
60
|
+
kd: [0, 0],
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Bunch default value
|
|
64
|
+
export const BunchMetaData: IMetaDataTest = {
|
|
65
|
+
name: 'Elementary Pentacle',
|
|
66
|
+
queen: true,
|
|
67
|
+
kd: [117, 3],
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/******************** STUB ABSTRACT IMPLEMENTATION
|
|
71
|
+
* Implementation of abstract component class for tests
|
|
72
|
+
* *****/
|
|
73
|
+
export class DTComponentWithMetaImpl extends DTComponentWithMeta<IMetaDataTest> {
|
|
74
|
+
protected _componentType: string = ComponentTypeTest;
|
|
75
|
+
|
|
76
|
+
copy(): DTComponentWithMeta<IMetaDataTest> {
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
toObject(): any {
|
|
81
|
+
return ToObjectTest;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
toString(): string {
|
|
85
|
+
return ToStringTest;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/******************** HELPER TEST CLASS
|
|
90
|
+
* Helper test class, inherits the main component
|
|
91
|
+
* Providing methods to property access and other facilities, in order to avoid using class methods
|
|
92
|
+
* *****/
|
|
93
|
+
export class DTComponentWithMetaTest extends DTComponentWithMetaImpl {
|
|
94
|
+
th_get_meta(): Partial<IMetaDataTest> {
|
|
95
|
+
return this._meta;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
th_set_meta(meta: Partial<IMetaDataTest>): void {
|
|
99
|
+
this._meta = meta;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/******************** HELPER METHODS
|
|
104
|
+
* Additional helper methods to use with testing
|
|
105
|
+
* *****/
|
|
106
|
+
// Mocked implementations for overridden methods (for children tests)
|
|
107
|
+
export function mockOverriddenMethods(mock: any) {
|
|
108
|
+
// Constructor
|
|
109
|
+
mock.prototype.constructor.mockImplementation(function (key?: string) {
|
|
110
|
+
this._id = IDTest;
|
|
111
|
+
this._key = key || this._id;
|
|
112
|
+
this._errors = [];
|
|
113
|
+
return this;
|
|
114
|
+
})
|
|
115
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import {afterEach, beforeEach, describe, expect, jest, test,} from '@jest/globals';
|
|
2
|
+
import {
|
|
3
|
+
DTComponentWithMetaTest,
|
|
4
|
+
HaileiMetaData,
|
|
5
|
+
IMetaDataTest,
|
|
6
|
+
MeldrineMetaData,
|
|
7
|
+
YssaliaMetaData
|
|
8
|
+
} from './DTComponentWithMeta.double';
|
|
9
|
+
import {mockOverriddenMethods} from "./DTComponent.double";
|
|
10
|
+
import {DTComponent, DTComponentWithMeta} from "../../src";
|
|
11
|
+
|
|
12
|
+
/******************** MOCK DEPENDENCIES
|
|
13
|
+
* All Dependencies used by the component are mocked with Jest
|
|
14
|
+
* *****/
|
|
15
|
+
jest.mock('../../src/core/DTComponent');
|
|
16
|
+
mockOverriddenMethods(DTComponent);
|
|
17
|
+
|
|
18
|
+
/************************* TESTS SUITES *******************************/
|
|
19
|
+
describe('class DYOToolsComponentWithMeta', () => {
|
|
20
|
+
let componentWithMetaTest: DTComponentWithMetaTest;
|
|
21
|
+
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
componentWithMetaTest = new DTComponentWithMetaTest();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
jest.resetAllMocks();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe('inheritance', () => {
|
|
31
|
+
test('check good inheritance for class', () => {
|
|
32
|
+
expect(DTComponentWithMeta.prototype instanceof DTComponent).toBeTruthy();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('getMeta()', () => {
|
|
37
|
+
test('return undefined if meta is empty', () => {
|
|
38
|
+
expect(componentWithMetaTest.getMeta('name')).toBeUndefined();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('return one meta by key', () => {
|
|
42
|
+
componentWithMetaTest.th_set_meta(HaileiMetaData);
|
|
43
|
+
|
|
44
|
+
expect(componentWithMetaTest.getMeta('name')).toBe(HaileiMetaData.name);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('setMeta()', () => {
|
|
49
|
+
test('set a new value for a meta', () => {
|
|
50
|
+
componentWithMetaTest.th_set_meta(HaileiMetaData);
|
|
51
|
+
componentWithMetaTest.setMeta('name', MeldrineMetaData.name);
|
|
52
|
+
|
|
53
|
+
const newMeta = componentWithMetaTest.th_get_meta();
|
|
54
|
+
expect(newMeta.name === MeldrineMetaData.name).toBeTruthy();
|
|
55
|
+
expect(newMeta.rank === HaileiMetaData.rank).toBeTruthy();
|
|
56
|
+
expect(newMeta.queen === HaileiMetaData.queen).toBeTruthy();
|
|
57
|
+
expect(newMeta.kd[0] === HaileiMetaData.kd[0]).toBeTruthy();
|
|
58
|
+
expect(newMeta.tribes[0] === HaileiMetaData.tribes[0]).toBeTruthy();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('getManyMeta()', () => {
|
|
63
|
+
test('return empty object meta by default', () => {
|
|
64
|
+
const keys: Array<keyof IMetaDataTest> = ['name', 'rank', 'tribes'];
|
|
65
|
+
|
|
66
|
+
expect(componentWithMetaTest.getManyMeta()).toStrictEqual({});
|
|
67
|
+
expect(componentWithMetaTest.getManyMeta(keys)).toStrictEqual({});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('return all meta', () => {
|
|
71
|
+
componentWithMetaTest.th_set_meta(HaileiMetaData);
|
|
72
|
+
|
|
73
|
+
expect(componentWithMetaTest.getManyMeta()).toStrictEqual(HaileiMetaData);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('return meta by keys', () => {
|
|
77
|
+
componentWithMetaTest.th_set_meta(HaileiMetaData);
|
|
78
|
+
const keys: Array<keyof IMetaDataTest> = ['name', 'kd', 'queen'];
|
|
79
|
+
|
|
80
|
+
expect(componentWithMetaTest.getManyMeta(keys)).toStrictEqual({
|
|
81
|
+
name: HaileiMetaData.name,
|
|
82
|
+
kd: HaileiMetaData.kd,
|
|
83
|
+
queen: HaileiMetaData.queen,
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('return meta by keys - unexisting keys', () => {
|
|
88
|
+
componentWithMetaTest.th_set_meta(YssaliaMetaData);
|
|
89
|
+
const keys: Array<keyof IMetaDataTest> = ['name', 'rank', 'tribes'];
|
|
90
|
+
|
|
91
|
+
expect(componentWithMetaTest.getManyMeta(keys)).toStrictEqual({
|
|
92
|
+
name: YssaliaMetaData.name,
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe('setManyMeta()', () => {
|
|
98
|
+
test('set new values', () => {
|
|
99
|
+
componentWithMetaTest.th_set_meta(HaileiMetaData);
|
|
100
|
+
const setValues: Partial<IMetaDataTest> = {
|
|
101
|
+
name: MeldrineMetaData.name,
|
|
102
|
+
queen: MeldrineMetaData.queen,
|
|
103
|
+
rank: MeldrineMetaData.rank,
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
componentWithMetaTest.setManyMeta(setValues);
|
|
107
|
+
|
|
108
|
+
const newMeta = componentWithMetaTest.th_get_meta();
|
|
109
|
+
expect(newMeta.name === MeldrineMetaData.name).toBeTruthy();
|
|
110
|
+
expect(newMeta.queen === MeldrineMetaData.queen).toBeTruthy();
|
|
111
|
+
expect(newMeta.kd[0] === HaileiMetaData.kd[0]).toBeTruthy();
|
|
112
|
+
expect(newMeta.rank === MeldrineMetaData.rank).toBeTruthy();
|
|
113
|
+
expect(newMeta.tribes[0] === HaileiMetaData.tribes[0]).toBeTruthy();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('set empty new values (keep former meta)', () => {
|
|
117
|
+
componentWithMetaTest.th_set_meta(HaileiMetaData);
|
|
118
|
+
|
|
119
|
+
componentWithMetaTest.setManyMeta({});
|
|
120
|
+
|
|
121
|
+
expect(componentWithMetaTest.th_get_meta()).toStrictEqual(HaileiMetaData);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import {DTBunch, DTElement} from '../../src';
|
|
2
|
+
import {IMetaDataTest} from './DTComponentWithMeta.double';
|
|
3
|
+
|
|
4
|
+
/** ****************** STUB PROPERTIES CONSTANTS
|
|
5
|
+
* Fixed properties to use with double classes, avoid auto generated and easy checking on test
|
|
6
|
+
* **** */
|
|
7
|
+
// Global constants
|
|
8
|
+
export const IDTest = 'DTElement-id-1234567';
|
|
9
|
+
export const KeyTest = 'DTElement-key-1234567';
|
|
10
|
+
export const DomainTest = 'DTElement-domain-test';
|
|
11
|
+
|
|
12
|
+
// Specific elements constants
|
|
13
|
+
export const HaileiIdTest = 'DTElement-id-Hailei';
|
|
14
|
+
export const HaileiKeyTest = 'DTElement-key-Hailei';
|
|
15
|
+
export const HaileiToObjectTest = { id: 'DTElement-id-Hailei', key: 'DTElement-key-Hailei', type: 'element' };
|
|
16
|
+
export const MeldrineIdTest = 'DTElement-id-Meldrine';
|
|
17
|
+
export const MeldrineKeyTest = 'DTElement-key-Meldrine';
|
|
18
|
+
export const MeldrineToObjectTest = { id: 'DTElement-id-Meldrine', key: 'DTElement-key-Meldrine', type: 'element' };
|
|
19
|
+
export const MaydenaIdTest = 'DTElement-id-Maydena';
|
|
20
|
+
export const MaydenaKeyTest = 'DTElement-key-Maydena';
|
|
21
|
+
export const MaydenaToObjectTest = { id: 'DTElement-id-Maydena', key: 'DTElement-key-Maydena', type: 'element' };
|
|
22
|
+
export const IldressIdTest = 'DTElement-id-Ildress';
|
|
23
|
+
export const IldressKeyTest = 'DTElement-key-Ildress';
|
|
24
|
+
export const IldressToObjectTest = { id: 'DTElement-id-Ildress', key: 'DTElement-key-Ildress', type: 'element' };
|
|
25
|
+
export const YssaliaIdTest = 'DTElement-id-Yssalia';
|
|
26
|
+
export const YssaliaKeyTest = 'DTElement-key-Yssalia';
|
|
27
|
+
export const YssaliaToObjectTest = { id: 'DTElement-id-Yssalia', key: 'DTElement-key-Yssalia', type: 'element' };
|
|
28
|
+
|
|
29
|
+
/** ****************** HELPER TEST CLASS
|
|
30
|
+
* Helper test class, inherits the main component
|
|
31
|
+
* Providing methods to property access and other facilities, in order to avoid using class methods
|
|
32
|
+
* **** */
|
|
33
|
+
export class DTElementTest extends DTElement<IMetaDataTest> {
|
|
34
|
+
th_get_id(): string {
|
|
35
|
+
return this._id;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
th_set_id(id: string): void {
|
|
39
|
+
this._id = id;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
th_get_key(): string {
|
|
43
|
+
return this._key;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
th_set_key(key: string): void {
|
|
47
|
+
this._key = key;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
th_get_componentType(): string {
|
|
51
|
+
return this._componentType;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
th_get_domain(): string {
|
|
55
|
+
return this._domain;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
th_set_domain(domain: string): void {
|
|
59
|
+
this._domain = domain;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
th_get_owner(): string {
|
|
63
|
+
return this._owner;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
th_set_owner(owner: string): void {
|
|
67
|
+
this._owner = owner;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
th_set_meta(meta: IMetaDataTest): void {
|
|
71
|
+
this._meta = meta;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
th_get_container(): DTBunch<any> | undefined {
|
|
75
|
+
return this._container;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
th_set_container(container: DTBunch<any>): void {
|
|
79
|
+
this._container = container;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/** ****************** STUB CLASS
|
|
83
|
+
* Stub class, for using in other component
|
|
84
|
+
* **** */
|
|
85
|
+
export class DTElementStub extends DTElement<IMetaDataTest> {
|
|
86
|
+
public parentIndex: number;
|
|
87
|
+
|
|
88
|
+
constructor(index = 0) {
|
|
89
|
+
super();
|
|
90
|
+
this._id = IDTest;
|
|
91
|
+
this._key = KeyTest;
|
|
92
|
+
this.parentIndex = index;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
getId(): string {
|
|
96
|
+
return IDTest;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
getKey(): string {
|
|
100
|
+
return KeyTest;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
export class DTElementStubExtended extends DTElementStub {
|
|
104
|
+
private propString: string;
|
|
105
|
+
|
|
106
|
+
private propArray: string[];
|
|
107
|
+
|
|
108
|
+
private propNumber: number;
|
|
109
|
+
|
|
110
|
+
private propBoolean: boolean;
|
|
111
|
+
|
|
112
|
+
private propObject: Record<string, unknown>;
|
|
113
|
+
|
|
114
|
+
private propMeta: Record<string, unknown>;
|
|
115
|
+
|
|
116
|
+
getPropString(): string {
|
|
117
|
+
return this.propString;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
setPropString(propString: string): void {
|
|
121
|
+
this.propString = propString;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
getPropArray(): string[] {
|
|
125
|
+
return this.propArray;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
setPropArray(propArray: string[]): void {
|
|
129
|
+
this.propArray = propArray;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
getPropNumber(): number {
|
|
133
|
+
return this.propNumber;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
setPropNumber(propNumber: number): void {
|
|
137
|
+
this.propNumber = propNumber;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
getPropBoolean(): boolean {
|
|
141
|
+
return this.propBoolean;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
setPropBoolean(propBoolean: boolean): void {
|
|
145
|
+
this.propBoolean = propBoolean;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
getPropObject(): Record<string, unknown> {
|
|
149
|
+
return this.propObject;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
setPropObject(propObject: Record<string, unknown>): void {
|
|
153
|
+
this.propObject = propObject;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
getPropMeta(): Record<string, unknown> {
|
|
157
|
+
return this.propMeta;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
setPropMeta(propMeta: Record<string, unknown>): void {
|
|
161
|
+
this.propMeta = propMeta;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import {beforeEach, describe, expect, jest, test} from '@jest/globals';
|
|
2
|
+
import {DomainTest, DTElementTest, IDTest, KeyTest} from './DTElement.double';
|
|
3
|
+
import {MeldrineMetaData} from './DTComponentWithMeta.double';
|
|
4
|
+
import {DTComponentPhysical, DTElement} from "../../src";
|
|
5
|
+
import {mockOverriddenMethods, OwnerTest} from "./DTComponentPhysical.double";
|
|
6
|
+
import {DTBunchStub, IDTest as bunchIdTest} from "./DTBunch.double";
|
|
7
|
+
|
|
8
|
+
/******************** MOCK DEPENDENCIES
|
|
9
|
+
* All Dependencies used by the component are mocked with Jest
|
|
10
|
+
* *****/
|
|
11
|
+
jest.mock('../../src/core/DTComponent');
|
|
12
|
+
jest.mock('../../src/core/DTComponentWithMeta');
|
|
13
|
+
jest.mock('../../src/core/DTComponentPhysical');
|
|
14
|
+
jest.mock('../../src/core/DTBunch');
|
|
15
|
+
// Add specific mock for inherited methods to have a basic implementation
|
|
16
|
+
mockOverriddenMethods(DTComponentPhysical);
|
|
17
|
+
|
|
18
|
+
/************************* TESTS SUITES *******************************/
|
|
19
|
+
describe('class DYOToolsElement', () => {
|
|
20
|
+
let elementTest: DTElementTest;
|
|
21
|
+
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
elementTest = new DTElementTest();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
jest.resetAllMocks();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe('inheritance', () => {
|
|
31
|
+
test('check good inheritance for class', () => {
|
|
32
|
+
expect(DTElement.prototype instanceof DTComponentPhysical).toBeTruthy();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('_componentType', () => {
|
|
37
|
+
test('componentType must be "element"', () => {
|
|
38
|
+
expect(elementTest.th_get_componentType()).toBe('element');
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe('getContainer()', () => {
|
|
43
|
+
test('return undefined if no container - default case', () => {
|
|
44
|
+
expect(elementTest.getContainer()).toBeUndefined();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('return container', () => {
|
|
48
|
+
const container = new DTBunchStub();
|
|
49
|
+
elementTest.th_set_container(container);
|
|
50
|
+
|
|
51
|
+
expect(elementTest.getContainer()).toBeDefined();
|
|
52
|
+
expect(elementTest.getContainer().getId()).toStrictEqual(bunchIdTest);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('setContainer()', () => {
|
|
57
|
+
test('set a new container for element', () => {
|
|
58
|
+
const container = new DTBunchStub();
|
|
59
|
+
|
|
60
|
+
elementTest.setContainer(container);
|
|
61
|
+
|
|
62
|
+
expect(elementTest.th_get_container()).toBeDefined();
|
|
63
|
+
expect(elementTest.th_get_container().getId()).toStrictEqual(bunchIdTest);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('removeContainer()', () => {
|
|
68
|
+
test('remove the current container', () => {
|
|
69
|
+
const bunchContainer = new DTBunchStub();
|
|
70
|
+
elementTest.th_set_container(bunchContainer);
|
|
71
|
+
|
|
72
|
+
elementTest.removeContainer();
|
|
73
|
+
expect(elementTest.th_get_container()).toBeUndefined();
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('copy()', () => {
|
|
78
|
+
// @see copy.spec.ts for unit tests about copy method
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
describe('toObject()', () => {
|
|
82
|
+
beforeEach(() => {
|
|
83
|
+
elementTest.th_set_id(IDTest);
|
|
84
|
+
elementTest.th_set_key(KeyTest);
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test('toObject output standard', () => {
|
|
88
|
+
const toObjectElement = elementTest.toObject();
|
|
89
|
+
|
|
90
|
+
expect(Object.keys(toObjectElement)).toStrictEqual(['id', 'key', 'type']);
|
|
91
|
+
expect(toObjectElement.id).toBe(IDTest);
|
|
92
|
+
expect(toObjectElement.key).toBe(KeyTest);
|
|
93
|
+
expect(toObjectElement.type).toBe('element');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('toObject output standard with owner', () => {
|
|
97
|
+
elementTest.th_set_owner(OwnerTest);
|
|
98
|
+
|
|
99
|
+
const toObjectElement = elementTest.toObject();
|
|
100
|
+
|
|
101
|
+
expect(Object.keys(toObjectElement)).toStrictEqual(['id', 'key', 'type', 'owner']);
|
|
102
|
+
expect(toObjectElement.owner).toBe(OwnerTest);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('toObject output standard with owner and meta', () => {
|
|
106
|
+
jest.spyOn(elementTest, 'getManyMeta').mockImplementation(function () {
|
|
107
|
+
return this._meta;
|
|
108
|
+
});
|
|
109
|
+
elementTest.th_set_owner(OwnerTest);
|
|
110
|
+
elementTest.th_set_meta(MeldrineMetaData);
|
|
111
|
+
|
|
112
|
+
const toObjectElement = elementTest.toObject();
|
|
113
|
+
|
|
114
|
+
expect(Object.keys(toObjectElement)).toStrictEqual(['id', 'key', 'type', 'owner', 'meta']);
|
|
115
|
+
expect(toObjectElement.meta).toStrictEqual(MeldrineMetaData);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe('toString()', () => {
|
|
120
|
+
beforeEach(() => {
|
|
121
|
+
elementTest.th_set_key(KeyTest);
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
test('string output standard', () => {
|
|
125
|
+
const toStringElement = elementTest.toString();
|
|
126
|
+
|
|
127
|
+
expect(toStringElement).toBe(`Component ${KeyTest} - Type: Element`);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test('string output standard with domain', () => {
|
|
131
|
+
elementTest.th_set_domain(DomainTest);
|
|
132
|
+
|
|
133
|
+
const toStringElement = elementTest.toString();
|
|
134
|
+
|
|
135
|
+
expect(toStringElement).toBe(`Component ${DomainTest} ${KeyTest} - Type: Element`);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test('string output standard with owner', () => {
|
|
139
|
+
elementTest.th_set_owner(OwnerTest);
|
|
140
|
+
|
|
141
|
+
const toStringElement = elementTest.toString();
|
|
142
|
+
|
|
143
|
+
expect(toStringElement).toBe(`Component ${KeyTest} - Type: Element - Owner: ${OwnerTest}`);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import {DTError} from '../../src';
|
|
2
|
+
import {expect} from "@jest/globals";
|
|
3
|
+
import DYOToolsComponent from "../../src/core/DTComponent";
|
|
4
|
+
import MockedFunction = jest.MockedFunction;
|
|
5
|
+
|
|
6
|
+
/******************** STUB PROPERTIES CONSTANTS
|
|
7
|
+
* Fixed properties to use with double classes, avoid auto generated and easy checking on test
|
|
8
|
+
* *****/
|
|
9
|
+
export const CodeTest = 'DTError-code-123456';
|
|
10
|
+
export const MessageTest = 'DTError-message-test';
|
|
11
|
+
export const TimestampTest = 1500000000000;
|
|
12
|
+
|
|
13
|
+
/******************** HELPER TEST CLASS
|
|
14
|
+
* Helper test class, inherits the main component
|
|
15
|
+
* Providing methods to property access and other facilities, in order to avoid using class methods
|
|
16
|
+
* *****/
|
|
17
|
+
export class DTErrorTest extends DTError {
|
|
18
|
+
th_get_code(): string {
|
|
19
|
+
return this.code;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
th_get_message(): string {
|
|
23
|
+
return this.message;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
th_get_timestamp(): Date {
|
|
27
|
+
return this.timestamp;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
th_set_timestamp(timestamp: Date): void {
|
|
31
|
+
this.timestamp = timestamp;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
th_get_initiator(): DYOToolsComponent {
|
|
35
|
+
return this.initiator;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
th_set_initiator(initiator: DYOToolsComponent): void {
|
|
39
|
+
this.initiator = initiator;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
th_get_convicted(): DYOToolsComponent {
|
|
43
|
+
return this.convicted;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
th_set_convicted(convicted: DYOToolsComponent): void {
|
|
47
|
+
this.convicted = convicted;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/******************** STUB CLASS
|
|
52
|
+
* Stub class, for using in other component
|
|
53
|
+
* *****/
|
|
54
|
+
export class DTErrorStub extends DTError {
|
|
55
|
+
constructor() {
|
|
56
|
+
super('', '');
|
|
57
|
+
this.code = CodeTest;
|
|
58
|
+
this.message = MessageTest;
|
|
59
|
+
this.timestamp = new Date(Math.random() * 100000000);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
getCode(): string {
|
|
63
|
+
return CodeTest;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
getMessage(): string {
|
|
67
|
+
return MessageTest;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
getTimestamp(): Date {
|
|
71
|
+
return this.timestamp;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/******************** HELPER METHODS
|
|
76
|
+
* Additional helper methods to use with testing
|
|
77
|
+
* *****/
|
|
78
|
+
export const checkCallForMockedDTError = (code, message, initiatorId, convictedId?) => {
|
|
79
|
+
const mockedErrorConstructor = DTError.prototype.constructor as MockedFunction<(code: string, message: string, initiator?: DYOToolsComponent, convicted?: DYOToolsComponent) => DTError>;
|
|
80
|
+
if (!mockedErrorConstructor.mock) {
|
|
81
|
+
throw new Error('The DTError Constructor is not a mock');
|
|
82
|
+
} else {
|
|
83
|
+
expect(mockedErrorConstructor.mock.calls.length).toBe(1);
|
|
84
|
+
expect(mockedErrorConstructor.mock.calls[0][0]).toBe(code);
|
|
85
|
+
expect(mockedErrorConstructor.mock.calls[0][1]).toBe(message);
|
|
86
|
+
expect(mockedErrorConstructor.mock.calls[0][2].getId()).toBe(initiatorId);
|
|
87
|
+
if (convictedId) {
|
|
88
|
+
expect(mockedErrorConstructor.mock.calls[0][3].getId()).toBe(convictedId);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|