Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests e2e Playwright: Defined global getEchoRequestParams #5223

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions tests/end2end/playwright/form-filter.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check
import { test, expect } from '@playwright/test';
import { gotoMap } from './globals';
import { gotoMap, getEchoRequestParams } from './globals';

test.describe('Form filter', () => {
test.beforeEach(async ({ page }) => {
Expand Down Expand Up @@ -30,10 +30,8 @@ test.describe('Form filter', () => {
await expect(page.locator(countFeature)).toHaveText('1');

let getMapRequest = await getMapPromise;
// Re-send the request with additionnal echo param to retrieve the WMS Request
let echoGetMap = await page.request.get(getMapRequest.url() + '&__echo__');
let originalUrl = decodeURIComponent(await echoGetMap.text());
let urlObj = new URLSearchParams((new URL(originalUrl).search));
// Re-send the request with additional echo param to retrieve the WMS Request search params
let urlObj = await getEchoRequestParams(page, getMapRequest.url())

expect(urlObj.get('filter')).toBe('form_filter_layer:"id" IN ( 2 ) ');

Expand All @@ -52,10 +50,8 @@ test.describe('Form filter', () => {

getMapRequest = await getMapPromise;

// Re-send the request with additionnal echo param to retrieve the WMS Request
echoGetMap = await page.request.get(getMapRequest.url() + '&__echo__');
originalUrl = decodeURIComponent(await echoGetMap.text());
urlObj = new URLSearchParams((new URL(originalUrl).search));
// Re-send the request with additional echo param to retrieve the WMS Request search params
urlObj = await getEchoRequestParams(page, getMapRequest.url())

expect(urlObj.get('filter')).toBeNull();

Expand Down Expand Up @@ -101,6 +97,5 @@ test.describe('Form filter', () => {
await page.locator('#liz-filter-field-textautocomplete').fill('mon');
await expect(page.locator('#ui-id-2 .ui-menu-item')).toHaveCount(1);
await expect(page.locator('#ui-id-2 .ui-menu-item div')).toHaveText('monuments');
});
});
});

18 changes: 18 additions & 0 deletions tests/end2end/playwright/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,21 @@ export async function reloadMap(page, check = true) {
await CatchErrors(page);
}
}

/**
* Re-send the request with additional "__echo__" param to retrieve the OGC Request search params
* @param {Page} page The page object
* @param {string} url The URL to re-send
*
* @return {Promise<URLSearchParams>}
*/
export async function getEchoRequestParams(page, url) {
// Re-send the request with additionnal echo param to retrieve the OGC Request
let echoResponse = await page.request.get(url + '&__echo__');
const originalUrl = decodeURIComponent(await echoResponse.text());
// When the request has not been logged by echo proxy
await expect(URL.canParse(originalUrl), originalUrl+' is not an URL!').toBeTruthy();
await expect(originalUrl).not.toContain('unfound')

return new URLSearchParams((new URL(originalUrl).search));
}
11 changes: 3 additions & 8 deletions tests/end2end/playwright/timemanage.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check
import { test, expect } from '@playwright/test';
import { gotoMap } from './globals';
import { gotoMap, getEchoRequestParams } from './globals';

test.describe('Time Manager', () => {

Expand Down Expand Up @@ -49,12 +49,8 @@ test.describe('Time Manager', () => {
await expect(urlMapRequest).toMatch(/FILTERTOKEN/);
await expect(urlMapRequest).toContain('FILTERTOKEN='+jsonFiltertokenResponse.token);

// Re-send the request with additionnal echo param to retrieve the WMS Request
let echoGetMap = await page.request.get(urlMapRequest + '&__echo__');
const originalUrl = decodeURIComponent(await echoGetMap.text());
// When the request has not been logged by echo proxy
await expect(URL.canParse(originalUrl), originalUrl+' is not an URL!').toBeTruthy();
await expect(originalUrl).not.toContain('unfound')
// Re-send the request with additional echo param to retrieve the WMS Request search params
const urlObj = await getEchoRequestParams(page, urlMapRequest)

// expected request params
const expectedParamValue = [
Expand All @@ -65,7 +61,6 @@ test.describe('Time Manager', () => {
{ 'param': 'filter', 'expectedvalue': 'time_manager_layer: ( ( "test_date" >= \'' + timeObj.start + '\' ) AND ( "test_date" <= \'' + timeObj.end + '\' ) ) ' },
];
// Check if WMS Request params are as expected
const urlObj = new URLSearchParams((new URL(originalUrl).search));
for (let obj of expectedParamValue) {
await expect(urlObj.has(obj.param), obj.param+' not in ['+Array.from(urlObj.keys()).join(', ')+']').toBeTruthy();
await expect(urlObj.get(obj.param), obj.param+'='+obj.expectedvalue+' not in ['+urlObj.toString().split('&').join(', ')+']').toBe(obj.expectedvalue);
Expand Down
Loading