Skip to content

Commit

Permalink
Merge pull request #5298 from rldhont/backport-5295-to-release_3_7
Browse files Browse the repository at this point in the history
[Backport release_3_7] Tests e2e playwright : Lint tests and POM
  • Loading branch information
Gustry authored Jan 30, 2025
2 parents 6cb258b + aaba2d4 commit e21a937
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 12 deletions.
3 changes: 2 additions & 1 deletion tests/end2end/playwright/attribute-table.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ test.describe('Attribute table', () => {
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');
expect(mediaFile).not.toBeNull
// 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('img.data-attr-thumbnail').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&/);
})
Expand Down
23 changes: 17 additions & 6 deletions tests/end2end/playwright/globals.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
// @ts-check
const { expect } = require('@playwright/test');
import { Page } from '@playwright/test';

/**
* Playwright Page
* @typedef {import('@playwright/test').Page} Page
*/

/**
* Integer
* @typedef {number} int
*/

/**
* Expect no errors in the map page
* @param {Page} page The page object
* @param {boolean} checkLayerTreeView Checking that tree view contains layers
*/
async function NoErrors(page, checkLayerTreeView = true) {
// No error
await expect(page.locator('p.error-msg')).toHaveCount(0);
Expand All @@ -13,10 +27,9 @@ async function NoErrors(page, checkLayerTreeView = true) {
}

/**
* CatchErrors function
* Some checks when the map is on error
* Expect errors in the map page
* @param {Page} page The page object
* @param {int} layersInTreeView The number of layers to find in the treeview.
* @param {int} layersInTreeView The number of layers to find in the tree view.
*/
async function CatchErrors(page, layersInTreeView = 0) {
// Error
Expand All @@ -29,7 +42,6 @@ async function CatchErrors(page, layersInTreeView = 0) {
}

/**
* gotoMap function
* Helper to load a map and do some basic checks
* @param {string} url The URL of the map to load
* @param {Page} page The page object
Expand Down Expand Up @@ -67,7 +79,6 @@ export async function gotoMap(url, page, mapMustLoad = true, layersInTreeView =
}

/**
* reloadMap function
* Helper to reload a map and do some basic checks
* @param {Page} page The page object
* @param {boolean} check If some basic checks must be done.
Expand Down
12 changes: 11 additions & 1 deletion tests/end2end/playwright/pages/admin.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
// @ts-check

import {expect, Locator, Page} from '@playwright/test';
import { expect } from '@playwright/test';
import { BasePage } from './base';

/**
* Playwright Page
* @typedef {import('@playwright/test').Page} Page
*/

/**
* Playwright Page
* @typedef {import('@playwright/test').Locator} Locator
*/

export class AdminPage extends BasePage {
/**
* Main administrator menu
Expand Down
12 changes: 11 additions & 1 deletion tests/end2end/playwright/pages/base.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
// @ts-check

import {expect, Locator, Page} from '@playwright/test';
import { expect } from '@playwright/test';

/**
* Playwright Page
* @typedef {import('@playwright/test').Page} Page
*/

/**
* Playwright Page
* @typedef {import('@playwright/test').Locator} Locator
*/

export class BasePage {
/** @type {Page} */
Expand Down
12 changes: 11 additions & 1 deletion tests/end2end/playwright/pages/project.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
// @ts-check
import {expect, Locator, Page} from '@playwright/test';
import { expect } from '@playwright/test';
import { gotoMap } from '../globals';
import { BasePage } from './base';

/**
* Playwright Page
* @typedef {import('@playwright/test').Page} Page
*/

/**
* Playwright Page
* @typedef {import('@playwright/test').Locator} Locator
*/

export class ProjectPage extends BasePage {
// Metadata
/**
Expand Down
9 changes: 7 additions & 2 deletions tests/end2end/playwright/requests-metadata.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
// @ts-check
import { test, expect } from '@playwright/test';

/**
* Playwright Page
* @typedef {import('@playwright/test').APIResponse} APIResponse
*/

const url = 'index.php/view/app/metadata';

/**
* Check for a JSON response about the metadata
* @param {Response} response The response object
* @param {APIResponse} response The response object
*
* @return {JSON} The JSON response
* @return {Promise<any>} The JSON response
*/
export async function checkJson(response) {
expect(response.ok()).toBeTruthy();
Expand Down

0 comments on commit e21a937

Please sign in to comment.