@luigi-project/testing-utilities 2.14.2-dev.202407300027 → 2.14.2-dev.20240810030
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 +44 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -251,6 +251,50 @@ describe('Another test using puppeteer ->', () => {
|
|
|
251
251
|
});
|
|
252
252
|
```
|
|
253
253
|
|
|
254
|
+
### Example how to use the library with Playwright
|
|
255
|
+
|
|
256
|
+
```javascript
|
|
257
|
+
import { test, expect } from '@playwright/test'; // <-- target e2e testing library
|
|
258
|
+
import { LuigiMockUtil } from '@luigi-project/testing-utilities';
|
|
259
|
+
|
|
260
|
+
let luigiMockUtil: LuigiMockUtil;
|
|
261
|
+
|
|
262
|
+
test.beforeEach(async ({ page }) => {
|
|
263
|
+
luigiMockUtil = new LuigiMockUtil(page);
|
|
264
|
+
|
|
265
|
+
await page.goto('http://localhost:4200');
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
test.afterEach(async ({ page }) => {
|
|
269
|
+
await page?.close();
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
test('should mock path exists', async ({ page }) => {
|
|
273
|
+
// Be sure '.pathExists' element is present
|
|
274
|
+
await page.locator('.pathExists').click().then(async () => {
|
|
275
|
+
await luigiMockUtil.mockPathExists('/test', false);
|
|
276
|
+
// Wait until session storage item is set
|
|
277
|
+
await new Promise(resolve => setTimeout(resolve, 500));
|
|
278
|
+
|
|
279
|
+
const storage = await page.evaluate(() => JSON.stringify(window.sessionStorage));
|
|
280
|
+
const result = await luigiMockUtil.getCleanSessionStorageData(storage);
|
|
281
|
+
|
|
282
|
+
await expect(result).toContain(luigiMockUtil.getMockedPathExistsOutput('/test', false));
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
test('should mock context update', async ({ page }) => {
|
|
287
|
+
const visualizationContainerId = luigiMockUtil.getVisualizationContainerId();
|
|
288
|
+
const context = {ctxKey: 'ctxValue'};
|
|
289
|
+
|
|
290
|
+
await luigiMockUtil.mockContext(context);
|
|
291
|
+
|
|
292
|
+
const container = page.locator(`#${visualizationContainerId} div:nth-child(1)`);
|
|
293
|
+
|
|
294
|
+
await expect(container).toHaveText(luigiMockUtil.getMockedContextOutput(context));
|
|
295
|
+
});
|
|
296
|
+
```
|
|
297
|
+
|
|
254
298
|
#### Functions provided
|
|
255
299
|
- **mockContext**: Mocks the context by sending Luigi context messages with the desired mocked context as parameter.
|
|
256
300
|
- **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()`.
|