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