From b50bd346bba54ebf95d578c2b53e21750c29d7c7 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 22 Jun 2025 19:39:43 +0300 Subject: [PATCH] Move way history ui tests to system tests --- test/controllers/old_ways_controller_test.rb | 40 +-------- test/system/element_history_test.rb | 92 ++++++++++++++++++++ 2 files changed, 93 insertions(+), 39 deletions(-) diff --git a/test/controllers/old_ways_controller_test.rb b/test/controllers/old_ways_controller_test.rb index ca18bad87..28c5ec1ca 100644 --- a/test/controllers/old_ways_controller_test.rb +++ b/test/controllers/old_ways_controller_test.rb @@ -12,47 +12,9 @@ class OldWaysControllerTest < ActionDispatch::IntegrationTest ) end - def test_history + def test_index way = create(:way, :with_history) sidebar_browse_check :way_history_path, way.id, "old_elements/index" - assert_select "h4", /^Version/ do - assert_select "a[href='#{old_way_path way, 1}']", :text => "1", :count => 1 - end - end - - def test_history_of_redacted - way = create(:way, :with_history, :version => 4) - way_v1 = way.old_ways.find_by(:version => 1) - way_v1.redact!(create(:redaction)) - way_v3 = way.old_ways.find_by(:version => 3) - way_v3.redact!(create(:redaction)) - - get way_history_path(:id => way) - assert_response :success - assert_template "old_elements/index" - - # there are 4 revisions of the redacted way, 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-way", 2 - end - - def test_unredacted_history_of_redacted - session_for(create(:moderator_user)) - way = create(:way, :with_history, :version => 4) - way_v1 = way.old_ways.find_by(:version => 1) - way_v1.redact!(create(:redaction)) - way_v3 = way.old_ways.find_by(:version => 3) - way_v3.redact!(create(:redaction)) - - get way_history_path(:id => way, :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-way", 4 end def test_show diff --git a/test/system/element_history_test.rb b/test/system/element_history_test.rb index 90a7345b2..ae2cd62d4 100644 --- a/test/system/element_history_test.rb +++ b/test/system/element_history_test.rb @@ -26,6 +26,28 @@ class ElementHistoryTest < ApplicationSystemTestCase end end + test "shows history of a way" do + way = create(:way, :with_history, :version => 2) + way_v1 = way.old_ways.find_by(:version => 1) + way_v2 = way.old_ways.find_by(:version => 2) + create(:old_way_tag, :old_way => way_v1, :k => "key", :v => "VALUE-ONE") + create(:old_way_tag, :old_way => way_v2, :k => "key", :v => "VALUE-TWO") + + visit way_history_path(way) + + 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 => way_path(way) + 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) @@ -38,6 +60,18 @@ class ElementHistoryTest < ApplicationSystemTestCase end end + test "shows history of a way to a regular user" do + way = create(:way, :with_history) + + visit way_history_path(way) + + within_sidebar do + assert_link "View Details", :href => way_path(way) + 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) @@ -63,6 +97,28 @@ class ElementHistoryTest < ApplicationSystemTestCase end end + test "shows history of a way with one redacted version" do + way = create(:way, :with_history, :version => 2) + way_v1 = way.old_ways.find_by(:version => 1) + way_v2 = way.old_ways.find_by(:version => 2) + create(:old_way_tag, :old_way => way_v1, :k => "key", :v => "VALUE-ONE") + create(:old_way_tag, :old_way => way_v2, :k => "key", :v => "VALUE-TWO") + way_v1.redact!(create(:redaction)) + + visit way_history_path(way) + + 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 way cannot be shown" + + assert_link "View Details", :href => way_path(way) + 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) @@ -104,6 +160,42 @@ class ElementHistoryTest < ApplicationSystemTestCase end end + test "shows history of a way with one redacted version to a moderator" do + way = create(:way, :with_history, :version => 2) + way_v1 = way.old_ways.find_by(:version => 1) + way_v2 = way.old_ways.find_by(:version => 2) + create(:old_way_tag, :old_way => way_v1, :k => "key", :v => "VALUE-ONE") + create(:old_way_tag, :old_way => way_v2, :k => "key", :v => "VALUE-TWO") + way_v1.redact!(create(:redaction)) + + sign_in_as(create(:moderator_user)) + visit way_history_path(way) + + within_sidebar do + assert_css "td", :text => "VALUE-TWO" + assert_no_css "td", :text => "VALUE-ONE" + assert_text "Version 1 of this way cannot be shown" + + assert_link "View Details", :href => way_path(way) + 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 way cannot be shown" + + assert_link "View Details", :href => way_path(way) + assert_link "View History" + assert_no_link "View Unredacted History" + + click_on "View History" + + assert_text "Version 1 of this way cannot be shown" + end + end + test "can view node history pages" do node = create(:node, :with_history, :version => 41) -- 2.39.5