]> git.openstreetmap.org Git - rails.git/blob - test/system/element_current_version_test.rb
Move way ui tests to system tests
[rails.git] / test / system / element_current_version_test.rb
1 require "application_system_test_case"
2
3 class ElementCurrentVersionTest < ApplicationSystemTestCase
4   test "shows a node with one version" do
5     node = create(:node, :lat => 60, :lon => 30)
6
7     visit node_path(node)
8
9     within_sidebar do
10       assert_css "h2", :text => "Node: #{node.id}"
11       within "h4", :text => "Version #1" do
12         assert_link "1", :href => old_node_path(node, 1)
13       end
14       assert_text(/Location: 60\.\d+, 30\.\d+/)
15       assert_no_text "Deleted"
16
17       assert_link "Download XML", :href => api_node_path(node)
18       assert_link "View History", :href => node_history_path(node)
19       assert_no_link "View Unredacted History"
20     end
21   end
22
23   test "shows a way with one version" do
24     way = create(:way)
25
26     visit way_path(way)
27
28     within_sidebar do
29       assert_css "h2", :text => "Way: #{way.id}"
30       within "h4", :text => "Version #1" do
31         assert_link "1", :href => old_way_path(way, 1)
32       end
33       assert_no_text "Deleted"
34
35       assert_link "Download XML", :href => api_way_path(way)
36       assert_link "View History", :href => way_history_path(way)
37       assert_no_link "View Unredacted History"
38     end
39   end
40
41   test "shows a node with two versions" do
42     node = create(:node, :with_history, :lat => 60, :lon => 30, :version => 2)
43
44     visit node_path(node)
45
46     within_sidebar do
47       assert_css "h2", :text => "Node: #{node.id}"
48       within "h4", :text => "Version #2" do
49         assert_link "2", :href => old_node_path(node, 2)
50       end
51       assert_text(/Location: 60\.\d+, 30\.\d+/)
52       assert_no_text "Deleted"
53
54       assert_link "Download XML", :href => api_node_path(node)
55       assert_link "View History", :href => node_history_path(node)
56       assert_no_link "View Unredacted History"
57       assert_link "Version #1", :href => old_node_path(node, 1)
58       assert_link "Version #2", :href => old_node_path(node, 2)
59     end
60   end
61
62   test "shows a way with two versions" do
63     way = create(:way, :version => 2)
64
65     visit way_path(way)
66
67     within_sidebar do
68       assert_css "h2", :text => "Way: #{way.id}"
69       within "h4", :text => "Version #2" do
70         assert_link "2", :href => old_way_path(way, 2)
71       end
72       assert_no_text "Deleted"
73
74       assert_link "Download XML", :href => api_way_path(way)
75       assert_link "View History", :href => way_history_path(way)
76       assert_no_link "View Unredacted History"
77       assert_link "Version #1", :href => old_way_path(way, 1)
78       assert_link "Version #2", :href => old_way_path(way, 2)
79     end
80   end
81
82   test "shows a deleted node" do
83     node = create(:node, :with_history, :lat => 60, :lon => 30, :visible => false, :version => 2)
84
85     visit node_path(node)
86
87     within_sidebar do
88       assert_css "h2", :text => "Node: #{node.id}"
89       within "h4", :text => "Version #2" do
90         assert_link "2", :href => old_node_path(node, 2)
91       end
92       assert_no_text "Location"
93       assert_text "Deleted"
94
95       assert_no_link "Download XML"
96       assert_link "View History", :href => node_history_path(node)
97       assert_no_link "View Unredacted History"
98     end
99   end
100
101   test "shows a deleted way" do
102     way = create(:way, :visible => false, :version => 2)
103
104     visit way_path(way)
105
106     within_sidebar do
107       assert_css "h2", :text => "Way: #{way.id}"
108       within "h4", :text => "Version #2" do
109         assert_link "2", :href => old_way_path(way, 2)
110       end
111       assert_text "Deleted"
112
113       assert_no_link "Download XML"
114       assert_link "View History", :href => way_history_path(way)
115       assert_no_link "View Unredacted History"
116     end
117   end
118
119   test "shows node navigation to regular users" do
120     node = create(:node, :with_history)
121
122     sign_in_as(create(:user))
123     visit node_path(node)
124
125     within_sidebar do
126       assert_link "View History", :href => node_history_path(node)
127       assert_no_link "View Unredacted History"
128     end
129   end
130
131   test "shows way navigation to regular users" do
132     way = create(:way, :with_history)
133
134     sign_in_as(create(:user))
135     visit way_path(way)
136
137     within_sidebar do
138       assert_link "View History", :href => way_history_path(way)
139       assert_no_link "View Unredacted History"
140     end
141   end
142
143   test "shows node navigation to moderators" do
144     node = create(:node, :with_history)
145
146     sign_in_as(create(:moderator_user))
147     visit node_path(node)
148
149     within_sidebar do
150       assert_link "View History", :href => node_history_path(node)
151       assert_link "View Unredacted History", :href => node_history_path(node, :show_redactions => true)
152     end
153   end
154
155   test "shows way navigation to moderators" do
156     way = create(:way, :with_history)
157
158     sign_in_as(create(:moderator_user))
159     visit way_path(way)
160
161     within_sidebar do
162       assert_link "View History", :href => way_history_path(way)
163       assert_link "View Unredacted History", :href => way_history_path(way, :show_redactions => true)
164     end
165   end
166
167   test "shows a link to containing relation of a node" do
168     node = create(:node)
169     containing_relation = create(:relation)
170     create(:relation_member, :relation => containing_relation, :member => node)
171
172     visit node_path(node)
173
174     within_sidebar do
175       assert_link :href => relation_path(containing_relation)
176     end
177   end
178
179   test "shows a link to containing relation of a way" do
180     way = create(:way)
181     containing_relation = create(:relation)
182     create(:relation_member, :relation => containing_relation, :member => way)
183
184     visit way_path(way)
185
186     within_sidebar do
187       assert_link :href => relation_path(containing_relation)
188     end
189   end
190
191   test "relation member nodes should be visible on the map when viewing relations" do
192     relation = create(:relation)
193     node = create(:node)
194     create(:relation_member, :relation => relation, :member => node)
195
196     visit relation_path(relation)
197
198     assert_selector "#map .leaflet-overlay-pane path"
199   end
200
201   test "map should center on a viewed node" do
202     node = create(:node, :lat => 59.55555, :lon => 29.55555)
203
204     visit node_path(node)
205
206     within "#map" do
207       click_on "Share"
208     end
209
210     share_url = find_by_id("long_input").value
211     assert_match %r{map=\d+/59\.\d+/29\.\d+}, share_url
212   end
213 end