From 97cccb8f5e5cf4f1dd354e6ba103e202a469f20f Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Fri, 30 May 2025 19:40:13 +0300 Subject: [PATCH] Use map control labels in system tests --- test/application_system_test_case.rb | 4 ++ test/system/browse_test.rb | 5 +- test/system/create_note_test.rb | 12 +++-- test/system/history_test.rb | 4 +- test/system/index_test.rb | 73 ++++++++++++++++++++++------ test/system/site_test.rb | 27 ++++++---- 6 files changed, 96 insertions(+), 29 deletions(-) diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index f7769426c..3e7de58b3 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -9,6 +9,10 @@ end class ApplicationSystemTestCase < ActionDispatch::SystemTestCase include ActionMailer::TestCase::ClearTestDeliveries + Capybara.configure do |config| + config.enable_aria_label = true + end + driven_by :selenium, :using => Settings.system_test_headless ? :headless_firefox : :firefox do |options| options.add_preference("intl.accept_languages", "en") options.binary = Settings.system_test_firefox_binary if Settings.system_test_firefox_binary diff --git a/test/system/browse_test.rb b/test/system/browse_test.rb index 3faf3b75f..7505b581d 100644 --- a/test/system/browse_test.rb +++ b/test/system/browse_test.rb @@ -16,7 +16,10 @@ class BrowseTest < ApplicationSystemTestCase visit node_path(node) - find("#map [aria-label='Share']").click + within "#map" do + click_on "Share" + end + share_url = find_by_id("long_input").value assert_match %r{map=\d+/59\.\d+/29\.\d+}, share_url end diff --git a/test/system/create_note_test.rb b/test/system/create_note_test.rb index 410d5dfb7..8fea218bf 100644 --- a/test/system/create_note_test.rb +++ b/test/system/create_note_test.rb @@ -41,14 +41,18 @@ class CreateNoteTest < ApplicationSystemTestCase assert_button "Add Note", :disabled => false end - find(".control-button.zoomout").click + within "#map" do + click_on "Zoom Out" + end within_sidebar do assert_content "Zoom in to add a note" assert_button "Add Note", :disabled => true end - find(".control-button.zoomin").click + within "#map" do + click_on "Zoom In" + end within_sidebar do assert_no_content "Zoom in to add a note" @@ -74,7 +78,9 @@ class CreateNoteTest < ApplicationSystemTestCase assert_button "Add Note", :disabled => true end - find(".control-button.zoomin").click + within "#map" do + click_on "Zoom In" + end within_sidebar do assert_no_content "Zoom in to add a note" diff --git a/test/system/history_test.rb b/test/system/history_test.rb index 21d0eb438..260ba3038 100644 --- a/test/system/history_test.rb +++ b/test/system/history_test.rb @@ -129,7 +129,9 @@ class HistoryTest < ApplicationSystemTestCase assert_no_link "changeset-close-to-fives" end - find("#map [aria-label='Zoom Out']").click(:shift) + within "#map" do + find_link("Zoom Out").click(:shift) + end within_sidebar do assert_link "changeset-at-fives" diff --git a/test/system/index_test.rb b/test/system/index_test.rb index d30b928df..f9b4c2d50 100644 --- a/test/system/index_test.rb +++ b/test/system/index_test.rb @@ -3,36 +3,70 @@ require "application_system_test_case" class IndexTest < ApplicationSystemTestCase test "should remove and add an overlay on share button click" do node = create(:node) + visit node_path(node) + assert_selector "#content.overlay-right-sidebar" - find(".control-share a").click + + within "#map" do + click_on "Share" + end + assert_no_selector "#content.overlay-right-sidebar" - find(".control-share a").click + + within "#map" do + click_on "Share" + end + assert_selector "#content.overlay-right-sidebar" end test "should add an overlay on close" do node = create(:node) + visit node_path(node) - find(".control-share a").click + + within "#map" do + click_on "Share" + end + assert_no_selector "#content.overlay-right-sidebar" - find("#map-ui .btn-close").click + + within "#map-ui" do + click_on "Close" + end + assert_selector "#content.overlay-right-sidebar" end test "should not add overlay when not closing right menu popup" do node = create(:node) + visit node_path(node) - find(".control-share a").click - find(".control-key a").click + within "#map" do + click_on "Share" + click_on "Map Key" + end + assert_no_selector "#content.overlay-right-sidebar" - find(".control-layers a").click + + within "#map" do + click_on "Layers" + end + assert_no_selector "#content.overlay-right-sidebar" - find(".control-key a").click + + within "#map" do + click_on "Map Key" + end + assert_no_selector "#content.overlay-right-sidebar" - find(".control-key a").click + within "#map" do + click_on "Map Key" + end + assert_selector "#content.overlay-right-sidebar" end @@ -64,12 +98,23 @@ class IndexTest < ApplicationSystemTestCase visit root_path(:anchor => "map=15/1/1") # view place of hidden note in case it is not rendered during note_path(hidden_note) visit note_path(hidden_note) - find(".leaflet-control.control-layers .control-button").click - find("#map-ui .overlay-layers .form-check-label", :text => "Map Notes").click - visible_note_marker = find(".leaflet-marker-icon[title=this-is-a-visible-note]") - assert_selector "#sidebar", :text => "Hidden Note Description" + within "#map" do + click_on "Layers" + end + within "#map-ui" do + check "Map Notes" + end + + within_sidebar do + assert_text "Hidden Note Description" + end + + visible_note_marker = find(".leaflet-marker-icon[title=this-is-a-visible-note]") visible_note_marker.click - assert_selector "#sidebar", :text => "Visible Note Description" + + within_sidebar do + assert_text "Visible Note Description" + end end end diff --git a/test/system/site_test.rb b/test/system/site_test.rb index 3ae9816f8..de37912f6 100644 --- a/test/system/site_test.rb +++ b/test/system/site_test.rb @@ -82,15 +82,22 @@ class SiteTest < ApplicationSystemTestCase test "notes layer tooltip appears on zoom out" do visit "/#map=10/40/-4" # depends on zoom levels where notes are allowed - find(".control-layers .control-button").click - notes_checkbox = find(".layers-ui .overlay-layers .form-check", :text => "Map Notes") - assert_not_matches_css notes_checkbox, ".disabled" - notes_checkbox.hover # try to trigger disabled tooltip - zoomout = find(".control-button.zoomout") - zoomout.hover # un-hover the tooltip that's being tested - zoomout.click(:shift) - assert_matches_css notes_checkbox, ".disabled" - notes_checkbox.hover - assert_selector ".tooltip", :text => "Zoom in" + within "#map" do + click_on "Layers" + end + within "#map-ui" do + assert_field "Map Notes" + find_field("Map Notes").hover # try to trigger disabled tooltip + end + within "#map" do + zoom_out = find_link("Zoom Out") + zoom_out.hover # un-hover the tooltip that's being tested + zoom_out.click(:shift) + end + within "#map-ui" do + assert_field "Map Notes", :disabled => true + find_field("Map Notes", :disabled => true).hover + end + assert_selector ".tooltip", :text => "Zoom in to see" end end -- 2.39.5