Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests - Use POM for the display in layer tree, tag it as read-only #5246

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Tests - Update one test to use POM, check some readonly
Gustry committed Jan 20, 2025
commit c0b6878f33f2f25dff7b25bed585b9b64004d170
4 changes: 4 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -262,6 +262,10 @@ You can then :

You can also install the handy [Playwright extension](https://marketplace.visualstudio.com/items?itemName=ms-playwright.playwright) on VSCode.

#### Writing tests

A tests doing only a **read-only** on Lizmap must be tagged as `@readonly`.

### Artifacts

When GitHub Action is failing, all screenshots and downloaded files are uploaded in an ZIP.
16 changes: 12 additions & 4 deletions tests/end2end/playwright/attribute-table.spec.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,11 @@ import { test, expect } from '@playwright/test';
import { ProjectPage } from './pages/project';
import { gotoMap } from './globals';

test.describe('Attribute table', () => {
test.describe('Attribute table',
{
tag: ['@readonly'],
},
() => {
test.beforeEach(async ({ page }) => {
const url = '/index.php/view/map/?repository=testsrepository&project=attribute_table';
await gotoMap(url, page)
@@ -16,11 +20,15 @@ test.describe('Attribute table', () => {
await project.openAttributeTable(layerName);
await expect(project.attributeTableHtml(layerName).locator('tbody tr')).toHaveCount(7);
// mediaFile as stored in data-src attributes
const mediaFile = await project.attributeTableHtml(layerName).locator('img.data-attr-thumbnail').first().getAttribute('data-src');
const locator = 'img.data-attr-thumbnail';
const mediaFile = await project.attributeTableHtml(layerName).locator(locator).first().getAttribute('data-src');
// ensure src contain "dynamic" mediaFile
await expect(project.attributeTableHtml(layerName).locator('img.data-attr-thumbnail').first()).toHaveAttribute('src', new RegExp(mediaFile));
await expect(project.attributeTableHtml(layerName).locator(locator).first()).toHaveAttribute('src', new RegExp(mediaFile));
// ensure src contain getMedia and projet URL
await expect(project.attributeTableHtml(layerName).locator('img.data-attr-thumbnail').first()).toHaveAttribute('src', /getMedia\?repository=testsrepository&project=attribute_table&/);
await expect(project.attributeTableHtml(layerName).locator(locator).first()).toHaveAttribute(
'src',
/getMedia\?repository=testsrepository&project=attribute_table&/
);
});
});

30 changes: 17 additions & 13 deletions tests/end2end/playwright/display_in_layer_tree.spec.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
// @ts-check
import { test, expect } from '@playwright/test';
import { gotoMap } from './globals';
import {ProjectPage} from "./pages/project";

test.describe('Display in layer tree', () => {
test.describe('Display in layer tree',
{
tag: ['@readonly', '@legend'],
}, () => {

test.beforeEach(async ({ page }) => {
const url = '/index.php/view/map?repository=testsrepository&project=display_in_legend';
await gotoMap(url, page)
});
test('display in layer tree unchecked => layer not visible in layer tree and layer in print request',
async ({ page }) => {
const project = new ProjectPage(page, 'display_in_legend');
await project.open();

test('display in layer tree unchecked => layer not visible in layer tree and layer in print request', async ({ page }) => {
// layer not visible in layer tree
await expect(page.getByTestId('polygons')).toHaveCount(0);
await expect(page.getByTestId('group-without-children')).toHaveCount(0);

const getPrintRequestPromise = page.waitForRequest(request => request.method() === 'POST' && request.postData() != null && request.postData()?.includes('GetPrint') === true);
const getPrintRequestPromise = page.waitForRequest(
request => request.method() === 'POST' &&
request.postData() != null && request.postData()?.includes('GetPrint') === true);

// layer in print request
const getPrintRequestContains = request => {
@@ -24,21 +29,20 @@ test.describe('Display in layer tree', () => {
expect(postData).toContain('map0%3ALAYERS=polygons')
};

await page.locator('#button-print').click();

await page.locator('#print-launch').click();
await project.buttonPrintPanel.click();
await project.buttonPrintLaunch.click();
getPrintRequestContains(await getPrintRequestPromise);

await page.getByTestId('Shapefiles').locator('input').first().uncheck();
await page.locator('#print-launch').click();
await project.buttonPrintLaunch.click();
getPrintRequestContains(await getPrintRequestPromise);

await page.getByTestId('townhalls_EPSG2154').locator('input').first().check();
await page.locator('#print-launch').click();
await project.buttonPrintLaunch.click();
getPrintRequestContains(await getPrintRequestPromise);

await page.getByTestId('Shapefiles').locator('input').first().uncheck();
await page.locator('#print-launch').click();
await project.buttonPrintLaunch.click();
getPrintRequestContains(await getPrintRequestPromise);
});
})
2 changes: 1 addition & 1 deletion tests/end2end/playwright/edition-form.spec.js
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ test.describe('Edition Form Validation', () => {
});

const project = new ProjectPage(page, 'form_edition_all_field_type');
await project.buttonEditing.click();
await project.buttonEditingPanel.click();
await page.locator('a#edition-draw').click();

// message
6 changes: 5 additions & 1 deletion tests/end2end/playwright/media.spec.js
Original file line number Diff line number Diff line change
@@ -4,7 +4,11 @@ import { gotoMap } from './globals';
import {ProjectPage} from "./pages/project";

test.describe('Media', () => {
test('Tests media are deleted', async ({ page }) => {
test('Tests media are deleted',
{
tag: ['@not-readonly'],
},
async ({ page }) => {

const baseUrl = 'index.php/view/media/getMedia?repository=testsrepository&project=form_edition_all_field_type&path=';
// on the feature from the "form_edition_upload" layer
19 changes: 16 additions & 3 deletions tests/end2end/playwright/pages/project.js
Original file line number Diff line number Diff line change
@@ -26,7 +26,17 @@ export class ProjectPage extends BasePage {
* Editing menu
* @type {Locator}
*/
buttonEditing;
buttonEditingPanel;
/**
* Dataviz button
* @type {Locator}
*/
buttonDatavizPanel;
/**
* Print button
* @type {Locator}
*/
buttonPrintPanel;

// Docks
/**
@@ -92,7 +102,10 @@ export class ProjectPage extends BasePage {
this.warningMessage = page.locator('#lizmap-warning-message');
this.search = page.locator('#search-query');
this.switcher = page.locator('#button-switcher');
this.buttonEditing = page.locator('#button-edition');
this.buttonEditingPanel = page.locator('#button-edition');
this.buttonDatavizPanel = page.locator('#button-dataviz');
this.buttonPrintPanel = page.locator('#button-print');
this.buttonPrintLaunch = page.locator('#print-launch');
}

/**
@@ -139,7 +152,7 @@ export class ProjectPage extends BasePage {
* @param {string} layer Name of the layer
*/
async openEditingFormWithLayer(layer){
await this.buttonEditing.click();
await this.buttonEditingPanel.click();
await this.page.locator('#edition-layer').selectOption({ label: layer });
await this.page.locator('a#edition-draw').click();
}
12 changes: 10 additions & 2 deletions tests/end2end/playwright/project_load_warning.spec.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,11 @@
import { test, expect } from '@playwright/test';
import { ProjectPage } from './pages/project';

test.describe('Project warnings in CFG as admin', () => {
test.describe('Project warnings in CFG as admin',
{
tag: ['@readonly'],
},
() => {
test.use({ storageState: 'playwright/.auth/admin.json' });

test('Visit map with a warning', async ({ page }) => {
@@ -13,7 +17,11 @@ test.describe('Project warnings in CFG as admin', () => {

});

test.describe('Project warnings in CFG as anonymous', () => {
test.describe('Project warnings in CFG as anonymous',
{
tag: ['@readonly'],
},
() => {

test('Visit map without a warning', async ({ page }) => {
const project = new ProjectPage(page, 'project_cfg_warnings');