Skip to content

Commit

Permalink
Tests e2e Playwright: Defined global getEchoRequestParams
Browse files Browse the repository at this point in the history
Method to re-send the request with additionnal echo param to retrieve the OGC Request parameters
  • Loading branch information
rldhont committed Jan 16, 2025
1 parent fe6dfdf commit 1a274b1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
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 additionnal echo param to retrieve the WMS Request 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 additionnal echo param to retrieve the WMS Request 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 additionnal echo param to retrieve the OGC Request parameters
* @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 additionnal echo param to retrieve the WMS Request parameters
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

0 comments on commit 1a274b1

Please sign in to comment.