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.
Files changed (209) hide show
  1. package/.c8rc.json +4 -4
  2. package/.eslintignore +1 -1
  3. package/.eslintrc.json +47 -47
  4. package/Makefile +34 -34
  5. package/dist/constants.d.ts +1 -0
  6. package/dist/constants.d.ts.map +1 -0
  7. package/dist/constants.js +24 -20
  8. package/dist/constants.js.map +1 -1
  9. package/dist/core/DTAction.d.ts +6 -4
  10. package/dist/core/DTAction.d.ts.map +1 -0
  11. package/dist/core/DTAction.js +3 -6
  12. package/dist/core/DTAction.js.map +1 -1
  13. package/dist/core/DTBunch.d.ts +8 -5
  14. package/dist/core/DTBunch.d.ts.map +1 -0
  15. package/dist/core/DTBunch.js +53 -19
  16. package/dist/core/DTBunch.js.map +1 -1
  17. package/dist/core/DTComponent.d.ts +13 -10
  18. package/dist/core/DTComponent.d.ts.map +1 -0
  19. package/dist/core/DTComponent.js +23 -10
  20. package/dist/core/DTComponent.js.map +1 -1
  21. package/dist/core/DTComponentPhysical.d.ts +11 -8
  22. package/dist/core/DTComponentPhysical.d.ts.map +1 -0
  23. package/dist/core/DTComponentPhysical.js +21 -6
  24. package/dist/core/DTComponentPhysical.js.map +1 -1
  25. package/dist/core/DTComponentWithMeta.d.ts +6 -3
  26. package/dist/core/DTComponentWithMeta.d.ts.map +1 -0
  27. package/dist/core/DTComponentWithMeta.js +21 -7
  28. package/dist/core/DTComponentWithMeta.js.map +1 -1
  29. package/dist/core/DTElement.d.ts +10 -8
  30. package/dist/core/DTElement.d.ts.map +1 -0
  31. package/dist/core/DTElement.js +8 -9
  32. package/dist/core/DTElement.js.map +1 -1
  33. package/dist/core/DTError.d.ts +8 -7
  34. package/dist/core/DTError.d.ts.map +1 -0
  35. package/dist/core/DTError.js +1 -5
  36. package/dist/core/DTError.js.map +1 -1
  37. package/dist/core/DTManager.d.ts +17 -14
  38. package/dist/core/DTManager.d.ts.map +1 -0
  39. package/dist/core/DTManager.js +84 -26
  40. package/dist/core/DTManager.js.map +1 -1
  41. package/dist/core/DTMaster.d.ts +19 -16
  42. package/dist/core/DTMaster.d.ts.map +1 -0
  43. package/dist/core/DTMaster.js +48 -31
  44. package/dist/core/DTMaster.js.map +1 -1
  45. package/dist/core/DTModule.d.ts +8 -5
  46. package/dist/core/DTModule.d.ts.map +1 -0
  47. package/dist/core/DTModule.js +6 -6
  48. package/dist/core/DTModule.js.map +1 -1
  49. package/dist/index.d.ts +1 -0
  50. package/dist/index.d.ts.map +1 -0
  51. package/dist/index.js +12 -28
  52. package/dist/index.js.map +1 -1
  53. package/dist/libs/DYOFinder.d.ts +1 -0
  54. package/dist/libs/DYOFinder.d.ts.map +1 -0
  55. package/dist/libs/DYOFinder.js +10 -14
  56. package/dist/libs/DYOFinder.js.map +1 -1
  57. package/dist/libs/dix/DIXModule.module.d.ts +8 -0
  58. package/dist/libs/dix/DIXModule.module.d.ts.map +1 -0
  59. package/dist/libs/dix/DIXModule.module.js +73 -0
  60. package/dist/libs/player/DTPlayer.element.d.ts +3 -2
  61. package/dist/libs/player/DTPlayer.element.d.ts.map +1 -0
  62. package/dist/libs/player/DTPlayer.element.js +2 -6
  63. package/dist/libs/player/DTPlayer.element.js.map +1 -1
  64. package/dist/libs/player/DTPlayer.manager.d.ts +8 -7
  65. package/dist/libs/player/DTPlayer.manager.d.ts.map +1 -0
  66. package/dist/libs/player/DTPlayer.manager.js +13 -20
  67. package/dist/libs/player/DTPlayer.manager.js.map +1 -1
  68. package/dist/tsconfig.dev.tsbuildinfo +1 -0
  69. package/dist/tsconfig.tsbuildinfo +1 -1
  70. package/dist/types/core.d.ts +40 -12
  71. package/dist/types/core.d.ts.map +1 -0
  72. package/dist/types/core.js +2 -6
  73. package/dist/types/core.js.map +1 -1
  74. package/dist/types/index.d.ts +1 -0
  75. package/dist/types/index.d.ts.map +1 -0
  76. package/dist/types/index.js +2 -19
  77. package/dist/types/index.js.map +1 -1
  78. package/dist/types/player.d.ts +1 -1
  79. package/dist/types/player.d.ts.map +1 -0
  80. package/dist/types/player.js +1 -3
  81. package/integration/data/components/DTHero.ts +42 -0
  82. package/integration/data/components/DTHeroManager.ts +11 -0
  83. package/integration/data/components/DTHeroPlayZone.ts +6 -0
  84. package/integration/data/components/DTHeroPlayerHand.ts +11 -0
  85. package/integration/data/components/index.ts +5 -0
  86. package/integration/data/in/heroIn.helper.ts +8 -0
  87. package/integration/data/in/playerIn.helper.ts +13 -0
  88. package/integration/data/out/heroOut.helper.ts +48 -0
  89. package/integration/endings/synchronisation.ending.ts +25 -0
  90. package/integration/scenes/drawCard.scene.ts +31 -0
  91. package/integration/scenes/empty.scene.ts +6 -0
  92. package/integration/scenes/playCard.scene.ts +23 -0
  93. package/integration/scenes/playerLeave.scene.ts +33 -0
  94. package/integration/stages/baseDix.stage.ts +137 -0
  95. package/integration/stages/syncDix.stage.ts +36 -0
  96. package/integration/tests/scenario1.spec.ts +55 -0
  97. package/integration/types/index.ts +24 -0
  98. package/jest-integration.config.ts +25 -0
  99. package/jest.config.ts +26 -0
  100. package/package.json +31 -19
  101. package/src/constants.ts +2 -0
  102. package/src/core/DTAction.ts +7 -5
  103. package/src/core/DTBunch.ts +78 -14
  104. package/src/core/DTComponent.ts +48 -15
  105. package/src/core/DTComponentPhysical.ts +45 -11
  106. package/src/core/DTComponentWithMeta.ts +37 -4
  107. package/src/core/DTElement.ts +19 -10
  108. package/src/core/DTError.ts +7 -7
  109. package/src/core/DTManager.ts +120 -30
  110. package/src/core/DTMaster.ts +76 -28
  111. package/src/core/DTModule.ts +12 -6
  112. package/src/index.ts +17 -17
  113. package/src/libs/DYOFinder.ts +175 -175
  114. package/src/libs/dix/DIXModule.module.ts +98 -0
  115. package/src/libs/player/DTPlayer.element.ts +2 -2
  116. package/src/libs/player/DTPlayer.manager.ts +20 -34
  117. package/src/types/core.ts +39 -4
  118. package/src/types/index.ts +2 -2
  119. package/src/types/player.ts +0 -1
  120. package/test/core/DTAction.double.ts +12 -28
  121. package/test/core/DTAction.spec.ts +8 -16
  122. package/test/core/DTBunch.double.ts +49 -135
  123. package/test/core/DTBunch.spec.ts +157 -245
  124. package/test/core/DTComponent.double.ts +17 -2
  125. package/test/core/DTComponent.spec.ts +6 -4
  126. package/test/core/DTComponentPhysical.double.ts +29 -43
  127. package/test/core/DTComponentPhysical.spec.ts +22 -19
  128. package/test/core/DTComponentWithMeta.double.ts +38 -31
  129. package/test/core/DTComponentWithMeta.spec.ts +23 -18
  130. package/test/core/DTElement.double.ts +32 -53
  131. package/test/core/DTElement.spec.ts +15 -38
  132. package/test/core/DTError.double.ts +18 -53
  133. package/test/core/DTError.spec.ts +21 -32
  134. package/test/core/DTManager.double.ts +74 -141
  135. package/test/core/DTManager.spec.ts +289 -380
  136. package/test/core/DTMaster.double.ts +56 -80
  137. package/test/core/DTMaster.spec.ts +185 -232
  138. package/test/core/DTModule.double.ts +12 -25
  139. package/test/core/DTModule.spec.ts +14 -28
  140. package/test/core/copy.spec.ts +9 -30
  141. package/tsconfig.dev.json +5 -8
  142. package/tsconfig.json +5 -8
  143. package/cucumber-report.html +0 -48
  144. package/docs/assets/navigation.js +0 -1
  145. package/docs/classes/core_DTAction.DYOToolsAction.html +0 -89
  146. package/docs/classes/core_DTBunch.DYOToolsBunch.html +0 -254
  147. package/docs/classes/core_DTComponent.DYOToolsComponent.html +0 -76
  148. package/docs/classes/core_DTComponentPhysical.DYOToolsComponentPhysical.html +0 -110
  149. package/docs/classes/core_DTComponentWithMeta.DYOToolsComponentWithMeta.html +0 -96
  150. package/docs/classes/core_DTElement.DYOToolsElement.html +0 -135
  151. package/docs/classes/core_DTError.DYOToolsError.html +0 -37
  152. package/docs/classes/core_DTManager.DYOToolsManager.html +0 -237
  153. package/docs/classes/core_DTMaster.DYOToolsMaster.html +0 -150
  154. package/docs/classes/core_DTModule.DYOToolsModule.html +0 -92
  155. package/docs/classes/libs_DYOFinder.DYOFinder.html +0 -34
  156. package/docs/classes/libs_player_DTPlayer_element.DYOToolsPlayer.html +0 -134
  157. package/docs/classes/libs_player_DTPlayer_manager.DYOToolsPlayerManager.html +0 -243
  158. package/docs/enums/types_core.FilterOperatorType.html +0 -10
  159. package/docs/hierarchy.html +0 -1
  160. package/docs/interfaces/types_core.DTBunchFilters.html +0 -6
  161. package/docs/interfaces/types_core.DTBunchOptions.html +0 -19
  162. package/docs/interfaces/types_core.DTBunchToObject.html +0 -7
  163. package/docs/interfaces/types_core.DTComponentOptions.html +0 -5
  164. package/docs/interfaces/types_core.DTComponentToObject.html +0 -4
  165. package/docs/interfaces/types_core.DTElementToObject.html +0 -7
  166. package/docs/interfaces/types_core.DTManagerFilters.html +0 -6
  167. package/docs/interfaces/types_core.DTManagerOptions.html +0 -8
  168. package/docs/interfaces/types_core.DTManagerToObject.html +0 -5
  169. package/docs/interfaces/types_core.DTMasterToObject.html +0 -8
  170. package/docs/interfaces/types_core.DTModuleToObject.html +0 -6
  171. package/docs/interfaces/types_core.DYOFinderConfigurationPropDefault.html +0 -4
  172. package/docs/interfaces/types_core.DYOFinderConfigurationPropObjectSearch.html +0 -4
  173. package/docs/interfaces/types_core.DYOFinderFilterOperatorAdvanced.html +0 -5
  174. package/docs/interfaces/types_core.DYOFinderFilterOperatorBase.html +0 -5
  175. package/docs/interfaces/types_player.DTPlayerManagerSimpleConfiguration.html +0 -3
  176. package/docs/modules/constants.html +0 -6
  177. package/docs/modules/core_DTAction.html +0 -2
  178. package/docs/modules/core_DTBunch.html +0 -2
  179. package/docs/modules/core_DTComponent.html +0 -2
  180. package/docs/modules/core_DTComponentPhysical.html +0 -2
  181. package/docs/modules/core_DTComponentWithMeta.html +0 -2
  182. package/docs/modules/core_DTElement.html +0 -2
  183. package/docs/modules/core_DTError.html +0 -2
  184. package/docs/modules/core_DTManager.html +0 -2
  185. package/docs/modules/core_DTMaster.html +0 -2
  186. package/docs/modules/core_DTModule.html +0 -2
  187. package/docs/modules/libs_DYOFinder.html +0 -2
  188. package/docs/modules/libs_player_DTPlayer_element.html +0 -2
  189. package/docs/modules/libs_player_DTPlayer_manager.html +0 -2
  190. package/docs/modules/types.html +0 -29
  191. package/docs/modules/types_core.html +0 -28
  192. package/docs/modules/types_player.html +0 -2
  193. package/docs/types/types_core.DTAcceptedMetaData.html +0 -2
  194. package/docs/types/types_core.DTManagerItemType.html +0 -1
  195. package/docs/types/types_core.DTManagerItemsType.html +0 -2
  196. package/docs/types/types_core.DYOFinderComponentType.html +0 -1
  197. package/docs/types/types_core.DYOFinderConfiguration.html +0 -2
  198. package/docs/types/types_core.DYOFinderConfigurationProp.html +0 -1
  199. package/docs/types/types_core.DYOFinderFilterOperator.html +0 -1
  200. package/docs/types/types_core.DYOFinderFilterOperatorArgument.html +0 -1
  201. package/docs/types/types_core.DYOFinderFilters.html +0 -1
  202. package/docs/types/types_core.StandardPrimitiveType.html +0 -2
  203. package/docs/types/types_core.StandardPrimitiveTypeWithArray.html +0 -1
  204. package/docs/variables/constants.bunchDefaultOptions.html +0 -2
  205. package/docs/variables/constants.componentBunchDefaultFinderConfiguration.html +0 -1
  206. package/docs/variables/constants.componentManagerDefaultFinderConfiguration.html +0 -1
  207. package/docs/variables/constants.componentPhysicalDefaultFinderConfiguration.html +0 -1
  208. package/docs/variables/constants.managerDefaultOptions.html +0 -2
  209. package/jest.config.js +0 -6
