From e1ae64c5d3bb415859c0dc21d83188df006be1a6 Mon Sep 17 00:00:00 2001 From: Marwin Hochfelsner <50826859+hlfan@users.noreply.github.com> Date: Sat, 3 May 2025 00:36:38 +0200 Subject: [PATCH] Add tests for directions --- test/system/directions_test.rb | 47 +++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/test/system/directions_test.rb b/test/system/directions_test.rb index 8ff78736b..4122be249 100644 --- a/test/system/directions_test.rb +++ b/test/system/directions_test.rb @@ -1,13 +1,48 @@ require "application_system_test_case" class DirectionsSystemTest < ApplicationSystemTestCase + test "updates route output on mode change" do + visit directions_path + stub_straight_routing(:start_instruction => "Start popup text") + + find_by_id("route_from").set("60 30").send_keys :enter + find_by_id("route_to").set("61 31").send_keys :enter + + within "#sidebar" do + assert_content "Start popup text (car)" + end + + choose "bicycle", :allow_label_click => true + + within "#sidebar" do + assert_content "Start popup text (bicycle)" + end + end + + test "swaps route endpoints on reverse button click" do + visit directions_path + stub_straight_routing(:start_instruction => "Start popup text") + + find_by_id("route_from").set("60 30").send_keys :enter + find_by_id("route_to").set("61 31").send_keys :enter + + click_on :class => "reverse_directions" + + start_location = find_by_id("route_from").value + finish_location = find_by_id("route_to").value + + click_on :class => "reverse_directions" + + assert_equal finish_location, find_by_id("route_from").value + assert_equal start_location, find_by_id("route_to").value + end + 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" + find_by_id("route_from").set("60 30").send_keys :enter + find_by_id("route_to").set("61 31").send_keys :enter within "#map" do assert_no_content "Start popup text" @@ -38,8 +73,8 @@ class DirectionsSystemTest < ApplicationSystemTestCase return Promise.resolve({ line: points, steps: [ - ["start", "1. #{start_instruction}", distance, points], - ["destination", "2. #{finish_instruction}", 0, [points[1]]] + ["start", `1. #{start_instruction} (${this.mode})`, distance, points], + ["destination", `2. #{finish_instruction} (${this.mode})`, 0, [points[1]]] ], distance, time @@ -51,7 +86,7 @@ class DirectionsSystemTest < ApplicationSystemTestCase execute_script <<~SCRIPT $(() => { for (const engine of OSM.Directions.engines) { - engine.getRoute = (points, signal) => { + engine.getRoute = function(points, signal) { #{callback_code} }; } -- 2.39.5