]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/5603'
authorTom Hughes <tom@compton.nu>
Wed, 5 Feb 2025 19:14:02 +0000 (19:14 +0000)
committerTom Hughes <tom@compton.nu>
Wed, 5 Feb 2025 19:14:02 +0000 (19:14 +0000)
app/assets/javascripts/index/directions.js
test/system/directions_test.rb [new file with mode: 0644]

index acba02d837e834ee77469141477e2e3048092958..681479e52aaf05da13fdbd7b4891aea4c2e17809 100644 (file)
@@ -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 (file)
index 0000000..08f5cb8
--- /dev/null
@@ -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, "<b>1.</b> #{start_instruction}", distance, points],
+          [points[1], 14, "<b>2.</b> #{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