Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/pull/5603'
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Feb 5, 2025
2 parents cfd2c5d + 53620c6 commit 361dcbb
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/index/directions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand Down
65 changes: 65 additions & 0 deletions test/system/directions_test.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 361dcbb

Please sign in to comment.