From: Tom Hughes Date: Wed, 5 Feb 2025 19:14:02 +0000 (+0000) Subject: Merge remote-tracking branch 'upstream/pull/5603' X-Git-Tag: live~25 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/361dcbb1dfd05c09034ed92da9bbf4305fcb8da9?hp=cfd2c5dddab88372905a23f7b9680df58feb9b53 Merge remote-tracking branch 'upstream/pull/5603' --- diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index acba02d83..681479e52 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -227,6 +227,7 @@ OSM.Directions = function (map) { directionsCloseButton.on("click", function () { map.removeLayer(polyline); $("#sidebar_content").html(""); + popup.close(); map.setSidebarOverlaid(true); // TODO: collapse width of sidebar back to previous }); diff --git a/test/system/directions_test.rb b/test/system/directions_test.rb new file mode 100644 index 000000000..08f5cb8e3 --- /dev/null +++ b/test/system/directions_test.rb @@ -0,0 +1,65 @@ +require "application_system_test_case" + +class DirectionsSystemTest < ApplicationSystemTestCase + test "removes popup on sidebar close" do + visit directions_path + stub_straight_routing(:start_instruction => "Start popup text") + + fill_in "route_from", :with => "60 30" + fill_in "route_to", :with => "61 31" + click_on "Go" + + within "#map" do + assert_no_content "Start popup text" + end + + within_sidebar do + direction_entry = find "td", :text => "Start popup text" + direction_entry.click + end + + within "#map" do + assert_content "Start popup text" + end + + within_sidebar do + find("button[aria-label='Close']").click + end + + within "#map" do + assert_no_content "Start popup text" + end + end + + private + + def stub_straight_routing(start_instruction: "Start here", finish_instruction: "Finish there") + stub_routing <<~CALLBACK + const distance = points[0].distanceTo(points[1]); + const time = distance * 30; + callback(false, { + line: points, + steps: [ + [points[0], 8, "1. #{start_instruction}", distance, points], + [points[1], 14, "2. #{finish_instruction}", 0, [points[1]]] + ], + distance, + time + }); + CALLBACK + end + + def stub_routing(callback_code) + execute_script <<~SCRIPT + $(() => { + for (const engine of OSM.Directions.engines) { + engine.getRoute = (points, callback) => { + setTimeout(() => { + #{callback_code} + }); + }; + } + }); + SCRIPT + end +end