Update the tests and remove cancel edits

Co-authored-by: Alexis Métaireau <alexis@notmyidea.org>
This commit is contained in:
Yohan Boniface 2025-03-14 10:36:26 +01:00
parent 75c71a9990
commit 3ad676ed59
7 changed files with 12 additions and 39 deletions

View file

@ -553,9 +553,7 @@ export default class Umap extends ServerStored {
used = false used = false
break break
} }
if (SAVEMANAGER.isDirty) { this.sync._undoManager.undo()
this.askForReset()
}
break break
case 'm': case 'm':
this._leafletMap.editTools.startMarker() this._leafletMap.editTools.startMarker()
@ -1161,21 +1159,6 @@ export default class Umap extends ServerStored {
}) })
} }
reset() {
if (this._leafletMap.editTools) this._leafletMap.editTools.stopDrawing()
this.resetProperties()
this.datalayersIndex = [].concat(this._datalayersIndex_bk)
// Iter over all datalayers, including deleted if any.
for (const datalayer of Object.values(this.datalayers)) {
if (datalayer.isDeleted) datalayer.connectToMap()
if (datalayer.isDirty) datalayer.reset()
}
this.ensurePanesOrder()
this._leafletMap.initTileLayers()
this.onDataLayersChanged()
this.isDirty = !this.id
}
async save() { async save() {
this.rules.commit() this.rules.commit()
const geojson = { const geojson = {
@ -1302,16 +1285,6 @@ export default class Umap extends ServerStored {
this._leafletMap.fire(name) this._leafletMap.fire(name)
} }
askForReset(e) {
if (this.getProperty('syncEnabled')) return
this.dialog
.confirm(translate('Are you sure you want to cancel your changes?'))
.then(() => {
this.reset()
this.disableEdit()
})
}
async initSyncEngine() { async initSyncEngine() {
// this.properties.websocketEnabled is set by the server admin // this.properties.websocketEnabled is set by the server admin
if (this.properties.websocketEnabled === false) return if (this.properties.websocketEnabled === false) return

View file

@ -629,6 +629,7 @@ U.Editable = L.Editable.extend({
const line = new U.LineString(this._umap, datalayer, { const line = new U.LineString(this._umap, datalayer, {
geometry: { type: 'LineString', coordinates: [] }, geometry: { type: 'LineString', coordinates: [] },
}) })
line._just_married = true
return line.ui return line.ui
}, },
@ -637,6 +638,7 @@ U.Editable = L.Editable.extend({
const poly = new U.Polygon(this._umap, datalayer, { const poly = new U.Polygon(this._umap, datalayer, {
geometry: { type: 'Polygon', coordinates: [] }, geometry: { type: 'Polygon', coordinates: [] },
}) })
poly._just_married = true
return poly.ui return poly.ui
}, },
@ -737,6 +739,8 @@ U.Editable = L.Editable.extend({
// Leaflet.Editable will delete the drawn shape if invalid // Leaflet.Editable will delete the drawn shape if invalid
// (eg. line has only one drawn point) // (eg. line has only one drawn point)
// So let's check if the layer has no more shape // So let's check if the layer has no more shape
event.layer.feature.pullGeometry(false)
console.log('onEscape', event.layer.feature.hasGeom())
if (!event.layer.feature.hasGeom()) { if (!event.layer.feature.hasGeom()) {
event.layer.feature.del() event.layer.feature.del()
} else { } else {

View file

@ -350,8 +350,7 @@ def test_should_redraw_list_on_feature_delete(live_server, openmap, page, bootst
buttons.first.click() buttons.first.click()
page.locator("dialog").get_by_role("button", name="OK").click() page.locator("dialog").get_by_role("button", name="OK").click()
expect(buttons).to_have_count(2) expect(buttons).to_have_count(2)
page.get_by_role("button", name="Cancel edits").click() page.get_by_role("button", name="Undo").click()
page.locator("dialog").get_by_role("button", name="OK").click()
expect(buttons).to_have_count(3) expect(buttons).to_have_count(3)

View file

@ -64,8 +64,7 @@ def test_cancel_deleting_datalayer_should_restore(
page.get_by_role("button", name="OK").click() page.get_by_role("button", name="OK").click()
expect(markers).to_have_count(0) expect(markers).to_have_count(0)
expect(page.get_by_text("test datalayer")).to_be_hidden() expect(page.get_by_text("test datalayer")).to_be_hidden()
page.get_by_role("button", name="Cancel edits").click() page.get_by_role("button", name="Undo").click()
page.locator("dialog").get_by_role("button", name="OK").click()
expect(markers).to_have_count(1) expect(markers).to_have_count(1)
expect(page.locator(".umap-browser").get_by_text("test datalayer")).to_be_visible() expect(page.locator(".umap-browser").get_by_text("test datalayer")).to_be_visible()

View file

@ -117,8 +117,7 @@ def test_should_reset_style_on_cancel(live_server, openmap, page, bootstrap):
expect(page.locator(".leaflet-overlay-pane path[fill='GoldenRod']")).to_have_count( expect(page.locator(".leaflet-overlay-pane path[fill='GoldenRod']")).to_have_count(
1 1
) )
page.get_by_role("button", name="Cancel edits").click() page.get_by_role("button", name="Undo").click()
page.locator("dialog").get_by_role("button", name="OK").click()
expect(page.locator(".leaflet-overlay-pane path[fill='DarkBlue']")).to_have_count(1) expect(page.locator(".leaflet-overlay-pane path[fill='DarkBlue']")).to_have_count(1)

View file

@ -294,7 +294,7 @@ def test_should_display_alert_on_conflict(context, live_server, datalayer, openm
page_two.locator('input[name="name"]').fill("name from page two") page_two.locator('input[name="name"]').fill("name from page two")
# Map should be in dirty status # Map should be in dirty status
expect(page_two.get_by_text("Cancel edits")).to_be_visible() expect(page_two.get_by_text("Undo")).to_be_visible()
with page_two.expect_response(re.compile(r".*/datalayer/update/.*")): with page_two.expect_response(re.compile(r".*/datalayer/update/.*")):
page_two.get_by_role("button", name="Save").click() page_two.get_by_role("button", name="Save").click()
@ -306,7 +306,7 @@ def test_should_display_alert_on_conflict(context, live_server, datalayer, openm
# We should have an alert with some actions # We should have an alert with some actions
expect(page_two.get_by_text("Whoops! Other contributor(s) changed")).to_be_visible() expect(page_two.get_by_text("Whoops! Other contributor(s) changed")).to_be_visible()
# Map should still be in dirty status # Map should still be in dirty status
expect(page_two.get_by_text("Cancel edits")).to_be_visible() expect(page_two.get_by_text("Undo")).to_be_visible()
# Override data from page two # Override data from page two
with page_two.expect_response(re.compile(r".*/datalayer/update/.*")): with page_two.expect_response(re.compile(r".*/datalayer/update/.*")):
@ -317,4 +317,4 @@ def test_should_display_alert_on_conflict(context, live_server, datalayer, openm
data = json.loads(Path(saved.geojson.path).read_text()) data = json.loads(Path(saved.geojson.path).read_text())
assert data["features"][0]["properties"]["name"] == "name from page two" assert data["features"][0]["properties"]["name"] == "name from page two"
# Map should not be in dirty status anymore # Map should not be in dirty status anymore
expect(page_two.get_by_text("Cancel edits")).to_be_hidden() expect(page_two.get_by_text("Undo")).to_be_hidden()

View file

@ -16,8 +16,7 @@ def test_reseting_map_would_remove_from_save_queue(
page.on("request", register_request) page.on("request", register_request)
page.locator('input[name="name"]').click() page.locator('input[name="name"]').click()
page.locator('input[name="name"]').fill("new name") page.locator('input[name="name"]').fill("new name")
page.get_by_role("button", name="Cancel edits").click() page.get_by_role("button", name="Undo").click()
page.get_by_role("button", name="OK").click()
page.wait_for_timeout(500) page.wait_for_timeout(500)
page.get_by_role("button", name="Edit").click() page.get_by_role("button", name="Edit").click()
page.get_by_role("button", name="Manage layers").click() page.get_by_role("button", name="Manage layers").click()