Skip to content

Commit

Permalink
Tests - Use more data-attributes to read in the auto popup
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Feb 6, 2025
1 parent bb9b553 commit b84269e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 40 deletions.
4 changes: 2 additions & 2 deletions lizmap/modules/view/templates/popupDefaultContent.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<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 data-field-name="{$attribute['name']}">{$attribute['name']|featurepopup:$attribute['value'],$repository,$project,$remoteStorageProfile}</td>
<td>{$attribute['name']|featurepopup:$attribute['value'],$repository,$project,$remoteStorageProfile}</td>
</tr>
{/if}
{/foreach}
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
4 changes: 2 additions & 2 deletions tests/end2end/playwright/editing-geometry.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ test.describe('Geometry editing',
// 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 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');
Expand All @@ -71,7 +71,7 @@ test.describe('Geometry editing',
// 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");
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();
Expand Down

0 comments on commit b84269e

Please sign in to comment.