diff --git a/tests/end2end/playwright/form-filter.spec.js b/tests/end2end/playwright/form-filter.spec.js index c2b0813fd..b24475fd2 100644 --- a/tests/end2end/playwright/form-filter.spec.js +++ b/tests/end2end/playwright/form-filter.spec.js @@ -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 }) => { @@ -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 ) '); @@ -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(); @@ -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'); - }); + }); }); - diff --git a/tests/end2end/playwright/globals.js b/tests/end2end/playwright/globals.js index abc542324..51d6a5fd9 100644 --- a/tests/end2end/playwright/globals.js +++ b/tests/end2end/playwright/globals.js @@ -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} + */ +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)); +} diff --git a/tests/end2end/playwright/timemanage.spec.js b/tests/end2end/playwright/timemanage.spec.js index 3258bdb72..6a113e44a 100644 --- a/tests/end2end/playwright/timemanage.spec.js +++ b/tests/end2end/playwright/timemanage.spec.js @@ -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', () => { @@ -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 = [ @@ -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);