Skip to content

Commit

Permalink
Merge pull request #5474 from 3liz/backport-5470-to-release_3_9
Browse files Browse the repository at this point in the history
[Backport release_3_9] Tests - Skip Lizmap warning when loading the map about outdated CFG if needed in tests
  • Loading branch information
Gustry authored Feb 27, 2025
2 parents 6c8ec8a + 0c66f6a commit e16a419
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 34 deletions.
54 changes: 32 additions & 22 deletions assets/src/modules/ExecuteJSFromServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,14 @@
export default function executeJSFromServer() {
lizMap.events.on({
uicreated: () => {
if (document.body.dataset.lizmapPluginUpdateWarningUrl) {
var messageOutdatedWarning = lizDict['project.plugin.outdated.warning'];
messageOutdatedWarning += `<br><a href="${document.body.dataset.lizmapPluginUpdateWarningUrl}">`;
messageOutdatedWarning += lizDict['visit.admin.panel.project.page'];
messageOutdatedWarning += '</a>';
messageOutdatedWarning += '<br>';
messageOutdatedWarning += lizDict['project.admin.panel.info'];
// The plugin can be easily updated, the popup can not be closed
lizMap.addMessage(messageOutdatedWarning, 'warning', false).attr('id', 'lizmap-warning-message');
} else if (document.body.dataset.lizmapPluginHasWarningsUrl) {
var messageHasWarnings = lizDict['project.has.warnings'];
messageHasWarnings += `<br><a href="${document.body.dataset.lizmapPluginHasWarningsUrl}">`;
messageHasWarnings += lizDict['visit.admin.panel.project.page'];
messageHasWarnings += '</a>';
messageHasWarnings += '<br>';
messageHasWarnings += lizDict['project.admin.panel.info'];
// It can take times to fix these issues, the popup can be closed
lizMap.addMessage(messageHasWarnings, 'warning', true).attr('id', 'lizmap-warning-message');
// skipWarningsDisplay is used in tests, to skip a possible warnings about old QGIS plugin used
if (!document.body.dataset.skipWarningsDisplay){
displayWarningsAdministrator();
}

if (document.body.dataset.lizmapHideLegend) {
document.querySelector('li.switcher.active #button-switcher')?.click();
}

if (document.body.dataset.lizmapActionWarningOld) {
lizMap.addMessage(document.body.dataset.lizmapActionWarningOld,'info',true).attr('id','lizmap-action-message');
}
}
});

Expand Down Expand Up @@ -98,3 +79,32 @@ export default function executeJSFromServer() {
});
}
}

/**
* Display messages to the user about deprecated features or outdated versions.
*/
function displayWarningsAdministrator() {
if (document.body.dataset.lizmapPluginUpdateWarningUrl) {
var messageOutdatedWarning = lizDict['project.plugin.outdated.warning'];
messageOutdatedWarning += `<br><a href="${document.body.dataset.lizmapPluginUpdateWarningUrl}">`;
messageOutdatedWarning += lizDict['visit.admin.panel.project.page'];
messageOutdatedWarning += '</a>';
messageOutdatedWarning += '<br>';
messageOutdatedWarning += lizDict['project.admin.panel.info'];
// The plugin can be easily updated, the popup can not be closed
lizMap.addMessage(messageOutdatedWarning, 'warning', false).attr('id', 'lizmap-warning-message');
} else if (document.body.dataset.lizmapPluginHasWarningsUrl) {
var messageHasWarnings = lizDict['project.has.warnings'];
messageHasWarnings += `<br><a href="${document.body.dataset.lizmapPluginHasWarningsUrl}">`;
messageHasWarnings += lizDict['visit.admin.panel.project.page'];
messageHasWarnings += '</a>';
messageHasWarnings += '<br>';
messageHasWarnings += lizDict['project.admin.panel.info'];
// It can take times to fix these issues, the popup can be closed
lizMap.addMessage(messageHasWarnings, 'warning', true).attr('id', 'lizmap-warning-message');
}

if (document.body.dataset.lizmapActionWarningOld) {
lizMap.addMessage(document.body.dataset.lizmapActionWarningOld,'info',true).attr('id','lizmap-action-message');
}
}
12 changes: 8 additions & 4 deletions lizmap/modules/view/controllers/lizMap.classic.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ function f($x)
$rep->addJsVariable('filterConfigData', $filterConfigData);
}

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

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

