From 1bf28b1fe911f70950056020c192e3ec065eed86 Mon Sep 17 00:00:00 2001 From: Etienne Trimaille Date: Mon, 30 Sep 2024 12:36:54 +0200 Subject: [PATCH 1/4] Tests - Improve Playwright helper to load a project with error --- .gitignore | 1 + tests/docker-conf/phpfpm/lizmapConfig.ini.php | 2 +- tests/end2end/playwright/globals.js | 26 +++++++++++++++---- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index bce9fc7231..6d630bf21d 100644 --- a/.gitignore +++ b/.gitignore @@ -115,6 +115,7 @@ tests/qgis-projects/webdav/test/* !tests/qgis-projects/webdav/test/test_upload.txt !tests/qgis-projects/ProJets 1982*! tests/qgis-projects/tests/media +tests/qgis-projects/tests/*_attachments.zip tests/qgis-server-plugins/* !tests/qgis-server-plugins/upgrade_projects.py tests/lizmap-qgis-plugin.master.zip diff --git a/tests/docker-conf/phpfpm/lizmapConfig.ini.php b/tests/docker-conf/phpfpm/lizmapConfig.ini.php index 0282363576..01b7e3d602 100644 --- a/tests/docker-conf/phpfpm/lizmapConfig.ini.php +++ b/tests/docker-conf/phpfpm/lizmapConfig.ini.php @@ -56,7 +56,7 @@ [repository:testsrepository] label="Tests repository" path="/srv/lzm/tests/qgis-projects/tests/" -allowUserDefinedThemes=0 +allowUserDefinedThemes=1 accessControlAllowOrigin="http://othersite.local:8130" [repository:badrepository] diff --git a/tests/end2end/playwright/globals.js b/tests/end2end/playwright/globals.js index cb43a50e25..139e16eea5 100644 --- a/tests/end2end/playwright/globals.js +++ b/tests/end2end/playwright/globals.js @@ -9,17 +9,31 @@ async function NoErrors(page) { await expect(page.getByText('An error occurred while loading this map. Some necessary resources may temporari')).toHaveCount(0); } -async function CatchErrors(page) { +/** + * CatchErrors function + * Some checks when the map is on error + * @param page The page object + * @param int layersInTreeView The number of layers to find in the treeview. + */ +async function CatchErrors(page, layersInTreeView = 0) { // Error await expect(page.locator('p.error-msg')).toHaveCount(1); - await expect(page.locator('#switcher lizmap-treeview ul li')).toHaveCount(0); + await expect(page.locator('#switcher lizmap-treeview ul li')).toHaveCount(layersInTreeView); // Error message displayed await expect(page.getByText('An error occurred while loading this map. Some necessary resources may temporari')).toBeVisible(); // Go back home link await expect(page.getByRole('link', { name: 'Go back to the home page.' })).toHaveCount(1); } -export async function gotoMap(url, page, check = true) { +/** + * gotoMap function + * Helper to load a map and do some basic checks + * @param string url The URL of the map to load + * @param page The page object + * @param boolean mapMustLoad If the loading of the map must be successful or not. Some error might be triggered when loading the map, on purpose. + * @param int layersInTreeView The number of layers to find in the treeview if the map is on error. + */ +export async function gotoMap(url, page, mapMustLoad = true, layersInTreeView = 0) { // TODO keep this function synchronized with the Cypress equivalent // Wait for WMS GetCapabilities promise @@ -28,7 +42,7 @@ export async function gotoMap(url, page, check = true) { // Wait for WMS GetCapabilities await getCapabilitiesWMSPromise; - if (check) { + if (mapMustLoad) { // Wait for WMS GetLegendGraphic promise const getLegendGraphicPromise = page.waitForRequest(request => request.method() === 'POST' && request.postData() != null && request.postData()?.includes('GetLegendGraphic') === true); // Normal check about the map @@ -39,8 +53,10 @@ export async function gotoMap(url, page, check = true) { // Wait to be sure the map is ready await page.waitForTimeout(1000) } else { + // Wait to be sure the map is ready + await page.waitForTimeout(1000) // Error - await CatchErrors(page); + await CatchErrors(page, layersInTreeView); } } From 69a07e8d1fcc000d506f54adaa007c6866869a56 Mon Sep 17 00:00:00 2001 From: rldhont Date: Fri, 18 Oct 2024 17:51:51 +0200 Subject: [PATCH 2/4] Tests e2e playwright: Goto map cannot wait for GetLegendGraphics request --- tests/end2end/playwright/globals.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/end2end/playwright/globals.js b/tests/end2end/playwright/globals.js index 139e16eea5..a799d8a7fd 100644 --- a/tests/end2end/playwright/globals.js +++ b/tests/end2end/playwright/globals.js @@ -1,10 +1,12 @@ // @ts-check const { expect } = require('@playwright/test'); -async function NoErrors(page) { +async function NoErrors(page, checkLayerTreeView = true) { // No error await expect(page.locator('p.error-msg')).toHaveCount(0); - await expect(page.locator('#switcher lizmap-treeview ul li')).not.toHaveCount(0); + if (checkLayerTreeView) { + await expect(page.locator('#switcher lizmap-treeview ul li')).not.toHaveCount(0); + } // Check no error message displayed await expect(page.getByText('An error occurred while loading this map. Some necessary resources may temporari')).toHaveCount(0); } @@ -32,8 +34,9 @@ async function CatchErrors(page, layersInTreeView = 0) { * @param page The page object * @param boolean mapMustLoad If the loading of the map must be successful or not. Some error might be triggered when loading the map, on purpose. * @param int layersInTreeView The number of layers to find in the treeview if the map is on error. + * @param boolean waitForGetLegendGraphics */ -export async function gotoMap(url, page, mapMustLoad = true, layersInTreeView = 0) { +export async function gotoMap(url, page, mapMustLoad = true, layersInTreeView = 0, waitForGetLegendGraphics = true) { // TODO keep this function synchronized with the Cypress equivalent // Wait for WMS GetCapabilities promise @@ -43,13 +46,15 @@ export async function gotoMap(url, page, mapMustLoad = true, layersInTreeView = // Wait for WMS GetCapabilities await getCapabilitiesWMSPromise; if (mapMustLoad) { - // Wait for WMS GetLegendGraphic promise - const getLegendGraphicPromise = page.waitForRequest(request => request.method() === 'POST' && request.postData() != null && request.postData()?.includes('GetLegendGraphic') === true); - // Normal check about the map - // Wait for WMS GetLegendGraphic - await getLegendGraphicPromise; + if (waitForGetLegendGraphics) { + // Wait for WMS GetLegendGraphic promise + const getLegendGraphicPromise = page.waitForRequest(request => request.method() === 'POST' && request.postData() != null && request.postData()?.includes('GetLegendGraphic') === true); + // Normal check about the map + // Wait for WMS GetLegendGraphic + await getLegendGraphicPromise; + } // No error - await NoErrors(page); + await NoErrors(page, waitForGetLegendGraphics); // Wait to be sure the map is ready await page.waitForTimeout(1000) } else { From 3bc96d122eccb52aa148ed6053230d6f27441d4b Mon Sep 17 00:00:00 2001 From: rldhont Date: Thu, 17 Oct 2024 17:59:22 +0200 Subject: [PATCH 3/4] Tests e2e Playwright: Added Location seach Testing that search is well activated. --- .../playwright/location_search.spec.js | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 tests/end2end/playwright/location_search.spec.js diff --git a/tests/end2end/playwright/location_search.spec.js b/tests/end2end/playwright/location_search.spec.js new file mode 100644 index 0000000000..4614401dac --- /dev/null +++ b/tests/end2end/playwright/location_search.spec.js @@ -0,0 +1,106 @@ +// @ts-check +import { test, expect } from '@playwright/test'; +import { gotoMap } from './globals'; + +test.describe('Location search', () => { + + test('Default', async ({ page }) => { + const url = '/index.php/view/map?repository=testsrepository&project=location_search'; + await gotoMap(url, page, true, 0, false); + + await expect(page.getByPlaceholder('Search')).toHaveCount(1); + + await page.getByPlaceholder('Search').click(); + await page.getByPlaceholder('Search').fill('arceaux'); + + let ignPromise = page.waitForRequest(/data.geopf.fr/); + + await page.getByPlaceholder('Search').press('Enter'); + await ignPromise; + + await expect(page.getByText('IGN', { exact: true })).toHaveCount(1); + await expect(page.getByText('Map data', { exact: true })).toHaveCount(1); + + await page.getByPlaceholder('Search').click(); + await page.getByPlaceholder('Search').fill('mosson'); + + let searchPromise = page.waitForRequest(/searchFts/); + await page.getByPlaceholder('Search').press('Enter'); + await searchPromise; + + await expect(page.getByText('IGN', { exact: true })).toHaveCount(1); + await expect(page.getByText('Map data', { exact: true })).toHaveCount(0); + await expect(page.getByText('Quartier', { exact: true })).toHaveCount(1); + }); + + test('Only IGN', async ({ page }) => { + await page.route('**/service/getProjectConfig*', async route => { + const response = await route.fetch(); + const json = await response.json(); + json.options['searches'] = [ + { + "type": "externalSearch", + "service": "ign" + } + ]; + await route.fulfill({ response, json }); + }); + + const url = '/index.php/view/map?repository=testsrepository&project=location_search'; + await gotoMap(url, page, true, 0, false); + await expect(page.getByPlaceholder('Search')).toHaveCount(1); + + await page.getByPlaceholder('Search').click(); + await page.getByPlaceholder('Search').fill('arceaux'); + + let ignPromise = page.waitForRequest(/data.geopf.fr/); + + await page.getByPlaceholder('Search').press('Enter'); + await ignPromise; + + await expect(page.getByText('IGN', { exact: true })).toHaveCount(1); + await expect(page.getByText('Map data', { exact: true })).toHaveCount(0); + }); + + test('Only Fts', async ({ page }) => { + await page.route('**/service/getProjectConfig*', async route => { + const response = await route.fetch(); + const json = await response.json(); + json.options['searches'] = [ + { + "type": "Fts", + "service": "lizmapFts", + "url": "/index.php/lizmap/searchFts/get" + } + ]; + await route.fulfill({ response, json }); + }); + + const url = '/index.php/view/map?repository=testsrepository&project=location_search'; + await gotoMap(url, page, true, 0, false); + + await expect(page.getByPlaceholder('Search')).toHaveCount(1); + + await page.getByPlaceholder('Search').click(); + await page.getByPlaceholder('Search').fill('arceaux'); + + let searchPromise = page.waitForRequest(/searchFts/); + + await page.getByPlaceholder('Search').press('Enter'); + await searchPromise; + + await expect(page.getByText('IGN', { exact: true })).toHaveCount(0); + await expect(page.getByText('Map data', { exact: true })).toHaveCount(1); + + await page.getByPlaceholder('Search').click(); + await page.getByPlaceholder('Search').fill('mosson'); + + searchPromise = page.waitForRequest(/searchFts/); + await page.getByPlaceholder('Search').press('Enter'); + await searchPromise; + + await expect(page.getByText('Map data', { exact: true })).toHaveCount(0); + await expect(page.getByText('Quartier', { exact: true })).toHaveCount(1); + }); + +}); From 259ee8936ed3641b765e5b9201ab316fd66b1543 Mon Sep 17 00:00:00 2001 From: rldhont Date: Wed, 23 Oct 2024 09:26:55 +0200 Subject: [PATCH 4/4] Partially revert 1bf28b1fe911f70950056020c192e3ec065eed86 - Disable user JavaScript for tests repository --- tests/docker-conf/phpfpm/lizmapConfig.ini.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/docker-conf/phpfpm/lizmapConfig.ini.php b/tests/docker-conf/phpfpm/lizmapConfig.ini.php index 01b7e3d602..0282363576 100644 --- a/tests/docker-conf/phpfpm/lizmapConfig.ini.php +++ b/tests/docker-conf/phpfpm/lizmapConfig.ini.php @@ -56,7 +56,7 @@ [repository:testsrepository] label="Tests repository" path="/srv/lzm/tests/qgis-projects/tests/" -allowUserDefinedThemes=1 +allowUserDefinedThemes=0 accessControlAllowOrigin="http://othersite.local:8130" [repository:badrepository]