Skip to content

Commit

Permalink
Tests - Use POM for the display in layer tree, tag it as read-only
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Jan 20, 2025
1 parent 370fb57 commit 52fe03e
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 21 deletions.
4 changes: 4 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 10 additions & 2 deletions tests/end2end/playwright/attribute-table.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -24,7 +28,11 @@ test.describe('Attribute table', () => {
});
});

test.describe('Attribute table data restricted to map extent', () => {
test.describe('Attribute table data restricted to map extent',
{
tag: ['@readonly'],
},
() => {
test.beforeEach(async ({ page }) => {
await page.route('**/service/getProjectConfig*', async route => {
const response = await route.fetch();
Expand Down
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 => {
Expand All @@ -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);
});
})
6 changes: 5 additions & 1 deletion tests/end2end/playwright/media.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 16 additions & 3 deletions tests/end2end/playwright/pages/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
/**
Expand Down Expand Up @@ -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');
}

/**
Expand Down Expand Up @@ -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();
}
Expand Down
12 changes: 10 additions & 2 deletions tests/end2end/playwright/project_load_warning.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand All @@ -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');
Expand Down

0 comments on commit 52fe03e

Please sign in to comment.