@@ -1,7 +1,8 @@
1
1
  import {DTComponent} from "../../src";
2
2
  import {DTErrorStub} from "./DTError.double";
3
3
  import {jest} from "@jest/globals";
4
- import {DTComponentOptions} from "../../src/types";
4
+ import {DIXObject, DTComponentOptions, DTComponentToDIXObject} from "../../src/types";
5
+ import * as domain from "domain";
5
6
 
6
7
  interface IOptionsTest extends DTComponentOptions {
7
8
  option1: boolean
@@ -18,6 +19,14 @@ export const ToObjectTest = { type: "DTComponent-test-toObject" };
18
19
  export const ToStringTest = "DTComponent-test-toString";
19
20
  export const DomainTest = "DTComponent-domain-test";
20
21
  export const SubKindTest = "DTComponent-subkind-test";
22
+ export const ToDIXObjectTest = {
23
+ [IDTest]: {
24
+ key: KeyTest,
25
+ componentType: ComponentTypeTest,
26
+ domain: DomainTest,
27
+ subKind: SubKindTest,
28
+ }
29
+ }
21
30
 
22
31
  /******************** STUB ABSTRACT IMPLEMENTATION
23
32
  * Implementation of abstract component class for tests
@@ -36,6 +45,9 @@ export class DTComponentImpl extends DTComponent<IOptionsTest> {
36
45
  toString(): string {
37
46
  return ToStringTest;
38
47
  }
48
+
49
+ updateFromDix(dix: Record<string, DIXObject>): void {
50
+ }
39
51
  }
40
52
 
41
53
  /******************** HELPER TEST CLASS
@@ -94,6 +106,9 @@ export class DTComponentTest extends DTComponentImpl {
94
106
  th_set_options(options: any): void {
95
107
  this._options = options;
96
108
  }
109
+
110
+ updateFromDix(dix: Record<string, DIXObject>): void {
111
+ }
97
112
  }
98
113
 
99
114
  /******************** STUB CLASS
@@ -107,7 +122,7 @@ export class DTComponentStub extends DTComponentTest {
107
122
  this.stubId = IDTest + (idSuffix && `-${idSuffix}`);
108
123
  }
109
124
 
110
- getId() {
125
+ _getStubId(): string {
111
126
  return this.stubId;
112
127
  }
113
128
  }
@@ -3,15 +3,15 @@ import {
3
3
  ComponentTypeTest,
4
4
  DomainTest,
5
5
  DTComponentTest,
6
- DTComponentImpl,
7
6
  IDTest,
8
7
  KeyTest,
9
8
  simulateHierarchy,
10
9
  SubKindTest,
10
+ ToDIXObjectTest,
11
11
  } from './DTComponent.double';
12
12
  import {DTErrorStub} from "./DTError.double";
13
13
 
14
- describe('class DYOToolsComponent', () => {
14
+ describe('class DTComponent', () => {
15
15
  let componentTest: DTComponentTest;
16
16
 
17
17
  beforeEach(() => {
@@ -49,15 +49,17 @@ describe('class DYOToolsComponent', () => {
49
49
  const component = new DTComponentTest();
50
50
 
51
51
  expect(component.th_get_options()).toStrictEqual({
52
- errors: false
52
+ errors: false,
53
+ syncId: undefined,
53
54
  });
54
55
  });
55
56
 
56
57
  test('creations with options', () => {
57
- const component = new DTComponentTest(KeyTest, { errors: true, option1: false, option2: true });
58
+ const component = new DTComponentTest(KeyTest, { errors: true, option1: false, option2: true, syncId: "123" });
58
59
 
59
60
  expect(component.th_get_options()).toStrictEqual({
60
61
  errors: true,
62
+ syncId: "123",
61
63
  option1: false,
62
64
  option2: true
63
65
  });
@@ -10,26 +10,19 @@ export const ComponentTypeTest = "DTComponentPhysical-componentType-test";
10
10
  export const ToObjectTest = { type: "DTComponentPhysical-test-toObject" };
11
11
  export const ToStringTest = "DTComponentPhysical-test-toString";
12
12
  export const OwnerTest = "owner-12345";
13
-
14
- /******************** STUB ABSTRACT IMPLEMENTATION
15
- * Implementation of abstract component class for tests
16
- * *****/
17
- export class DTComponentPhysicalImpl extends DTComponentPhysical<IMetaDataTest> {
18
- protected _componentType: string = ComponentTypeTest;
19
-
20
- copy(): DTComponentPhysical<IMetaDataTest> {
21
- return this;
13
+ export const ParentToDIXObjectTest = {
14
+ [IDTest]: {
15
+ key: KeyTest,
16
+ componentType: ComponentTypeTest,
17
+ meta: {}
22
18
  }
23
-
24
- toObject(): any {
25
- return ToObjectTest;
26
- }
27
-
28
- toString(): string {
29
- return ToStringTest;
30
- }
31
-
32
- do(): void {
19
+ }
20
+ export const ToDIXObjectTest = {
21
+ [IDTest]: {
22
+ key: KeyTest,
23
+ componentType: ComponentTypeTest,
24
+ meta: {},
25
+ owner: OwnerTest,
33
26
  }
34
27
  }
35
28
 
@@ -37,40 +30,33 @@ export class DTComponentPhysicalImpl extends DTComponentPhysical<IMetaDataTest>
37
30
  * Helper test class, inherits the main component
38
31
  * Providing methods to property access and other facilities, in order to avoid using class methods
39
32
  * *****/
40
- export class DTComponentPhysicalTest extends DTComponentPhysicalImpl {
41
- th_get_owner(): string {
42
- return this._owner;
43
- }
33
+ export class DTComponentPhysicalTest extends DTComponentPhysical<IMetaDataTest> {
34
+ protected _componentType: string = ComponentTypeTest;
44
35
 
45
- th_set_owner(owner: string): void {
36
+ constructor(
37
+ id: string = IDTest,
38
+ key: string = KeyTest,
39
+ owner?: string,
40
+ ) {
41
+ super(key);
42
+ this._id = id;
46
43
  this._owner = owner;
47
44
  }
48
- }
49
45
 
50
- /******************** STUB CLASS
51
- * Stub class, for using in other component
52
- * *****/
53
- export class DTComponentPhysicalStub extends DTComponentPhysicalTest {
54
- private readonly stubId: string;
46
+ copy(): DTComponentPhysical<IMetaDataTest> {
47
+ return this;
48
+ }
55
49
 
56
- constructor(idSuffix: string = "") {
57
- super();
58
- this.stubId = IDTest + (idSuffix && `-${idSuffix}`);
50
+ toObject(): any {
51
+ return ToObjectTest;
59
52
  }
60
53
 
61
- getId() {
62
- return this.stubId;
54
+ toString(): string {
55
+ return ToStringTest;
63
56
  }
64
57
  }
65
58
 
66
59
  /******************** HELPER METHODS
67
60
  * Additional helper methods to use with testing
68
61
  * *****/
69
- // Mocked implementations for overridden methods (for children tests)
70
- export function mockOverriddenMethods(mock: any) {
71
- // Constructor
72
- mock.prototype.constructor.mockImplementation(function (key?: string) {
73
- this._id = IDTest;
74
- this._key = key || this._id;
75
- })
76
- }
62
+
@@ -1,18 +1,9 @@
1
1
  import {beforeEach, describe, expect, jest, test} from '@jest/globals';
2
- import {mockOverriddenMethods} from "./DTComponentWithMeta.double";
3
- import {DTComponentPhysicalTest, OwnerTest} from './DTComponentPhysical.double';
2
+ import {DTComponentPhysicalTest, IDTest, KeyTest, OwnerTest} from './DTComponentPhysical.double';
4
3
  import {DTComponentPhysical, DTComponentWithMeta} from "../../src";
5
4
 
6
- /******************** MOCK DEPENDENCIES
7
- * All Dependencies used by the component are mocked with Jest
8
- * *****/
9
- jest.mock('../../src/core/DTComponent');
10
- jest.mock('../../src/core/DTComponentWithMeta');
11
- // Add specific mock for inherited methods to have a basic implementation
12
- mockOverriddenMethods(DTComponentWithMeta);
13
-
14
5
  /************************* TESTS SUITES *******************************/
15
- describe('class DYOToolsComponentPhysical', () => {
6
+ describe('class DTComponentPhysical', () => {
16
7
  let componentPhysicalTest: DTComponentPhysicalTest;
17
8
 
18
9
  beforeEach(() => {
@@ -31,19 +22,23 @@ describe('class DYOToolsComponentPhysical', () => {
31
22
 
32
23
  describe('getManager()', () => {
33
24
  test('call get context with manager accessor', () => {
25
+ const getContextSpy = jest.spyOn(componentPhysicalTest, 'getContext');
26
+
34
27
  componentPhysicalTest.getManager();
35
28
 
36
- expect((componentPhysicalTest.getContext as any).mock.calls.length).toBe(1);
37
- expect((componentPhysicalTest.getContext as any).mock.calls[0][0]).toBe('manager');
29
+ expect(getContextSpy.mock.calls.length).toBe(1);
30
+ expect(getContextSpy.mock.calls[0][0]).toBe('manager');
38
31
  });
39
32
  });
40
33
 
41
34
  describe('getMaster()', () => {
42
35
  test('call get context with master accessor', () => {
36
+ const getContextSpy = jest.spyOn(componentPhysicalTest, 'getContext');
37
+
43
38
  componentPhysicalTest.getMaster();
44
39
 
45
- expect((componentPhysicalTest.getContext as any).mock.calls.length).toBe(1);
46
- expect((componentPhysicalTest.getContext as any).mock.calls[0][0]).toBe('master');
40
+ expect(getContextSpy.mock.calls.length).toBe(1);
41
+ expect(getContextSpy.mock.calls[0][0]).toBe('master');
47
42
  });
48
43
  });
49
44
 
@@ -53,7 +48,7 @@ describe('class DYOToolsComponentPhysical', () => {
53
48
  });
54
49
 
55
50
  test('return owner when set', () => {
56
- componentPhysicalTest.th_set_owner(OwnerTest);
51
+ componentPhysicalTest = new DTComponentPhysicalTest(IDTest, KeyTest, OwnerTest);
57
52
 
58
53
  expect(componentPhysicalTest.getOwner()).toBe(OwnerTest);
59
54
  });
@@ -63,16 +58,24 @@ describe('class DYOToolsComponentPhysical', () => {
63
58
  test('add a new owner', () => {
64
59
  componentPhysicalTest.setOwner(OwnerTest);
65
60
 
66
- expect(componentPhysicalTest.th_get_owner()).toBe(OwnerTest);
61
+ expect(componentPhysicalTest.getOwner()).toBe(OwnerTest);
67
62
  });
68
63
  });
69
64
 
70
65
  describe('removeOwner()', () => {
71
66
  test('remove the current Owner', () => {
72
- componentPhysicalTest.th_set_owner(OwnerTest);
67
+ componentPhysicalTest = new DTComponentPhysicalTest(IDTest, KeyTest, OwnerTest);
73
68
 
74
69
  componentPhysicalTest.removeOwner();
75
- expect(componentPhysicalTest.th_get_owner()).toBeUndefined();
70
+ expect(componentPhysicalTest.getOwner()).toBeUndefined();
76
71
  });
77
72
  });
73
+
74
+ // describe('toDIXObject()', () => {
75
+ // test('return parent and owner', () => {
76
+ // const dixObject = componentPhysicalTest.toDIXObject();
77
+ //
78
+ // expect(dixObject).toStrictEqual(ToDIXObjectTest);
79
+ // });
80
+ // });
78
81
  });
@@ -67,49 +67,56 @@ export const BunchMetaData: IMetaDataTest = {
67
67
  kd: [117, 3],
68
68
  };
69
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
- }
70
+ // DIX
71
+ export const ParentToDIXObjectTest = {
72
+ [IDTest]: {
73
+ key: KeyTest,
74
+ componentType: ComponentTypeTest
75
+ }
76
+ }
77
+ export const ToDIXObjectTest = {
78
+ [IDTest]: {
79
+ key: KeyTest,
80
+ componentType: ComponentTypeTest,
81
+ meta: JSON.stringify(HaileiMetaData),
82
+ }
87
83
  }
88
84
 
89
85
  /******************** HELPER TEST CLASS
90
86
  * Helper test class, inherits the main component
91
87
  * Providing methods to property access and other facilities, in order to avoid using class methods
92
88
  * *****/
93
- export class DTComponentWithMetaTest extends DTComponentWithMetaImpl {
94
- th_get_meta(): Partial<IMetaDataTest> {
89
+ export class DTComponentWithMetaTest extends DTComponentWithMeta<IMetaDataTest> {
90
+ protected _componentType: string = ComponentTypeTest;
91
+
92
+ constructor(
93
+ id: string = IDTest,
94
+ key: string = KeyTest,
95
+ meta: Partial<IMetaDataTest> = {},
96
+ ) {
97
+ super(IDTest);
98
+ this._id = id;
99
+ this._meta = meta;
100
+ }
101
+
102
+ _getMeta(): Partial<IMetaDataTest> {
95
103
  return this._meta;
96
104
  }
97
105
 
98
- th_set_meta(meta: Partial<IMetaDataTest>): void {
99
- this._meta = meta;
106
+ copy(): DTComponentWithMeta<IMetaDataTest> {
107
+ return this;
108
+ }
109
+
110
+ toObject(): any {
111
+ return ToObjectTest;
112
+ }
113
+
114
+ toString(): string {
115
+ return ToStringTest;
100
116
  }
101
117
  }
102
118
 
103
119
  /******************** HELPER METHODS
104
120
  * Additional helper methods to use with testing
105
121
  * *****/
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
- }
122
+
@@ -2,21 +2,16 @@ import {afterEach, beforeEach, describe, expect, jest, test,} from '@jest/global
2
2
  import {
3
3
  DTComponentWithMetaTest,
4
4
  HaileiMetaData,
5
+ IDTest,
5
6
  IMetaDataTest,
7
+ KeyTest,
6
8
  MeldrineMetaData,
7
9
  YssaliaMetaData
8
10
  } from './DTComponentWithMeta.double';
9
- import {mockOverriddenMethods} from "./DTComponent.double";
10
11
  import {DTComponent, DTComponentWithMeta} from "../../src";
11
12
 
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
13
  /************************* TESTS SUITES *******************************/
19
- describe('class DYOToolsComponentWithMeta', () => {
14
+ describe('class DTComponentWithMeta', () => {
20
15
  let componentWithMetaTest: DTComponentWithMetaTest;
21
16
 
22
17
  beforeEach(() => {
@@ -39,7 +34,7 @@ describe('class DYOToolsComponentWithMeta', () => {
39
34
  });
40
35
 
41
36
  test('return one meta by key', () => {
42
- componentWithMetaTest.th_set_meta(HaileiMetaData);
37
+ componentWithMetaTest = new DTComponentWithMetaTest(IDTest, KeyTest, { ...HaileiMetaData });
43
38
 
44
39
  expect(componentWithMetaTest.getMeta('name')).toBe(HaileiMetaData.name);
45
40
  });
@@ -47,10 +42,10 @@ describe('class DYOToolsComponentWithMeta', () => {
47
42
 
48
43
  describe('setMeta()', () => {
49
44
  test('set a new value for a meta', () => {
50
- componentWithMetaTest.th_set_meta(HaileiMetaData);
45
+ componentWithMetaTest = new DTComponentWithMetaTest(IDTest, KeyTest, { ...HaileiMetaData });
51
46
  componentWithMetaTest.setMeta('name', MeldrineMetaData.name);
52
47
 
53
- const newMeta = componentWithMetaTest.th_get_meta();
48
+ const newMeta = componentWithMetaTest._getMeta();
54
49
  expect(newMeta.name === MeldrineMetaData.name).toBeTruthy();
55
50
  expect(newMeta.rank === HaileiMetaData.rank).toBeTruthy();
56
51
  expect(newMeta.queen === HaileiMetaData.queen).toBeTruthy();
@@ -68,13 +63,13 @@ describe('class DYOToolsComponentWithMeta', () => {
68
63
  });
69
64
 
70
65
  test('return all meta', () => {
71
- componentWithMetaTest.th_set_meta(HaileiMetaData);
66
+ componentWithMetaTest = new DTComponentWithMetaTest(IDTest, KeyTest, { ...HaileiMetaData });
72
67
 
73
68
  expect(componentWithMetaTest.getManyMeta()).toStrictEqual(HaileiMetaData);
74
69
  });
75
70
 
76
71
  test('return meta by keys', () => {
77
- componentWithMetaTest.th_set_meta(HaileiMetaData);
72
+ componentWithMetaTest = new DTComponentWithMetaTest(IDTest, KeyTest, { ...HaileiMetaData });
78
73
  const keys: Array<keyof IMetaDataTest> = ['name', 'kd', 'queen'];
79
74
 
80
75
  expect(componentWithMetaTest.getManyMeta(keys)).toStrictEqual({
@@ -85,7 +80,7 @@ describe('class DYOToolsComponentWithMeta', () => {
85
80
  });
86
81
 
87
82
  test('return meta by keys - unexisting keys', () => {
88
- componentWithMetaTest.th_set_meta(YssaliaMetaData);
83
+ componentWithMetaTest = new DTComponentWithMetaTest(IDTest, KeyTest, { ...YssaliaMetaData });
89
84
  const keys: Array<keyof IMetaDataTest> = ['name', 'rank', 'tribes'];
90
85
 
91
86
  expect(componentWithMetaTest.getManyMeta(keys)).toStrictEqual({
@@ -96,7 +91,7 @@ describe('class DYOToolsComponentWithMeta', () => {
96
91
 
97
92
  describe('setManyMeta()', () => {
98
93
  test('set new values', () => {
99
- componentWithMetaTest.th_set_meta(HaileiMetaData);
94
+ componentWithMetaTest = new DTComponentWithMetaTest(IDTest, KeyTest, { ...HaileiMetaData });
100
95
  const setValues: Partial<IMetaDataTest> = {
101
96
  name: MeldrineMetaData.name,
102
97
  queen: MeldrineMetaData.queen,
@@ -105,7 +100,7 @@ describe('class DYOToolsComponentWithMeta', () => {
105
100
 
106
101
  componentWithMetaTest.setManyMeta(setValues);
107
102
 
108
- const newMeta = componentWithMetaTest.th_get_meta();
103
+ const newMeta = componentWithMetaTest._getMeta();
109
104
  expect(newMeta.name === MeldrineMetaData.name).toBeTruthy();
110
105
  expect(newMeta.queen === MeldrineMetaData.queen).toBeTruthy();
111
106
  expect(newMeta.kd[0] === HaileiMetaData.kd[0]).toBeTruthy();
@@ -114,11 +109,21 @@ describe('class DYOToolsComponentWithMeta', () => {
114
109
  });
115
110
 
116
111
  test('set empty new values (keep former meta)', () => {
117
- componentWithMetaTest.th_set_meta(HaileiMetaData);
112
+ componentWithMetaTest = new DTComponentWithMetaTest(IDTest, KeyTest, { ...HaileiMetaData });
118
113
 
119
114
  componentWithMetaTest.setManyMeta({});
120
115
 
121
- expect(componentWithMetaTest.th_get_meta()).toStrictEqual(HaileiMetaData);
116
+ expect(componentWithMetaTest._getMeta()).toStrictEqual(HaileiMetaData);
122
117
  });
123
118
  });
119
+
120
+ // describe('toDIXObject()', () => {
121
+ // test('return parent and meta', () => {
122
+ // componentWithMetaTest = new DTComponentWithMetaTest(IDTest, KeyTest, { ...HaileiMetaData });
123
+ //
124
+ // const dixObject = componentWithMetaTest.toDIXObject();
125
+ //
126
+ // expect(dixObject).toStrictEqual(ToDIXObjectTest);
127
+ // });
128
+ // });
124
129
  });
@@ -1,5 +1,7 @@
1
1
  import {DTBunch, DTElement} from '../../src';
2
2
  import {IMetaDataTest} from './DTComponentWithMeta.double';
3
+ import {DTElementToObject} from "../../src/types";
4
+ import {DTBunchStub} from "./DTBunch.double";
3
5
 
4
6
  /** ****************** STUB PROPERTIES CONSTANTS
5
7
  * Fixed properties to use with double classes, avoid auto generated and easy checking on test
@@ -13,91 +15,68 @@ export const DomainTest = 'DTElement-domain-test';
13
15
  export const HaileiIdTest = 'DTElement-id-Hailei';
14
16
  export const HaileiKeyTest = 'DTElement-key-Hailei';
15
17
  export const HaileiToObjectTest = { id: 'DTElement-id-Hailei', key: 'DTElement-key-Hailei', type: 'element' };
18
+
16
19
  export const MeldrineIdTest = 'DTElement-id-Meldrine';
17
20
  export const MeldrineKeyTest = 'DTElement-key-Meldrine';
18
21
  export const MeldrineToObjectTest = { id: 'DTElement-id-Meldrine', key: 'DTElement-key-Meldrine', type: 'element' };
22
+
19
23
  export const MaydenaIdTest = 'DTElement-id-Maydena';
20
24
  export const MaydenaKeyTest = 'DTElement-key-Maydena';
21
25
  export const MaydenaToObjectTest = { id: 'DTElement-id-Maydena', key: 'DTElement-key-Maydena', type: 'element' };
26
+
22
27
  export const IldressIdTest = 'DTElement-id-Ildress';
23
28
  export const IldressKeyTest = 'DTElement-key-Ildress';
24
29
  export const IldressToObjectTest = { id: 'DTElement-id-Ildress', key: 'DTElement-key-Ildress', type: 'element' };
30
+
25
31
  export const YssaliaIdTest = 'DTElement-id-Yssalia';
26
32
  export const YssaliaKeyTest = 'DTElement-key-Yssalia';
27
33
  export const YssaliaToObjectTest = { id: 'DTElement-id-Yssalia', key: 'DTElement-key-Yssalia', type: 'element' };
28
34
 
35
+
29
36
  /** ****************** HELPER TEST CLASS
30
37
  * Helper test class, inherits the main component
31
38
  * Providing methods to property access and other facilities, in order to avoid using class methods
32
39
  * **** */
33
40
  export class DTElementTest extends DTElement<IMetaDataTest> {
34
- th_get_id(): string {
35
- return this._id;
36
- }
37
41
 
38
- th_set_id(id: string): void {
42
+ constructor(
43
+ id: string = IDTest,
44
+ key: string = KeyTest,
45
+ container: DTBunchStub | undefined = undefined,
46
+ domain?: string,
47
+ ) {
48
+ super(key);
39
49
  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 {
50
+ this._container = container as DTBunch;
59
51
  this._domain = domain;
60
52
  }
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
53
  }
82
54
  /** ****************** STUB CLASS
83
55
  * Stub class, for using in other component
84
56
  * **** */
85
57
  export class DTElementStub extends DTElement<IMetaDataTest> {
86
58
  public parentIndex: number;
87
-
88
- constructor(index = 0) {
59
+ public mockedToObject: DTElementToObject<IMetaDataTest>;
60
+
61
+ constructor(
62
+ index = 0,
63
+ id: string = IDTest,
64
+ key: string = KeyTest,
65
+ meta: Partial<IMetaDataTest> = {},
66
+ owner: string | undefined = undefined,
67
+ toObject: DTElementToObject<IMetaDataTest> = HaileiToObjectTest,
68
+ ) {
89
69
  super();
90
- this._id = IDTest;
91
- this._key = KeyTest;
70
+ this._id = id;
71
+ this._key = key;
72
+ this._meta = meta;
73
+ this._owner = owner;
92
74
  this.parentIndex = index;
75
+ this.mockedToObject = toObject;
93
76
  }
94
77
 
95
- getId(): string {
96
- return IDTest;
97
- }
98
-
99
- getKey(): string {
100
- return KeyTest;
78
+ toObject(): DTElementToObject<IMetaDataTest> {
79
+ return this.mockedToObject;
101
80
  }
102
81
  }
103
82
  export class DTElementStubExtended extends DTElementStub {