From 00d58877f915c352f49a906352666e8617bd8f0e Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 22 Jun 2025 19:47:40 +0300 Subject: [PATCH] Move relation history ui tests to system tests --- .../old_relations_controller_test.rb | 40 +------- test/system/element_history_test.rb | 92 +++++++++++++++++++ 2 files changed, 93 insertions(+), 39 deletions(-) diff --git a/test/controllers/old_relations_controller_test.rb b/test/controllers/old_relations_controller_test.rb index 2d86400a0..0031519f7 100644 --- a/test/controllers/old_relations_controller_test.rb +++ b/test/controllers/old_relations_controller_test.rb @@ -12,47 +12,9 @@ class OldRelationsControllerTest < ActionDispatch::IntegrationTest ) end - def test_history + def test_index relation = create(:relation, :with_history) sidebar_browse_check :relation_history_path, relation.id, "old_elements/index" - assert_select "h4", /^Version/ do - assert_select "a[href='#{old_relation_path relation, 1}']", :text => "1", :count => 1 - end - end - - def test_history_of_redacted - relation = create(:relation, :with_history, :version => 4) - relation_v1 = relation.old_relations.find_by(:version => 1) - relation_v1.redact!(create(:redaction)) - relation_v3 = relation.old_relations.find_by(:version => 3) - relation_v3.redact!(create(:redaction)) - - get relation_history_path(:id => relation) - assert_response :success - assert_template "old_elements/index" - - # there are 4 revisions of the redacted relation, but only 2 - # should be showing details here. - assert_select ".browse-section", 4 - assert_select ".browse-section.browse-redacted", 2 - assert_select ".browse-section.browse-relation", 2 - end - - def test_unredacted_history_of_redacted - session_for(create(:moderator_user)) - relation = create(:relation, :with_history, :version => 4) - relation_v1 = relation.old_relations.find_by(:version => 1) - relation_v1.redact!(create(:redaction)) - relation_v3 = relation.old_relations.find_by(:version => 3) - relation_v3.redact!(create(:redaction)) - - get relation_history_path(:id => relation, :params => { :show_redactions => true }) - assert_response :success - assert_template "old_elements/index" - - assert_select ".browse-section", 4 - assert_select ".browse-section.browse-redacted", 0 - assert_select ".browse-section.browse-relation", 4 end def test_show diff --git a/test/system/element_history_test.rb b/test/system/element_history_test.rb index ae2cd62d4..36e523c1e 100644 --- a/test/system/element_history_test.rb +++ b/test/system/element_history_test.rb @@ -48,6 +48,28 @@ class ElementHistoryTest < ApplicationSystemTestCase end end + test "shows history of a relation" do + relation = create(:relation, :with_history, :version => 2) + relation_v1 = relation.old_relations.find_by(:version => 1) + relation_v2 = relation.old_relations.find_by(:version => 2) + create(:old_relation_tag, :old_relation => relation_v1, :k => "key", :v => "VALUE-ONE") + create(:old_relation_tag, :old_relation => relation_v2, :k => "key", :v => "VALUE-TWO") + + visit relation_history_path(relation) + + 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_link "View Details", :href => relation_path(relation) + 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) @@ -72,6 +94,18 @@ class ElementHistoryTest < ApplicationSystemTestCase end end + test "shows history of a relation to a regular user" do + relation = create(:relation, :with_history) + + visit relation_history_path(relation) + + within_sidebar do + assert_link "View Details", :href => relation_path(relation) + 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) @@ -119,6 +153,28 @@ class ElementHistoryTest < ApplicationSystemTestCase end end + test "shows history of a relation with one redacted version" do + relation = create(:relation, :with_history, :version => 2) + relation_v1 = relation.old_relations.find_by(:version => 1) + relation_v2 = relation.old_relations.find_by(:version => 2) + create(:old_relation_tag, :old_relation => relation_v1, :k => "key", :v => "VALUE-ONE") + create(:old_relation_tag, :old_relation => relation_v2, :k => "key", :v => "VALUE-TWO") + relation_v1.redact!(create(:redaction)) + + visit relation_history_path(relation) + + within_sidebar do + assert_css "h4", :text => "Version #2" + assert_css "td", :text => "VALUE-TWO" + assert_no_css "td", :text => "VALUE-ONE" + assert_text "Version 1 of this relation cannot be shown" + + assert_link "View Details", :href => relation_path(relation) + 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) @@ -196,6 +252,42 @@ class ElementHistoryTest < ApplicationSystemTestCase end end + test "shows history of a relation with one redacted version to a moderator" do + relation = create(:relation, :with_history, :version => 2) + relation_v1 = relation.old_relations.find_by(:version => 1) + relation_v2 = relation.old_relations.find_by(:version => 2) + create(:old_relation_tag, :old_relation => relation_v1, :k => "key", :v => "VALUE-ONE") + create(:old_relation_tag, :old_relation => relation_v2, :k => "key", :v => "VALUE-TWO") + relation_v1.redact!(create(:redaction)) + + sign_in_as(create(:moderator_user)) + visit relation_history_path(relation) + + within_sidebar do + assert_css "td", :text => "VALUE-TWO" + assert_no_css "td", :text => "VALUE-ONE" + assert_text "Version 1 of this relation cannot be shown" + + assert_link "View Details", :href => relation_path(relation) + 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_no_text "Version 1 of this relation cannot be shown" + + assert_link "View Details", :href => relation_path(relation) + assert_link "View History" + assert_no_link "View Unredacted History" + + click_on "View History" + + assert_text "Version 1 of this relation cannot be shown" + end + end + test "can view node history pages" do node = create(:node, :with_history, :version => 41) -- 2.39.5