dyo-tools 0.4.0 → 0.4.1

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 (157) hide show
  1. package/{dist/index.d.ts → index.d.ts} +1 -0
  2. package/{dist/index.d.ts.map → index.d.ts.map} +1 -1
  3. package/{dist/index.js → index.js} +1 -0
  4. package/package.json +6 -56
  5. package/.c8rc.json +0 -4
  6. package/.eslintignore +0 -2
  7. package/.eslintrc.json +0 -47
  8. package/Makefile +0 -34
  9. package/README.md +0 -0
  10. package/babel.config.js +0 -1
  11. package/docs/.nojekyll +0 -1
  12. package/docs/assets/highlight.css +0 -29
  13. package/docs/assets/main.js +0 -59
  14. package/docs/assets/search.js +0 -1
  15. package/docs/assets/style.css +0 -1414
  16. package/docs/index.html +0 -1
  17. package/integration/data/components/DTHero.ts +0 -42
  18. package/integration/data/components/DTHeroManager.ts +0 -11
  19. package/integration/data/components/DTHeroPlayZone.ts +0 -6
  20. package/integration/data/components/DTHeroPlayerHand.ts +0 -11
  21. package/integration/data/components/index.ts +0 -5
  22. package/integration/data/in/heroIn.helper.ts +0 -8
  23. package/integration/data/in/playerIn.helper.ts +0 -13
  24. package/integration/data/out/heroOut.helper.ts +0 -48
  25. package/integration/endings/synchronisation.ending.ts +0 -25
  26. package/integration/scenes/drawCard.scene.ts +0 -31
  27. package/integration/scenes/empty.scene.ts +0 -6
  28. package/integration/scenes/playCard.scene.ts +0 -23
  29. package/integration/scenes/playerLeave.scene.ts +0 -33
  30. package/integration/stages/baseDix.stage.ts +0 -137
  31. package/integration/stages/syncDix.stage.ts +0 -36
  32. package/integration/tests/scenario1.spec.ts +0 -55
  33. package/integration/types/index.ts +0 -24
  34. package/jest-integration.config.ts +0 -25
  35. package/jest.config.ts +0 -26
  36. package/src/constants.ts +0 -87
  37. package/src/core/DTAction.ts +0 -54
  38. package/src/core/DTBunch.ts +0 -531
  39. package/src/core/DTComponent.ts +0 -258
  40. package/src/core/DTComponentPhysical.ts +0 -88
  41. package/src/core/DTComponentWithMeta.ts +0 -98
  42. package/src/core/DTElement.ts +0 -111
  43. package/src/core/DTError.ts +0 -78
  44. package/src/core/DTManager.ts +0 -555
  45. package/src/core/DTMaster.ts +0 -366
  46. package/src/core/DTModule.ts +0 -96
  47. package/src/index.ts +0 -17
  48. package/src/libs/DYOFinder.ts +0 -175
  49. package/src/libs/dix/DIXModule.module.ts +0 -98
  50. package/src/libs/player/DTPlayer.element.ts +0 -9
  51. package/src/libs/player/DTPlayer.manager.ts +0 -70
  52. package/src/types/core.ts +0 -204
  53. package/src/types/index.ts +0 -2
  54. package/src/types/player.ts +0 -5
  55. package/test/core/DTAction.double.ts +0 -62
  56. package/test/core/DTAction.spec.ts +0 -68
  57. package/test/core/DTBunch.double.ts +0 -175
  58. package/test/core/DTBunch.spec.ts +0 -822
  59. package/test/core/DTComponent.double.ts +0 -179
  60. package/test/core/DTComponent.spec.ts +0 -297
  61. package/test/core/DTComponentPhysical.double.ts +0 -62
  62. package/test/core/DTComponentPhysical.spec.ts +0 -81
  63. package/test/core/DTComponentWithMeta.double.ts +0 -122
  64. package/test/core/DTComponentWithMeta.spec.ts +0 -129
  65. package/test/core/DTElement.double.ts +0 -142
  66. package/test/core/DTElement.spec.ts +0 -123
  67. package/test/core/DTError.double.ts +0 -57
  68. package/test/core/DTError.spec.ts +0 -78
  69. package/test/core/DTManager.double.ts +0 -149
  70. package/test/core/DTManager.spec.ts +0 -874
  71. package/test/core/DTMaster.double.ts +0 -117
  72. package/test/core/DTMaster.spec.ts +0 -537
  73. package/test/core/DTModule.double.ts +0 -67
  74. package/test/core/DTModule.spec.ts +0 -124
  75. package/test/core/copy.spec.ts +0 -222
  76. package/test/libs/DYOFinder.double.ts +0 -152
  77. package/test/libs/DYOFinder.spec.ts +0 -194
  78. package/test/libs/player/DTPlayer.element.double.ts +0 -55
  79. package/test/libs/player/DTPlayer.element.spec.ts +0 -28
  80. package/test/libs/player/DTPlayer.manager.double.ts +0 -92
  81. package/test/libs/player/DTPlayer.manager.spec.ts +0 -178
  82. package/tsconfig.dev.json +0 -19
  83. package/tsconfig.json +0 -18
  84. /package/{dist/constants.d.ts → constants.d.ts} +0 -0
  85. /package/{dist/constants.d.ts.map → constants.d.ts.map} +0 -0
  86. /package/{dist/constants.js → constants.js} +0 -0
  87. /package/{dist/constants.js.map → constants.js.map} +0 -0
  88. /package/{dist/core → core}/DTAction.d.ts +0 -0
  89. /package/{dist/core → core}/DTAction.d.ts.map +0 -0
  90. /package/{dist/core → core}/DTAction.js +0 -0
  91. /package/{dist/core → core}/DTAction.js.map +0 -0
  92. /package/{dist/core → core}/DTBunch.d.ts +0 -0
  93. /package/{dist/core → core}/DTBunch.d.ts.map +0 -0
  94. /package/{dist/core → core}/DTBunch.js +0 -0
  95. /package/{dist/core → core}/DTBunch.js.map +0 -0
  96. /package/{dist/core → core}/DTComponent.d.ts +0 -0
  97. /package/{dist/core → core}/DTComponent.d.ts.map +0 -0
  98. /package/{dist/core → core}/DTComponent.js +0 -0
  99. /package/{dist/core → core}/DTComponent.js.map +0 -0
  100. /package/{dist/core → core}/DTComponentPhysical.d.ts +0 -0
  101. /package/{dist/core → core}/DTComponentPhysical.d.ts.map +0 -0
  102. /package/{dist/core → core}/DTComponentPhysical.js +0 -0
  103. /package/{dist/core → core}/DTComponentPhysical.js.map +0 -0
  104. /package/{dist/core → core}/DTComponentWithMeta.d.ts +0 -0
  105. /package/{dist/core → core}/DTComponentWithMeta.d.ts.map +0 -0
  106. /package/{dist/core → core}/DTComponentWithMeta.js +0 -0
  107. /package/{dist/core → core}/DTComponentWithMeta.js.map +0 -0
  108. /package/{dist/core → core}/DTElement.d.ts +0 -0
  109. /package/{dist/core → core}/DTElement.d.ts.map +0 -0
  110. /package/{dist/core → core}/DTElement.js +0 -0
  111. /package/{dist/core → core}/DTElement.js.map +0 -0
  112. /package/{dist/core → core}/DTError.d.ts +0 -0
  113. /package/{dist/core → core}/DTError.d.ts.map +0 -0
  114. /package/{dist/core → core}/DTError.js +0 -0
  115. /package/{dist/core → core}/DTError.js.map +0 -0
  116. /package/{dist/core → core}/DTManager.d.ts +0 -0
  117. /package/{dist/core → core}/DTManager.d.ts.map +0 -0
  118. /package/{dist/core → core}/DTManager.js +0 -0
  119. /package/{dist/core → core}/DTManager.js.map +0 -0
  120. /package/{dist/core → core}/DTMaster.d.ts +0 -0
  121. /package/{dist/core → core}/DTMaster.d.ts.map +0 -0
  122. /package/{dist/core → core}/DTMaster.js +0 -0
  123. /package/{dist/core → core}/DTMaster.js.map +0 -0
  124. /package/{dist/core → core}/DTModule.d.ts +0 -0
  125. /package/{dist/core → core}/DTModule.d.ts.map +0 -0
  126. /package/{dist/core → core}/DTModule.js +0 -0
  127. /package/{dist/core → core}/DTModule.js.map +0 -0
  128. /package/{dist/index.js.map → index.js.map} +0 -0
  129. /package/{dist/libs → libs}/DYOFinder.d.ts +0 -0
  130. /package/{dist/libs → libs}/DYOFinder.d.ts.map +0 -0
  131. /package/{dist/libs → libs}/DYOFinder.js +0 -0
  132. /package/{dist/libs → libs}/DYOFinder.js.map +0 -0
  133. /package/{dist/libs → libs}/dix/DIXModule.module.d.ts +0 -0
  134. /package/{dist/libs → libs}/dix/DIXModule.module.d.ts.map +0 -0
  135. /package/{dist/libs → libs}/dix/DIXModule.module.js +0 -0
  136. /package/{dist/libs → libs}/player/DTPlayer.element.d.ts +0 -0
  137. /package/{dist/libs → libs}/player/DTPlayer.element.d.ts.map +0 -0
  138. /package/{dist/libs → libs}/player/DTPlayer.element.js +0 -0
  139. /package/{dist/libs → libs}/player/DTPlayer.element.js.map +0 -0
  140. /package/{dist/libs → libs}/player/DTPlayer.manager.d.ts +0 -0
  141. /package/{dist/libs → libs}/player/DTPlayer.manager.d.ts.map +0 -0
  142. /package/{dist/libs → libs}/player/DTPlayer.manager.js +0 -0
  143. /package/{dist/libs → libs}/player/DTPlayer.manager.js.map +0 -0
  144. /package/{dist/tsconfig.dev.tsbuildinfo → tsconfig.dev.tsbuildinfo} +0 -0
  145. /package/{dist/tsconfig.tsbuildinfo → tsconfig.tsbuildinfo} +0 -0
  146. /package/{dist/types → types}/core.d.ts +0 -0
  147. /package/{dist/types → types}/core.d.ts.map +0 -0
  148. /package/{dist/types → types}/core.js +0 -0
  149. /package/{dist/types → types}/core.js.map +0 -0
  150. /package/{dist/types → types}/index.d.ts +0 -0
  151. /package/{dist/types → types}/index.d.ts.map +0 -0
  152. /package/{dist/types → types}/index.js +0 -0
  153. /package/{dist/types → types}/index.js.map +0 -0
  154. /package/{dist/types → types}/player.d.ts +0 -0
  155. /package/{dist/types → types}/player.d.ts.map +0 -0
  156. /package/{dist/types → types}/player.js +0 -0
  157. /package/{dist/types → types}/player.js.map +0 -0
