From f8d08ea53919d06c98d92241603f899c02b8af34 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Fri, 22 Mar 2024 10:36:09 +0100 Subject: [PATCH] chore: more pw tests --- umap/tests/integration/test_browser.py | 40 ++++++++++++++++++++++++ umap/tests/integration/test_owned_map.py | 12 +++++++ 2 files changed, 52 insertions(+) diff --git a/umap/tests/integration/test_browser.py b/umap/tests/integration/test_browser.py index bc1a0282..7f8dde35 100644 --- a/umap/tests/integration/test_browser.py +++ b/umap/tests/integration/test_browser.py @@ -291,3 +291,43 @@ def test_should_use_color_variable(live_server, map, page): expect(features.nth(1)).to_have_css("background-color", "rgb(139, 0, 0)") # DarkBlue (default color) expect(features.nth(2)).to_have_css("background-color", "rgb(0, 0, 139)") + + +def test_should_allow_to_toggle_datalayer_visibility(live_server, map, page, bootstrap): + page.goto(f"{live_server.url}{map.get_absolute_url()}") + markers = page.locator(".leaflet-marker-icon") + paths = page.locator(".leaflet-overlay-pane path") + expect(markers).to_have_count(1) + expect(paths).to_have_count(2) + toggle = page.locator('#umap-ui-container').get_by_title("Show/hide layer") + toggle.click() + expect(markers).to_have_count(0) + expect(paths).to_have_count(0) + + +def test_should_have_edit_buttons_in_edit_mode(live_server, map, page, bootstrap): + # Faster than doing a login + map.edit_status = Map.ANONYMOUS + map.save() + page.goto(f"{live_server.url}{map.get_absolute_url()}") + browser = page.locator('#umap-ui-container') + edit_layer = browser.get_by_title("Edit", exact=True) + in_table = browser.get_by_title("Edit properties in a table") + delete_layer = browser.get_by_title("Delete layer") + edit_feature = browser.get_by_title("Edit this feature") + delete_feature = browser.get_by_title("Delete this feature") + expect(edit_layer).to_be_hidden() + expect(in_table).to_be_hidden() + expect(delete_layer).to_be_hidden() + # Does not work + # to_have_count does not seem to case about the elements being visible or not + # and to_be_hidden is not happy if the selector resolve to more than on element + # expect(edit_feature).to_have_count(0) + # expect(delete_feature).to_be_hidden() + # Switch to edit mode + page.get_by_role("button", name="Edit").click() + expect(edit_layer).to_be_visible() + expect(in_table).to_be_visible() + expect(delete_layer).to_be_visible() + expect(edit_feature).to_have_count(3) + expect(delete_feature).to_have_count(3) diff --git a/umap/tests/integration/test_owned_map.py b/umap/tests/integration/test_owned_map.py index 6316940b..78daff60 100644 --- a/umap/tests/integration/test_owned_map.py +++ b/umap/tests/integration/test_owned_map.py @@ -134,6 +134,18 @@ def test_owner_has_delete_map_button(map, live_server, login): advanced.click() delete = page.get_by_role("button", name="Delete", exact=True) expect(delete).to_be_visible() + dialog_shown = False + + def handle_dialog(dialog): + dialog.accept() + nonlocal dialog_shown + dialog_shown = True + + page.on("dialog", handle_dialog) + with page.expect_navigation(): + delete.click() + assert dialog_shown + assert Map.objects.all().count() == 0 def test_editor_do_not_have_delete_map_button(map, live_server, login, user):