Skip to content

Commit b8fe675

Browse files
committed
Tests - Skip Lizmap warning when loading the map about outdated CFG if needed in tests
1 parent 20f2a38 commit b8fe675

File tree

5 files changed

+66
-34
lines changed

5 files changed

+66
-34
lines changed

assets/src/modules/ExecuteJSFromServer.js

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,14 @@
44
export default function executeJSFromServer() {
55
lizMap.events.on({
66
uicreated: () => {
7-
if (document.body.dataset.lizmapPluginUpdateWarningUrl) {
8-
var messageOutdatedWarning = lizDict['project.plugin.outdated.warning'];
9-
messageOutdatedWarning += `<br><a href="${document.body.dataset.lizmapPluginUpdateWarningUrl}">`;
10-
messageOutdatedWarning += lizDict['visit.admin.panel.project.page'];
11-
messageOutdatedWarning += '</a>';
12-
messageOutdatedWarning += '<br>';
13-
messageOutdatedWarning += lizDict['project.admin.panel.info'];
14-
// The plugin can be easily updated, the popup can not be closed
15-
lizMap.addMessage(messageOutdatedWarning, 'warning', false).attr('id', 'lizmap-warning-message');
16-
} else if (document.body.dataset.lizmapPluginHasWarningsUrl) {
17-
var messageHasWarnings = lizDict['project.has.warnings'];
18-
messageHasWarnings += `<br><a href="${document.body.dataset.lizmapPluginHasWarningsUrl}">`;
19-
messageHasWarnings += lizDict['visit.admin.panel.project.page'];
20-
messageHasWarnings += '</a>';
21-
messageHasWarnings += '<br>';
22-
messageHasWarnings += lizDict['project.admin.panel.info'];
23-
// It can take times to fix these issues, the popup can be closed
24-
lizMap.addMessage(messageHasWarnings, 'warning', true).attr('id', 'lizmap-warning-message');
7+
// skipWarningsDisplay is used in tests, to skip a possible warnings about old QGIS plugin used
8+
if (!document.body.dataset.skipWarningsDisplay){
9+
displayWarningsAdministrator();
2510
}
2611

2712
if (document.body.dataset.lizmapHideLegend) {
2813
document.querySelector('li.switcher.active #button-switcher')?.click();
2914
}
30-
31-
if (document.body.dataset.lizmapActionWarningOld) {
32-
lizMap.addMessage(document.body.dataset.lizmapActionWarningOld,'info',true).attr('id','lizmap-action-message');
33-
}
3415
}
3516
});
3617

@@ -104,3 +85,32 @@ export default function executeJSFromServer() {
10485
});
10586
}
10687
}
88+
89+
/**
90+
* Display messages to the user about deprecated features or outdated versions.
91+
*/
92+
function displayWarningsAdministrator() {
93+
if (document.body.dataset.lizmapPluginUpdateWarningUrl) {
94+
var messageOutdatedWarning = lizDict['project.plugin.outdated.warning'];
95+
messageOutdatedWarning += `<br><a href="${document.body.dataset.lizmapPluginUpdateWarningUrl}">`;
96+
messageOutdatedWarning += lizDict['visit.admin.panel.project.page'];
97+
messageOutdatedWarning += '</a>';
98+
messageOutdatedWarning += '<br>';
99+
messageOutdatedWarning += lizDict['project.admin.panel.info'];
100+
// The plugin can be easily updated, the popup can not be closed
101+
lizMap.addMessage(messageOutdatedWarning, 'warning', false).attr('id', 'lizmap-warning-message');
102+
} else if (document.body.dataset.lizmapPluginHasWarningsUrl) {
103+
var messageHasWarnings = lizDict['project.has.warnings'];
104+
messageHasWarnings += `<br><a href="${document.body.dataset.lizmapPluginHasWarningsUrl}">`;
105+
messageHasWarnings += lizDict['visit.admin.panel.project.page'];
106+
messageHasWarnings += '</a>';
107+
messageHasWarnings += '<br>';
108+
messageHasWarnings += lizDict['project.admin.panel.info'];
109+
// It can take times to fix these issues, the popup can be closed
110+
lizMap.addMessage(messageHasWarnings, 'warning', true).attr('id', 'lizmap-warning-message');
111+
}
112+
113+
if (document.body.dataset.lizmapActionWarningOld) {
114+
lizMap.addMessage(document.body.dataset.lizmapActionWarningOld,'info',true).attr('id','lizmap-action-message');
115+
}
116+
}

lizmap/modules/view/controllers/lizMap.classic.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ function f($x)
271271
$rep->addJsVariable('filterConfigData', $filterConfigData);
272272
}
273273

274-
// Add atlas.js for atlas feature and additionnal CSS for right-dock max-width
274+
// Add atlas.js for atlas feature and additional CSS for right-dock max-width
275275
if ($lproj->hasAtlasEnabled()) {
276276
// Add JS
277277
$rep->addJSLink($bp.'assets/js/atlas.js', array('defer' => ''));
@@ -325,7 +325,7 @@ function f($x)
325325
}
326326
}
327327

