1 # frozen_string_literal: true
 
   3 require "application_system_test_case"
 
   5 class ElementHistoryTest < ApplicationSystemTestCase
 
   6   test "shows history of a node" do
 
   7     node = create(:node, :with_history, :version => 2, :lat => 60, :lon => 30)
 
   8     node_v1 = node.old_nodes.find_by(:version => 1)
 
   9     node_v2 = node.old_nodes.find_by(:version => 2)
 
  10     create(:old_node_tag, :old_node => node_v1, :k => "key", :v => "VALUE-ONE")
 
  11     create(:old_node_tag, :old_node => node_v2, :k => "key", :v => "VALUE-TWO")
 
  12     node_v1.update(:lat => 59, :lon => 29)
 
  14     visit node_history_path(node)
 
  17       v2_heading = find :element, "h4", :text => "Version #2"
 
  18       v1_heading = find :element, "h4", :text => "Version #1", :below => v2_heading
 
  20       assert_css "td", :text => "VALUE-TWO", :below => v2_heading, :above => v1_heading
 
  21       assert_css "td", :text => "VALUE-ONE", :below => v1_heading
 
  22       assert_text(/Location: 60\.\d+, 30\.\d+/)
 
  23       assert_text(/Location: 59\.\d+, 29\.\d+/)
 
  25       assert_link "Node", :href => node_path(node)
 
  26       assert_no_link "History", :exact => true
 
  27       assert_no_link "Unredacted History"
 
  31   test "shows history of a way" do
 
  32     way = create(:way, :with_history, :version => 2)
 
  33     way_v1 = way.old_ways.find_by(:version => 1)
 
  34     way_v2 = way.old_ways.find_by(:version => 2)
 
  35     create(:old_way_tag, :old_way => way_v1, :k => "key", :v => "VALUE-ONE")
 
  36     create(:old_way_tag, :old_way => way_v2, :k => "key", :v => "VALUE-TWO")
 
  38     visit way_history_path(way)
 
  41       v2_heading = find :element, "h4", :text => "Version #2"
 
  42       v1_heading = find :element, "h4", :text => "Version #1", :below => v2_heading
 
  44       assert_css "td", :text => "VALUE-TWO", :below => v2_heading, :above => v1_heading
 
  45       assert_css "td", :text => "VALUE-ONE", :below => v1_heading
 
  47       assert_link "Way", :href => way_path(way)
 
  48       assert_no_link "History", :exact => true
 
  49       assert_no_link "Unredacted History"
 
  53   test "shows history of a relation" do
 
  54     relation = create(:relation, :with_history, :version => 2)
 
  55     relation_v1 = relation.old_relations.find_by(:version => 1)
 
  56     relation_v2 = relation.old_relations.find_by(:version => 2)
 
  57     create(:old_relation_tag, :old_relation => relation_v1, :k => "key", :v => "VALUE-ONE")
 
  58     create(:old_relation_tag, :old_relation => relation_v2, :k => "key", :v => "VALUE-TWO")
 
  60     visit relation_history_path(relation)
 
  63       v2_heading = find :element, "h4", :text => "Version #2"
 
  64       v1_heading = find :element, "h4", :text => "Version #1", :below => v2_heading
 
  66       assert_css "td", :text => "VALUE-TWO", :below => v2_heading, :above => v1_heading
 
  67       assert_css "td", :text => "VALUE-ONE", :below => v1_heading
 
  69       assert_link "Relation", :href => relation_path(relation)
 
  70       assert_no_link "History", :exact => true
 
  71       assert_no_link "Unredacted History"
 
  75   test "shows history of a node to a regular user" do
 
  76     node = create(:node, :with_history)
 
  78     visit node_history_path(node)
 
  81       assert_link "Node", :href => node_path(node)
 
  82       assert_no_link "History", :exact => true
 
  83       assert_no_link "Unredacted History"
 
  87   test "shows history of a way to a regular user" do
 
  88     way = create(:way, :with_history)
 
  90     visit way_history_path(way)
 
  93       assert_link "Way", :href => way_path(way)
 
  94       assert_no_link "History", :exact => true
 
  95       assert_no_link "Unredacted History"
 
  99   test "shows history of a relation to a regular user" do
 
 100     relation = create(:relation, :with_history)
 
 102     visit relation_history_path(relation)
 
 105       assert_link "Relation", :href => relation_path(relation)
 
 106       assert_no_link "History", :exact => true
 
 107       assert_no_link "Unredacted History"
 
 111   test "shows history of a node with one redacted version" do
 
 112     node = create(:node, :with_history, :version => 2, :lat => 60, :lon => 30)
 
 113     node_v1 = node.old_nodes.find_by(:version => 1)
 
 114     node_v2 = node.old_nodes.find_by(:version => 2)
 
 115     create(:old_node_tag, :old_node => node_v1, :k => "key", :v => "VALUE-ONE")
 
 116     create(:old_node_tag, :old_node => node_v2, :k => "key", :v => "VALUE-TWO")
 
 117     node_v1.update(:lat => 59, :lon => 29)
 
 118     node_v1.redact!(create(:redaction))
 
 120     visit node_history_path(node)
 
 123       assert_css "h4", :text => "Version #2"
 
 124       assert_css "td", :text => "VALUE-TWO"
 
 125       assert_no_css "td", :text => "VALUE-ONE"
 
 126       assert_text(/Location: 60\.\d+, 30\.\d+/)
 
 127       assert_no_text(/Location: 59\.\d+, 29\.\d+/)
 
 128       assert_text "Version 1 of this node cannot be shown"
 
 130       assert_link "Node", :href => node_path(node)
 
 131       assert_no_link "History", :exact => true
 
 132       assert_no_link "Unredacted History"
 
 136   test "shows history of a way with one redacted version" do
 
 137     way = create(:way, :with_history, :version => 2)
 
 138     way_v1 = way.old_ways.find_by(:version => 1)
 
 139     way_v2 = way.old_ways.find_by(:version => 2)
 
 140     create(:old_way_tag, :old_way => way_v1, :k => "key", :v => "VALUE-ONE")
 
 141     create(:old_way_tag, :old_way => way_v2, :k => "key", :v => "VALUE-TWO")
 
 142     way_v1.redact!(create(:redaction))
 
 144     visit way_history_path(way)
 
 147       assert_css "h4", :text => "Version #2"
 
 148       assert_css "td", :text => "VALUE-TWO"
 
 149       assert_no_css "td", :text => "VALUE-ONE"
 
 150       assert_text "Version 1 of this way cannot be shown"
 
 152       assert_link "Way", :href => way_path(way)
 
 153       assert_no_link "History", :exact => true
 
 154       assert_no_link "Unredacted History"
 
 158   test "shows history of a relation with one redacted version" do
 
 159     relation = create(:relation, :with_history, :version => 2)
 
 160     relation_v1 = relation.old_relations.find_by(:version => 1)
 
 161     relation_v2 = relation.old_relations.find_by(:version => 2)
 
 162     create(:old_relation_tag, :old_relation => relation_v1, :k => "key", :v => "VALUE-ONE")
 
 163     create(:old_relation_tag, :old_relation => relation_v2, :k => "key", :v => "VALUE-TWO")
 
 164     relation_v1.redact!(create(:redaction))
 
 166     visit relation_history_path(relation)
 
 169       assert_css "h4", :text => "Version #2"
 
 170       assert_css "td", :text => "VALUE-TWO"
 
 171       assert_no_css "td", :text => "VALUE-ONE"
 
 172       assert_text "Version 1 of this relation cannot be shown"
 
 174       assert_link "Relation", :href => relation_path(relation)
 
 175       assert_no_link "History", :exact => true
 
 176       assert_no_link "Unredacted History"
 
 180   test "shows history of a node with one redacted version to a moderator" do
 
 181     node = create(:node, :with_history, :version => 2, :lat => 60, :lon => 30)
 
 182     node_v1 = node.old_nodes.find_by(:version => 1)
 
 183     node_v2 = node.old_nodes.find_by(:version => 2)
 
 184     create(:old_node_tag, :old_node => node_v1, :k => "key", :v => "VALUE-ONE")
 
 185     create(:old_node_tag, :old_node => node_v2, :k => "key", :v => "VALUE-TWO")
 
 186     node_v1.update(:lat => 59, :lon => 29)
 
 187     node_v1.redact!(create(:redaction))
 
 189     sign_in_as(create(:moderator_user))
 
 190     visit node_history_path(node)
 
 193       assert_css "td", :text => "VALUE-TWO"
 
 194       assert_no_css "td", :text => "VALUE-ONE"
 
 195       assert_text(/Location: 60\.\d+, 30\.\d+/)
 
 196       assert_no_text(/Location: 59\.\d+, 29\.\d+/)
 
 197       assert_text "Version 1 of this node cannot be shown"
 
 199       assert_link "Node", :href => node_path(node)
 
 200       assert_no_link "History", :exact => true
 
 201       assert_link "Unredacted History"
 
 203       click_on "Unredacted History"
 
 205       assert_css "td", :text => "VALUE-TWO"
 
 206       assert_css "td", :text => "VALUE-ONE"
 
 207       assert_text(/Location: 60\.\d+, 30\.\d+/)
 
 208       assert_text(/Location: 59\.\d+, 29\.\d+/)
 
 209       assert_no_text "Version 1 of this node cannot be shown"
 
 211       assert_link "Node", :href => node_path(node)
 
 212       assert_link "History", :exact => true
 
 213       assert_no_link "Unredacted History"
 
 215       click_on "History", :exact => true
 
 217       assert_text "Version 1 of this node cannot be shown"
 
 221   test "shows history of a way with one redacted version to a moderator" do
 
 222     way = create(:way, :with_history, :version => 2)
 
 223     way_v1 = way.old_ways.find_by(:version => 1)
 
 224     way_v2 = way.old_ways.find_by(:version => 2)
 
 225     create(:old_way_tag, :old_way => way_v1, :k => "key", :v => "VALUE-ONE")
 
 226     create(:old_way_tag, :old_way => way_v2, :k => "key", :v => "VALUE-TWO")
 
 227     way_v1.redact!(create(:redaction))
 
 229     sign_in_as(create(:moderator_user))
 
 230     visit way_history_path(way)
 
 233       assert_css "td", :text => "VALUE-TWO"
 
 234       assert_no_css "td", :text => "VALUE-ONE"
 
 235       assert_text "Version 1 of this way cannot be shown"
 
 237       assert_link "Way", :href => way_path(way)
 
 238       assert_no_link "History", :exact => true
 
 239       assert_link "Unredacted History"
 
 241       click_on "Unredacted History"
 
 243       assert_css "td", :text => "VALUE-TWO"
 
 244       assert_css "td", :text => "VALUE-ONE"
 
 245       assert_no_text "Version 1 of this way cannot be shown"
 
 247       assert_link "Way", :href => way_path(way)
 
 248       assert_link "History", :exact => true
 
 249       assert_no_link "Unredacted History"
 
 251       click_on "History", :exact => true
 
 253       assert_text "Version 1 of this way cannot be shown"
 
 257   test "shows history of a relation with one redacted version to a moderator" do
 
 258     relation = create(:relation, :with_history, :version => 2)
 
 259     relation_v1 = relation.old_relations.find_by(:version => 1)
 
 260     relation_v2 = relation.old_relations.find_by(:version => 2)
 
 261     create(:old_relation_tag, :old_relation => relation_v1, :k => "key", :v => "VALUE-ONE")
 
 262     create(:old_relation_tag, :old_relation => relation_v2, :k => "key", :v => "VALUE-TWO")
 
 263     relation_v1.redact!(create(:redaction))
 
 265     sign_in_as(create(:moderator_user))
 
 266     visit relation_history_path(relation)
 
 269       assert_css "td", :text => "VALUE-TWO"
 
 270       assert_no_css "td", :text => "VALUE-ONE"
 
 271       assert_text "Version 1 of this relation cannot be shown"
 
 273       assert_link "Relation", :href => relation_path(relation)
 
 274       assert_no_link "History", :exact => true
 
 275       assert_link "Unredacted History"
 
 277       click_on "Unredacted History"
 
 279       assert_css "td", :text => "VALUE-TWO"
 
 280       assert_css "td", :text => "VALUE-ONE"
 
 281       assert_no_text "Version 1 of this relation cannot be shown"
 
 283       assert_link "Relation", :href => relation_path(relation)
 
 284       assert_link "History", :exact => true
 
 285       assert_no_link "Unredacted History"
 
 287       click_on "History", :exact => true
 
 289       assert_text "Version 1 of this relation cannot be shown"
 
 293   test "can view node history pages" do
 
 294     node = create(:node, :with_history, :version => 41)
 
 296     visit node_path(node)
 
 298     check_element_history_pages(->(v) { old_node_path(node, v) })
 
 301   test "can view way history pages" do
 
 302     way = create(:way, :with_history, :version => 41)
 
 306     check_element_history_pages(->(v) { old_way_path(way, v) })
 
 309   test "can view relation history pages" do
 
 310     relation = create(:relation, :with_history, :version => 41)
 
 312     visit relation_path(relation)
 
 314     check_element_history_pages(->(v) { old_relation_path(relation, v) })
 
 319   def check_element_history_pages(get_path)
 
 321       click_on "History", :exact => true
 
 324         assert_link v.to_s, :href => get_path.call(v)
 
 327       click_on "Older Versions"
 
 330         assert_link v.to_s, :href => get_path.call(v)
 
 333       click_on "Older Versions"
 
 336         assert_link v.to_s, :href => get_path.call(v)
 
 339       assert_no_link "Older Versions"