From 03b9cf8b2be815564982c403b30c2cd3dabdb207 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 22 Jun 2025 15:27:21 +0300 Subject: [PATCH] Move node ui tests to system tests --- test/controllers/nodes_controller_test.rb | 75 ---------------- test/system/element_current_version_test.rb | 95 +++++++++++++++++++++ 2 files changed, 95 insertions(+), 75 deletions(-) diff --git a/test/controllers/nodes_controller_test.rb b/test/controllers/nodes_controller_test.rb index 11c8f8d8e..b3005c0dc 100644 --- a/test/controllers/nodes_controller_test.rb +++ b/test/controllers/nodes_controller_test.rb @@ -13,81 +13,6 @@ class NodesControllerTest < ActionDispatch::IntegrationTest def test_show node = create(:node) sidebar_browse_check :node_path, node.id, "elements/show" - assert_select "h4", /^Version/ do - assert_select "a[href='#{old_node_path node, 1}']", :text => "1", :count => 1 - end - assert_select ".secondary-actions a[href='#{api_node_path node}']", :count => 1 - assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1 - end - - def test_show_multiple_versions - node = create(:node, :with_history, :version => 2) - sidebar_browse_check :node_path, node.id, "elements/show" - assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1 - assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 1 - assert_select ".secondary-actions a[href='#{old_node_path node, 2}']", :count => 1 - end - - def test_show_relation_member - member = create(:node) - relation = create(:relation) - create(:relation_member, :relation => relation, :member => member) - sidebar_browse_check :node_path, member.id, "elements/show" - assert_select "a[href='#{relation_path relation}']", :count => 1 - end - - def test_show_deleted - node = create(:node, :visible => false) - sidebar_browse_check :node_path, node.id, "elements/show" - assert_select "h4", /^Version/ do - assert_select "a[href='#{old_node_path node, 1}']", :text => "1", :count => 1 - end - assert_select "a[href='#{api_node_path node}']", :count => 0 - end - - def test_show_redacted - node = create(:node, :with_history, :deleted, :version => 2) - node_v1 = node.old_nodes.find_by(:version => 1) - node_v1.redact!(create(:redaction)) - - get node_path(node) - assert_response :success - assert_template "elements/show" - - # check that we don't show lat/lon for a redacted node. - assert_select ".browse-section", 1 - assert_select ".browse-section.browse-node", 1 - assert_select ".browse-section.browse-node .latitude", 0 - assert_select ".browse-section.browse-node .longitude", 0 - end - - def test_show_secondary_actions_to_anonymous_user - node = create(:node, :with_history) - get node_path(node) - assert_response :success - assert_select ".secondary-actions a", :text => "View Details", :count => 0 - assert_select ".secondary-actions a", :text => "View History", :count => 1 - assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0 - end - - def test_show_secondary_actions_to_regular_user - session_for(create(:user)) - node = create(:node, :with_history) - get node_path(node) - assert_response :success - assert_select ".secondary-actions a", :text => "View Details", :count => 0 - assert_select ".secondary-actions a", :text => "View History", :count => 1 - assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0 - end - - def test_show_secondary_actions_to_moderator - session_for(create(:moderator_user)) - node = create(:node, :with_history) - get node_path(node) - assert_response :success - assert_select ".secondary-actions a", :text => "View Details", :count => 0 - assert_select ".secondary-actions a", :text => "View History", :count => 1 - assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 1 end def test_show_timeout diff --git a/test/system/element_current_version_test.rb b/test/system/element_current_version_test.rb index 06ee3ea07..4a5a464f8 100644 --- a/test/system/element_current_version_test.rb +++ b/test/system/element_current_version_test.rb @@ -1,6 +1,101 @@ require "application_system_test_case" class ElementCurrentVersionTest < ApplicationSystemTestCase + test "shows a node with one version" do + node = create(:node, :lat => 60, :lon => 30) + + visit node_path(node) + + within_sidebar do + assert_css "h2", :text => "Node: #{node.id}" + within "h4", :text => "Version #1" do + assert_link "1", :href => old_node_path(node, 1) + end + assert_text(/Location: 60\.\d+, 30\.\d+/) + assert_no_text "Deleted" + + assert_link "Download XML", :href => api_node_path(node) + assert_link "View History", :href => node_history_path(node) + assert_no_link "View Unredacted History" + end + end + + test "shows a node with two versions" do + node = create(:node, :with_history, :lat => 60, :lon => 30, :version => 2) + + visit node_path(node) + + within_sidebar do + assert_css "h2", :text => "Node: #{node.id}" + within "h4", :text => "Version #2" do + assert_link "2", :href => old_node_path(node, 2) + end + assert_text(/Location: 60\.\d+, 30\.\d+/) + assert_no_text "Deleted" + + assert_link "Download XML", :href => api_node_path(node) + assert_link "View History", :href => node_history_path(node) + assert_no_link "View Unredacted History" + assert_link "Version #1", :href => old_node_path(node, 1) + assert_link "Version #2", :href => old_node_path(node, 2) + end + end + + test "shows a deleted node" do + node = create(:node, :with_history, :lat => 60, :lon => 30, :visible => false, :version => 2) + + visit node_path(node) + + within_sidebar do + assert_css "h2", :text => "Node: #{node.id}" + within "h4", :text => "Version #2" do + assert_link "2", :href => old_node_path(node, 2) + end + assert_no_text "Location" + assert_text "Deleted" + + assert_no_link "Download XML" + assert_link "View History", :href => node_history_path(node) + assert_no_link "View Unredacted History" + end + end + + test "shows node navigation to regular users" do + node = create(:node, :with_history) + + sign_in_as(create(:user)) + visit node_path(node) + + within_sidebar do + assert_link "View History", :href => node_history_path(node) + assert_no_link "View Unredacted History" + end + end + + test "shows node navigation to moderators" do + node = create(:node, :with_history) + + sign_in_as(create(:moderator_user)) + visit node_path(node) + + within_sidebar do + assert_link "View History", :href => node_history_path(node) + assert_link "View Unredacted History", :href => node_history_path(node, :show_redactions => true) + end + end + + test "shows a link to containing relation of a node" do + node = create(:node) + containing_relation = create(:relation) + create(:relation_member, :relation => containing_relation, :member => node) + + visit node_path(node) + + within_sidebar do + assert_link :href => relation_path(containing_relation) + end + end + test "relation member nodes should be visible on the map when viewing relations" do relation = create(:relation) node = create(:node) -- 2.39.5