328-
// Get additionnal JS and CSS from modules
328+
// Get additional JS and CSS from modules
329329
$additions = jEvent::notify('getMapAdditions', array('repository' => $repository, 'project' => $project))->getResponse();
330330
foreach ($additions as $addition) {
331331
if (is_array($addition)) {
@@ -366,13 +366,17 @@ function f($x)
366366
}
367367
}
368368

369+
if ($this->boolParam('skip_warnings_display') == true) {
370+
$rep->setBodyAttributes(array('data-skip-warnings-display' => true));
371+
}
372+
369373
$countUserJs = 0;
370374
// Override default theme by themes found in folder media/themes/...
371375
// Theme name can be 'default' and apply to all projects in a repository
372376
// or the project name and only apply to it
373-
// Also if media/themes/default/css is found one directory above repositorie's one
377+
// Also if media/themes/default/css is found one directory above repositories one
374378
// it will apply to all repositories
375-
if ($lrep->allowUserDefinedThemes() && $this->param('no_user_defined_js') != '1') {
379+
if ($lrep->allowUserDefinedThemes() && $this->boolParam('no_user_defined_js') != true) {
376380
$repositoryPath = $lrep->getPath();
377381
$cssArray = array('main', 'map', 'media');
378382
$themeArray = array('default', $project);

tests/end2end/playwright/filter-layer-by-user.spec.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import { getAuthStorageStatePath, gotoMap } from './globals';
55
test.describe('Filter layer data by user - not connected', () => {
66

77
test.beforeEach(async ({ page }) => {
8-
const url = '/index.php/view/map/?repository=testsrepository&project=filter_layer_by_user';
8+
const url =
9+
'/index.php/view/map/?' +
10+
'repository=testsrepository&' +
11+
'project=filter_layer_by_user&' +
12+
'skip_warnings_display=1';
913
await gotoMap(url, page);
1014

1115
// Close dock to access all features on map
@@ -179,7 +183,11 @@ test.describe('Filter layer data by user - user in group a', () => {
179183
test.use({ storageState: getAuthStorageStatePath('user_in_group_a') });
180184

181185
test.beforeEach(async ({ page }) => {
182-
const url = '/index.php/view/map/?repository=testsrepository&project=filter_layer_by_user';
186+
const url = '' +
187+
'/index.php/view/map/?' +
188+
'repository=testsrepository&' +
189+
'project=filter_layer_by_user&' +
190+
'skip_warnings_display=1';
183191
await gotoMap(url, page);
184192

185193
// Close dock to access all features on map
@@ -375,7 +383,10 @@ test.describe('Filter layer data by user - admin', () => {
375383
test.use({ storageState: getAuthStorageStatePath('admin') });
376384

377385
test.beforeEach(async ({ page }) => {
378-
const url = '/index.php/view/map/?repository=testsrepository&project=filter_layer_by_user';
386+
const url = '/index.php/view/map/?' +
387+
'repository=testsrepository&' +
388+
'project=filter_layer_by_user&' +
389+
'skip_warnings_display=1';
379390
await gotoMap(url, page);
380391

381392
// Close dock to access all features on map

tests/end2end/playwright/pages/project.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,16 @@ export class ProjectPage extends BasePage {
148148
/**
149149
* open function
150150
* Open the URL for the given project and repository
151-
*/
152-
async open(){
153-
await gotoMap(`/index.php/view/map?repository=${this.repository}&project=${this.project}`, this.page);
151+
* @param {boolean} skip_warnings_display Skip UI warnings when loading the map, true by default.
152+
*/
153+
async open(skip_warnings_display = true){
154+
// By default, do not display warnings about old QGIS plugin or outdated Action JSON file
155+
await gotoMap(
156+
`/index.php/view/map?
157+
repository=${this.repository}&
158+
project=${this.project}&
159+
skip_warnings_display=${skip_warnings_display}&`,
160+
this.page);
154161
}
155162

156163
/**

tests/end2end/playwright/project_load_warning.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ test.describe('Project warnings in CFG as admin',
1212

1313
test('Visit map with a warning', async ({ page }) => {
1414
const project = new ProjectPage(page, 'project_cfg_warnings');
15-
await project.open();
15+
await project.open(false);
1616
await expect(project.warningMessage).toBeVisible();
1717
});
1818

@@ -25,7 +25,7 @@ test.describe('Project warnings in CFG as anonymous',
2525

2626
test('Visit map without a warning', async ({ page }) => {
2727
const project = new ProjectPage(page, 'project_cfg_warnings');
28-
await project.open();
28+
await project.open(false);
2929
await expect(project.warningMessage).toHaveCount(0);
3030
});
3131

0 commit comments

Comments
 (0)