diff --git a/tests/end2end/playwright/globals.js b/tests/end2end/playwright/globals.js index 2694f1e8c0..80d9a61048 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 { 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); + }); + +});