]> git.openstreetmap.org Git - rails.git/blob - test/system/directions_test.rb
Create template for sidebar close controls
[rails.git] / test / system / directions_test.rb
1 require "application_system_test_case"
2
3 class DirectionsSystemTest < ApplicationSystemTestCase
4   test "removes popup on sidebar close" do
5     visit directions_path
6     stub_straight_routing(:start_instruction => "Start popup text")
7
8     fill_in "route_from", :with => "60 30"
9     fill_in "route_to", :with => "61 31"
10     click_on "Go"
11
12     within "#map" do
13       assert_no_content "Start popup text"
14     end
15
16     within_sidebar do
17       direction_entry = find "td", :text => "Start popup text"
18       direction_entry.click
19     end
20
21     within "#map" do
22       assert_content "Start popup text"
23     end
24
25     find("#sidebar .sidebar-close-controls button[aria-label='Close']").click
26
27     within "#map" do
28       assert_no_content "Start popup text"
29     end
30   end
31
32   private
33
34   def stub_straight_routing(start_instruction: "Start here", finish_instruction: "Finish there")
35     stub_routing <<~CALLBACK
36       const distance = points[0].distanceTo(points[1]);
37       const time = distance * 30;
38       return Promise.resolve({
39         line: points,
40         steps: [
41           [points[0],  8, "<b>1.</b> #{start_instruction}", distance, points],
42           [points[1], 14, "<b>2.</b> #{finish_instruction}", 0, [points[1]]]
43         ],
44         distance,
45         time
46       });
47     CALLBACK
48   end
49
50   def stub_routing(callback_code)
51     execute_script <<~SCRIPT
52       $(() => {
53         for (const engine of OSM.Directions.engines) {
54           engine.getRoute = (points, signal) => {
55               #{callback_code}
56           };
57         }
58       });
59     SCRIPT
60   end
61 end