1 require "application_system_test_case"
3 class DirectionsSystemTest < ApplicationSystemTestCase
4 test "updates route output on mode change" do
6 stub_straight_routing(:start_instruction => "Start popup text")
8 find_by_id("route_from").set("60 30").send_keys :enter
9 find_by_id("route_to").set("61 31").send_keys :enter
12 assert_content "Start popup text (car)"
15 choose "bicycle", :allow_label_click => true
18 assert_content "Start popup text (bicycle)"
22 test "swaps route endpoints on reverse button click" do
24 stub_straight_routing(:start_instruction => "Start popup text")
26 find_by_id("route_from").set("60 30").send_keys :enter
27 find_by_id("route_to").set("61 31").send_keys :enter
29 click_on :class => "reverse_directions"
31 start_location = find_by_id("route_from").value
32 finish_location = find_by_id("route_to").value
34 click_on :class => "reverse_directions"
36 assert_equal finish_location, find_by_id("route_from").value
37 assert_equal start_location, find_by_id("route_to").value
40 test "removes popup on sidebar close" do
42 stub_straight_routing(:start_instruction => "Start popup text")
44 find_by_id("route_from").set("60 30").send_keys :enter
45 find_by_id("route_to").set("61 31").send_keys :enter
48 assert_no_content "Start popup text"
52 direction_entry = find "td", :text => "Start popup text"
57 assert_content "Start popup text"
60 find("#sidebar .sidebar-close-controls button[aria-label='Close']").click
63 assert_no_content "Start popup text"
69 def stub_straight_routing(start_instruction: "Start here", finish_instruction: "Finish there")
70 stub_routing <<~CALLBACK
71 const distance = points[0].distanceTo(points[1]);
72 const time = distance * 30;
73 return Promise.resolve({
76 ["start", `<b>1.</b> #{start_instruction} (${this.mode})`, distance, points],
77 ["destination", `<b>2.</b> #{finish_instruction} (${this.mode})`, 0, [points[1]]]
85 def stub_routing(callback_code)
86 execute_script <<~SCRIPT
88 for (const engine of OSM.Directions.engines) {
89 engine.getRoute = function(points, signal) {