@luigi-project/testing-utilities 2.9.1-dev.202402280955 → 2.9.1-dev.202403100026
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/luigi-mock-engine.js +111 -115
- package/luigi-mock-util.d.ts +1 -1
- package/package.json +1 -1
package/luigi-mock-engine.js
CHANGED
|
@@ -15,123 +15,119 @@ export class LuigiMockEngine {
|
|
|
15
15
|
static initPostMessageHook() {
|
|
16
16
|
return async () => {
|
|
17
17
|
// Check if Luigi Client is running standalone
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
window.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const mockListener = window.luigiMockEnvironment.mockListeners[e.data.msg];
|
|
49
|
-
if (mockListener) {
|
|
50
|
-
mockListener(e);
|
|
18
|
+
if (window.parent === window) {
|
|
19
|
+
console.debug('Detected standalone mode');
|
|
20
|
+
// Check and skip if Luigi environment is already mocked
|
|
21
|
+
if (window.luigiMockEnvironment) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
// mock target origin
|
|
25
|
+
if (window.LuigiClient) {
|
|
26
|
+
window.LuigiClient.setTargetOrigin('*');
|
|
27
|
+
}
|
|
28
|
+
window.luigiMockEnvironment = {
|
|
29
|
+
msgListener: function (e) {
|
|
30
|
+
if (e.data.msg && (e.data.msg.startsWith('luigi.') || e.data.msg === 'storage')) {
|
|
31
|
+
if (e.data.msg === 'luigi.get-context') {
|
|
32
|
+
window.postMessage({
|
|
33
|
+
msg: 'luigi.init',
|
|
34
|
+
emulated: true,
|
|
35
|
+
internal: {
|
|
36
|
+
viewStackSize: 1
|
|
37
|
+
},
|
|
38
|
+
context: e.data.context
|
|
39
|
+
}, '*');
|
|
40
|
+
}
|
|
41
|
+
// vizualise retrieved event data
|
|
42
|
+
LuigiMockEngine.visualize(JSON.stringify(e.data));
|
|
43
|
+
// Check and run mocked callback if it exists
|
|
44
|
+
const mockListener = window.luigiMockEnvironment.mockListeners[e.data.msg];
|
|
45
|
+
if (mockListener) {
|
|
46
|
+
mockListener(e);
|
|
47
|
+
}
|
|
51
48
|
}
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
mockListeners: {
|
|
55
|
-
'luigi.navigation.pathExists': (event) => {
|
|
56
|
-
const mockData = window.sessionStorage.getItem('luigiMockData');
|
|
57
|
-
let mockDataParsed = mockData ? JSON.parse(mockData) : undefined;
|
|
58
|
-
const inputPath = event.data.data.link;
|
|
59
|
-
const pathExists = mockDataParsed && mockDataParsed.pathExists && mockDataParsed.pathExists[inputPath];
|
|
60
|
-
const response = {
|
|
61
|
-
msg: 'luigi.navigation.pathExists.answer',
|
|
62
|
-
data: {
|
|
63
|
-
correlationId: event.data.data.id,
|
|
64
|
-
pathExists: pathExists ? pathExists : false
|
|
65
|
-
},
|
|
66
|
-
emulated: true
|
|
67
|
-
};
|
|
68
|
-
window.postMessage(response, '*');
|
|
69
|
-
},
|
|
70
|
-
//ux
|
|
71
|
-
'luigi.ux.confirmationModal.show': (event) => {
|
|
72
|
-
const response = {
|
|
73
|
-
msg: 'luigi.ux.confirmationModal.hide',
|
|
74
|
-
data: event.data,
|
|
75
|
-
emulated: true
|
|
76
|
-
};
|
|
77
|
-
window.postMessage(response, '*');
|
|
78
|
-
},
|
|
79
|
-
'luigi.ux.alert.show': (event) => {
|
|
80
|
-
const response = {
|
|
81
|
-
msg: 'luigi.ux.alert.hide',
|
|
82
|
-
data: event.data,
|
|
83
|
-
emulated: true
|
|
84
|
-
};
|
|
85
|
-
window.postMessage(response, '*');
|
|
86
49
|
},
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
50
|
+
mockListeners: {
|
|
51
|
+
'luigi.navigation.pathExists': (event) => {
|
|
52
|
+
const mockData = window.sessionStorage.getItem('luigiMockData');
|
|
53
|
+
let mockDataParsed = mockData ? JSON.parse(mockData) : undefined;
|
|
54
|
+
const inputPath = event.data.data.link;
|
|
55
|
+
const pathExists = mockDataParsed && mockDataParsed.pathExists && mockDataParsed.pathExists[inputPath];
|
|
56
|
+
const response = {
|
|
57
|
+
msg: 'luigi.navigation.pathExists.answer',
|
|
58
|
+
data: {
|
|
59
|
+
correlationId: event.data.data.id,
|
|
60
|
+
pathExists: pathExists ? pathExists : false
|
|
61
|
+
},
|
|
62
|
+
emulated: true
|
|
63
|
+
};
|
|
64
|
+
window.postMessage(response, '*');
|
|
65
|
+
},
|
|
66
|
+
//ux
|
|
67
|
+
'luigi.ux.confirmationModal.show': (event) => {
|
|
68
|
+
const response = {
|
|
69
|
+
msg: 'luigi.ux.confirmationModal.hide',
|
|
70
|
+
data: event.data,
|
|
71
|
+
emulated: true
|
|
72
|
+
};
|
|
73
|
+
window.postMessage(response, '*');
|
|
74
|
+
},
|
|
75
|
+
'luigi.ux.alert.show': (event) => {
|
|
76
|
+
const response = {
|
|
77
|
+
msg: 'luigi.ux.alert.hide',
|
|
78
|
+
data: event.data,
|
|
79
|
+
emulated: true
|
|
80
|
+
};
|
|
81
|
+
window.postMessage(response, '*');
|
|
82
|
+
},
|
|
83
|
+
'luigi.ux.set-current-locale': (event) => {
|
|
84
|
+
const response = {
|
|
85
|
+
msg: 'luigi.current-locale-changed',
|
|
86
|
+
currentLocale: event.data.data.currentLocale,
|
|
87
|
+
emulated: true
|
|
88
|
+
};
|
|
89
|
+
window.postMessage(response, '*');
|
|
90
|
+
},
|
|
91
|
+
// linkManager
|
|
92
|
+
'luigi.navigation.open': (event) => {
|
|
93
|
+
const response = {
|
|
94
|
+
msg: 'luigi.navigate.ok',
|
|
95
|
+
data: event.data,
|
|
96
|
+
emulated: true
|
|
97
|
+
};
|
|
98
|
+
window.postMessage(response, '*');
|
|
99
|
+
},
|
|
100
|
+
'luigi.navigation.splitview.close': (event) => {
|
|
101
|
+
const response = {
|
|
102
|
+
msg: 'luigi.navigate.ok',
|
|
103
|
+
data: event.data,
|
|
104
|
+
emulated: true
|
|
105
|
+
};
|
|
106
|
+
window.postMessage(response, '*');
|
|
107
|
+
},
|
|
108
|
+
'luigi.navigation.splitview.collapse': (event) => {
|
|
109
|
+
const response = {
|
|
110
|
+
msg: 'luigi.navigate.ok',
|
|
111
|
+
data: event.data,
|
|
112
|
+
emulated: true
|
|
113
|
+
};
|
|
114
|
+
window.postMessage(response, '*');
|
|
115
|
+
},
|
|
116
|
+
'luigi.navigation.splitview.expand': (event) => {
|
|
117
|
+
const response = {
|
|
118
|
+
msg: 'luigi.navigate.ok',
|
|
119
|
+
data: event.data,
|
|
120
|
+
emulated: true
|
|
121
|
+
};
|
|
122
|
+
window.postMessage(response, '*');
|
|
123
|
+
},
|
|
124
|
+
// storage
|
|
125
|
+
storage: () => { }
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
// Listen to the global 'message' event of the window object
|
|
129
|
+
window.addEventListener('message', window.luigiMockEnvironment.msgListener);
|
|
130
|
+
}
|
|
135
131
|
};
|
|
136
132
|
}
|
|
137
133
|
/*
|
package/luigi-mock-util.d.ts
CHANGED