Skip to content

Commit

Permalink
Merge pull request #5372 from 3liz/backport-5365-to-release_3_9
Browse files Browse the repository at this point in the history
[Backport release_3_9] Tests - Switch to parametrized test instead of manual test for data editing
  • Loading branch information
Gustry authored Feb 6, 2025
2 parents 6a9e539 + 542781b commit 7bad961
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 69 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 @@ -9,7 +9,7 @@
<tbody>
{foreach $attributes as $attribute}
{if $attribute['name'] != 'geometry' && $attribute['name'] != 'maptip'}
<tr {if $attribute['value']=='' || $attribute['value']=='NULL' } class="empty-data" {/if}>
<tr data-field-name="{$attribute['name']}" {if $attribute['value']=='' || $attribute['value']=='NULL' } class="empty-data" {/if}>
<th>{$attribute['name']}</th>
<td>{$attribute['name']|featurepopup:$attribute['value'],$repository,$project,$remoteStorageProfile}</td>
</tr>
Expand Down
50 changes: 14 additions & 36 deletions tests/end2end/playwright/dnd-form.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,14 @@ test.describe(
await project.clickOnMap(600, 200);
await expect(project.popupContent).toBeVisible();

// Fixme if there is a better way to get the table from the ID in the cell
// if the test is run multiple times, Postgres will increment the ID
const table = await project.popupContent.getByRole("row", { name: ids['id'] }).locator("..");
await expect(table).toBeVisible();

const feature = await project.identifyContentLocator(ids['id']);
// First row
await expect(table.locator('tr:nth-child(1) th')).toHaveText('id');
await expect(table.locator('tr:nth-child(1) td')).toHaveText(ids['id']);
await expect(feature.locator(`tr[data-field-name="id"] td`)).toHaveText(ids['id']);
///Second row
await expect(table.locator('tr:nth-child(2) > th')).toHaveText('field_in_dnd_form');
await expect(table.locator('tr:nth-child(2) > td')).toHaveText('value in DND form');
await expect(feature.locator(`tr[data-field-name="field_in_dnd_form"] td`)).toHaveText('value in DND form');
// Third row should be hidden
await expect(table.locator('tr:nth-child(3)')).toHaveClass('empty-data');
await expect(table.locator('tr:nth-child(3) > th')).toHaveText('field_not_in_dnd_form');
await expect(table.locator('tr:nth-child(3) > td')).toBeEmpty();
await expect(feature.locator(`tr[data-field-name="field_not_in_dnd_form"]`)).toHaveClass('empty-data');
await expect(feature.locator(`tr[data-field-name="field_not_in_dnd_form"] td`)).toBeEmpty();
});

test('With non spatial data creation, not remove data', async function ({ page }) {
Expand Down Expand Up @@ -85,14 +78,9 @@ test.describe(
await firstLine.click();

// Check the auto popup
await expect(popup.locator('tr:nth-child(1) > th')).toHaveText('id');
await expect(popup.locator('tr:nth-child(1) > td')).toHaveText('1');

await expect(popup.locator('tr:nth-child(2) > th')).toHaveText('field_in_dnd_form');
await expect(popup.locator('tr:nth-child(2) > td')).toHaveText('test_geom');

await expect(popup.locator('tr:nth-child(3) > th')).toHaveText('field_not_in_dnd_form');
await expect(popup.locator('tr:nth-child(3) > td')).toHaveText('test_geom');
await expect(popup.locator('tr[data-field-name="id"] td')).toHaveText('1');
await expect(popup.locator('tr[data-field-name="field_in_dnd_form"] td')).toHaveText('test_geom');
await expect(popup.locator('tr[data-field-name="field_not_in_dnd_form"] td')).toHaveText('test_geom');

// Assert data has not been removed after form submission without modification
await featureEdit.click();
Expand All @@ -101,14 +89,9 @@ test.describe(
// Check popup content again
// Fixme, strange, the test doesn't re-click on the row, so the test is false, because the popup is not refreshed
// Check the auto popup
await expect(popup.locator('tr:nth-child(1) > th')).toHaveText('id');
await expect(popup.locator('tr:nth-child(1) > td')).toHaveText('1');

await expect(popup.locator('tr:nth-child(2) > th')).toHaveText('field_in_dnd_form');
await expect(popup.locator('tr:nth-child(2) > td')).toHaveText('test_geom');

await expect(popup.locator('tr:nth-child(3) > th')).toHaveText('field_not_in_dnd_form');
await expect(popup.locator('tr:nth-child(3) > td')).toHaveText('test_geom');
await expect(popup.locator('tr[data-field-name="id"] td')).toHaveText('1');
await expect(popup.locator('tr[data-field-name="field_in_dnd_form"] td')).toHaveText('test_geom');
await expect(popup.locator('tr[data-field-name="field_not_in_dnd_form"] td')).toHaveText('test_geom');

// Assert data has changed after form submission with modification
await featureEdit.click();
Expand All @@ -122,14 +105,9 @@ test.describe(
await firstLine.first().click();

// Check popup content again
await expect(popup.locator('tr:nth-child(1) > th')).toHaveText('id');
await expect(popup.locator('tr:nth-child(1) > td')).toHaveText('1');

await expect(popup.locator('tr:nth-child(2) > th')).toHaveText('field_in_dnd_form');
await expect(popup.locator('tr:nth-child(2) > td')).toHaveText('modified');

await expect(popup.locator('tr:nth-child(3) > th')).toHaveText('field_not_in_dnd_form');
await expect(popup.locator('tr:nth-child(3) > td')).toHaveText('test_geom');
await expect(popup.locator('tr[data-field-name="id"] td')).toHaveText('1');
await expect(popup.locator('tr[data-field-name="field_in_dnd_form"] td')).toHaveText('modified');
await expect(popup.locator('tr[data-field-name="field_not_in_dnd_form"] td')).toHaveText('test_geom');

// Write back original data
// Fixme refresh database data?
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(`tr[data-field-name="${field}"] td`)).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(`tr[data-field-name="${field}"] td`)).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 7bad961

Please sign in to comment.