if ($this->boolParam('skip_warnings_display') == true) {
$rep->setBodyAttributes(array('data-skip-warnings-display' => true));
}

$countUserJs = 0;
// Override default theme by themes found in folder media/themes/...
// Theme name can be 'default' and apply to all projects in a repository
// or the project name and only apply to it
// Also if media/themes/default/css is found one directory above repositorie's one
// Also if media/themes/default/css is found one directory above repositories one
// it will apply to all repositories
if ($lrep->allowUserDefinedThemes() && $this->param('no_user_defined_js') != '1') {
if ($lrep->allowUserDefinedThemes() && $this->boolParam('no_user_defined_js') != true) {
$repositoryPath = $lrep->getPath();
$cssArray = array('main', 'map', 'media');
$themeArray = array('default', $project);
Expand Down
17 changes: 14 additions & 3 deletions tests/end2end/playwright/filter-layer-by-user.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { getAuthStorageStatePath, gotoMap } from './globals';
test.describe('Filter layer data by user - not connected', () => {

test.beforeEach(async ({ page }) => {
const url = '/index.php/view/map/?repository=testsrepository&project=filter_layer_by_user';
const url =
'/index.php/view/map/?' +
'repository=testsrepository&' +
'project=filter_layer_by_user&' +
'skip_warnings_display=1';
await gotoMap(url, page);

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

test.beforeEach(async ({ page }) => {
const url = '/index.php/view/map/?repository=testsrepository&project=filter_layer_by_user';
const url = '' +
'/index.php/view/map/?' +
'repository=testsrepository&' +
'project=filter_layer_by_user&' +
'skip_warnings_display=1';
await gotoMap(url, page);

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

test.beforeEach(async ({ page }) => {
const url = '/index.php/view/map/?repository=testsrepository&project=filter_layer_by_user';
const url = '/index.php/view/map/?' +
'repository=testsrepository&' +
'project=filter_layer_by_user&' +
'skip_warnings_display=1';
await gotoMap(url, page);

// Close dock to access all features on map
Expand Down
13 changes: 10 additions & 3 deletions tests/end2end/playwright/pages/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,16 @@ export class ProjectPage extends BasePage {
/**
* open function
* Open the URL for the given project and repository
*/
async open(){
await gotoMap(`/index.php/view/map?repository=${this.repository}&project=${this.project}`, this.page);
* @param {boolean} skip_warnings_display Skip UI warnings when loading the map, true by default.
*/
async open(skip_warnings_display = true){
// By default, do not display warnings about old QGIS plugin or outdated Action JSON file
await gotoMap(
`/index.php/view/map?
repository=${this.repository}&
project=${this.project}&
skip_warnings_display=${skip_warnings_display}&`,
this.page);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/end2end/playwright/project_load_warning.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test.describe('Project warnings in CFG as admin',

test('Visit map with a warning', async ({ page }) => {
const project = new ProjectPage(page, 'project_cfg_warnings');
await project.open();
await project.open(false);
await expect(project.warningMessage).toBeVisible();
});

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

test('Visit map without a warning', async ({ page }) => {
const project = new ProjectPage(page, 'project_cfg_warnings');
await project.open();
await project.open(false);
await expect(project.warningMessage).toHaveCount(0);
});

Expand Down

2 comments on commit e16a419

@3liz-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest weekly run of end2end "playwright" tests failed with this latest commit on the branch release_3_9 😣

CC @nboisteault and @Gustry, please have a look to the logs. Maybe it's a false positive ?

Visit https://github.com/3liz/lizmap-web-client/actions/runs/13622813048

@3liz-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest weekly run of end2end "playwright" tests failed with this latest commit on the branch release_3_9 😣

CC @nboisteault and @Gustry, please have a look to the logs. Maybe it's a false positive ?

Visit https://github.com/3liz/lizmap-web-client/actions/runs/13622813048

Please sign in to comment.