From 55bb2437313da9e1628a6c69f7ead6e7946760ab Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Mon, 8 Jan 2024 16:02:16 +0300 Subject: [PATCH] Turn hide/unhide comment controls into buttons --- app/assets/javascripts/index/changeset.js | 15 ++--- app/assets/stylesheets/common.scss | 5 -- app/views/browse/changeset.html.erb | 10 +-- test/application_system_test_case.rb | 5 ++ test/system/changeset_comments_test.rb | 78 +++++++++++++++++++++++ 5 files changed, 93 insertions(+), 20 deletions(-) diff --git a/app/assets/javascripts/index/changeset.js b/app/assets/javascripts/index/changeset.js index c6e77bc71..23d24d141 100644 --- a/app/assets/javascripts/index/changeset.js +++ b/app/assets/javascripts/index/changeset.js @@ -30,7 +30,7 @@ OSM.Changeset = function (map) { var data; $(form).find("#comment-error").prop("hidden", true); - $(form).find("input[type=submit]").prop("disabled", true); + $(form).find("button").prop("disabled", true); if (include_data) { data = { text: $(form.text).val() }; @@ -49,22 +49,17 @@ OSM.Changeset = function (map) { error: function (xhr) { $(form).find("#comment-error").text(xhr.responseText); $(form).find("#comment-error").prop("hidden", false); - $(form).find("input[type=submit]").prop("disabled", false); + $(form).find("button").prop("disabled", false); } }); } function initialize() { - content.find("input[name=comment]").on("click", function (e) { + content.find("button").on("click", function (e) { e.preventDefault(); var data = $(e.target).data(); - updateChangeset(e.target.form, data.method, data.url, true); - }); - - content.find(".action-button").on("click", function (e) { - e.preventDefault(); - var data = $(e.target).data(); - updateChangeset(e.target.form, data.method, data.url); + var include_data = e.target.name === "comment"; + updateChangeset(e.target.form, data.method, data.url, include_data); }); content.find("textarea").on("input", function (e) { diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/common.scss index f0746117d..18eab1316 100644 --- a/app/assets/stylesheets/common.scss +++ b/app/assets/stylesheets/common.scss @@ -647,11 +647,6 @@ tr.turn:hover { } } - span.action-button:hover { - cursor: pointer; - text-decoration: underline; - } - .note-description { overflow: hidden; margin: 0 0 10px 10px; diff --git a/app/views/browse/changeset.html.erb b/app/views/browse/changeset.html.erb index 583ac107f..1190423f6 100644 --- a/app/views/browse/changeset.html.erb +++ b/app/views/browse/changeset.html.erb @@ -18,9 +18,9 @@ <% if current_user %>
<% if @changeset.subscribers.exists?(current_user.id) %> - + <% else %> - + <% end %>
<% end %> @@ -38,7 +38,7 @@ :time_ago => friendly_date_ago(comment.created_at), :user => link_to(comment.author.display_name, user_path(comment.author))) %> <% if current_user and current_user.moderator? %> - — <%= t("javascripts.changesets.show.hide_comment") %> + — <% end %>
@@ -51,7 +51,7 @@ <%= t(".hidden_comment_by_html", :time_ago => friendly_date_ago(comment.created_at), :user => link_to(comment.author.display_name, user_path(comment.author))) %> - — <%= t("javascripts.changesets.show.unhide_comment") %> + —
<%= comment.body.to_html %> @@ -79,7 +79,7 @@
- " data-changeset-id="<%= @changeset.id %>" data-method="POST" data-url="<%= changeset_comment_url(@changeset) %>" disabled="1" class="btn btn-sm btn-primary" /> +
<% else %> diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index 7931546d4..ef8f0e371 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -33,6 +33,11 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase end end + def sign_out + visit logout_path + click_on "Logout", :match => :first + end + def within_sidebar(&block) within "#sidebar_content", &block end diff --git a/test/system/changeset_comments_test.rb b/test/system/changeset_comments_test.rb index 51695c516..82fd81286 100644 --- a/test/system/changeset_comments_test.rb +++ b/test/system/changeset_comments_test.rb @@ -44,4 +44,82 @@ class ChangesetCommentsTest < ApplicationSystemTestCase assert_content "Some newly added changeset comment" end end + + test "regular users can't hide comments" do + changeset = create(:changeset, :closed) + create(:changeset_comment, :changeset => changeset, :body => "Unwanted comment") + sign_in_as(create(:user)) + visit changeset_path(changeset) + + within_sidebar do + assert_text "Unwanted comment" + assert_no_button "hide" + end + end + + test "moderators can hide comments" do + changeset = create(:changeset, :closed) + create(:changeset_comment, :changeset => changeset, :body => "Unwanted comment") + + visit changeset_path(changeset) + + within_sidebar do + assert_text "Unwanted comment" + end + + sign_in_as(create(:moderator_user)) + visit changeset_path(changeset) + + within_sidebar do + assert_text "Unwanted comment" + assert_button "hide", :exact => true + assert_no_button "unhide", :exact => true + + click_on "hide", :exact => true + + assert_text "Unwanted comment" + assert_no_button "hide", :exact => true + assert_button "unhide", :exact => true + end + + sign_out + visit changeset_path(changeset) + + within_sidebar do + assert_no_text "Unwanted comment" + end + end + + test "moderators can unhide comments" do + changeset = create(:changeset, :closed) + create(:changeset_comment, :changeset => changeset, :body => "Wanted comment", :visible => false) + + visit changeset_path(changeset) + + within_sidebar do + assert_no_text "Wanted comment" + end + + sign_in_as(create(:moderator_user)) + visit changeset_path(changeset) + + within_sidebar do + assert_text "Wanted comment" + assert_no_button "hide", :exact => true + assert_button "unhide", :exact => true + + click_on "unhide", :exact => true + + assert_text "Wanted comment" + assert_button "hide", :exact => true + assert_no_button "unhide", :exact => true + end + + sign_out + visit changeset_path(changeset) + + within_sidebar do + assert_text "Wanted comment" + end + end end -- 2.39.5