@adaas/a-utils 0.1.29 → 0.1.31

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.
@@ -0,0 +1,133 @@
1
+ import { A_Component, A_Concept, A_Container, A_Context, A_Feature, A_Inject, A_Scope } from "@adaas/a-concept";
2
+ import { A_SignalBusFeatures, A_SignalFeatures } from "@adaas/a-utils/lib/A-Signal/A-Signal.constants";
3
+ import { A_SignalBus } from "@adaas/a-utils/lib/A-Signal/components/A-SignalBus.component";
4
+ import { A_SignalConfig } from "@adaas/a-utils/lib/A-Signal/context/A-SignalConfig.context";
5
+ import { A_Signal } from "@adaas/a-utils/lib/A-Signal/entities/A-Signal.entity";
6
+ import { A_SignalVector } from "@adaas/a-utils/lib/A-Signal/entities/A-SignalVector.entity";
7
+
8
+
9
+
10
+ jest.retryTimes(0);
11
+
12
+ describe('A-Signal tests', () => {
13
+ it('Should Allow to emit basic signal structure', async () => {
14
+
15
+ let result: A_SignalVector | undefined = undefined;
16
+
17
+ class UserIntentionListener extends A_Component {
18
+ @A_Concept.Start()
19
+ async start(
20
+ @A_Inject(A_Scope) scope: A_Scope,
21
+ @A_Inject(A_SignalBus) bus: A_SignalBus
22
+ ) {
23
+
24
+
25
+ const signal = new A_Signal({
26
+ data: {
27
+ buttonId: 'submit-order'
28
+ }
29
+ })
30
+ await signal.emit(scope)
31
+ }
32
+
33
+
34
+ @A_Feature.Extend()
35
+ async [A_SignalBusFeatures.Emit](
36
+ @A_Inject(A_SignalVector) vector: A_SignalVector
37
+ ) {
38
+ result = vector;
39
+ }
40
+ }
41
+
42
+ const concept = new A_Concept({
43
+ name: 'test-concept',
44
+ containers: [new A_Container({
45
+ name: 'test-container',
46
+ components: [A_SignalBus, UserIntentionListener],
47
+ fragments: [
48
+ new A_SignalConfig({
49
+ structure: [A_Signal]
50
+ })
51
+ ]
52
+ })]
53
+ });
54
+
55
+ await concept.load();
56
+ await concept.start();
57
+
58
+ expect(result).toBeDefined();
59
+ expect(result).toBeInstanceOf(A_SignalVector);
60
+ expect(result!.length).toBe(1);
61
+ expect((await result!.toDataVector())[0]?.buttonId).toBe('submit-order');
62
+
63
+ });
64
+ it('Should Allow to work with custom Signals', async () => {
65
+
66
+ class UserIntentionSignal extends A_Signal<{ buttonId: string }> { }
67
+
68
+ class UserMousePositionSignal extends A_Signal<{ x: number, y: number }> {
69
+ static async default(): Promise<A_Signal | undefined> {
70
+ return Promise.resolve(new UserMousePositionSignal({
71
+ data: { x: 0, y: 0 }
72
+ }));
73
+ }
74
+ }
75
+ class UserElementHoverSignal extends A_Signal<{ elementId: string }> { }
76
+
77
+
78
+
79
+ let result: A_SignalVector | undefined = undefined;
80
+
81
+ class UserIntentionListener extends A_Component {
82
+ @A_Concept.Start()
83
+ async start(
84
+ @A_Inject(A_Scope) scope: A_Scope,
85
+ @A_Inject(A_SignalBus) bus: A_SignalBus
86
+ ) {
87
+
88
+ const signal = new UserIntentionSignal({
89
+ data: {
90
+ buttonId: 'submit-order'
91
+ }
92
+ })
93
+
94
+ await signal.emit(scope)
95
+ }
96
+
97
+
98
+ @A_Feature.Extend()
99
+ async [A_SignalBusFeatures.Emit](
100
+ @A_Inject(A_SignalVector) vector: A_SignalVector
101
+ ) {
102
+ result = vector;
103
+ }
104
+ }
105
+
106
+ const concept = new A_Concept({
107
+ name: 'test-concept',
108
+ containers: [new A_Container({
109
+ name: 'test-container',
110
+ components: [A_SignalBus, UserIntentionListener],
111
+ fragments: [
112
+ new A_SignalConfig({
113
+ structure: [UserIntentionSignal, UserMousePositionSignal, UserElementHoverSignal]
114
+ })
115
+ ]
116
+ })]
117
+ });
118
+
119
+ await concept.load();
120
+ await concept.start();
121
+
122
+
123
+ expect(result).toBeDefined();
124
+ expect(result).toBeInstanceOf(A_SignalVector);
125
+ expect(result!.length).toBe(3);
126
+
127
+ expect((await result!.toDataVector())[0]?.buttonId).toBe('submit-order');
128
+ expect((await result!.toDataVector())[1]?.x).toBe(0);
129
+ expect((await result!.toDataVector())[1]?.y).toBe(0);
130
+ expect((await result!.toDataVector())[2]).toBeUndefined();
131
+
132
+ });
133
+ })
@@ -1,33 +0,0 @@
1
- import { A_Concept, A_Container } from "@adaas/a-concept"
2
- import { A_ConfigLoader } from "@adaas/a-utils/lib/A-Config/A-Config.container";
3
- import { A_Config } from "@adaas/a-utils/lib/A-Config/A-Config.context";
4
- import { ENVConfigReader } from "@adaas/a-utils/lib/A-Config/components/ENVConfigReader.component";
5
- import { A_Polyfill } from "@adaas/a-utils/lib/A-Polyfill/A-Polyfill.component";
6
-
7
-
8
-
9
- (async () => {
10
-
11
-
12
- const service1 = new A_ConfigLoader({
13
- name: 'ConfigLoaderContainer',
14
- components: [
15
- A_Polyfill, ENVConfigReader
16
- ]
17
- })
18
-
19
- const concept = new A_Concept({
20
- name: 'test-config',
21
- containers: [service1],
22
- });
23
-
24
-
25
- await concept.load();
26
- await concept.start();
27
-
28
-
29
- const config = service1.scope.resolve<A_Config<['ADAAS_SSO_LOCATION']>>(A_Config)!;
30
-
31
- console.log('config: ', config.get('ADAAS_SSO_LOCATION'))
32
-
33
- })()