From fae5f4b0de87fc389e0e4f38288200ca6d175e24 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 22 Jun 2025 19:31:29 +0300 Subject: [PATCH] Move node history ui tests to system tests --- test/controllers/old_nodes_controller_test.rb | 81 +------------- test/system/element_history_test.rb | 103 ++++++++++++++++++ 2 files changed, 108 insertions(+), 76 deletions(-) diff --git a/test/controllers/old_nodes_controller_test.rb b/test/controllers/old_nodes_controller_test.rb index d9aa3e643..ed41b71ad 100644 --- a/test/controllers/old_nodes_controller_test.rb +++ b/test/controllers/old_nodes_controller_test.rb @@ -12,99 +12,28 @@ class OldNodesControllerTest < ActionDispatch::IntegrationTest ) end - def test_history + def test_index node = create(:node, :with_history) sidebar_browse_check :node_history_path, node.id, "old_elements/index" - assert_select "h4", /^Version/ do - assert_select "a[href='#{old_node_path node, 1}']", :text => "1", :count => 1 - end - end - - def test_history_of_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_history_path(:id => node) - assert_response :success - assert_template "old_elements/index" - - # there are 2 revisions of the redacted node, but only one - # should be showing details here. - assert_select ".browse-section", 2 - assert_select ".browse-section.browse-redacted", 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_unredacted_history_of_redacted - session_for(create(:moderator_user)) - node = create(:node, :with_history, :deleted, :version => 2) - node_v1 = node.old_nodes.find_by(:version => 1) - node_v1.redact!(create(:redaction)) + def test_index_show_redactions_to_unauthorized + node = create(:node, :with_history) get node_history_path(:id => node, :params => { :show_redactions => true }) - assert_response :success - assert_template "old_elements/index" - assert_select ".browse-section", 2 - assert_select ".browse-section.browse-redacted", 0 - assert_select ".browse-section.browse-node", 2 + assert_response :redirect end - def test_anonymous_user_history_page_secondary_actions + def test_index_show_redactions_to_regular_user node = create(:node, :with_history) - get node_history_path(:id => node) - assert_response :success - assert_select ".secondary-actions a", :text => "View Details", :count => 1 - assert_select ".secondary-actions a", :text => "View History", :count => 0 - assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0 - end - def test_regular_user_history_page_secondary_actions session_for(create(:user)) - node = create(:node, :with_history) - get node_history_path(:id => node) - assert_response :success - assert_select ".secondary-actions a", :text => "View Details", :count => 1 - assert_select ".secondary-actions a", :text => "View History", :count => 0 - assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0 - end - - def test_moderator_user_history_page_secondary_actions - session_for(create(:moderator_user)) - node = create(:node, :with_history) - get node_history_path(:id => node) - assert_response :success - assert_select ".secondary-actions a", :text => "View Details", :count => 1 - assert_select ".secondary-actions a", :text => "View History", :count => 0 - assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 1 - end - - def test_anonymous_user_unredacted_history_page_secondary_actions - node = create(:node, :with_history) get node_history_path(:id => node, :params => { :show_redactions => true }) - assert_response :redirect - end - def test_regular_user_unredacted_history_page_secondary_actions - session_for(create(:user)) - node = create(:node, :with_history) - get node_history_path(:id => node, :params => { :show_redactions => true }) assert_response :redirect end - def test_moderator_user_unredacted_history_page_secondary_actions - session_for(create(:moderator_user)) - node = create(:node, :with_history) - get node_history_path(:id => node, :params => { :show_redactions => true }) - assert_response :success - assert_select ".secondary-actions a", :text => "View Details", :count => 1 - 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 node = create(:node, :with_history) diff --git a/test/system/element_history_test.rb b/test/system/element_history_test.rb index 259a49110..90a7345b2 100644 --- a/test/system/element_history_test.rb +++ b/test/system/element_history_test.rb @@ -1,6 +1,109 @@ require "application_system_test_case" class ElementHistoryTest < ApplicationSystemTestCase + test "shows history of a node" do + node = create(:node, :with_history, :version => 2, :lat => 60, :lon => 30) + node_v1 = node.old_nodes.find_by(:version => 1) + node_v2 = node.old_nodes.find_by(:version => 2) + create(:old_node_tag, :old_node => node_v1, :k => "key", :v => "VALUE-ONE") + create(:old_node_tag, :old_node => node_v2, :k => "key", :v => "VALUE-TWO") + node_v1.update(:lat => 59, :lon => 29) + + visit node_history_path(node) + + within_sidebar do + v2_heading = find :element, "h4", :text => "Version #2" + v1_heading = find :element, "h4", :text => "Version #1", :below => v2_heading + + assert_css "td", :text => "VALUE-TWO", :below => v2_heading, :above => v1_heading + assert_css "td", :text => "VALUE-ONE", :below => v1_heading + assert_text(/Location: 60\.\d+, 30\.\d+/) + assert_text(/Location: 59\.\d+, 29\.\d+/) + + assert_link "View Details", :href => node_path(node) + assert_no_link "View History" + assert_no_link "View Unredacted History" + end + end + + test "shows history of a node to a regular user" do + node = create(:node, :with_history) + + visit node_history_path(node) + + within_sidebar do + assert_link "View Details", :href => node_path(node) + assert_no_link "View History" + assert_no_link "View Unredacted History" + end + end + + test "shows history of a node with one redacted version" do + node = create(:node, :with_history, :version => 2, :lat => 60, :lon => 30) + node_v1 = node.old_nodes.find_by(:version => 1) + node_v2 = node.old_nodes.find_by(:version => 2) + create(:old_node_tag, :old_node => node_v1, :k => "key", :v => "VALUE-ONE") + create(:old_node_tag, :old_node => node_v2, :k => "key", :v => "VALUE-TWO") + node_v1.update(:lat => 59, :lon => 29) + node_v1.redact!(create(:redaction)) + + visit node_history_path(node) + + within_sidebar do + assert_css "h4", :text => "Version #2" + assert_css "td", :text => "VALUE-TWO" + assert_no_css "td", :text => "VALUE-ONE" + assert_text(/Location: 60\.\d+, 30\.\d+/) + assert_no_text(/Location: 59\.\d+, 29\.\d+/) + assert_text "Version 1 of this node cannot be shown" + + assert_link "View Details", :href => node_path(node) + assert_no_link "View History" + assert_no_link "View Unredacted History" + end + end + + test "shows history of a node with one redacted version to a moderator" do + node = create(:node, :with_history, :version => 2, :lat => 60, :lon => 30) + node_v1 = node.old_nodes.find_by(:version => 1) + node_v2 = node.old_nodes.find_by(:version => 2) + create(:old_node_tag, :old_node => node_v1, :k => "key", :v => "VALUE-ONE") + create(:old_node_tag, :old_node => node_v2, :k => "key", :v => "VALUE-TWO") + node_v1.update(:lat => 59, :lon => 29) + node_v1.redact!(create(:redaction)) + + sign_in_as(create(:moderator_user)) + visit node_history_path(node) + + within_sidebar do + assert_css "td", :text => "VALUE-TWO" + assert_no_css "td", :text => "VALUE-ONE" + assert_text(/Location: 60\.\d+, 30\.\d+/) + assert_no_text(/Location: 59\.\d+, 29\.\d+/) + assert_text "Version 1 of this node cannot be shown" + + assert_link "View Details", :href => node_path(node) + assert_no_link "View History" + assert_link "View Unredacted History" + + click_on "View Unredacted History" + + assert_css "td", :text => "VALUE-TWO" + assert_css "td", :text => "VALUE-ONE" + assert_text(/Location: 60\.\d+, 30\.\d+/) + assert_text(/Location: 59\.\d+, 29\.\d+/) + assert_no_text "Version 1 of this node cannot be shown" + + assert_link "View Details", :href => node_path(node) + assert_link "View History" + assert_no_link "View Unredacted History" + + click_on "View History" + + assert_text "Version 1 of this node cannot be shown" + end + end + test "can view node history pages" do node = create(:node, :with_history, :version => 41) -- 2.39.5