]> git.openstreetmap.org Git - rails.git/blob - test/system/element_history_test.rb
Move way history ui tests to system tests
[rails.git] / test / system / element_history_test.rb
1 require "application_system_test_case"
2
3 class ElementHistoryTest < ApplicationSystemTestCase
4   test "shows history of a node" do
5     node = create(:node, :with_history, :version => 2, :lat => 60, :lon => 30)
6     node_v1 = node.old_nodes.find_by(:version => 1)
7     node_v2 = node.old_nodes.find_by(:version => 2)
8     create(:old_node_tag, :old_node => node_v1, :k => "key", :v => "VALUE-ONE")
9     create(:old_node_tag, :old_node => node_v2, :k => "key", :v => "VALUE-TWO")
10     node_v1.update(:lat => 59, :lon => 29)
11
12     visit node_history_path(node)
13
14     within_sidebar do
15       v2_heading = find :element, "h4", :text => "Version #2"
16       v1_heading = find :element, "h4", :text => "Version #1", :below => v2_heading
17
18       assert_css "td", :text => "VALUE-TWO", :below => v2_heading, :above => v1_heading
19       assert_css "td", :text => "VALUE-ONE", :below => v1_heading
20       assert_text(/Location: 60\.\d+, 30\.\d+/)
21       assert_text(/Location: 59\.\d+, 29\.\d+/)
22
23       assert_link "View Details", :href => node_path(node)
24       assert_no_link "View History"
25       assert_no_link "View Unredacted History"
26     end
27   end
28
29   test "shows history of a way" do
30     way = create(:way, :with_history, :version => 2)
31     way_v1 = way.old_ways.find_by(:version => 1)
32     way_v2 = way.old_ways.find_by(:version => 2)
33     create(:old_way_tag, :old_way => way_v1, :k => "key", :v => "VALUE-ONE")
34     create(:old_way_tag, :old_way => way_v2, :k => "key", :v => "VALUE-TWO")
35
36     visit way_history_path(way)
37
38     within_sidebar do
39       v2_heading = find :element, "h4", :text => "Version #2"
40       v1_heading = find :element, "h4", :text => "Version #1", :below => v2_heading
41
42       assert_css "td", :text => "VALUE-TWO", :below => v2_heading, :above => v1_heading
43       assert_css "td", :text => "VALUE-ONE", :below => v1_heading
44
45       assert_link "View Details", :href => way_path(way)
46       assert_no_link "View History"
47       assert_no_link "View Unredacted History"
48     end
49   end
50
51   test "shows history of a node to a regular user" do
52     node = create(:node, :with_history)
53
54     visit node_history_path(node)
55
56     within_sidebar do
57       assert_link "View Details", :href => node_path(node)
58       assert_no_link "View History"
59       assert_no_link "View Unredacted History"
60     end
61   end
62
63   test "shows history of a way to a regular user" do
64     way = create(:way, :with_history)
65
66     visit way_history_path(way)
67
68     within_sidebar do
69       assert_link "View Details", :href => way_path(way)
70       assert_no_link "View History"
71       assert_no_link "View Unredacted History"
72     end
73   end
74
75   test "shows history of a node with one redacted version" do
76     node = create(:node, :with_history, :version => 2, :lat => 60, :lon => 30)
77     node_v1 = node.old_nodes.find_by(:version => 1)
78     node_v2 = node.old_nodes.find_by(:version => 2)
79     create(:old_node_tag, :old_node => node_v1, :k => "key", :v => "VALUE-ONE")
80     create(:old_node_tag, :old_node => node_v2, :k => "key", :v => "VALUE-TWO")
81     node_v1.update(:lat => 59, :lon => 29)
82     node_v1.redact!(create(:redaction))
83
84     visit node_history_path(node)
85
86     within_sidebar do
87       assert_css "h4", :text => "Version #2"
88       assert_css "td", :text => "VALUE-TWO"
89       assert_no_css "td", :text => "VALUE-ONE"
90       assert_text(/Location: 60\.\d+, 30\.\d+/)
91       assert_no_text(/Location: 59\.\d+, 29\.\d+/)
92       assert_text "Version 1 of this node cannot be shown"
93
94       assert_link "View Details", :href => node_path(node)
95       assert_no_link "View History"
96       assert_no_link "View Unredacted History"
97     end
98   end
99
100   test "shows history of a way with one redacted version" do
101     way = create(:way, :with_history, :version => 2)
102     way_v1 = way.old_ways.find_by(:version => 1)
103     way_v2 = way.old_ways.find_by(:version => 2)
104     create(:old_way_tag, :old_way => way_v1, :k => "key", :v => "VALUE-ONE")
105     create(:old_way_tag, :old_way => way_v2, :k => "key", :v => "VALUE-TWO")
106     way_v1.redact!(create(:redaction))
107
108     visit way_history_path(way)
109
110     within_sidebar do
111       assert_css "h4", :text => "Version #2"
112       assert_css "td", :text => "VALUE-TWO"
113       assert_no_css "td", :text => "VALUE-ONE"
114       assert_text "Version 1 of this way cannot be shown"
115
116       assert_link "View Details", :href => way_path(way)
117       assert_no_link "View History"
118       assert_no_link "View Unredacted History"
119     end
120   end
121
122   test "shows history of a node with one redacted version to a moderator" do
123     node = create(:node, :with_history, :version => 2, :lat => 60, :lon => 30)
124     node_v1 = node.old_nodes.find_by(:version => 1)
125     node_v2 = node.old_nodes.find_by(:version => 2)
126     create(:old_node_tag, :old_node => node_v1, :k => "key", :v => "VALUE-ONE")
127     create(:old_node_tag, :old_node => node_v2, :k => "key", :v => "VALUE-TWO")
128     node_v1.update(:lat => 59, :lon => 29)
129     node_v1.redact!(create(:redaction))
130
131     sign_in_as(create(:moderator_user))
132     visit node_history_path(node)
133
134     within_sidebar do
135       assert_css "td", :text => "VALUE-TWO"
136       assert_no_css "td", :text => "VALUE-ONE"
137       assert_text(/Location: 60\.\d+, 30\.\d+/)
138       assert_no_text(/Location: 59\.\d+, 29\.\d+/)
139       assert_text "Version 1 of this node cannot be shown"
140
141       assert_link "View Details", :href => node_path(node)
142       assert_no_link "View History"
143       assert_link "View Unredacted History"
144
145       click_on "View Unredacted History"
146
147       assert_css "td", :text => "VALUE-TWO"
148       assert_css "td", :text => "VALUE-ONE"
149       assert_text(/Location: 60\.\d+, 30\.\d+/)
150       assert_text(/Location: 59\.\d+, 29\.\d+/)
151       assert_no_text "Version 1 of this node cannot be shown"
152
153       assert_link "View Details", :href => node_path(node)
154       assert_link "View History"
155       assert_no_link "View Unredacted History"
156
157       click_on "View History"
158
159       assert_text "Version 1 of this node cannot be shown"
160     end
161   end
162
163   test "shows history of a way with one redacted version to a moderator" do
164     way = create(:way, :with_history, :version => 2)
165     way_v1 = way.old_ways.find_by(:version => 1)
166     way_v2 = way.old_ways.find_by(:version => 2)
167     create(:old_way_tag, :old_way => way_v1, :k => "key", :v => "VALUE-ONE")
168     create(:old_way_tag, :old_way => way_v2, :k => "key", :v => "VALUE-TWO")
169     way_v1.redact!(create(:redaction))
170
171     sign_in_as(create(:moderator_user))
172     visit way_history_path(way)
173
174     within_sidebar do
175       assert_css "td", :text => "VALUE-TWO"
176       assert_no_css "td", :text => "VALUE-ONE"
177       assert_text "Version 1 of this way cannot be shown"
178
179       assert_link "View Details", :href => way_path(way)
180       assert_no_link "View History"
181       assert_link "View Unredacted History"
182
183       click_on "View Unredacted History"
184
185       assert_css "td", :text => "VALUE-TWO"
186       assert_css "td", :text => "VALUE-ONE"
187       assert_no_text "Version 1 of this way cannot be shown"
188
189       assert_link "View Details", :href => way_path(way)
190       assert_link "View History"
191       assert_no_link "View Unredacted History"
192
193       click_on "View History"
194
195       assert_text "Version 1 of this way cannot be shown"
196     end
197   end
198
199   test "can view node history pages" do
200     node = create(:node, :with_history, :version => 41)
201
202     visit node_path(node)
203
204     check_element_history_pages(->(v) { old_node_path(node, v) })
205   end
206
207   test "can view way history pages" do
208     way = create(:way, :with_history, :version => 41)
209
210     visit way_path(way)
211
212     check_element_history_pages(->(v) { old_way_path(way, v) })
213   end
214
215   test "can view relation history pages" do
216     relation = create(:relation, :with_history, :version => 41)
217
218     visit relation_path(relation)
219
220     check_element_history_pages(->(v) { old_relation_path(relation, v) })
221   end
222
223   private
224
225   def check_element_history_pages(get_path)
226     within_sidebar do
227       click_on "View History"
228
229       41.downto(22) do |v|
230         assert_link v.to_s, :href => get_path.call(v)
231       end
232
233       click_on "Older Versions"
234
235       41.downto(2) do |v|
236         assert_link v.to_s, :href => get_path.call(v)
237       end
238
239       click_on "Older Versions"
240
241       41.downto(1) do |v|
242         assert_link v.to_s, :href => get_path.call(v)
243       end
244
245       assert_no_link "Older Versions"
246     end
247   end
248 end