]> git.openstreetmap.org Git - rails.git/blob - test/system/element_history_test.rb
Move node 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 node to a regular user" do
30     node = create(:node, :with_history)
31
32     visit node_history_path(node)
33
34     within_sidebar do
35       assert_link "View Details", :href => node_path(node)
36       assert_no_link "View History"
37       assert_no_link "View Unredacted History"
38     end
39   end
40
41   test "shows history of a node with one redacted version" do
42     node = create(:node, :with_history, :version => 2, :lat => 60, :lon => 30)
43     node_v1 = node.old_nodes.find_by(:version => 1)
44     node_v2 = node.old_nodes.find_by(:version => 2)
45     create(:old_node_tag, :old_node => node_v1, :k => "key", :v => "VALUE-ONE")
46     create(:old_node_tag, :old_node => node_v2, :k => "key", :v => "VALUE-TWO")
47     node_v1.update(:lat => 59, :lon => 29)
48     node_v1.redact!(create(:redaction))
49
50     visit node_history_path(node)
51
52     within_sidebar do
53       assert_css "h4", :text => "Version #2"
54       assert_css "td", :text => "VALUE-TWO"
55       assert_no_css "td", :text => "VALUE-ONE"
56       assert_text(/Location: 60\.\d+, 30\.\d+/)
57       assert_no_text(/Location: 59\.\d+, 29\.\d+/)
58       assert_text "Version 1 of this node cannot be shown"
59
60       assert_link "View Details", :href => node_path(node)
61       assert_no_link "View History"
62       assert_no_link "View Unredacted History"
63     end
64   end
65
66   test "shows history of a node with one redacted version to a moderator" do
67     node = create(:node, :with_history, :version => 2, :lat => 60, :lon => 30)
68     node_v1 = node.old_nodes.find_by(:version => 1)
69     node_v2 = node.old_nodes.find_by(:version => 2)
70     create(:old_node_tag, :old_node => node_v1, :k => "key", :v => "VALUE-ONE")
71     create(:old_node_tag, :old_node => node_v2, :k => "key", :v => "VALUE-TWO")
72     node_v1.update(:lat => 59, :lon => 29)
73     node_v1.redact!(create(:redaction))
74
75     sign_in_as(create(:moderator_user))
76     visit node_history_path(node)
77
78     within_sidebar do
79       assert_css "td", :text => "VALUE-TWO"
80       assert_no_css "td", :text => "VALUE-ONE"
81       assert_text(/Location: 60\.\d+, 30\.\d+/)
82       assert_no_text(/Location: 59\.\d+, 29\.\d+/)
83       assert_text "Version 1 of this node cannot be shown"
84
85       assert_link "View Details", :href => node_path(node)
86       assert_no_link "View History"
87       assert_link "View Unredacted History"
88
89       click_on "View Unredacted History"
90
91       assert_css "td", :text => "VALUE-TWO"
92       assert_css "td", :text => "VALUE-ONE"
93       assert_text(/Location: 60\.\d+, 30\.\d+/)
94       assert_text(/Location: 59\.\d+, 29\.\d+/)
95       assert_no_text "Version 1 of this node cannot be shown"
96
97       assert_link "View Details", :href => node_path(node)
98       assert_link "View History"
99       assert_no_link "View Unredacted History"
100
101       click_on "View History"
102
103       assert_text "Version 1 of this node cannot be shown"
104     end
105   end
106
107   test "can view node history pages" do
108     node = create(:node, :with_history, :version => 41)
109
110     visit node_path(node)
111
112     check_element_history_pages(->(v) { old_node_path(node, v) })
113   end
114
115   test "can view way history pages" do
116     way = create(:way, :with_history, :version => 41)
117
118     visit way_path(way)
119
120     check_element_history_pages(->(v) { old_way_path(way, v) })
121   end
122
123   test "can view relation history pages" do
124     relation = create(:relation, :with_history, :version => 41)
125
126     visit relation_path(relation)
127
128     check_element_history_pages(->(v) { old_relation_path(relation, v) })
129   end
130
131   private
132
133   def check_element_history_pages(get_path)
134     within_sidebar do
135       click_on "View History"
136
137       41.downto(22) do |v|
138         assert_link v.to_s, :href => get_path.call(v)
139       end
140
141       click_on "Older Versions"
142
143       41.downto(2) do |v|
144         assert_link v.to_s, :href => get_path.call(v)
145       end
146
147       click_on "Older Versions"
148
149       41.downto(1) do |v|
150         assert_link v.to_s, :href => get_path.call(v)
151       end
152
153       assert_no_link "Older Versions"
154     end
155   end
156 end