@@ -1,179 +0,0 @@
1
- import {DTComponent} from "../../src";
2
- import {DTErrorStub} from "./DTError.double";
3
- import {jest} from "@jest/globals";
4
- import {DIXObject, DTComponentOptions, DTComponentToDIXObject} from "../../src/types";
5
- import * as domain from "domain";
6
-
7
- interface IOptionsTest extends DTComponentOptions {
8
- option1: boolean
9
- option2: boolean
10
- }
11
-
12
- /******************** STUB PROPERTIES CONSTANTS
13
- * Fixed properties to use with double classes, avoid auto generated and easy checking on test
14
- * *****/
15
- export const IDTest = "DTComponent-id-1234567";
16
- export const KeyTest = "DTComponent-key-1234567";
17
- export const ComponentTypeTest = "DTComponent-componentType-test";
18
- export const ToObjectTest = { type: "DTComponent-test-toObject" };
19
- export const ToStringTest = "DTComponent-test-toString";
20
- export const DomainTest = "DTComponent-domain-test";
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
- }
30
-
31
- /******************** STUB ABSTRACT IMPLEMENTATION
32
- * Implementation of abstract component class for tests
33
- * *****/
34
- export class DTComponentImpl extends DTComponent<IOptionsTest> {
35
- protected _componentType: string = ComponentTypeTest;
36
-
37
- copy(): DTComponent {
38
- return this;
39
- }
40
-
41
- toObject(): any {
42
- return ToObjectTest;
43
- }
44
-
45
- toString(): string {
46
- return ToStringTest;
47
- }
48
-
49
- updateFromDix(dix: Record<string, DIXObject>): void {
50
- }
51
- }
52
-
53
- /******************** HELPER TEST CLASS
54
- * Helper test class, inherits the main component
55
- * Providing methods to property access and other facilities, in order to avoid using class methods
56
- * *****/
57
- export class DTComponentTest extends DTComponentImpl {
58
- th_get_id(): string {
59
- return this._id;
60
- }
61
-
62
- th_set_id(id: string): void {
63
- this._id = id;
64
- }
65
-
66
- th_get_key(): string {
67
- return this._key;
68
- }
69
-
70
- th_set_key(key: string): void {
71
- this._key = key;
72
- }
73
-
74
- th_set_componentType(componentType: string): void {
75
- this._componentType = componentType;
76
- }
77
-
78
- th_set_domain(domain: string): void {
79
- this._domain = domain;
80
- }
81
-
82
- th_set_subKind(subKind: string): void {
83
- this._subKind = subKind;
84
- }
85
-
86
- th_get_context(): DTComponent | undefined {
87
- return this._context;
88
- }
89
-
90
- th_set_context(context: DTComponentTest): void {
91
- this._context = context;
92
- }
93
-
94
- th_get_errors(): Array<DTErrorStub> {
95
- return this._errors;
96
- }
97
-
98
- th_set_errors(errors: Array<DTErrorStub>): void {
99
- this._errors = errors;
100
- }
101
-
102
- th_get_options(): any {
103
- return this._options;
104
- }
105
-
106
- th_set_options(options: any): void {
107
- this._options = options;
108
- }
109
-
110
- updateFromDix(dix: Record<string, DIXObject>): void {
111
- }
112
- }
113
-
114
- /******************** STUB CLASS
115
- * Stub class, for using in other component
116
- * *****/
117
- export class DTComponentStub extends DTComponentTest {
118
- private readonly stubId: string;
119
-
120
- constructor(idSuffix: string = "") {
121
- super();
122
- this.stubId = IDTest + (idSuffix && `-${idSuffix}`);
123
- }
124
-
125
- _getStubId(): string {
126
- return this.stubId;
127
- }
128
- }
129
-
130
- /******************** HELPER METHODS
131
- * Additional helper methods to use with testing
132
- * *****/
133
- // Mocked implementations for overridden methods (for children tests)
134
- export function mockOverriddenMethods(mock: any) {
135
- // Constructor
136
- mock.prototype.constructor.mockImplementation(function (key?: string) {
137
- this._id = IDTest;
138
- this._key = key || this._id;
139
- this._errors = [];
140
- return this;
141
- })
142
- }
143
-
144
- // Hierarchy Simulation
145
- type simulateHierarchyOptions = {
146
- mockGetContext: boolean
147
- }
148
- export function simulateHierarchy(
149
- ranks: number = 3,
150
- options: simulateHierarchyOptions = { mockGetContext: false }): DTComponentTest[] {
151
- const hierarchyComponents = [];
152
- let lastRankComponent: DTComponentTest;
153
-
154
- for (let i = 1; i <= ranks; i++) {
155
- const componentRank = new DTComponentTest();
156
- componentRank.th_set_componentType(`rank${i}`);
157
- if (lastRankComponent) {
158
- componentRank.th_set_context(lastRankComponent);
159
- }
160
-
161
- if (options.mockGetContext) {
162
- if (lastRankComponent) {
163
- const lastComponentRankScoped = lastRankComponent;
164
- jest.spyOn(componentRank, 'getContext').mockImplementation(function () {
165
- return lastComponentRankScoped;
166
- });
167
- } else {
168
- jest.spyOn(componentRank, 'getContext').mockImplementation(function () {
169
- return undefined;
170
- });
171
- }
172
- }
173
-
174
- hierarchyComponents.push(componentRank);
175
- lastRankComponent = componentRank;
176
- }
177
-
178
- return hierarchyComponents;
179
- }
@@ -1,297 +0,0 @@
1
- import {afterEach, beforeEach, describe, expect, jest, test,} from '@jest/globals';
2
- import {
3
- ComponentTypeTest,
4
- DomainTest,
5
- DTComponentTest,
6
- IDTest,
7
- KeyTest,
8
- simulateHierarchy,
9
- SubKindTest,
10
- ToDIXObjectTest,
11
- } from './DTComponent.double';
12
- import {DTErrorStub} from "./DTError.double";
13
-
14
- describe('class DTComponent', () => {
15
- let componentTest: DTComponentTest;
16
-
17
- beforeEach(() => {
18
- componentTest = new DTComponentTest();
19
- });
20
-
21
- afterEach(() => {
22
- jest.clearAllMocks();
23
- });
24
-
25
- describe('constructor()', () => {
26
- test('creation without key', () => {
27
- const component = new DTComponentTest();
28
- const component2 = new DTComponentTest(null);
29
-
30
- expect(component.th_get_key()).toBe(component.th_get_id());
31
- expect(component2.th_get_key()).toBe(component2.th_get_id());
32
- });
33
-
34
- test('creation with key', () => {
35
- const component = new DTComponentTest(KeyTest);
36
-
37
- expect(component.th_get_key()).toBe(KeyTest);
38
- expect(component.th_get_id() !== component.th_get_key()).toBeTruthy();
39
- });
40
-
41
- test('creations have unique ids', () => {
42
- const component = new DTComponentTest(KeyTest);
43
- const component2 = new DTComponentTest(KeyTest);
44
-
45
- expect(component.th_get_id() !== component2.th_get_id()).toBeTruthy();
46
- });
47
-
48
- test('creations without options - default', () => {
49
- const component = new DTComponentTest();
50
-
51
- expect(component.th_get_options()).toStrictEqual({
52
- errors: false,
53
- syncId: undefined,
54
- });
55
- });
56
-
57
- test('creations with options', () => {
58
- const component = new DTComponentTest(KeyTest, { errors: true, option1: false, option2: true, syncId: "123" });
59
-
60
- expect(component.th_get_options()).toStrictEqual({
61
- errors: true,
62
- syncId: "123",
63
- option1: false,
64
- option2: true
65
- });
66
- });
67
- });
68
-
69
- describe('getId()', () => {
70
- test('return id', () => {
71
- componentTest.th_set_id(IDTest);
72
- expect(componentTest.getId()).toBe(IDTest);
73
- });
74
- });
75
-
76
- describe('getKey()', () => {
77
- test('return key', () => {
78
- componentTest.th_set_key(KeyTest);
79
- expect(componentTest.getKey()).toBe(KeyTest);
80
- });
81
- });
82
-
83
- describe('getComponentType()', () => {
84
- test('return componentType', () => {
85
- const componentTestSet = new DTComponentTest();
86
- componentTestSet.th_set_componentType(`${ComponentTypeTest}-set`);
87
-
88
- expect(componentTest.getComponentType()).toBe(ComponentTypeTest);
89
- expect(componentTestSet.getComponentType()).toBe(`${ComponentTypeTest}-set`);
90
- });
91
- });
92
-
93
- describe('getDomain()', () => {
94
- test('return domain', () => {
95
- const componentTestSet = new DTComponentTest();
96
- componentTestSet.th_set_domain(DomainTest);
97
-
98
- expect(componentTest.getDomain()).toBeUndefined();
99
- expect(componentTestSet.getDomain()).toBe(DomainTest);
100
- });
101
- });
102
-
103
- describe('getSubKind()', () => {
104
- test('return subkind', () => {
105
- const componentTestSet = new DTComponentTest();
106
- componentTestSet.th_set_subKind(SubKindTest);
107
-
108
- expect(componentTest.getSubKind()).toBeUndefined();
109
- expect(componentTestSet.getSubKind()).toBe(SubKindTest);
110
- });
111
- });
112
-
113
- describe('getContext()', () => {
114
- beforeEach(() => {
115
- componentTest = new DTComponentTest();
116
- });
117
-
118
- test('return context', () => {
119
- const component = new DTComponentTest();
120
- const componentTestSet = new DTComponentTest();
121
- componentTestSet.th_set_context(component);
122
- jest.spyOn(component, 'getComponentType').mockImplementation(function () {
123
- return this._componentType;
124
- });
125
- jest.spyOn(componentTestSet, 'getComponentType').mockImplementation(function () {
126
- return this._componentType;
127
- });
128
-
129
- expect(componentTest.getContext()).toBeUndefined();
130
- expect(componentTestSet.getContext()).toStrictEqual(component);
131
- });
132
-
133
- test('return context with Hierarchy - simple case', () => {
134
- const [componentRank1, componentRank2, componentRank3] = simulateHierarchy();
135
- jest.spyOn(componentRank3, 'getComponentType').mockImplementation(function () {
136
- return this._componentType;
137
- });
138
-
139
- expect(componentRank3.getContext()).toStrictEqual(componentRank2);
140
- expect(componentRank3.getContext('rank2')).toStrictEqual(componentRank2);
141
- expect(componentRank3.getContext('rank1')).toStrictEqual(componentRank1);
142
- expect(componentRank3.getContext('rank0')).toBeUndefined();
143
- });
144
-
145
- test('return context with Hierarchy - same type case so return first one', () => {
146
- const [componentRank0, componentRank2, componentRank3] = simulateHierarchy();
147
- const componentRank1 = new DTComponentTest();
148
- componentRank1.th_set_componentType('rank1');
149
- componentRank1.th_set_context(componentRank0);
150
- componentRank2.th_set_context(componentRank1);
151
- jest.spyOn(componentRank1, 'getComponentType').mockImplementation(function () {
152
- return this._componentType;
153
- });
154
-
155
- expect(componentRank3.getContext('rank1')).toStrictEqual(componentRank1);
156
- });
157
- });
158
-
159
- describe('setContext()', () => {
160
- test('change context', () => {
161
- const componentRank1 = new DTComponentTest();
162
- componentRank1.th_set_componentType('rank1');
163
-
164
- componentTest.setContext(componentRank1);
165
- expect(componentTest.th_get_context()).toBe(componentRank1);
166
- });
167
- });
168
-
169
- describe('removeContext()', () => {
170
- test('remove the current Context', () => {
171
- const componentRankSup = new DTComponentTest();
172
- componentTest.th_set_context(componentRankSup);
173
-
174
- componentTest.removeContext();
175
- expect(componentTest.th_get_context()).toBeUndefined();
176
- });
177
- });
178
-
179
- describe('getErrors()', () => {
180
- test('return empty errors by default', () => {
181
- expect(componentTest.getErrors()).toStrictEqual([]);
182
- });
183
-
184
- test('return array of errors if defined', () => {
185
- const errors = [new DTErrorStub(), new DTErrorStub()];
186
- componentTest.th_set_errors(errors);
187
-
188
- expect(componentTest.getErrors()).toStrictEqual(errors);
189
- });
190
-
191
- test('return errors from higher level component', () => {
192
- const [componentRank1, componentRank2, componentRank3] = simulateHierarchy(3, { mockGetContext: true });
193
- componentRank1.th_set_errors([new DTErrorStub(), new DTErrorStub(), new DTErrorStub()]);
194
- componentRank2.th_set_errors([new DTErrorStub(), new DTErrorStub()]);
195
- componentRank3.th_set_errors([new DTErrorStub()]);
196
-
197
- expect(componentRank1.getErrors().length).toEqual(3);
198
- expect(componentRank2.getErrors().length).toEqual(3);
199
- expect(componentRank3.getErrors().length).toEqual(3);
200
- })
201
- });
202
-
203
- describe('getLastError()', () => {
204
- test('return undefined if no errors', () => {
205
- expect(componentTest.getLastError()).toBeUndefined();
206
- });
207
-
208
- test('return the last error', () => {
209
- const lastError = new DTErrorStub();
210
- const errors = [new DTErrorStub(), new DTErrorStub(), lastError];
211
- componentTest.th_set_errors(errors);
212
-
213
- expect(componentTest.getLastError().getTimestamp().toString()).toStrictEqual(lastError.getTimestamp().toString());
214
- });
215
-
216
- test('return the last error from higher level component', () => {
217
- const [componentRank1, componentRank2, componentRank3] = simulateHierarchy(3, { mockGetContext: true });
218
- const lastError = new DTErrorStub();
219
- componentRank1.th_set_errors([new DTErrorStub(), new DTErrorStub(), lastError]);
220
- componentRank2.th_set_errors([new DTErrorStub(), new DTErrorStub()]);
221
- componentRank3.th_set_errors([new DTErrorStub()]);
222
-
223
- expect(componentRank1.getLastError().getTimestamp().toString()).toStrictEqual(lastError.getTimestamp().toString());
224
- expect(componentRank2.getLastError().getTimestamp().toString()).toStrictEqual(lastError.getTimestamp().toString());
225
- expect(componentRank3.getLastError().getTimestamp().toString()).toStrictEqual(lastError.getTimestamp().toString());
226
- });
227
- });
228
-
229
- describe('triggerError()', () => {
230
- test('default throw an exception error - option errors false', () => {
231
- const error = new DTErrorStub();
232
-
233
- expect(() => componentTest.triggerError(error)).toThrow(error);
234
- });
235
-
236
- test('stack new error - option errors true', () => {
237
- componentTest.th_set_options({ errors: true });
238
- const error = new DTErrorStub();
239
-
240
- componentTest.triggerError(error);
241
- expect(componentTest.th_get_errors().length).toBe(1);
242
- });
243
-
244
- test('throw new error in higher level component - option errors false', () => {
245
- const [componentRank1, componentRank2, componentRank3] = simulateHierarchy(3, { mockGetContext: true });
246
- componentRank1.th_set_options({ errors: false });
247
- componentRank2.th_set_options({ errors: true });
248
- componentRank3.th_set_options({ errors: true });
249
- const error = new DTErrorStub();
250
-
251
- expect(() => componentRank3.triggerError(error)).toThrow(error);
252
- expect(componentRank2.th_get_errors().length).toBe(0);
253
- expect(componentRank1.th_get_errors().length).toBe(0);
254
- });
255
-
256
- test('stack new error in higher level component - option errors true', () => {
257
- const [componentRank1, componentRank2, componentRank3] = simulateHierarchy(3, { mockGetContext: true });
258
- componentRank1.th_set_options({ errors: true });
259
- componentRank2.th_set_options({ errors: false });
260
- const error = new DTErrorStub();
261
-
262
- componentRank3.triggerError(error);
263
- expect(componentRank1.th_get_errors().length).toBe(1);
264
- expect(componentRank2.th_get_errors().length).toBe(0);
265
- expect(componentRank3.th_get_errors().length).toBe(0);
266
- });
267
- });
268
-
269
- describe('clearErrors()', () => {
270
- test('reset errors array', () => {
271
- componentTest.th_set_errors([new DTErrorStub(), new DTErrorStub()]);
272
-
273
- componentTest.clearErrors();
274
- expect(componentTest.th_get_errors().length).toBe(0);
275
- });
276
-
277
- test('reset errors in higher level components', () => {
278
- const [componentRank1, componentRank2, componentRank3] = simulateHierarchy(3, { mockGetContext: true });
279
- componentRank1.th_set_errors([new DTErrorStub(), new DTErrorStub(), new DTErrorStub()]);
280
- componentRank2.th_set_errors([new DTErrorStub(), new DTErrorStub()]);
281
- componentRank3.th_set_errors([new DTErrorStub()]);
282
-
283
- componentRank3.clearErrors();
284
- expect(componentRank1.th_get_errors().length).toBe(0);
285
- expect(componentRank2.th_get_errors().length).toBe(0);
286
- expect(componentRank3.th_get_errors().length).toBe(0);
287
- });
288
- });
289
-
290
- describe('getOptions()', () => {
291
- test('return options', () => {
292
- componentTest.th_set_options({ errors: true, option1: false, option2: true });
293
-
294
- expect(componentTest.getOptions()).toStrictEqual({ errors: true, option1: false, option2: true });
295
- });
296
- });
297
- });
@@ -1,62 +0,0 @@
1
- import {DTComponentPhysical} 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
- export const IDTest = "DTComponentPhysical-id-1234567";
8
- export const KeyTest = "DTComponentPhysical-key-1234567";
9
- export const ComponentTypeTest = "DTComponentPhysical-componentType-test";
10
- export const ToObjectTest = { type: "DTComponentPhysical-test-toObject" };
11
- export const ToStringTest = "DTComponentPhysical-test-toString";
12
- export const OwnerTest = "owner-12345";
13
- export const ParentToDIXObjectTest = {
14
- [IDTest]: {
15
- key: KeyTest,
16
- componentType: ComponentTypeTest,
17
- meta: {}
18
- }
19
- }
20
- export const ToDIXObjectTest = {
21
- [IDTest]: {
22
- key: KeyTest,
23
- componentType: ComponentTypeTest,
24
- meta: {},
25
- owner: OwnerTest,
26
- }
27
- }
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 DTComponentPhysicalTest extends DTComponentPhysical<IMetaDataTest> {
34
- protected _componentType: string = ComponentTypeTest;
35
-
36
- constructor(
37
- id: string = IDTest,
38
- key: string = KeyTest,
39
- owner?: string,
40
- ) {
41
- super(key);
42
- this._id = id;
43
- this._owner = owner;
44
- }
45
-
46
- copy(): DTComponentPhysical<IMetaDataTest> {
47
- return this;
48
- }
49
-
50
- toObject(): any {
51
- return ToObjectTest;
52
- }
53
-
54
- toString(): string {
55
- return ToStringTest;
56
- }
57
- }
58
-
59
- /******************** HELPER METHODS
60
- * Additional helper methods to use with testing
61
- * *****/
62
-
@@ -1,81 +0,0 @@
1
- import {beforeEach, describe, expect, jest, test} from '@jest/globals';
2
- import {DTComponentPhysicalTest, IDTest, KeyTest, OwnerTest} from './DTComponentPhysical.double';
3
- import {DTComponentPhysical, DTComponentWithMeta} from "../../src";
4
-
5
- /************************* TESTS SUITES *******************************/
6
- describe('class DTComponentPhysical', () => {
7
- let componentPhysicalTest: DTComponentPhysicalTest;
8
-
9
- beforeEach(() => {
10
- componentPhysicalTest = new DTComponentPhysicalTest();
11
- });
12
-
13
- afterEach(() => {
14
- jest.resetAllMocks();
15
- });
16
-
17
- describe('inheritance', () => {
18
- test('check good inheritance for class', () => {
19
- expect(DTComponentPhysical.prototype instanceof DTComponentWithMeta).toBeTruthy();
20
- });
21
- });
22
-
23
- describe('getManager()', () => {
24
- test('call get context with manager accessor', () => {
25
- const getContextSpy = jest.spyOn(componentPhysicalTest, 'getContext');
26
-
27
- componentPhysicalTest.getManager();
28
-
29
- expect(getContextSpy.mock.calls.length).toBe(1);
30
- expect(getContextSpy.mock.calls[0][0]).toBe('manager');
31
- });
32
- });
33
-
34
- describe('getMaster()', () => {
35
- test('call get context with master accessor', () => {
36
- const getContextSpy = jest.spyOn(componentPhysicalTest, 'getContext');
37
-
38
- componentPhysicalTest.getMaster();
39
-
40
- expect(getContextSpy.mock.calls.length).toBe(1);
41
- expect(getContextSpy.mock.calls[0][0]).toBe('master');
42
- });
43
- });
44
-
45
- describe('getOwner()', () => {
46
- test('return empty owner by default', () => {
47
- expect(componentPhysicalTest.getOwner()).toBeUndefined();
48
- });
49
-
50
- test('return owner when set', () => {
51
- componentPhysicalTest = new DTComponentPhysicalTest(IDTest, KeyTest, OwnerTest);
52
-
53
- expect(componentPhysicalTest.getOwner()).toBe(OwnerTest);
54
- });
55
- });
56
-
57
- describe('setOwner()', () => {
58
- test('add a new owner', () => {
59
- componentPhysicalTest.setOwner(OwnerTest);
60
-
61
- expect(componentPhysicalTest.getOwner()).toBe(OwnerTest);
62
- });
63
- });
64
-
65
- describe('removeOwner()', () => {
66
- test('remove the current Owner', () => {
67
- componentPhysicalTest = new DTComponentPhysicalTest(IDTest, KeyTest, OwnerTest);
68
-
69
- componentPhysicalTest.removeOwner();
70
- expect(componentPhysicalTest.getOwner()).toBeUndefined();
71
- });
72
- });
73
-
74
- // describe('toDIXObject()', () => {
75
- // test('return parent and owner', () => {
76
- // const dixObject = componentPhysicalTest.toDIXObject();
77
- //
78
- // expect(dixObject).toStrictEqual(ToDIXObjectTest);
79
- // });
80
- // });
81
- });