Skip to content

Commit

Permalink
Tests - Use a parametrized test for points/lines/polygons manual tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Feb 6, 2025
1 parent e2fd46d commit bb9b553
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 33 deletions.
2 changes: 1 addition & 1 deletion lizmap/modules/view/templates/popupDefaultContent.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{if $attribute['name'] != 'geometry' && $attribute['name'] != 'maptip'}
<tr {if $attribute['value']=='' || $attribute['value']=='NULL' } class="empty-data" {/if}>
<th>{$attribute['name']}</th>
<td>{$attribute['name']|featurepopup:$attribute['value'],$repository,$project,$remoteStorageProfile}</td>
<td data-field-name="{$attribute['name']}">{$attribute['name']|featurepopup:$attribute['value'],$repository,$project,$remoteStorageProfile}</td>
</tr>
{/if}
{/foreach}
Expand Down
83 changes: 83 additions & 0 deletions tests/end2end/playwright/editing-geometry.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// @ts-check
import {expect, test} from '@playwright/test';
import {editedFeatureIds } from './globals';
import {ProjectPage} from "./pages/project";

test.describe('Geometry editing',
{
tag: ['@write'],
}, () => {
[
{ layerName: 'point_2154', geom: 'point', layerId: 'form_edition_point_2154_bfabce3b_eb48_4631_b43f_d1db3772f0a5' },
{ layerName: 'point_3857', geom: 'point', layerId: 'form_edition_point_3857_c23f4950_b9a9_4d41_b3af_048cf01dc0cd' },
{ layerName: 'point_4326', geom: 'point', layerId: 'form_edition_point_4326_f1955711_4ebd_4c78_a9fd_58083b600d6a' },
{ layerName: 'line_2154', geom: 'line', layerId: 'form_edition_line_2154_8797dd9f_d762_436f_91b6_1f06a37e9cf3' },
{ layerName: 'line_3857', geom: 'line', layerId: 'form_edition_line_3857_fd8ff719_81b7_4719_ad71_2a5fdebcbb13' },
{ layerName: 'line_4326', geom: 'line', layerId: 'form_edition_line_4326_2e2d506d_414a_4731_a1bb_17e33c490923' },
{ layerName: 'polygon_2154', geom: 'polygon', layerId: 'form_edition_polygon_2154_6b836ded_12c4_44ee_a6c4_44bf0a0d349e' },
{ layerName: 'polygon_3857', geom: 'polygon', layerId: 'form_edition_polygon_3857_980ac178_da20_4105_bf91_e8801a050dec' },
{ layerName: 'polygon_4326', geom: 'polygon', layerId: 'form_edition_polygon_4326_36f846ad_6690_4d2d_b48d_c342db7c07e9' },
].forEach(({ layerName, geom, layerId}) => {

test(`Layer ${layerName} : create and edit attributes and geometry`, async ({ page }) => {
const project = new ProjectPage(page, 'form_edition_simple_fields');
await project.open();

const field = 'label';

// Add new data
await project.openEditingFormWithLayer(layerName);
await project.editingField(field).fill("VALUE NEW");

const x1 = 600;
const y1 = 200;
await project.clickOnMapLegacy(x1, y1);
if (geom === 'polygon'){
await project.clickOnMapLegacy(x1, y1 + 100);
}
if (geom === 'line' || geom === 'polygon') {
await project.dblClickOnMapLegacy(x1 + 100, y1);
}
await project.editingSubmitForm();

// Fetch inserted ID
const ids = await editedFeatureIds(page);

// Open its popup, check the auto popup and then edit it
await project.clickOnMap(x1, y1);
const lastFeature = await project.identifyContentLocator(ids['id'], layerId);
await expect(lastFeature.locator(`td[data-field-name="${field}"]`)).toHaveText("VALUE NEW");
await lastFeature.locator(".feature-edit").click();

await expect(project.editingField(field)).toHaveValue('VALUE NEW');

// Edit attribute
await project.editingField(field).fill("VALUE EDITED");

// Edit the first point of the geometry with a translation of Y + 200
const delta_y = 200;
await project.mapOl2.dragTo(project.mapOl2, {
sourcePosition: { x: x1, y: y1 },
targetPosition: { x: x1, y: y1 + delta_y },
});
await project.editingSubmitForm();

// Check the ID has not changed
const idsEdited = await editedFeatureIds(page);
await expect(ids['id']).toEqual(idsEdited['id']);

// Open its popup using the new point in the geometry
// The popup must open, it means the geometry has been updated
// Check the updated value and remove the feature
await project.clickOnMap(x1, y1 + delta_y);
const feature = await project.identifyContentLocator(ids['id'], layerId);
await expect(feature.locator(`td[data-field-name="${field}"]`)).toHaveText("VALUE EDITED");

page.on('dialog', dialog => dialog.accept());
await feature.locator(".feature-delete").click();
await expect(page.locator(".jelix-msg-item-success")).toHaveText("The feature has been deleted.");

});

});
});
18 changes: 18 additions & 0 deletions tests/end2end/playwright/pages/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,24 @@ export class ProjectPage extends BasePage {
await this.page.locator('a#edition-draw').click();
}

