@luigi-project/testing-utilities 2.14.2-dev.202407220726 → 2.14.2-dev.202407240028
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/README.md +27 -37
- package/luigi-mock-engine.js +5 -6
- package/luigi-mock-util.d.ts +8 -26
- package/luigi-mock-util.js +94 -126
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -79,19 +79,20 @@ describe('Another test using cypress', () => {
|
|
|
79
79
|
cy.get('.pathExists').click().then(() => {
|
|
80
80
|
luigiMockUtil.mockPathExists('/test', false);
|
|
81
81
|
});
|
|
82
|
-
cy.getAllSessionStorage().then((
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
cy.getAllSessionStorage().then((result: any) => {
|
|
83
|
+
expect(result).to.deep.equal({
|
|
84
|
+
"http://localhost:4200": {
|
|
85
|
+
luigiMockData: '{"pathExists":{"/test":false}}'
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
})
|
|
87
89
|
});
|
|
88
90
|
|
|
89
91
|
it('should mock context update', () => {
|
|
90
|
-
const visualizationContainerId = luigiMockUtil.getVisualizationContainerId();
|
|
91
92
|
const context = {ctxKey: 'ctxValue'};
|
|
92
93
|
|
|
93
94
|
luigiMockUtil.mockContext(context);
|
|
94
|
-
cy.get('#'
|
|
95
|
+
cy.get('#luigi-debug-vis-cnt').contains('{"msg":"luigi.get-context","context":{"ctxKey":"ctxValue"}}');
|
|
95
96
|
});
|
|
96
97
|
});
|
|
97
98
|
```
|
|
@@ -112,25 +113,22 @@ describe('Another test using nightwatch', function () {
|
|
|
112
113
|
await browser.expect.element('.pathExists').to.be.present;
|
|
113
114
|
await browser.element('.pathExists').click().then(() => {
|
|
114
115
|
luigiMockUtil.mockPathExists('/test', false);
|
|
115
|
-
browser.execute(() => window.sessionStorage, [], function (
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
expect(result).to.contains(luigiMockUtil.getMockedPathExistsOutput('/test', false));
|
|
116
|
+
browser.execute(() => window.sessionStorage.getItem('luigiMockData'), [], function (result) {
|
|
117
|
+
expect(result.value).to.contains('{"pathExists":{"/test":false}}');
|
|
119
118
|
});
|
|
120
119
|
});
|
|
121
120
|
});
|
|
122
121
|
|
|
123
122
|
it('should mock context update', async () => {
|
|
124
|
-
const visualizationContainerId = luigiMockUtil.getVisualizationContainerId();
|
|
125
123
|
const context = {ctxKey: 'ctxValue'};
|
|
126
124
|
|
|
127
125
|
await luigiMockUtil.mockContext(context);
|
|
128
|
-
// Wait until
|
|
129
|
-
await browser.waitForElementPresent('#'
|
|
130
|
-
const wrapper = browser.expect.element('#'
|
|
126
|
+
// Wait until '#luigi-debug-vis-cnt' element is present
|
|
127
|
+
await browser.waitForElementPresent('#luigi-debug-vis-cnt', undefined, undefined, false, () => {
|
|
128
|
+
const wrapper = browser.expect.element('#luigi-debug-vis-cnt');
|
|
131
129
|
|
|
132
130
|
wrapper.to.be.present;
|
|
133
|
-
wrapper.text.to.contains(
|
|
131
|
+
wrapper.text.to.contains('{"msg":"luigi.get-context","context":{"ctxKey":"ctxValue"}}');
|
|
134
132
|
});
|
|
135
133
|
});
|
|
136
134
|
|
|
@@ -160,23 +158,21 @@ describe('Another test using webdriverio', () => {
|
|
|
160
158
|
// Wait until session storage item is set
|
|
161
159
|
await browser.setTimeout(defaultTimeout);
|
|
162
160
|
|
|
163
|
-
const
|
|
164
|
-
const result = await luigiMockUtil.getCleanSessionStorageData(storage);
|
|
161
|
+
const result = await browser.execute(() => window.sessionStorage.getItem('luigiMockData'));
|
|
165
162
|
|
|
166
|
-
await expect(result).
|
|
163
|
+
await expect(result).toEqual('{"pathExists":{"/test":false}}');
|
|
167
164
|
});
|
|
168
165
|
|
|
169
166
|
it('should mock context update', async () => {
|
|
170
167
|
luigiMockUtil = new LuigiMockUtil(browser);
|
|
171
168
|
|
|
172
|
-
const visualizationContainerId = luigiMockUtil.getVisualizationContainerId();
|
|
173
169
|
const context = {ctxKey: 'ctxValue'};
|
|
174
170
|
|
|
175
171
|
await browser.url(baseUrl);
|
|
176
172
|
await luigiMockUtil.mockContext(context);
|
|
177
|
-
// Wait until
|
|
173
|
+
// Wait until '#luigi-debug-vis-cnt' element is present
|
|
178
174
|
await browser.setTimeout(defaultTimeout);
|
|
179
|
-
await expect($('#'
|
|
175
|
+
await expect($('#luigi-debug-vis-cnt')).toHaveHTML(expect.stringContaining('{"msg":"luigi.get-context","context":{"ctxKey":"ctxValue"}}'));
|
|
180
176
|
});
|
|
181
177
|
});
|
|
182
178
|
```
|
|
@@ -225,27 +221,25 @@ describe('Another test using puppeteer ->', () => {
|
|
|
225
221
|
// Wait until session storage item is set
|
|
226
222
|
await new Promise(resolve => setTimeout(resolve, 500));
|
|
227
223
|
|
|
228
|
-
const
|
|
229
|
-
const result = await luigiMockUtil.getCleanSessionStorageData(storage);
|
|
224
|
+
const result = await page.evaluate(() => window.sessionStorage.getItem('luigiMockData'));
|
|
230
225
|
|
|
231
|
-
await expect(result).toContain(
|
|
226
|
+
await expect(result).toContain('{"pathExists":{"/test":false}}');
|
|
232
227
|
});
|
|
233
228
|
});
|
|
234
229
|
});
|
|
235
230
|
|
|
236
231
|
it('should mock context update', async () => {
|
|
237
|
-
const visualizationContainerId = luigiMockUtil.getVisualizationContainerId();
|
|
238
232
|
const context = {ctxKey: 'ctxValue'};
|
|
239
233
|
|
|
240
234
|
await luigiMockUtil.mockContext(context);
|
|
241
|
-
// Wait until
|
|
242
|
-
await page.waitForSelector('#'
|
|
235
|
+
// Wait until '#luigi-debug-vis-cnt' element is present
|
|
236
|
+
await page.waitForSelector('#luigi-debug-vis-cnt').then(async () => {
|
|
243
237
|
const result = await page
|
|
244
|
-
.locator(
|
|
238
|
+
.locator('#luigi-debug-vis-cnt div:nth-child(1)')
|
|
245
239
|
.map(div => div.innerText)
|
|
246
240
|
.wait();
|
|
247
241
|
|
|
248
|
-
expect(result).toContain(
|
|
242
|
+
expect(result).toContain('{"msg":"luigi.get-context","context":{"ctxKey":"ctxValue"}}');
|
|
249
243
|
});
|
|
250
244
|
});
|
|
251
245
|
});
|
|
@@ -253,11 +247,7 @@ describe('Another test using puppeteer ->', () => {
|
|
|
253
247
|
|
|
254
248
|
#### Functions provided
|
|
255
249
|
- **mockContext**: Mocks the context by sending Luigi context messages with the desired mocked context as parameter.
|
|
256
|
-
- **mockPathExists**: This method serves as a mock for the Luigi Client `pathExists()` function. It is used in e2e tests when component being tested utilizes a call to `LuigiClient.linkManager().pathExists()
|
|
250
|
+
- **mockPathExists**: This method serves as a mock for the Luigi Client `pathExists()` function. It is used in e2e tests when component being tested utilizes a call to `LuigiClient.linkManager().pathExists()`
|
|
257
251
|
- **modalOpenedWithTitle**: Checks on the printed DOM Luigi message responses for a modal with given title being opened. In such a case, a message would be printed containing a `modal.title`. Returns `false` if such element was not found.
|
|
258
|
-
- **
|
|
259
|
-
- **
|
|
260
|
-
- **getCleanSessionStorageData**: Returns parsed session storage data used for testing.
|
|
261
|
-
- **getVisualizationContainerId**: Returns ID of Luigi visualization container added in the DOM for testing.
|
|
262
|
-
- **getMSG**: Returns list of messages, representing message elements added in the DOM for testing.
|
|
263
|
-
- **parseLuigiMockedMessages**: Parses the elements added by LuigiMockModule into the DOM and assigns them to the local messages variable.
|
|
252
|
+
- **getMSG**: Return list of messages, representing message elements added in the DOM for testing.
|
|
253
|
+
- **parseLuigiMockedMessages**: Parses the elements added by LuigiMockModule into the DOM and assigns them to the local messages variable
|
package/luigi-mock-engine.js
CHANGED
|
@@ -135,18 +135,17 @@ export class LuigiMockEngine {
|
|
|
135
135
|
* which holds data that is useful for e2e testing.
|
|
136
136
|
*/
|
|
137
137
|
static visualize(data) {
|
|
138
|
-
|
|
139
|
-
const dataWrapper = document.createElement('div');
|
|
140
|
-
let luigiVisualizationContainer = document.querySelector('#' + visualizationContainerId);
|
|
138
|
+
let luigiVisualizationContainer = document.querySelector('#luigi-debug-vis-cnt');
|
|
141
139
|
// Construct element structure if not already constructed
|
|
142
140
|
if (!luigiVisualizationContainer) {
|
|
143
141
|
luigiVisualizationContainer = document.createElement('div');
|
|
144
|
-
luigiVisualizationContainer.setAttribute('id',
|
|
142
|
+
luigiVisualizationContainer.setAttribute('id', 'luigi-debug-vis-cnt');
|
|
145
143
|
// Hide the added DOM element to avoid interferring/overlapping with other elements during testing.
|
|
146
144
|
luigiVisualizationContainer.setAttribute('style', 'display:none');
|
|
147
145
|
document.body.appendChild(luigiVisualizationContainer);
|
|
148
146
|
}
|
|
149
|
-
|
|
150
|
-
|
|
147
|
+
const line = document.createElement('div');
|
|
148
|
+
line.textContent = data;
|
|
149
|
+
luigiVisualizationContainer.appendChild(line);
|
|
151
150
|
}
|
|
152
151
|
}
|
package/luigi-mock-util.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
export declare class LuigiMockUtil {
|
|
2
|
-
private sessionStorageItemName;
|
|
3
|
-
private visualizationContainerId;
|
|
4
2
|
private messages;
|
|
5
3
|
private browser;
|
|
6
4
|
private win;
|
|
7
5
|
constructor(browser: any, win?: any);
|
|
6
|
+
/**
|
|
7
|
+
* Returns the global window object.
|
|
8
|
+
* @returns the glboal win object
|
|
9
|
+
*/
|
|
10
|
+
private getGlobalThis;
|
|
8
11
|
/**
|
|
9
12
|
* Parses the elements added by LuigiMockModule into the DOM and assigns them to the local this.messages variable
|
|
10
13
|
* @returns {Promise<void>} - A Promise that resolves when parsing is complete.
|
|
@@ -14,7 +17,7 @@ export declare class LuigiMockUtil {
|
|
|
14
17
|
* Mocks the context by sending luigi context messages with the desired mocked context as parameter.
|
|
15
18
|
* @param mockContext an object representing the context to be mocked
|
|
16
19
|
*/
|
|
17
|
-
mockContext(mockContext: Record<string, any>)
|
|
20
|
+
mockContext: (mockContext: Record<string, any>) => void;
|
|
18
21
|
/**
|
|
19
22
|
* This method serves as a mock for the luigi client pathExists() function.
|
|
20
23
|
* It is used in e2e tests when component being tested utilizes a call to `LuigiClient.linkManager().pathExists()`
|
|
@@ -31,7 +34,7 @@ export declare class LuigiMockUtil {
|
|
|
31
34
|
* await mockPathExists('pathToCheck', false);
|
|
32
35
|
*
|
|
33
36
|
*/
|
|
34
|
-
mockPathExists(path: string, exists: boolean)
|
|
37
|
+
mockPathExists: (path: string, exists: boolean) => void;
|
|
35
38
|
/**
|
|
36
39
|
* Checks on the printed DOM Luigi message responses for a modal with given title
|
|
37
40
|
* having been opened. In such a case a message would be printed containing a modal.title.
|
|
@@ -60,28 +63,7 @@ export declare class LuigiMockUtil {
|
|
|
60
63
|
*/
|
|
61
64
|
modalOpenedWithTitle(title: string): Promise<boolean>;
|
|
62
65
|
/**
|
|
63
|
-
*
|
|
64
|
-
*/
|
|
65
|
-
getMockedContextOutput(context: Record<string, any>): string;
|
|
66
|
-
/**
|
|
67
|
-
* Returns output of 'mockPathExists' method with given arguments.
|
|
68
|
-
*/
|
|
69
|
-
getMockedPathExistsOutput(path: string, exists: boolean): string;
|
|
70
|
-
/**
|
|
71
|
-
* Returns parsed session storage data used for testing.
|
|
72
|
-
*/
|
|
73
|
-
getCleanSessionStorageData(data: any): string;
|
|
74
|
-
/**
|
|
75
|
-
* Returns ID of Luigi visualization container added in the DOM for testing.
|
|
76
|
-
*/
|
|
77
|
-
getVisualizationContainerId(): string;
|
|
78
|
-
/**
|
|
79
|
-
* Returns list of messages, representing message elements added in the DOM for testing.
|
|
66
|
+
* Return list of messages, representing message elements added in the DOM for testing.
|
|
80
67
|
*/
|
|
81
68
|
getMSG(): any[];
|
|
82
|
-
/**
|
|
83
|
-
* Returns the global window object.
|
|
84
|
-
* @returns the global win object
|
|
85
|
-
*/
|
|
86
|
-
private getGlobalThis;
|
|
87
69
|
}
|
package/luigi-mock-util.js
CHANGED
|
@@ -1,11 +1,101 @@
|
|
|
1
1
|
export class LuigiMockUtil {
|
|
2
2
|
constructor(browser, win) {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Mocks the context by sending luigi context messages with the desired mocked context as parameter.
|
|
5
|
+
* @param mockContext an object representing the context to be mocked
|
|
6
|
+
*/
|
|
7
|
+
this.mockContext = (mockContext) => {
|
|
8
|
+
const window = this.getGlobalThis();
|
|
9
|
+
const postMessageToLuigi = (context) => {
|
|
10
|
+
window.postMessage({ msg: 'luigi.get-context', context }, '*');
|
|
11
|
+
return Object.assign(Object.assign({}, context), { windowMessage: 'isPosted' });
|
|
12
|
+
};
|
|
13
|
+
try {
|
|
14
|
+
switch (true) {
|
|
15
|
+
case 'evaluate' in this.browser:
|
|
16
|
+
this.browser.evaluate(postMessageToLuigi, mockContext);
|
|
17
|
+
break;
|
|
18
|
+
case 'execute' in this.browser:
|
|
19
|
+
this.browser.execute(postMessageToLuigi, mockContext);
|
|
20
|
+
break;
|
|
21
|
+
case 'executeScript' in this.browser:
|
|
22
|
+
this.browser.executeScript(postMessageToLuigi, mockContext);
|
|
23
|
+
break;
|
|
24
|
+
default:
|
|
25
|
+
this.browser(postMessageToLuigi.bind(this, mockContext));
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
console.debug('Failed to mock context: ', error);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* This method serves as a mock for the luigi client pathExists() function.
|
|
35
|
+
* It is used in e2e tests when component being tested utilizes a call to `LuigiClient.linkManager().pathExists()`
|
|
36
|
+
*
|
|
37
|
+
* @param path the path to check
|
|
38
|
+
* @param exists mocked boolean representing if path should exist or not
|
|
39
|
+
* @example For the following call in your angular component:
|
|
40
|
+
* `LuigiClient.linkManager().pathExists('pathToCheck')`
|
|
41
|
+
*
|
|
42
|
+
* // You need to call the following to mock pathExists() returning `true` for a given 'pathToCheck':
|
|
43
|
+
* await mockPathExists('pathToCheck', true);
|
|
44
|
+
*
|
|
45
|
+
* // You need to call the following to mock pathExists() returning `false` for a given 'pathToCheck':
|
|
46
|
+
* await mockPathExists('pathToCheck', false);
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
this.mockPathExists = (path, exists) => {
|
|
50
|
+
const window = this.getGlobalThis();
|
|
51
|
+
const mockContext = { path, exists };
|
|
52
|
+
/**
|
|
53
|
+
* Sets the path exists mock data in sessionStorage.
|
|
54
|
+
* @param {string} path - The path for which mock data is to be set.
|
|
55
|
+
* @param {boolean} exists - Boolean indicating whether the path exists.
|
|
56
|
+
* @returns {Object} - Object indicating session storage item.
|
|
57
|
+
*/
|
|
58
|
+
const setPathExistsMockData = (context) => {
|
|
59
|
+
window.sessionStorage.clear();
|
|
60
|
+
const pathExistsMockData = {
|
|
61
|
+
pathExists: {
|
|
62
|
+
[context['path']]: context['exists']
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
window.sessionStorage.setItem('luigiMockData', JSON.stringify(pathExistsMockData));
|
|
66
|
+
return Object.assign(Object.assign({}, pathExistsMockData), { sessionItem: 'isStored' });
|
|
67
|
+
};
|
|
68
|
+
try {
|
|
69
|
+
switch (true) {
|
|
70
|
+
case 'evaluate' in this.browser:
|
|
71
|
+
this.browser.evaluate(setPathExistsMockData, mockContext);
|
|
72
|
+
break;
|
|
73
|
+
case 'execute' in this.browser:
|
|
74
|
+
this.browser.execute(setPathExistsMockData, mockContext);
|
|
75
|
+
break;
|
|
76
|
+
case 'executeScript' in this.browser:
|
|
77
|
+
this.browser.executeScript(setPathExistsMockData, mockContext);
|
|
78
|
+
break;
|
|
79
|
+
default:
|
|
80
|
+
this.browser(setPathExistsMockData.bind(this, mockContext));
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
console.debug('Failed to mock path exists: ', error);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
5
88
|
this.messages = [];
|
|
6
89
|
this.browser = browser;
|
|
7
90
|
this.win = win;
|
|
8
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Returns the global window object.
|
|
94
|
+
* @returns the glboal win object
|
|
95
|
+
*/
|
|
96
|
+
getGlobalThis() {
|
|
97
|
+
return this.win || globalThis;
|
|
98
|
+
}
|
|
9
99
|
/**
|
|
10
100
|
* Parses the elements added by LuigiMockModule into the DOM and assigns them to the local this.messages variable
|
|
11
101
|
* @returns {Promise<void>} - A Promise that resolves when parsing is complete.
|
|
@@ -13,7 +103,7 @@ export class LuigiMockUtil {
|
|
|
13
103
|
async parseLuigiMockedMessages() {
|
|
14
104
|
const window = this.getGlobalThis();
|
|
15
105
|
const getTextNodeValues = () => {
|
|
16
|
-
const debugCtn = window.getElementById(
|
|
106
|
+
const debugCtn = window.getElementById('luigi-debug-vis-cnt');
|
|
17
107
|
return Array.from((debugCtn === null || debugCtn === void 0 ? void 0 : debugCtn.childNodes) || []).map((item) => item.textContent || '');
|
|
18
108
|
};
|
|
19
109
|
let textElements;
|
|
@@ -47,91 +137,6 @@ export class LuigiMockUtil {
|
|
|
47
137
|
console.debug('Failed to parse luigi mocked messages: ', error);
|
|
48
138
|
}
|
|
49
139
|
}
|
|
50
|
-
/**
|
|
51
|
-
* Mocks the context by sending luigi context messages with the desired mocked context as parameter.
|
|
52
|
-
* @param mockContext an object representing the context to be mocked
|
|
53
|
-
*/
|
|
54
|
-
mockContext(mockContext) {
|
|
55
|
-
const window = this.getGlobalThis();
|
|
56
|
-
const postMessageToLuigi = (context) => {
|
|
57
|
-
window.postMessage({ msg: 'luigi.get-context', context }, '*');
|
|
58
|
-
return Object.assign(Object.assign({}, context), { windowMessage: 'isPosted' });
|
|
59
|
-
};
|
|
60
|
-
try {
|
|
61
|
-
switch (true) {
|
|
62
|
-
case 'evaluate' in this.browser:
|
|
63
|
-
this.browser.evaluate(postMessageToLuigi, mockContext);
|
|
64
|
-
break;
|
|
65
|
-
case 'execute' in this.browser:
|
|
66
|
-
this.browser.execute(postMessageToLuigi, mockContext);
|
|
67
|
-
break;
|
|
68
|
-
case 'executeScript' in this.browser:
|
|
69
|
-
this.browser.executeScript(postMessageToLuigi, mockContext);
|
|
70
|
-
break;
|
|
71
|
-
default:
|
|
72
|
-
this.browser(postMessageToLuigi.bind(this, mockContext));
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
77
|
-
console.debug('Failed to mock context: ', error);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* This method serves as a mock for the luigi client pathExists() function.
|
|
82
|
-
* It is used in e2e tests when component being tested utilizes a call to `LuigiClient.linkManager().pathExists()`
|
|
83
|
-
*
|
|
84
|
-
* @param path the path to check
|
|
85
|
-
* @param exists mocked boolean representing if path should exist or not
|
|
86
|
-
* @example For the following call in your angular component:
|
|
87
|
-
* `LuigiClient.linkManager().pathExists('pathToCheck')`
|
|
88
|
-
*
|
|
89
|
-
* // You need to call the following to mock pathExists() returning `true` for a given 'pathToCheck':
|
|
90
|
-
* await mockPathExists('pathToCheck', true);
|
|
91
|
-
*
|
|
92
|
-
* // You need to call the following to mock pathExists() returning `false` for a given 'pathToCheck':
|
|
93
|
-
* await mockPathExists('pathToCheck', false);
|
|
94
|
-
*
|
|
95
|
-
*/
|
|
96
|
-
mockPathExists(path, exists) {
|
|
97
|
-
const window = this.getGlobalThis();
|
|
98
|
-
const mockContext = { path, exists };
|
|
99
|
-
/**
|
|
100
|
-
* Sets the path exists mock data in sessionStorage.
|
|
101
|
-
* @param {string} path - The path for which mock data is to be set.
|
|
102
|
-
* @param {boolean} exists - Boolean indicating whether the path exists.
|
|
103
|
-
* @returns {Object} - Object indicating session storage item.
|
|
104
|
-
*/
|
|
105
|
-
const setPathExistsMockData = (context) => {
|
|
106
|
-
window.sessionStorage.clear();
|
|
107
|
-
const pathExistsMockData = {
|
|
108
|
-
pathExists: {
|
|
109
|
-
[context['path']]: context['exists']
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
window.sessionStorage.setItem(this.sessionStorageItemName, JSON.stringify(pathExistsMockData));
|
|
113
|
-
return Object.assign(Object.assign({}, pathExistsMockData), { sessionItem: 'isStored' });
|
|
114
|
-
};
|
|
115
|
-
try {
|
|
116
|
-
switch (true) {
|
|
117
|
-
case 'evaluate' in this.browser:
|
|
118
|
-
this.browser.evaluate(setPathExistsMockData, mockContext);
|
|
119
|
-
break;
|
|
120
|
-
case 'execute' in this.browser:
|
|
121
|
-
this.browser.execute(setPathExistsMockData, mockContext);
|
|
122
|
-
break;
|
|
123
|
-
case 'executeScript' in this.browser:
|
|
124
|
-
this.browser.executeScript(setPathExistsMockData, mockContext);
|
|
125
|
-
break;
|
|
126
|
-
default:
|
|
127
|
-
this.browser(setPathExistsMockData.bind(this, mockContext));
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
catch (error) {
|
|
132
|
-
console.debug('Failed to mock path exists: ', error);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
140
|
/**
|
|
136
141
|
* Checks on the printed DOM Luigi message responses for a modal with given title
|
|
137
142
|
* having been opened. In such a case a message would be printed containing a modal.title.
|
|
@@ -181,46 +186,9 @@ export class LuigiMockUtil {
|
|
|
181
186
|
return false;
|
|
182
187
|
}
|
|
183
188
|
/**
|
|
184
|
-
*
|
|
185
|
-
*/
|
|
186
|
-
getMockedContextOutput(context) {
|
|
187
|
-
return `{"msg":"luigi.get-context","context":${JSON.stringify(context)}}`;
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Returns output of 'mockPathExists' method with given arguments.
|
|
191
|
-
*/
|
|
192
|
-
getMockedPathExistsOutput(path, exists) {
|
|
193
|
-
return JSON.stringify({ [this.sessionStorageItemName]: { pathExists: { [path]: exists } } }).slice(1, -1);
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Returns parsed session storage data used for testing.
|
|
197
|
-
*/
|
|
198
|
-
getCleanSessionStorageData(data) {
|
|
199
|
-
if (typeof data === 'string') {
|
|
200
|
-
data = JSON.parse(data);
|
|
201
|
-
}
|
|
202
|
-
return JSON.stringify(data)
|
|
203
|
-
.replace(/\\/g, '')
|
|
204
|
-
.replace(/"{/g, '{')
|
|
205
|
-
.replace(/}"/g, '}');
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Returns ID of Luigi visualization container added in the DOM for testing.
|
|
209
|
-
*/
|
|
210
|
-
getVisualizationContainerId() {
|
|
211
|
-
return this.visualizationContainerId;
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Returns list of messages, representing message elements added in the DOM for testing.
|
|
189
|
+
* Return list of messages, representing message elements added in the DOM for testing.
|
|
215
190
|
*/
|
|
216
191
|
getMSG() {
|
|
217
192
|
return this.messages;
|
|
218
193
|
}
|
|
219
|
-
/**
|
|
220
|
-
* Returns the global window object.
|
|
221
|
-
* @returns the global win object
|
|
222
|
-
*/
|
|
223
|
-
getGlobalThis() {
|
|
224
|
-
return this.win || globalThis;
|
|
225
|
-
}
|
|
226
194
|
}
|