Skip to content

Commit

Permalink
Tests - Use more expectParametersToContain and toHaveLength
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Feb 10, 2025
1 parent d456053 commit e2d0b15
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 52 deletions.
2 changes: 1 addition & 1 deletion tests/end2end/playwright/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export async function expectParametersToContain(title, parameters, expectedParam

await expect(
searchParams.size,
`Check "${title}" : Not enough parameters compared to expected!`
`Check "${title}" : Not enough parameters compared to expected\nGot ${Array.from(searchParams.keys()).join(', ')}!`
).toBeGreaterThanOrEqual(Object.keys(expectedParameters).length)

for (const param in expectedParameters) {
Expand Down
62 changes: 37 additions & 25 deletions tests/end2end/playwright/map-projects-switcher.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 { getAuthStorageStatePath, gotoMap } from './globals';
import {expectParametersToContain, getAuthStorageStatePath, gotoMap } from './globals';

test.describe('Map projects switcher', () => {

Expand Down Expand Up @@ -34,20 +34,22 @@ test.describe('Map projects switcher', () => {
await expect(page.locator('#_projectSwitcher')).toHaveText('Off');
})

test('Switcher form map to map', async ({ page }) => {
test('Switcher from map to map', async ({ page }) => {
await gotoMap('index.php/view/map?repository=testsrepository&project=base_layers', page);

// Check scale
await expect(page.locator('#overview-bar .ol-scale-text')).toHaveText('1 : ' + (144448).toLocaleString(locale));

// Go to an other map
// Go to another map
await page.locator('#button-projects').click();
await page.locator('li').filter({ hasText: 'base_layers_user_defined' }).getByRole('link').nth(1).click();

let checked_url = new URL(page.url());
await expect(checked_url.searchParams.get('repository')).toBe('testsrepository')
await expect(checked_url.searchParams.get('project')).toBe('base_layers_user_defined')
await expect(checked_url.hash).toHaveLength(0);
let expectedParameters = {
'REPOSITORY': 'testsrepository',
'PROJECT': 'base_layers_user_defined',
}
await expectParametersToContain('GetMap', page.url(), expectedParameters);
await expect(URL(page.url()).hash).toHaveLength(0);

// Zoom in
await page.locator('#navbar button.btn.zoom-in').click();
Expand All @@ -56,16 +58,19 @@ test.describe('Map projects switcher', () => {
// Wait for OL transition
await page.waitForTimeout(1000);

// Go to an other map
// Go to another map
await page.locator('#button-projects').click();
await page.locator('li').filter({ hasText: 'base_layers' }).getByRole('link').nth(1).click();

// Wait for OL transition
await page.waitForTimeout(1000);

checked_url = new URL(page.url());
await expect(checked_url.searchParams.get('repository')).toBe('testsrepository')
await expect(checked_url.searchParams.get('project')).toBe('base_layers')
expectedParameters = {
'REPOSITORY': 'testsrepository',
'PROJECT': 'base_layers',
}
await expectParametersToContain('GetMap', page.url(), expectedParameters);
let checked_url = new URL();
await expect(checked_url.hash).not.toHaveLength(0);
await expect(checked_url.hash).toMatch(/^#3\.838\d+,43\.5883\d+,3\.912\d+,43\.6241\d+/)

Expand All @@ -81,16 +86,19 @@ test.describe('Map projects switcher', () => {
// Check scale
await expect(page.locator('#overview-bar .ol-scale-text')).toHaveText('1 : ' + (72224).toLocaleString(locale));

// Go to an other map
// Go to another map
await page.locator('#button-projects').click();
await page.locator('li').filter({ hasText: 'attribute_table' }).getByRole('link').nth(1).click();

// Wait for OL transition
await page.waitForTimeout(1000);

checked_url = new URL(page.url());
await expect(checked_url.searchParams.get('repository')).toBe('testsrepository')
await expect(checked_url.searchParams.get('project')).toBe('attribute_table')
expectedParameters = {
'REPOSITORY': 'testsrepository',
'PROJECT': 'attribute_table',
}
await expectParametersToContain('GetMap', page.url(), expectedParameters);
checked_url = new URL();
await expect(checked_url.hash).not.toHaveLength(0);
await expect(checked_url.hash).toMatch(/^#3\.8007\d+,43\.570\d+,3\.950\d+,43\.6419\d+/)

Expand All @@ -110,17 +118,19 @@ test.describe('Map projects switcher', () => {
// Check scale
await expect(page.locator('#overview-bar .ol-scale-text')).toHaveText('1 : ' + (10000).toLocaleString(locale));

// Go to an other map
// Go to another map
await page.locator('#button-projects').click();
await page.locator('li').filter({ hasText: 'base_layers_user_defined' }).getByRole('link').nth(1).click();

// Wait for OL transition
await page.waitForTimeout(1000);

checked_url = new URL(page.url());
await expect(checked_url.searchParams.get('repository')).toBe('testsrepository')
await expect(checked_url.searchParams.get('project')).toBe('base_layers_user_defined')
await expect(checked_url.hash).toMatch(/^#3\.8611\d+,43\.599\d+,3\.8898\d+,43\.6132\d+/)
expectedParameters = {
'REPOSITORY': 'testsrepository',
'PROJECT': 'base_layers_user_defined',
}
await expectParametersToContain('GetMap', page.url(), expectedParameters);
await expect(URL(page.url()).hash).toMatch(/^#3\.8611\d+,43\.599\d+,3\.8898\d+,43\.6132\d+/)

// Wait for OL transition
await page.waitForTimeout(1000);
Expand All @@ -133,17 +143,19 @@ test.describe('Map projects switcher', () => {
// Wait for OL transition
await page.waitForTimeout(1000);

// Go to an other map
// Go to another map
await page.locator('#button-projects').click();
await page.locator('li').filter({ hasText: 'base_layers' }).getByRole('link').nth(1).click();

// Wait for OL transition
await page.waitForTimeout(1000);

checked_url = new URL(page.url());
await expect(checked_url.searchParams.get('repository')).toBe('testsrepository')
await expect(checked_url.searchParams.get('project')).toBe('base_layers')
await expect(checked_url.hash).toHaveLength(0);
expectedParameters = {
'REPOSITORY': 'testsrepository',
'PROJECT': 'base_layers',
}
await expectParametersToContain('GetMap', page.url(), expectedParameters);
await expect(URL(page.url()).hash).toHaveLength(0);

// Check scale
await expect(page.locator('#overview-bar .ol-scale-text')).toHaveText('1 : ' + (144448).toLocaleString(locale));
Expand Down
46 changes: 37 additions & 9 deletions tests/end2end/playwright/permalink.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ test.describe('Permalink', () => {
const share_value = await page.locator('#input-share-permalink').inputValue();
const share_url = new URL(share_value);
await expect(share_url.pathname).toBe('/index.php/view/map')
await expect(share_url.search).toBe('?repository=testsrepository&project=layer_legends')
const expectedParameters = {
'REPOSITORY': 'testsrepository',
'PROJECT': 'layer_legends',
}
await expectParametersToContain('URL', share_value, expectedParameters);
await expect(share_url.hash).toMatch(/#3.5148\d+,43.4213\d+,4.2324\d+,43.7692\d+|/)
await expect(share_url.hash).toContain('|layer_legend_single_symbol,layer_legend_categorized,layer_legend_ruled,tramway_lines,legend_option_test|d%C3%A9faut,d%C3%A9faut,d%C3%A9faut,a_single,|1,1,1,1,1')
});
Expand Down Expand Up @@ -75,7 +79,11 @@ test.describe('Permalink', () => {
const share_value = await page.locator('#input-share-permalink').inputValue();
const share_url = new URL(share_value);
await expect(share_url.pathname).toBe('/index.php/view/map')
await expect(share_url.search).toBe('?repository=testsrepository&project=permalink')
const expectedParameters = {
'REPOSITORY': 'testsrepository',
'PROJECT': 'permalink',
}
await expectParametersToContain('URL', share_value, expectedParameters);
await expect(share_url.hash).toMatch(/#3.798064\d+,43.597569\d+,3.904383\d+,43.672963\d+\|/)
await expect(share_url.hash).toContain('|sousquartiers,Les%20quartiers%20%C3%A0%20Montpellier|red,d%C3%A9faut|0.6,0.8')
});
Expand Down Expand Up @@ -601,7 +609,11 @@ test.describe('Automatic permalink disabled', () => {
const share_value = await page.locator('#input-share-permalink').inputValue();
const share_url = new URL(share_value);
await expect(share_url.pathname).toBe('/index.php/view/map')
await expect(share_url.search).toBe('?repository=testsrepository&project=layer_legends')
const expectedParameters = {
'REPOSITORY': 'testsrepository',
'PROJECT': 'layer_legends',
}
await expectParametersToContain('URL', share_value, expectedParameters);
await expect(share_url.hash).toMatch(/#3.5148\d+,43.4213\d+,4.2324\d+,43.7692\d+|/)
await expect(share_url.hash).toContain('|layer_legend_single_symbol,layer_legend_categorized,layer_legend_ruled,tramway_lines,legend_option_test|d%C3%A9faut,d%C3%A9faut,d%C3%A9faut,a_single,|1,1,1,1,1')
});
Expand Down Expand Up @@ -644,7 +656,11 @@ test.describe('Automatic permalink disabled', () => {
const share_value = await page.locator('#input-share-permalink').inputValue();
const share_url = new URL(share_value);
await expect(share_url.pathname).toBe('/index.php/view/map')
await expect(share_url.search).toBe('?repository=testsrepository&project=permalink')
const expectedParameters = {
'REPOSITORY': 'testsrepository',
'PROJECT': 'permalink',
}
await expectParametersToContain('URL', share_value, expectedParameters);
await expect(share_url.hash).toMatch(/#3.798064\d+,43.597569\d+,3.904383\d+,43.672963\d+\|/)
await expect(share_url.hash).toContain('|sousquartiers,Les%20quartiers%20%C3%A0%20Montpellier|red,d%C3%A9faut|0.6,0.8')
});
Expand Down Expand Up @@ -689,7 +705,11 @@ test.describe('Automatic permalink disabled', () => {
const share_value = await page.locator('#input-share-permalink').inputValue();
const share_url = new URL(share_value);
await expect(share_url.pathname).toBe('/index.php/view/map')
await expect(share_url.search).toBe('?repository=testsrepository&project=layer_legends')
const expectedParameters = {
'REPOSITORY': 'testsrepository',
'PROJECT': 'layer_legends',
}
await expectParametersToContain('URL', share_value, expectedParameters);
await expect(share_url.hash).toMatch(/#3.45433\d+,43.48926\d+,4.17242\d+,43.8367\d+\|/)
await expect(share_url.hash).toContain('|layer_legend_single_symbol,layer_legend_categorized,layer_legend_ruled,tramway_lines,legend_option_test,Group%20as%20layer|d%C3%A9faut,d%C3%A9faut,d%C3%A9faut,categorized,,|0.6,1,1,1,1,1')
});
Expand Down Expand Up @@ -721,7 +741,7 @@ test.describe('BBox parameter', () => {
const getMapPromise = page.waitForRequest(/GetMap/);
await page.getByLabel('sousquartiers').check();
const getMapRequest = await getMapPromise;
const expectedParameters = {
let expectedParameters = {
'SERVICE': 'WMS',
'VERSION': '1.3.0',
'REQUEST': 'GetMap',
Expand All @@ -740,7 +760,11 @@ test.describe('BBox parameter', () => {
const new_share_value = await page.locator('#input-share-permalink').inputValue();
const new_share_url = new URL(new_share_value);
await expect(new_share_url.pathname).toBe('/index.php/view/map')
await expect(new_share_url.search).toBe('?repository=testsrepository&project=permalink')
expectedParameters = {
'REPOSITORY': 'testsrepository',
'PROJECT': 'permalink',
}
await expectParametersToContain('URL', new_share_url, expectedParameters);
await expect(new_share_url.hash).toMatch(/#3.77950\d+,43.60047\d+,3.92309\d+,43.67003\d+\|/)
await expect(new_share_url.hash).toContain('|sousquartiers|d%C3%A9faut|1')
});
Expand Down Expand Up @@ -770,7 +794,7 @@ test.describe('BBox parameter', () => {
const getMapPromise = page.waitForRequest(/GetMap/);
await page.getByLabel('sousquartiers').check();
const getMapRequest = await getMapPromise;
const expectedParameters = {
let expectedParameters = {
'SERVICE': 'WMS',
'VERSION': '1.3.0',
'REQUEST': 'GetMap',
Expand All @@ -789,7 +813,11 @@ test.describe('BBox parameter', () => {
const new_share_value = await page.locator('#input-share-permalink').inputValue();
const new_share_url = new URL(new_share_value);
await expect(new_share_url.pathname).toBe('/index.php/view/map')
await expect(new_share_url.search).toBe('?repository=testsrepository&project=permalink')
expectedParameters = {
'REPOSITORY': 'testsrepository',
'PROJECT': 'permalink',
}
await expectParametersToContain('URL', new_share_url, expectedParameters);
await expect(new_share_url.hash).toMatch(/#3.77950\d+,43.60047\d+,3.92309\d+,43.67003\d+\|/)
await expect(new_share_url.hash).toContain('|sousquartiers|d%C3%A9faut|1')
});
Expand Down
28 changes: 14 additions & 14 deletions tests/end2end/playwright/print.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ test.describe('Print', () => {
// 'multiline_label': 'Multiline label',
})
let getPrintParams = await expectParametersToContain('Print requests 1', getPrintRequest.postData() ?? '', expectedParameters1)
await expect(getPrintParams.size).toBe(15)
await expect(Array.from(getPrintParams.keys())).toHaveLength(15)

// Close message
await page.locator('.btn-close').click();
Expand All @@ -101,7 +101,7 @@ test.describe('Print', () => {
'map0:OPACITIES': '204,255,255',
})
getPrintParams = await expectParametersToContain('Print requests 2', getPrintRequest.postData() ?? '', expectedParameters2)
await expect(getPrintParams.size).toBe(13)
await expect(Array.from(getPrintParams.keys())).toHaveLength(13)

// Test `print_overview` template
await page.locator('#print-template').selectOption('2');
Expand All @@ -127,7 +127,7 @@ test.describe('Print', () => {
'map0:EXTENT': /761864.\d+,6274266.\d+,779334.\d+,6284518.\d+/,
})
getPrintParams = await expectParametersToContain('Print requests 3', getPrintRequest.postData() ?? '', expectedParameters3)
await expect(getPrintParams.size).toBe(14)
await expect(Array.from(getPrintParams.keys())).toHaveLength(14)

// Redlining with circle
await page.locator('#button-draw').click();
Expand Down Expand Up @@ -196,7 +196,7 @@ test.describe('Print', () => {
})
/* eslint-enable no-useless-escape */
getPrintParams = await expectParametersToContain('Print requests 4', getPrintRequest.postData() ?? '', expectedParameters4)
await expect(getPrintParams.size).toBe(17)
await expect(Array.from(getPrintParams.keys())).toHaveLength(17)
});

test('Print requests with selection', async ({ page }) => {
Expand Down Expand Up @@ -235,7 +235,7 @@ test.describe('Print', () => {
'SELECTIONTOKEN': /[a-z\d]+/,
}
const getPrintParams = await expectParametersToContain('Print requests with selection', getPrintRequest.postData() ?? '', expectedParameters)
await expect(getPrintParams.size).toBe(16)
await expect(Array.from(getPrintParams.keys())).toHaveLength(16)
});

test('Print requests with filter', async ({ page }) => {
Expand Down Expand Up @@ -284,7 +284,7 @@ test.describe('Print', () => {
'FILTERTOKEN': /[a-z\d]+/,
}
const getPrintParams = await expectParametersToContain('Print requests with filter', getPrintRequest.postData() ?? '', expectedParameters)
await expect(getPrintParams.size).toBe(16)
await expect(Array.from(getPrintParams.keys())).toHaveLength(16)
});
});

Expand Down Expand Up @@ -339,7 +339,7 @@ test.describe('Print in popup', () => {
'EXP_FILTER': '$id IN (1)',
}
const getPrintParams = await expectParametersToContain('Atlas print in popup requests', getPrintRequest.postData() ?? '', expectedParameters)
await expect(getPrintParams.size).toBe(10)
await expect(Array.from(getPrintParams.keys())).toHaveLength(10)
await expect(getPrintParams.has('CRS')).toBe(false)
await expect(getPrintParams.has('LAYERS')).toBe(false)
await expect(getPrintParams.has('ATLAS_PK')).toBe(false)
Expand Down Expand Up @@ -521,7 +521,7 @@ test.describe('Print 3857', () => {
// 'multiline_label': 'Multiline label',
})
let getPrintParams = await expectParametersToContain('Print requests 1', getPrintRequest.postData() ?? '', expectedParameters1)
await expect(getPrintParams.size).toBe(15)
await expect(Array.from(getPrintParams.keys())).toHaveLength(15)

// Test `print_map` template
await page.locator('#print-template').selectOption('1');
Expand All @@ -548,7 +548,7 @@ test.describe('Print 3857', () => {
'map0:OPACITIES': '204,255,255',
})
getPrintParams = await expectParametersToContain('Print requests 2', getPrintRequest.postData() ?? '', expectedParameters2)
await expect(getPrintParams.size).toBe(13)
await expect(Array.from(getPrintParams.keys())).toHaveLength(13)

// Close message
await page.locator('.btn-close').click();
Expand Down Expand Up @@ -619,7 +619,7 @@ test.describe('Print 3857', () => {
})
/* eslint-enable no-useless-escape */
getPrintParams = await expectParametersToContain('Print requests 3', getPrintRequest.postData() ?? '', expectedParameters3)
await expect(getPrintParams.size).toBe(17)
await expect(Array.from(getPrintParams.keys())).toHaveLength(17)
});
});

Expand Down Expand Up @@ -666,7 +666,7 @@ test.describe('Print base layers', () => {
'map0:OPACITIES': '255',
})
let getPrintParams = await expectParametersToContain('Print requests 1', getPrintRequest.postData() ?? '', expectedParameters1)
await expect(getPrintParams.size).toBe(13)
await expect(Array.from(getPrintParams.keys())).toHaveLength(13)

let getPrintResponse = await getPrintRequest.response();
await expect(getPrintResponse?.status()).toBe(200)
Expand Down Expand Up @@ -696,7 +696,7 @@ test.describe('Print base layers', () => {
'map0:OPACITIES': '255,255',
})
getPrintParams = await expectParametersToContain('Print requests 2', getPrintRequest.postData() ?? '', expectedParameters2)
await expect(getPrintParams.size).toBe(13)
await expect(Array.from(getPrintParams.keys())).toHaveLength(13)

getPrintResponse = await getPrintRequest.response();
await expect(getPrintResponse?.status()).toBe(200)
Expand Down Expand Up @@ -725,7 +725,7 @@ test.describe('Print base layers', () => {
'map0:OPACITIES': '255',
})
getPrintParams = await expectParametersToContain('Print requests 3', getPrintRequest.postData() ?? '', expectedParameters3)
await expect(getPrintParams.size).toBe(13)
await expect(Array.from(getPrintParams.keys())).toHaveLength(13)

getPrintResponse = await getPrintRequest.response();
await expect(getPrintResponse?.status()).toBe(200)
Expand Down Expand Up @@ -754,7 +754,7 @@ test.describe('Print base layers', () => {
'map0:OPACITIES': '255,255',
})
getPrintParams = await expectParametersToContain('Print requests 4', getPrintRequest.postData() ?? '', expectedParameters4)
await expect(getPrintParams.size).toBe(13)
await expect(Array.from(getPrintParams.keys())).toHaveLength(13)

getPrintResponse = await getPrintRequest.response();
await expect(getPrintResponse?.status()).toBe(200)
Expand Down
Loading

0 comments on commit e2d0b15

Please sign in to comment.