/**
* Identify content locator, for a given feature ID and layer ID if necessary
* @param {string} featureId Feature ID, optional
* @param {string} layerId Layer ID, optional
* @returns {Locator} Locator for HTML identify content
*/
async identifyContentLocator(featureId = '', layerId= '') {
let selector = `div.lizmapPopupSingleFeature`;
if (featureId) {
selector +=`[data-feature-id="${featureId}"]`;
}
if (layerId) {
selector += `[data-layer-id="${layerId}"]`;
}
return this.popupContent.locator(selector);
}


/**
* clickOnMap function
* Click on the map at the given position
Expand Down
23 changes: 0 additions & 23 deletions tests/qgis-projects/tests/form_edition_simple_fields.md

This file was deleted.

18 changes: 9 additions & 9 deletions tests/qgis-projects/tests/form_edition_simple_fields.qgs.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@
"allow_without_geom": "False",
"modifyAttribute": "True",
"modifyGeometry": "True",
"deleteFeature": "False"
"deleteFeature": "True"
},
"geometryType": "line",
"order": 0
Expand All @@ -534,7 +534,7 @@
"allow_without_geom": "False",
"modifyAttribute": "True",
"modifyGeometry": "True",
"deleteFeature": "False"
"deleteFeature": "True"
},
"geometryType": "line",
"order": 1
Expand All @@ -553,7 +553,7 @@
"allow_without_geom": "False",
"modifyAttribute": "True",
"modifyGeometry": "True",
"deleteFeature": "False"
"deleteFeature": "True"
},
"geometryType": "line",
"order": 2
Expand All @@ -572,7 +572,7 @@
"allow_without_geom": "False",
"modifyAttribute": "True",
"modifyGeometry": "True",
"deleteFeature": "False"
"deleteFeature": "True"
},
"geometryType": "point",
"order": 3
Expand All @@ -591,7 +591,7 @@
"allow_without_geom": "False",
"modifyAttribute": "True",
"modifyGeometry": "True",
"deleteFeature": "False"
"deleteFeature": "True"
},
"geometryType": "point",
"order": 4
Expand All @@ -610,7 +610,7 @@
"allow_without_geom": "False",
"modifyAttribute": "True",
"modifyGeometry": "True",
"deleteFeature": "False"
"deleteFeature": "True"
},
"geometryType": "point",
"order": 5
Expand All @@ -629,7 +629,7 @@
"allow_without_geom": "False",
"modifyAttribute": "True",
"modifyGeometry": "True",
"deleteFeature": "False"
"deleteFeature": "True"
},
"geometryType": "polygon",
"order": 6
Expand All @@ -648,7 +648,7 @@
"allow_without_geom": "False",
"modifyAttribute": "True",
"modifyGeometry": "True",
"deleteFeature": "False"
"deleteFeature": "True"
},
"geometryType": "polygon",
"order": 7
Expand All @@ -667,7 +667,7 @@
"allow_without_geom": "False",
"modifyAttribute": "True",
"modifyGeometry": "True",
"deleteFeature": "False"
"deleteFeature": "True"
},
"geometryType": "polygon",
"order": 8
Expand Down

0 comments on commit bb9b553

Please sign in to comment.