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