From fab9f1a38a192c55317ce651fa193433b2908d63 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 22 Jun 2025 17:41:55 +0300 Subject: [PATCH] Move old node ui tests to system tests --- test/controllers/old_nodes_controller_test.rb | 111 ++------------- test/system/element_old_version_test.rb | 131 ++++++++++++++++++ 2 files changed, 145 insertions(+), 97 deletions(-) create mode 100644 test/system/element_old_version_test.rb diff --git a/test/controllers/old_nodes_controller_test.rb b/test/controllers/old_nodes_controller_test.rb index aba69b03a..d9aa3e643 100644 --- a/test/controllers/old_nodes_controller_test.rb +++ b/test/controllers/old_nodes_controller_test.rb @@ -105,113 +105,38 @@ class OldNodesControllerTest < ActionDispatch::IntegrationTest assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0 end - def test_visible_with_one_version + def test_show node = create(:node, :with_history) - get old_node_path(node, 1) - assert_response :success - assert_template "old_nodes/show" - assert_template :layout => "map" - assert_select "h4", /^Version/ do - assert_select "a[href='#{old_node_path node, 1}']", :count => 0 - end - assert_select ".secondary-actions a[href='#{api_node_version_path node, 1}']", :count => 1 - assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1 - assert_select ".secondary-actions a[href='#{old_node_path node, 1, :params => { :show_redactions => true }}']", :count => 0 - assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1 - end - def test_visible_with_two_versions - node = create(:node, :with_history, :version => 2) get old_node_path(node, 1) - assert_response :success - assert_template "old_nodes/show" - assert_template :layout => "map" - assert_select "h4", /^Version/ do - assert_select "a[href='#{old_node_path node, 1}']", :count => 0 - end - assert_select ".secondary-actions a[href='#{api_node_version_path node, 1}']", :count => 1 - assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1 - assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1 - assert_select ".secondary-actions a[href='#{old_node_path node, 2}']", :count => 1 - get old_node_path(node, 2) assert_response :success assert_template "old_nodes/show" assert_template :layout => "map" - assert_select "h4", /^Version/ do - assert_select "a[href='#{old_node_path node, 2}']", :count => 0 - end - assert_select ".secondary-actions a[href='#{api_node_version_path node, 2}']", :count => 1 - assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1 - 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 end - test "show unrevealed redacted versions to anonymous users" do - node = create_redacted_node - get old_node_path(node, 1) - assert_response :success - assert_template "old_nodes/show" - assert_template :layout => "map" - assert_select "td", :text => "TOP SECRET", :count => 0 - assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1 - assert_select ".secondary-actions a[href='#{old_node_path node, 1, :params => { :show_redactions => true }}']", :count => 0 - assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 0 - assert_select ".secondary-actions a[href='#{api_node_version_path node, 1}']", :count => 0 - end - - test "show unrevealed redacted versions to regular users" do - session_for(create(:user)) - node = create_redacted_node - get old_node_path(node, 1) - assert_response :success - assert_template "old_nodes/show" - assert_template :layout => "map" - assert_select "td", :text => "TOP SECRET", :count => 0 - assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1 - assert_select ".secondary-actions a[href='#{old_node_path node, 1, :params => { :show_redactions => true }}']", :count => 0 - assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 0 - assert_select ".secondary-actions a[href='#{api_node_version_path node, 1}']", :count => 0 - end - - test "show unrevealed redacted versions to moderators" do - session_for(create(:moderator_user)) - node = create_redacted_node - get old_node_path(node, 1) - assert_response :success - assert_template "old_nodes/show" - assert_template :layout => "map" - assert_select "td", :text => "TOP SECRET", :count => 0 - assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1 - assert_select ".secondary-actions a[href='#{old_node_path node, 1, :params => { :show_redactions => true }}']", :count => 1 - assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 0 - assert_select ".secondary-actions a[href='#{api_node_version_path node, 1}']", :count => 0 - end + def test_show_redacted_to_unauthorized_users + node = create(:node, :with_history, :version => 2) + node.old_nodes.find_by(:version => 1).redact!(create(:redaction)) - test "don't reveal redacted versions to anonymous users" do - node = create_redacted_node get old_node_path(node, 1, :params => { :show_redactions => true }) + assert_response :redirect end - test "don't reveal redacted versions to regular users" do + def test_show_redacted_to_regular_users + node = create(:node, :with_history, :version => 2) + node.old_nodes.find_by(:version => 1).redact!(create(:redaction)) + session_for(create(:user)) - node = create_redacted_node get old_node_path(node, 1, :params => { :show_redactions => true }) - assert_response :redirect - end - test "reveal redacted versions to moderators" do - session_for(create(:moderator_user)) - node = create_redacted_node - get old_node_path(node, 1, :params => { :show_redactions => true }) - assert_response :success - assert_select "td", :text => "TOP SECRET", :count => 1 - assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 1 + assert_response :redirect end - def test_not_found + def test_show_not_found get old_node_path(0, 0) + assert_response :not_found assert_template "browse/not_found" assert_template :layout => "map" @@ -220,22 +145,14 @@ class OldNodesControllerTest < ActionDispatch::IntegrationTest def test_show_timeout node = create(:node, :with_history) + with_settings(:web_timeout => -1) do get old_node_path(node, 1) end + assert_response :error assert_template :layout => "map" assert_dom "h2", "Timeout Error" assert_dom "p", /#{Regexp.quote("the node with the id #{node.id}")}/ end - - private - - def create_redacted_node - create(:node, :with_history, :version => 2) do |node| - node_v1 = node.old_nodes.find_by(:version => 1) - create(:old_node_tag, :old_node => node_v1, :k => "name", :v => "TOP SECRET") - node_v1.redact!(create(:redaction)) - end - end end diff --git a/test/system/element_old_version_test.rb b/test/system/element_old_version_test.rb new file mode 100644 index 000000000..e0306f030 --- /dev/null +++ b/test/system/element_old_version_test.rb @@ -0,0 +1,131 @@ +require "application_system_test_case" + +class ElementOldVersionTest < ApplicationSystemTestCase + test "shows a node with one version" do + node = create(:node, :with_history, :lat => 60, :lon => 30) + + visit old_node_path(node, 1) + + within_sidebar do + assert_css "h2", :text => "Node: #{node.id}" + assert_css "h4", :text => "Version #1" + assert_text(/Location: 60\.\d+, 30\.\d+/) + + assert_link "Download XML", :href => api_node_version_path(node, 1) + assert_link "View Details", :href => node_path(node) + assert_link "View History", :href => node_history_path(node) + end + end + + test "shows a node with two versions" do + node = create(:node, :with_history, :version => 2, :lat => 60, :lon => 30) + node.old_nodes.find_by(:version => 1).update(:lat => 59, :lon => 29) + + visit old_node_path(node, 1) + + within_sidebar do + assert_css "h2", :text => "Node: #{node.id}" + assert_css "h4", :text => "Version #1" + assert_text(/Location: 59\.\d+, 29\.\d+/) + + assert_link "Download XML", :href => api_node_version_path(node, 1) + assert_link "View Details", :href => node_path(node) + assert_link "View History", :href => node_history_path(node) + + click_on "Version #2" + + assert_css "h2", :text => "Node: #{node.id}" + assert_css "h4", :text => "Version #2" + assert_text(/Location: 60\.\d+, 30\.\d+/) + + assert_link "Download XML", :href => api_node_version_path(node, 2) + assert_link "View Details", :href => node_path(node) + assert_link "View History", :href => node_history_path(node) + end + end + + test "show a redacted node version" do + node = create_redacted_node + + visit old_node_path(node, 1) + + within_sidebar do + assert_css "h2", :text => "Node: #{node.id}" + assert_text "Version 1 of this node cannot be shown" + assert_no_text "Location" + assert_no_text "TOP SECRET" + + assert_no_link "Download XML" + assert_no_link "View Redacted Data" + assert_link "View Details", :href => node_path(node) + assert_link "View History", :href => node_history_path(node) + end + end + + test "show a redacted node version to a regular user" do + node = create_redacted_node + + sign_in_as(create(:user)) + visit old_node_path(node, 1) + + within_sidebar do + assert_css "h2", :text => "Node: #{node.id}" + assert_text "Version 1 of this node cannot be shown" + assert_no_text "Location" + assert_no_text "TOP SECRET" + + assert_no_link "Download XML" + assert_no_link "View Redacted Data" + assert_link "View Details", :href => node_path(node) + assert_link "View History", :href => node_history_path(node) + end + end + + test "show a redacted node version to a moderator" do + node = create_redacted_node + + sign_in_as(create(:moderator_user)) + visit old_node_path(node, 1) + + within_sidebar do + assert_css "h2", :text => "Node: #{node.id}" + assert_text "Version 1 of this node cannot be shown" + assert_no_text "Location" + assert_no_text "TOP SECRET" + + assert_no_link "Download XML" + assert_link "View Redacted Data" + assert_no_link "View Redaction Message" + assert_link "View Details", :href => node_path(node) + assert_link "View History", :href => node_history_path(node) + + click_on "View Redacted Data" + + assert_css "h2", :text => "Node: #{node.id}" + assert_css "h4", :text => "Redacted Version #1" + assert_text(/Location: 59\.\d+, 29\.\d+/) + assert_text "TOP SECRET" + + assert_no_link "Download XML" + assert_no_link "View Redacted Data" + assert_link "View Redaction Message" + assert_link "View Details", :href => node_path(node) + assert_link "View History", :href => node_history_path(node) + + click_on "View Redaction Message" + + assert_text "Version 1 of this node cannot be shown" + end + end + + private + + def create_redacted_node + create(:node, :with_history, :version => 2, :lat => 60, :lon => 30) do |node| + node_v1 = node.old_nodes.find_by(:version => 1) + node_v1.update(:lat => 59, :lon => 29) + create(:old_node_tag, :old_node => node_v1, :k => "name", :v => "TOP SECRET") + node_v1.redact!(create(:redaction)) + end + end +end -- 2.39.5