From 288f62cdd2041af28ba17904987d26877979c153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 17 Nov 2025 04:24:08 +0100 Subject: [PATCH] Use coordinates as marker labels when there's only one mappable When editing/showing a proposal or an investment, the most relevant information regarding the marker are the coordinates. The title of the proposal or investment is redundant because we already know the marker is about that proposal/investment. There's one problem with this approach, though: when editing a proposal or an investment, the aria-label of the marker isn't updated automatically when we move the marker to a different place. This behaviour will only affect people who use both a screen reader and a mouse, since keyboard users can't change the position of the marker in the first place. We'll deal with this issue when we make it possible to change the position of a marker using the keyboard. --- app/components/shared/map_location_component.rb | 2 +- .../shared/map_location_component_spec.rb | 17 ++--------------- spec/shared/system/mappable.rb | 5 ++++- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/app/components/shared/map_location_component.rb b/app/components/shared/map_location_component.rb index bd59e52db..11bcbccba 100644 --- a/app/components/shared/map_location_component.rb +++ b/app/components/shared/map_location_component.rb @@ -62,7 +62,7 @@ class Shared::MapLocationComponent < ApplicationComponent marker_investments_coordinates: investments_coordinates, marker_latitude: map_location.latitude.presence, marker_longitude: map_location.longitude.presence, - marker_title: map_location.title.presence || marker_coordinates_text, + marker_title: marker_coordinates_text, marker_clustering: feature?("map.feature.marker_clustering"), geozones: geozones_data }.merge(input_selectors) diff --git a/spec/components/shared/map_location_component_spec.rb b/spec/components/shared/map_location_component_spec.rb index be8b045ba..f16a85e31 100644 --- a/spec/components/shared/map_location_component_spec.rb +++ b/spec/components/shared/map_location_component_spec.rb @@ -30,7 +30,7 @@ describe Shared::MapLocationComponent do end describe "marker title" do - it "uses the mappable title when there's a mappable with a title" do + it "uses the coordinates when there's a mappable" do map_location = build( :map_location, proposal: Proposal.new(title: "Meet me here"), @@ -40,7 +40,7 @@ describe Shared::MapLocationComponent do render_inline Shared::MapLocationComponent.new(map_location) - expect(page).to have_css "[data-marker-title='Meet me here']" + expect(page).to have_css "[data-marker-title='Latitude: 25.25. Longitude: 13.14']" end it "uses the coordinates when there's no mappable" do @@ -51,19 +51,6 @@ describe Shared::MapLocationComponent do expect(page).to have_css "[data-marker-title='Latitude: 25.25. Longitude: 13.14']" end - it "uses the coordinates when the mappable has an empty title" do - map_location = build( - :map_location, - proposal: Proposal.new(title: ""), - latitude: "25.25", - longitude: "13.14" - ) - - render_inline Shared::MapLocationComponent.new(map_location) - - expect(page).to have_css "[data-marker-title='Latitude: 25.25. Longitude: 13.14']" - end - it "is not present when the map location isn't available" do map_location = build(:map_location, latitude: "25.25", longitude: nil) diff --git a/spec/shared/system/mappable.rb b/spec/shared/system/mappable.rb index b0d33be04..1b130a46f 100644 --- a/spec/shared/system/mappable.rb +++ b/spec/shared/system/mappable.rb @@ -175,6 +175,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, visit send(mappable_edit_path, id: mappable.id) expect(page).to have_content "Navigate the map to the location and place the marker." + expect(page).to have_css ".map-icon[aria-label='Latitude: 51.48. Longitude: 0.0']" expect(page).to have_field "#{mappable_factory_name}_map_location_attributes_latitude", type: :hidden, with: "51.48" expect(page).to have_field "#{mappable_factory_name}_map_location_attributes_longitude", type: :hidden, @@ -255,8 +256,10 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, do_login_for user, management: management if management visit send(mappable_show_path, arguments) + label = "Latitude: #{map_location.latitude}. Longitude: #{map_location.longitude}" + within ".map-location" do - expect(page).to have_css ".map-icon[aria-label='#{mappable.title}']" + expect(page).to have_css ".map-icon[aria-label='#{label}']" end end