@adaas/a-concept 0.1.18 → 0.1.19
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/dist/index.d.ts +2 -0
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/src/global/A-Abstraction/A-Abstraction-Extend.decorator.js +11 -4
- package/dist/src/global/A-Abstraction/A-Abstraction-Extend.decorator.js.map +1 -1
- package/dist/src/global/A-Component/A-Component.meta.js +2 -1
- package/dist/src/global/A-Component/A-Component.meta.js.map +1 -1
- package/dist/src/global/A-Component/A-Component.types.d.ts +2 -11
- package/dist/src/global/A-Concept/A-Concept.types.d.ts +4 -21
- package/dist/src/global/A-Container/A-Container.meta.js +4 -2
- package/dist/src/global/A-Container/A-Container.meta.js.map +1 -1
- package/dist/src/global/A-Container/A-Container.types.d.ts +2 -11
- package/dist/src/global/A-Feature/A-Feature-Define.decorator.js +1 -1
- package/dist/src/global/A-Feature/A-Feature-Define.decorator.js.map +1 -1
- package/dist/src/global/A-Feature/A-Feature-Extend.decorator.js +14 -5
- package/dist/src/global/A-Feature/A-Feature-Extend.decorator.js.map +1 -1
- package/dist/src/global/A-Feature/A-Feature.class.d.ts +2 -1
- package/dist/src/global/A-Feature/A-Feature.class.js +7 -3
- package/dist/src/global/A-Feature/A-Feature.class.js.map +1 -1
- package/dist/src/global/A-Feature/A-Feature.types.d.ts +69 -27
- package/dist/src/global/A-Stage/A-Stage.class.d.ts +37 -28
- package/dist/src/global/A-Stage/A-Stage.class.js +62 -98
- package/dist/src/global/A-Stage/A-Stage.class.js.map +1 -1
- package/dist/src/global/A-Stage/A-Stage.types.d.ts +30 -3
- package/dist/src/global/A-Stage/A-Stage.types.js.map +1 -1
- package/dist/src/global/A-StepManager/A-StepManager.class.d.ts +20 -0
- package/dist/src/{helpers/A_StepsManager.class.js → global/A-StepManager/A-StepManager.class.js} +38 -64
- package/dist/src/global/A-StepManager/A-StepManager.class.js.map +1 -0
- package/dist/src/global/A-StepManager/A-StepManager.error.d.ts +4 -0
- package/dist/src/global/A-StepManager/A-StepManager.error.js +9 -0
- package/dist/src/global/A-StepManager/A-StepManager.error.js.map +1 -0
- package/index.ts +2 -1
- package/package.json +3 -3
- package/src/global/A-Abstraction/A-Abstraction-Extend.decorator.ts +18 -6
- package/src/global/A-Component/A-Component.meta.ts +2 -1
- package/src/global/A-Component/A-Component.types.ts +2 -11
- package/src/global/A-Concept/A-Concept.types.ts +4 -21
- package/src/global/A-Container/A-Container.meta.ts +4 -2
- package/src/global/A-Container/A-Container.types.ts +2 -11
- package/src/global/A-Feature/A-Feature-Define.decorator.ts +1 -0
- package/src/global/A-Feature/A-Feature-Extend.decorator.ts +21 -7
- package/src/global/A-Feature/A-Feature.class.ts +8 -1
- package/src/global/A-Feature/A-Feature.types.ts +80 -33
- package/src/global/A-Stage/A-Stage.class.ts +71 -143
- package/src/global/A-Stage/A-Stage.types.ts +34 -3
- package/src/{helpers/A_StepsManager.class.ts → global/A-StepManager/A-StepManager.class.ts} +53 -87
- package/src/global/A-StepManager/A-StepManager.error.ts +10 -0
- package/tests/A-Abstraction.test.ts +273 -255
- package/tests/A-Feature.test.ts +270 -271
- package/tests/A-StepManager.test.ts +346 -0
- package/dist/src/helpers/A_StepsManager.class.d.ts +0 -35
- package/dist/src/helpers/A_StepsManager.class.js.map +0 -1
package/tests/A-Feature.test.ts
CHANGED
|
@@ -11,277 +11,277 @@ import { A_TYPES__ComponentMetaKey } from '@adaas/a-concept/global/A-Component/A
|
|
|
11
11
|
jest.retryTimes(0);
|
|
12
12
|
|
|
13
13
|
describe('A-Feature tests', () => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
// const feature = new A_Feature({
|
|
19
|
-
// name: 'testFeature',
|
|
20
|
-
// component: testComponent,
|
|
21
|
-
// });
|
|
22
|
-
|
|
23
|
-
// expect(feature).toBeInstanceOf(A_Feature);
|
|
24
|
-
// expect(feature.scope.parent).toBe(A_Context.root);
|
|
25
|
-
|
|
26
|
-
// });
|
|
27
|
-
// it('Should Allow to create a feature with steps', async () => {
|
|
28
|
-
// const template = [
|
|
29
|
-
// {
|
|
30
|
-
// name: 'A_Component.testHandler',
|
|
31
|
-
// component: A_Component,
|
|
32
|
-
// handler: 'testHandler',
|
|
33
|
-
// }
|
|
34
|
-
// ]
|
|
35
|
-
|
|
36
|
-
// const feature = new A_Feature({
|
|
37
|
-
// name: 'testFeature',
|
|
38
|
-
// scope: new A_Scope(),
|
|
39
|
-
// template
|
|
40
|
-
// });
|
|
41
|
-
|
|
42
|
-
// expect(feature).toBeInstanceOf(A_Feature);
|
|
43
|
-
// });
|
|
44
|
-
// it('Should be possible to execute a feature with steps as a template on the component', async () => {
|
|
45
|
-
// // 1) create a base component with some feature
|
|
46
|
-
// class MyExtendedComponent extends A_Component {
|
|
47
|
-
|
|
48
|
-
// async testHandler(
|
|
49
|
-
// @A_Inject(A_Caller) caller: MyComponent
|
|
50
|
-
// ) {
|
|
51
|
-
// caller.sum = 2;
|
|
52
|
-
// }
|
|
53
|
-
// }
|
|
54
|
-
|
|
55
|
-
// // 2) create a custom component with a defined template feature
|
|
56
|
-
// class MyComponent extends A_Component {
|
|
57
|
-
// sum: number = 0;
|
|
58
|
-
|
|
59
|
-
// @A_Feature.Define({
|
|
60
|
-
// invoke: true,
|
|
61
|
-
// template: [{
|
|
62
|
-
// name: 'MyExtendedComponent.testHandler',
|
|
63
|
-
// component: MyExtendedComponent,
|
|
64
|
-
// handler: 'testHandler',
|
|
65
|
-
// behavior: 'sync',
|
|
66
|
-
// before: [],
|
|
67
|
-
// after: []
|
|
68
|
-
// },
|
|
69
|
-
// {
|
|
70
|
-
// name: 'MyExtendedComponent.testHandler',
|
|
71
|
-
// component: MyExtendedComponent,
|
|
72
|
-
// handler: 'testHandler'
|
|
73
|
-
// }]
|
|
74
|
-
// })
|
|
75
|
-
// async testHandler() { }
|
|
76
|
-
// }
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
// // 3) create a running scope
|
|
80
|
-
// const scope = new A_Scope({ name: 'TestScope' });
|
|
81
|
-
// scope.register(MyExtendedComponent);
|
|
82
|
-
// scope.register(MyComponent);
|
|
83
|
-
|
|
84
|
-
// // 4) create an instance of the component from the scope
|
|
85
|
-
// const myComponent = scope.resolve(MyComponent);
|
|
86
|
-
// expect(myComponent).toBeInstanceOf(MyComponent);
|
|
87
|
-
// expect(myComponent.sum).toBe(0);
|
|
88
|
-
|
|
89
|
-
// // 5) call the feature caller to execute the feature
|
|
90
|
-
// await myComponent.testHandler();
|
|
91
|
-
|
|
92
|
-
// // 6) check the results
|
|
93
|
-
// expect(myComponent.sum).toBe(2);
|
|
94
|
-
|
|
95
|
-
// });
|
|
96
|
-
// it('Should be possible to execute a feature with steps as a template on the component with string component declaration', async () => {
|
|
97
|
-
// // 1) create a base component with some feature
|
|
98
|
-
// class MyExtendedComponent2 extends A_Component {
|
|
99
|
-
|
|
100
|
-
// async testHandler(
|
|
101
|
-
// @A_Inject(A_Caller) caller: MyComponent2
|
|
102
|
-
// ) {
|
|
103
|
-
// caller.sum = 2;
|
|
104
|
-
// }
|
|
105
|
-
// }
|
|
106
|
-
|
|
107
|
-
// // 2) create a custom component with a defined template feature
|
|
108
|
-
// class MyComponent2 extends A_Component {
|
|
109
|
-
// sum: number = 0;
|
|
110
|
-
|
|
111
|
-
// @A_Feature.Define({
|
|
112
|
-
// invoke: true,
|
|
113
|
-
// template: [{
|
|
114
|
-
// name: 'MyExtendedComponent2.testHandler',
|
|
115
|
-
// component: 'MyExtendedComponent2',
|
|
116
|
-
// handler: 'testHandler',
|
|
117
|
-
// behavior: 'sync',
|
|
118
|
-
// before: [],
|
|
119
|
-
// after: []
|
|
120
|
-
// }]
|
|
121
|
-
// })
|
|
122
|
-
// async testHandler() { }
|
|
123
|
-
// }
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
// // 3) create a running scope
|
|
127
|
-
// const scope = new A_Scope({ name: 'TestScope' });
|
|
128
|
-
// scope.register(MyExtendedComponent2);
|
|
129
|
-
// scope.register(MyComponent2);
|
|
130
|
-
|
|
131
|
-
// // 4) create an instance of the component from the scope
|
|
132
|
-
// const myComponent = scope.resolve(MyComponent2);
|
|
133
|
-
// expect(myComponent).toBeInstanceOf(MyComponent2);
|
|
134
|
-
// expect(myComponent.sum).toBe(0);
|
|
135
|
-
|
|
136
|
-
// // 5) call the feature caller to execute the feature
|
|
137
|
-
// await myComponent.testHandler();
|
|
138
|
-
|
|
139
|
-
// // 6) check the results
|
|
140
|
-
// expect(myComponent.sum).toBe(2);
|
|
141
|
-
|
|
142
|
-
// });
|
|
143
|
-
// it('Should execute feature steps in base order', async () => {
|
|
144
|
-
// const executionOrder: string[] = [];
|
|
145
|
-
|
|
146
|
-
// // 1) create a base component with some feature
|
|
147
|
-
// class My_Component extends A_Component {
|
|
148
|
-
// async methodA() {
|
|
149
|
-
// await this.call('myFeature')
|
|
150
|
-
// }
|
|
151
|
-
|
|
152
|
-
// @A_Feature.Extend({
|
|
153
|
-
// name: 'myFeature',
|
|
154
|
-
// })
|
|
155
|
-
// async stepOne(
|
|
156
|
-
// ) {
|
|
157
|
-
// executionOrder.push('stepOne');
|
|
158
|
-
// }
|
|
159
|
-
|
|
160
|
-
// @A_Feature.Extend({
|
|
161
|
-
// name: 'myFeature',
|
|
162
|
-
// })
|
|
163
|
-
// async stepTwo(
|
|
164
|
-
// ) {
|
|
165
|
-
// executionOrder.push('stepTwo');
|
|
166
|
-
// }
|
|
167
|
-
|
|
168
|
-
// @A_Feature.Extend({
|
|
169
|
-
// name: 'myFeature',
|
|
170
|
-
// })
|
|
171
|
-
// async stepThree(
|
|
172
|
-
// ) {
|
|
173
|
-
// executionOrder.push('stepThree');
|
|
174
|
-
// }
|
|
175
|
-
// }
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
// // 2) create a running scope
|
|
179
|
-
// const scope = new A_Scope({ name: 'TestScope', components: [My_Component] });
|
|
180
|
-
|
|
181
|
-
// // 3) create an instance of the component from the scope
|
|
182
|
-
// const myComponent = scope.resolve(My_Component);
|
|
183
|
-
// expect(myComponent).toBeInstanceOf(My_Component);
|
|
184
|
-
|
|
185
|
-
// // 4) call the feature caller to execute the feature
|
|
186
|
-
// await myComponent.methodA();
|
|
187
|
-
|
|
188
|
-
// // 5) check the results
|
|
189
|
-
// expect(executionOrder).toEqual(['stepOne', 'stepTwo', 'stepThree']);
|
|
190
|
-
// });
|
|
191
|
-
// it('Should execute feature steps in proper order', async () => {
|
|
192
|
-
// const executionOrder: string[] = [];
|
|
193
|
-
|
|
194
|
-
// // 1) create a base component with some feature
|
|
195
|
-
// class My_Component extends A_Component {
|
|
196
|
-
// async methodA() {
|
|
197
|
-
// await this.call('myFeature')
|
|
198
|
-
// }
|
|
199
|
-
|
|
200
|
-
// @A_Feature.Extend({
|
|
201
|
-
// name: 'myFeature',
|
|
202
|
-
// after: ['My_Component.stepTwo'],
|
|
203
|
-
// })
|
|
204
|
-
// async stepOne(
|
|
205
|
-
// ) {
|
|
206
|
-
// executionOrder.push('stepOne');
|
|
207
|
-
// }
|
|
208
|
-
|
|
209
|
-
// @A_Feature.Extend({
|
|
210
|
-
// name: 'myFeature',
|
|
211
|
-
// })
|
|
212
|
-
// async stepTwo(
|
|
213
|
-
// ) {
|
|
214
|
-
// executionOrder.push('stepTwo');
|
|
215
|
-
// }
|
|
216
|
-
// }
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
// // 2) create a running scope
|
|
220
|
-
// const scope = new A_Scope({ name: 'TestScope', components: [My_Component] });
|
|
221
|
-
|
|
222
|
-
// // 3) create an instance of the component from the scope
|
|
223
|
-
// const myComponent = scope.resolve(My_Component);
|
|
224
|
-
// expect(myComponent).toBeInstanceOf(My_Component);
|
|
225
|
-
|
|
226
|
-
// // 4) call the feature caller to execute the feature
|
|
227
|
-
// await myComponent.methodA();
|
|
228
|
-
|
|
229
|
-
// // 5) check the results
|
|
230
|
-
// expect(executionOrder).toEqual(['stepTwo', 'stepOne']);
|
|
231
|
-
// });
|
|
232
|
-
|
|
233
|
-
// it('Should allow to define a feature', async () => {
|
|
234
|
-
// const executionOrder: string[] = [];
|
|
235
|
-
|
|
236
|
-
// // 1) create a base component with some feature
|
|
237
|
-
// class My_Component extends A_Component {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
// @A_Feature.Define({ invoke: true })
|
|
241
|
-
// @A_Feature.Extend({
|
|
242
|
-
// name: 'myFeature',
|
|
243
|
-
// })
|
|
244
|
-
// async feature1(
|
|
245
|
-
// @A_Inject(A_Component) component: A_Component
|
|
246
|
-
// ) { }
|
|
247
|
-
|
|
248
|
-
// @A_Feature.Extend({
|
|
249
|
-
// name: 'feature1',
|
|
250
|
-
// })
|
|
251
|
-
// async feature1Extension() {
|
|
252
|
-
// executionOrder.push('stepOne');
|
|
253
|
-
// }
|
|
254
|
-
|
|
255
|
-
// @A_Feature.Define()
|
|
256
|
-
// async feature2() {
|
|
257
|
-
// await this.call('feature2');
|
|
258
|
-
// }
|
|
259
|
-
|
|
260
|
-
// @A_Feature.Extend({
|
|
261
|
-
// name: 'feature2',
|
|
262
|
-
// })
|
|
263
|
-
// async feature2Extension() {
|
|
264
|
-
// executionOrder.push('stepTwo');
|
|
265
|
-
// }
|
|
266
|
-
|
|
267
|
-
// }
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
// // 2) create a running scope
|
|
271
|
-
// const scope = new A_Scope({ name: 'TestScope', components: [My_Component] });
|
|
272
|
-
|
|
273
|
-
// // 3) create an instance of the component from the scope
|
|
274
|
-
// const myComponent = scope.resolve(My_Component);
|
|
275
|
-
// expect(myComponent).toBeInstanceOf(My_Component);
|
|
14
|
+
it('Should Allow to create a feature from component', async () => {
|
|
15
|
+
const testComponent = new A_Component()
|
|
16
|
+
A_Context.root.register(testComponent);
|
|
276
17
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
18
|
+
const feature = new A_Feature({
|
|
19
|
+
name: 'testFeature',
|
|
20
|
+
component: testComponent,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
expect(feature).toBeInstanceOf(A_Feature);
|
|
24
|
+
expect(feature.scope.parent).toBe(A_Context.root);
|
|
25
|
+
|
|
26
|
+
});
|
|
27
|
+
it('Should Allow to create a feature with steps', async () => {
|
|
28
|
+
const template = [
|
|
29
|
+
{
|
|
30
|
+
name: 'A_Component.testHandler',
|
|
31
|
+
component: A_Component,
|
|
32
|
+
handler: 'testHandler',
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
const feature = new A_Feature({
|
|
37
|
+
name: 'testFeature',
|
|
38
|
+
scope: new A_Scope(),
|
|
39
|
+
template
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
expect(feature).toBeInstanceOf(A_Feature);
|
|
43
|
+
});
|
|
44
|
+
it('Should be possible to execute a feature with steps as a template on the component', async () => {
|
|
45
|
+
// 1) create a base component with some feature
|
|
46
|
+
class MyExtendedComponent extends A_Component {
|
|
47
|
+
|
|
48
|
+
async testHandler(
|
|
49
|
+
@A_Inject(A_Caller) caller: MyComponent
|
|
50
|
+
) {
|
|
51
|
+
caller.sum = 2;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// 2) create a custom component with a defined template feature
|
|
56
|
+
class MyComponent extends A_Component {
|
|
57
|
+
sum: number = 0;
|
|
58
|
+
|
|
59
|
+
@A_Feature.Define({
|
|
60
|
+
invoke: true,
|
|
61
|
+
template: [{
|
|
62
|
+
name: 'MyExtendedComponent.testHandler',
|
|
63
|
+
component: MyExtendedComponent,
|
|
64
|
+
handler: 'testHandler',
|
|
65
|
+
behavior: 'sync',
|
|
66
|
+
before: [],
|
|
67
|
+
after: []
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: 'MyExtendedComponent.testHandler',
|
|
71
|
+
component: MyExtendedComponent,
|
|
72
|
+
handler: 'testHandler'
|
|
73
|
+
}]
|
|
74
|
+
})
|
|
75
|
+
async testHandler() { }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
// 3) create a running scope
|
|
80
|
+
const scope = new A_Scope({ name: 'TestScope' });
|
|
81
|
+
scope.register(MyExtendedComponent);
|
|
82
|
+
scope.register(MyComponent);
|
|
83
|
+
|
|
84
|
+
// 4) create an instance of the component from the scope
|
|
85
|
+
const myComponent = scope.resolve(MyComponent);
|
|
86
|
+
expect(myComponent).toBeInstanceOf(MyComponent);
|
|
87
|
+
expect(myComponent.sum).toBe(0);
|
|
88
|
+
|
|
89
|
+
// 5) call the feature caller to execute the feature
|
|
90
|
+
await myComponent.testHandler();
|
|
91
|
+
|
|
92
|
+
// 6) check the results
|
|
93
|
+
expect(myComponent.sum).toBe(2);
|
|
94
|
+
|
|
95
|
+
});
|
|
96
|
+
it('Should be possible to execute a feature with steps as a template on the component with string component declaration', async () => {
|
|
97
|
+
// 1) create a base component with some feature
|
|
98
|
+
class MyExtendedComponent2 extends A_Component {
|
|
99
|
+
|
|
100
|
+
async testHandler(
|
|
101
|
+
@A_Inject(A_Caller) caller: MyComponent2
|
|
102
|
+
) {
|
|
103
|
+
caller.sum = 2;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// 2) create a custom component with a defined template feature
|
|
108
|
+
class MyComponent2 extends A_Component {
|
|
109
|
+
sum: number = 0;
|
|
110
|
+
|
|
111
|
+
@A_Feature.Define({
|
|
112
|
+
invoke: true,
|
|
113
|
+
template: [{
|
|
114
|
+
name: 'MyExtendedComponent2.testHandler',
|
|
115
|
+
component: 'MyExtendedComponent2',
|
|
116
|
+
handler: 'testHandler',
|
|
117
|
+
behavior: 'sync',
|
|
118
|
+
before: [],
|
|
119
|
+
after: []
|
|
120
|
+
}]
|
|
121
|
+
})
|
|
122
|
+
async testHandler() { }
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
// 3) create a running scope
|
|
127
|
+
const scope = new A_Scope({ name: 'TestScope' });
|
|
128
|
+
scope.register(MyExtendedComponent2);
|
|
129
|
+
scope.register(MyComponent2);
|
|
130
|
+
|
|
131
|
+
// 4) create an instance of the component from the scope
|
|
132
|
+
const myComponent = scope.resolve(MyComponent2);
|
|
133
|
+
expect(myComponent).toBeInstanceOf(MyComponent2);
|
|
134
|
+
expect(myComponent.sum).toBe(0);
|
|
135
|
+
|
|
136
|
+
// 5) call the feature caller to execute the feature
|
|
137
|
+
await myComponent.testHandler();
|
|
138
|
+
|
|
139
|
+
// 6) check the results
|
|
140
|
+
expect(myComponent.sum).toBe(2);
|
|
141
|
+
|
|
142
|
+
});
|
|
143
|
+
it('Should execute feature steps in base order', async () => {
|
|
144
|
+
const executionOrder: string[] = [];
|
|
145
|
+
|
|
146
|
+
// 1) create a base component with some feature
|
|
147
|
+
class My_Component extends A_Component {
|
|
148
|
+
async methodA() {
|
|
149
|
+
await this.call('myFeature')
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
@A_Feature.Extend({
|
|
153
|
+
name: 'myFeature',
|
|
154
|
+
})
|
|
155
|
+
async stepOne(
|
|
156
|
+
) {
|
|
157
|
+
executionOrder.push('stepOne');
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
@A_Feature.Extend({
|
|
161
|
+
name: 'myFeature',
|
|
162
|
+
})
|
|
163
|
+
async stepTwo(
|
|
164
|
+
) {
|
|
165
|
+
executionOrder.push('stepTwo');
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
@A_Feature.Extend({
|
|
169
|
+
name: 'myFeature',
|
|
170
|
+
})
|
|
171
|
+
async stepThree(
|
|
172
|
+
) {
|
|
173
|
+
executionOrder.push('stepThree');
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
// 2) create a running scope
|
|
179
|
+
const scope = new A_Scope({ name: 'TestScope', components: [My_Component] });
|
|
180
|
+
|
|
181
|
+
// 3) create an instance of the component from the scope
|
|
182
|
+
const myComponent = scope.resolve(My_Component);
|
|
183
|
+
expect(myComponent).toBeInstanceOf(My_Component);
|
|
184
|
+
|
|
185
|
+
// 4) call the feature caller to execute the feature
|
|
186
|
+
await myComponent.methodA();
|
|
187
|
+
|
|
188
|
+
// 5) check the results
|
|
189
|
+
expect(executionOrder).toEqual(['stepOne', 'stepTwo', 'stepThree']);
|
|
190
|
+
});
|
|
191
|
+
it('Should execute feature steps in proper order', async () => {
|
|
192
|
+
const executionOrder: string[] = [];
|
|
193
|
+
|
|
194
|
+
// 1) create a base component with some feature
|
|
195
|
+
class My_Component extends A_Component {
|
|
196
|
+
async methodA() {
|
|
197
|
+
await this.call('myFeature')
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
@A_Feature.Extend({
|
|
201
|
+
name: 'myFeature',
|
|
202
|
+
after: ['My_Component.stepTwo'],
|
|
203
|
+
})
|
|
204
|
+
async stepOne(
|
|
205
|
+
) {
|
|
206
|
+
executionOrder.push('stepOne');
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
@A_Feature.Extend({
|
|
210
|
+
name: 'myFeature',
|
|
211
|
+
})
|
|
212
|
+
async stepTwo(
|
|
213
|
+
) {
|
|
214
|
+
executionOrder.push('stepTwo');
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
// 2) create a running scope
|
|
220
|
+
const scope = new A_Scope({ name: 'TestScope', components: [My_Component] });
|
|
221
|
+
|
|
222
|
+
// 3) create an instance of the component from the scope
|
|
223
|
+
const myComponent = scope.resolve(My_Component);
|
|
224
|
+
expect(myComponent).toBeInstanceOf(My_Component);
|
|
225
|
+
|
|
226
|
+
// 4) call the feature caller to execute the feature
|
|
227
|
+
await myComponent.methodA();
|
|
228
|
+
|
|
229
|
+
// 5) check the results
|
|
230
|
+
expect(executionOrder).toEqual(['stepTwo', 'stepOne']);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('Should allow to define a feature', async () => {
|
|
234
|
+
const executionOrder: string[] = [];
|
|
235
|
+
|
|
236
|
+
// 1) create a base component with some feature
|
|
237
|
+
class My_Component extends A_Component {
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
@A_Feature.Define({ invoke: true })
|
|
241
|
+
@A_Feature.Extend({
|
|
242
|
+
name: 'myFeature',
|
|
243
|
+
})
|
|
244
|
+
async feature1(
|
|
245
|
+
@A_Inject(A_Component) component: A_Component
|
|
246
|
+
) { }
|
|
247
|
+
|
|
248
|
+
@A_Feature.Extend({
|
|
249
|
+
name: 'feature1',
|
|
250
|
+
})
|
|
251
|
+
async feature1Extension() {
|
|
252
|
+
executionOrder.push('stepOne');
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
@A_Feature.Define()
|
|
256
|
+
async feature2() {
|
|
257
|
+
await this.call('feature2');
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
@A_Feature.Extend({
|
|
261
|
+
name: 'feature2',
|
|
262
|
+
})
|
|
263
|
+
async feature2Extension() {
|
|
264
|
+
executionOrder.push('stepTwo');
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
// 2) create a running scope
|
|
271
|
+
const scope = new A_Scope({ name: 'TestScope', components: [My_Component] });
|
|
272
|
+
|
|
273
|
+
// 3) create an instance of the component from the scope
|
|
274
|
+
const myComponent = scope.resolve(My_Component);
|
|
275
|
+
expect(myComponent).toBeInstanceOf(My_Component);
|
|
276
|
+
|
|
277
|
+
// 4) call the feature caller to execute the feature
|
|
278
|
+
await myComponent.feature1(new A_Component());
|
|
279
|
+
|
|
280
|
+
await myComponent.feature2();
|
|
281
|
+
|
|
282
|
+
// 5) check the results
|
|
283
|
+
expect(executionOrder).toEqual(['stepOne', 'stepTwo']);
|
|
284
|
+
});
|
|
285
285
|
it('Should inherit feature definitions & extensions', async () => {
|
|
286
286
|
const executionOrder: string[] = [];
|
|
287
287
|
|
|
@@ -321,7 +321,6 @@ describe('A-Feature tests', () => {
|
|
|
321
321
|
expect(executionOrder).toEqual(['stepOne', 'stepTwo']);
|
|
322
322
|
});
|
|
323
323
|
|
|
324
|
-
|
|
325
324
|
it('Should allow override feature extension', async () => {
|
|
326
325
|
const executionOrder: string[] = [];
|
|
327
326
|
|