]> git.openstreetmap.org Git - rails.git/blob - test/system/search_test.rb
Add frozen_string_literal comments to ruby files
[rails.git] / test / system / search_test.rb
1 # frozen_string_literal: true
2
3 require "application_system_test_case"
4
5 class SearchTest < ApplicationSystemTestCase
6   def setup
7     stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/search\?})
8       .to_return(:status => 404)
9
10     stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/reverse\?})
11       .to_return(:status => 404)
12
13     stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/reverse\?.*zoom=$})
14       .to_return(:status => 400, :body => <<-BODY)
15         <?xml version="1.0" encoding="UTF-8"?>
16         <error>
17           <code>400</code>
18           <message>Parameter 'zoom' must be a number.</message>
19         </error>
20       BODY
21
22     stub_request(:get, %r{^https://nominatim\.openstreetmap\.org/reverse\?.*zoom=15$})
23       .to_return(:status => 200, :body => <<-BODY)
24         <?xml version="1.0" encoding="UTF-8"?>
25         <reversegeocode timestamp="Sun, 01 Mar 15 22:49:45 +0000" attribution="Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright" querystring="accept-language=&amp;lat=51.76320&amp;lon=-0.00760&amp;zoom=15">
26           <result place_id="150696" osm_type="node" osm_id="28825933" ref="Broxbourne" lat="51.7465723" lon="-0.0190782">Broxbourne, Hertfordshire, East of England, England, United Kingdom</result>
27           <addressparts>
28             <suburb>Broxbourne</suburb>
29             <city>Broxbourne</city>
30             <county>Hertfordshire</county>
31             <state_district>East of England</state_district>
32             <state>England</state>
33             <country>United Kingdom</country>
34             <country_code>gb</country_code>
35           </addressparts>
36         </reversegeocode>
37       BODY
38   end
39
40   test "click on 'where is this' sets search input value and makes reverse geocoding request with zoom" do
41     visit "/#map=15/51.76320/-0.00760"
42
43     assert_field "Search", :with => ""
44     click_on "Where is this?"
45
46     assert_field "Search", :with => "51.76320, -0.00760"
47     assert_link "Broxbourne, Hertfordshire, East of England, England, United Kingdom"
48   end
49
50   test "'Show address' from context menu makes reverse geocoding request with zoom" do
51     visit "/#map=15/51.76320/-0.00760"
52
53     find_by_id("map").right_click
54     click_on "Show address"
55
56     assert_link "Broxbourne, Hertfordshire, East of England, England, United Kingdom"
57   end
58
59   test "query search link sets search input value" do
60     visit search_path(:query => "2.341, 7.896")
61
62     assert_field "Search", :with => "2.341, 7.896"
63   end
64
65   test "latlon search link sets search input value" do
66     visit search_path(:lat => "4.321", :lon => "9.876")
67
68     assert_field "Search", :with => "4.321, 9.876"
69   end
70
71   test "search adds viewbox param to Nominatim link" do
72     visit "/"
73
74     fill_in "query", :with => "paris"
75     click_on "Go"
76
77     within_sidebar do
78       assert_link "Nominatim", :href => /&viewbox=/
79     end
80   end
81
82   test "search adds zoom param to reverse Nominatim link" do
83     visit "/#map=7/1.234/6.789"
84
85     fill_in "query", :with => "60 30"
86     click_on "Go"
87
88     within_sidebar do
89       assert_link "Nominatim", :href => /&zoom=7/
90     end
91   end
92 end