1 # frozen_string_literal: true
 
   3 require "application_system_test_case"
 
   5 class ElementCurrentVersionTest < ApplicationSystemTestCase
 
   6   test "shows a node with one version" do
 
   7     node = create(:node, :lat => 60, :lon => 30)
 
  12       assert_css "h2", :text => "Node: #{node.id}"
 
  13       within "h4", :text => "Version #1" do
 
  14         assert_link "1", :href => old_node_path(node, 1)
 
  16       assert_text(/Location: 60\.\d+, 30\.\d+/)
 
  17       assert_no_text "Deleted"
 
  19       assert_link "Download XML", :href => api_node_path(node)
 
  20       assert_link "History", :exact => true, :href => node_history_path(node)
 
  21       assert_no_link "Unredacted History"
 
  25   test "shows a way with one version" do
 
  31       assert_css "h2", :text => "Way: #{way.id}"
 
  32       within "h4", :text => "Version #1" do
 
  33         assert_link "1", :href => old_way_path(way, 1)
 
  35       assert_no_text "Deleted"
 
  37       assert_link "Download XML", :href => api_way_path(way)
 
  38       assert_link "History", :exact => true, :href => way_history_path(way)
 
  39       assert_no_link "Unredacted History"
 
  43   test "shows a relation with one version" do
 
  44     relation = create(:relation)
 
  46     visit relation_path(relation)
 
  49       assert_css "h2", :text => "Relation: #{relation.id}"
 
  50       within "h4", :text => "Version #1" do
 
  51         assert_link "1", :href => old_relation_path(relation, 1)
 
  53       assert_no_text "Deleted"
 
  55       assert_link "Download XML", :href => api_relation_path(relation)
 
  56       assert_link "History", :exact => true, :href => relation_history_path(relation)
 
  57       assert_no_link "Unredacted History"
 
  61   test "shows a node with two versions" do
 
  62     node = create(:node, :with_history, :lat => 60, :lon => 30, :version => 2)
 
  67       assert_css "h2", :text => "Node: #{node.id}"
 
  68       within "h4", :text => "Version #2" do
 
  69         assert_link "2", :href => old_node_path(node, 2)
 
  71       assert_text(/Location: 60\.\d+, 30\.\d+/)
 
  72       assert_no_text "Deleted"
 
  74       assert_link "Download XML", :href => api_node_path(node)
 
  75       assert_link "History", :exact => true, :href => node_history_path(node)
 
  76       assert_no_link "Unredacted History"
 
  77       assert_link "Version #1", :href => old_node_path(node, 1)
 
  78       assert_link "Version #2", :href => old_node_path(node, 2)
 
  82   test "shows a way with two versions" do
 
  83     way = create(:way, :version => 2)
 
  88       assert_css "h2", :text => "Way: #{way.id}"
 
  89       within "h4", :text => "Version #2" do
 
  90         assert_link "2", :href => old_way_path(way, 2)
 
  92       assert_no_text "Deleted"
 
  94       assert_link "Download XML", :href => api_way_path(way)
 
  95       assert_link "History", :exact => true, :href => way_history_path(way)
 
  96       assert_no_link "Unredacted History"
 
  97       assert_link "Version #1", :href => old_way_path(way, 1)
 
  98       assert_link "Version #2", :href => old_way_path(way, 2)
 
 102   test "shows a relation with two versions" do
 
 103     relation = create(:relation, :version => 2)
 
 105     visit relation_path(relation)
 
 108       assert_css "h2", :text => "Relation: #{relation.id}"
 
 109       within "h4", :text => "Version #2" do
 
 110         assert_link "2", :href => old_relation_path(relation, 2)
 
 112       assert_no_text "Deleted"
 
 114       assert_link "Download XML", :href => api_relation_path(relation)
 
 115       assert_link "History", :exact => true, :href => relation_history_path(relation)
 
 116       assert_no_link "Unredacted History"
 
 117       assert_link "Version #1", :href => old_relation_path(relation, 1)
 
 118       assert_link "Version #2", :href => old_relation_path(relation, 2)
 
 122   test "shows a deleted node" do
 
 123     node = create(:node, :with_history, :lat => 60, :lon => 30, :visible => false, :version => 2)
 
 125     visit node_path(node)
 
 128       assert_css "h2", :text => "Node: #{node.id}"
 
 129       within "h4", :text => "Version #2" do
 
 130         assert_link "2", :href => old_node_path(node, 2)
 
 132       assert_no_text "Location"
 
 133       assert_text "Deleted"
 
 135       assert_no_link "Download XML"
 
 136       assert_link "History", :exact => true, :href => node_history_path(node)
 
 137       assert_no_link "Unredacted History"
 
 141   test "shows a deleted way" do
 
 142     way = create(:way, :visible => false, :version => 2)
 
 147       assert_css "h2", :text => "Way: #{way.id}"
 
 148       within "h4", :text => "Version #2" do
 
 149         assert_link "2", :href => old_way_path(way, 2)
 
 151       assert_text "Deleted"
 
 153       assert_no_link "Download XML"
 
 154       assert_link "History", :exact => true, :href => way_history_path(way)
 
 155       assert_no_link "Unredacted History"
 
 159   test "shows a deleted relation" do
 
 160     relation = create(:relation, :visible => false, :version => 2)
 
 162     visit relation_path(relation)
 
 165       assert_css "h2", :text => "Relation: #{relation.id}"
 
 166       within "h4", :text => "Version #2" do
 
 167         assert_link "2", :href => old_relation_path(relation, 2)
 
 169       assert_text "Deleted"
 
 171       assert_no_link "Download XML"
 
 172       assert_link "History", :exact => true, :href => relation_history_path(relation)
 
 173       assert_no_link "Unredacted History"
 
 177   test "shows node navigation to regular users" do
 
 178     node = create(:node, :with_history)
 
 180     sign_in_as(create(:user))
 
 181     visit node_path(node)
 
 184       assert_link "History", :exact => true, :href => node_history_path(node)
 
 185       assert_no_link "Unredacted History"
 
 189   test "shows way navigation to regular users" do
 
 190     way = create(:way, :with_history)
 
 192     sign_in_as(create(:user))
 
 196       assert_link "History", :exact => true, :href => way_history_path(way)
 
 197       assert_no_link "Unredacted History"
 
 201   test "shows relation navigation to regular users" do
 
 202     relation = create(:relation, :with_history)
 
 204     sign_in_as(create(:user))
 
 205     visit relation_path(relation)
 
 208       assert_link "History", :exact => true, :href => relation_history_path(relation)
 
 209       assert_no_link "Unredacted History"
 
 213   test "shows node navigation to moderators" do
 
 214     node = create(:node, :with_history)
 
 216     sign_in_as(create(:moderator_user))
 
 217     visit node_path(node)
 
 220       assert_link "History", :exact => true, :href => node_history_path(node)
 
 221       assert_link "Unredacted History", :href => node_history_path(node, :show_redactions => true)
 
 225   test "shows way navigation to moderators" do
 
 226     way = create(:way, :with_history)
 
 228     sign_in_as(create(:moderator_user))
 
 232       assert_link "History", :exact => true, :href => way_history_path(way)
 
 233       assert_link "Unredacted History", :href => way_history_path(way, :show_redactions => true)
 
 237   test "shows relation navigation to moderators" do
 
 238     relation = create(:relation, :with_history)
 
 240     sign_in_as(create(:moderator_user))
 
 241     visit relation_path(relation)
 
 244       assert_link "History", :exact => true, :href => relation_history_path(relation)
 
 245       assert_link "Unredacted History", :href => relation_history_path(relation, :show_redactions => true)
 
 249   test "shows a link to containing relation of a node" do
 
 251     containing_relation = create(:relation)
 
 252     create(:relation_member, :relation => containing_relation, :member => node)
 
 254     visit node_path(node)
 
 257       assert_link :href => relation_path(containing_relation)
 
 261   test "shows a link to containing relation of a way" do
 
 263     containing_relation = create(:relation)
 
 264     create(:relation_member, :relation => containing_relation, :member => way)
 
 269       assert_link :href => relation_path(containing_relation)
 
 273   test "shows a link to containing relation of a relation" do
 
 274     relation = create(:relation)
 
 275     containing_relation = create(:relation)
 
 276     create(:relation_member, :relation => containing_relation, :member => relation)
 
 278     visit relation_path(relation)
 
 281       assert_link :href => relation_path(containing_relation)
 
 285   test "relation member nodes should be visible on the map when viewing relations" do
 
 286     relation = create(:relation)
 
 288     create(:relation_member, :relation => relation, :member => node)
 
 290     visit relation_path(relation)
 
 292     assert_selector "#map .leaflet-overlay-pane path"
 
 295   test "map should center on a viewed node" do
 
 296     node = create(:node, :lat => 59.55555, :lon => 29.55555)
 
 298     visit node_path(node)
 
 304     share_url = find_by_id("long_input").value
 
 305     assert_match %r{map=\d+/59\.\d+/29\.\d+}, share_url