From 53620c62d33eea4d7abb99ed70b4d6365f99d8c2 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Wed, 21 Aug 2024 15:19:00 +0300 Subject: [PATCH 1/1] Test if closing sidebar removes directions popup --- test/system/directions_test.rb | 65 ++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 test/system/directions_test.rb 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 -- 2.39.5