From 77107d2209a182a54c7ad5c4656dda30ff7596da Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 22 Jun 2025 16:02:21 +0300 Subject: [PATCH] Move relation ui tests to system tests --- test/controllers/relations_controller_test.rb | 21 ----- test/system/element_current_version_test.rb | 92 +++++++++++++++++++ 2 files changed, 92 insertions(+), 21 deletions(-) diff --git a/test/controllers/relations_controller_test.rb b/test/controllers/relations_controller_test.rb index 71b12e099..95c4601ef 100644 --- a/test/controllers/relations_controller_test.rb +++ b/test/controllers/relations_controller_test.rb @@ -13,27 +13,6 @@ class RelationsControllerTest < ActionDispatch::IntegrationTest def test_show relation = create(:relation) sidebar_browse_check :relation_path, relation.id, "elements/show" - assert_select "h4", /^Version/ do - assert_select "a[href='#{old_relation_path relation, 1}']", :text => "1", :count => 1 - end - assert_select ".secondary-actions a[href='#{api_relation_path relation}']", :count => 1 - assert_select ".secondary-actions a[href='#{relation_history_path relation}']", :count => 1 - end - - def test_show_multiple_versions - relation = create(:relation, :with_history, :version => 2) - sidebar_browse_check :relation_path, relation.id, "elements/show" - assert_select ".secondary-actions a[href='#{relation_history_path relation}']", :count => 1 - assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 1 - assert_select ".secondary-actions a[href='#{old_relation_path relation, 2}']", :count => 1 - end - - def test_show_relation_member - member = create(:relation) - relation = create(:relation) - create(:relation_member, :relation => relation, :member => member) - sidebar_browse_check :relation_path, member.id, "elements/show" - assert_select "a[href='#{relation_path relation}']", :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 7998151f1..908b30cd3 100644 --- a/test/system/element_current_version_test.rb +++ b/test/system/element_current_version_test.rb @@ -38,6 +38,24 @@ class ElementCurrentVersionTest < ApplicationSystemTestCase end end + test "shows a relation with one version" do + relation = create(:relation) + + visit relation_path(relation) + + within_sidebar do + assert_css "h2", :text => "Relation: #{relation.id}" + within "h4", :text => "Version #1" do + assert_link "1", :href => old_relation_path(relation, 1) + end + assert_no_text "Deleted" + + assert_link "Download XML", :href => api_relation_path(relation) + assert_link "View History", :href => relation_history_path(relation) + 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) @@ -79,6 +97,26 @@ class ElementCurrentVersionTest < ApplicationSystemTestCase end end + test "shows a relation with two versions" do + relation = create(:relation, :version => 2) + + visit relation_path(relation) + + within_sidebar do + assert_css "h2", :text => "Relation: #{relation.id}" + within "h4", :text => "Version #2" do + assert_link "2", :href => old_relation_path(relation, 2) + end + assert_no_text "Deleted" + + assert_link "Download XML", :href => api_relation_path(relation) + assert_link "View History", :href => relation_history_path(relation) + assert_no_link "View Unredacted History" + assert_link "Version #1", :href => old_relation_path(relation, 1) + assert_link "Version #2", :href => old_relation_path(relation, 2) + end + end + test "shows a deleted node" do node = create(:node, :with_history, :lat => 60, :lon => 30, :visible => false, :version => 2) @@ -116,6 +154,24 @@ class ElementCurrentVersionTest < ApplicationSystemTestCase end end + test "shows a deleted relation" do + relation = create(:relation, :visible => false, :version => 2) + + visit relation_path(relation) + + within_sidebar do + assert_css "h2", :text => "Relation: #{relation.id}" + within "h4", :text => "Version #2" do + assert_link "2", :href => old_relation_path(relation, 2) + end + assert_text "Deleted" + + assert_no_link "Download XML" + assert_link "View History", :href => relation_history_path(relation) + assert_no_link "View Unredacted History" + end + end + test "shows node navigation to regular users" do node = create(:node, :with_history) @@ -140,6 +196,18 @@ class ElementCurrentVersionTest < ApplicationSystemTestCase end end + test "shows relation navigation to regular users" do + relation = create(:relation, :with_history) + + sign_in_as(create(:user)) + visit relation_path(relation) + + within_sidebar do + assert_link "View History", :href => relation_history_path(relation) + assert_no_link "View Unredacted History" + end + end + test "shows node navigation to moderators" do node = create(:node, :with_history) @@ -164,6 +232,18 @@ class ElementCurrentVersionTest < ApplicationSystemTestCase end end + test "shows relation navigation to moderators" do + relation = create(:relation, :with_history) + + sign_in_as(create(:moderator_user)) + visit relation_path(relation) + + within_sidebar do + assert_link "View History", :href => relation_history_path(relation) + assert_link "View Unredacted History", :href => relation_history_path(relation, :show_redactions => true) + end + end + test "shows a link to containing relation of a node" do node = create(:node) containing_relation = create(:relation) @@ -188,6 +268,18 @@ class ElementCurrentVersionTest < ApplicationSystemTestCase end end + test "shows a link to containing relation of a relation" do + relation = create(:relation) + containing_relation = create(:relation) + create(:relation_member, :relation => containing_relation, :member => relation) + + visit relation_path(relation) + + 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