Use a button to delete comments
As mentioned in commit 5311daadf, there are several reasons to use
buttons in these situations. And, as mentioned in the previous commits,
using buttons instead of links for actions requiring confirmation will
help us test for accessibility issues.
This commit is contained in:
@@ -1543,8 +1543,13 @@ table {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.delete-comment-form {
|
||||||
|
display: inline;
|
||||||
|
}
|
||||||
|
|
||||||
.delete-comment {
|
.delete-comment {
|
||||||
@include has-fa-icon(trash-alt, regular);
|
@include has-fa-icon(trash-alt, regular);
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
&:not(:hover):not(:active) {
|
&:not(:hover):not(:active) {
|
||||||
color: $delete;
|
color: $delete;
|
||||||
|
|||||||
@@ -5,10 +5,10 @@
|
|||||||
<% if can?(:hide, comment) || can?(:hide, comment.user) %>
|
<% if can?(:hide, comment) || can?(:hide, comment.user) %>
|
||||||
<% if comment.author == current_user %>
|
<% if comment.author == current_user %>
|
||||||
<span class="divider"> • </span>
|
<span class="divider"> • </span>
|
||||||
<%= link_to t("comments.actions.delete"),
|
<%= button_to t("comments.actions.delete"),
|
||||||
hide_comment_path(comment),
|
hide_comment_path(comment),
|
||||||
method: :put, remote: true, class: "delete-comment",
|
method: :put, remote: true, class: "delete-comment", form_class: "delete-comment-form",
|
||||||
data: { confirm: t("comments.actions.confirm_delete") } %>
|
data: { confirm: t("comments.actions.confirm_delete") } %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= render Shared::ModerationActionsComponent.new(comment) %>
|
<%= render Shared::ModerationActionsComponent.new(comment) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -336,16 +336,16 @@ describe "Comments" do
|
|||||||
visit polymorphic_path(resource)
|
visit polymorphic_path(resource)
|
||||||
|
|
||||||
accept_confirm("Are you sure? This action will delete this comment. You can't undo this action.") do
|
accept_confirm("Are you sure? This action will delete this comment. You can't undo this action.") do
|
||||||
within(".comment-body", text: "This was a mistake") { click_link "Delete comment" }
|
within(".comment-body", text: "This was a mistake") { click_button "Delete comment" }
|
||||||
end
|
end
|
||||||
|
|
||||||
expect(page).not_to have_content "This was a mistake"
|
expect(page).not_to have_content "This was a mistake"
|
||||||
expect(page).not_to have_link "Delete comment"
|
expect(page).not_to have_button "Delete comment"
|
||||||
|
|
||||||
refresh
|
refresh
|
||||||
|
|
||||||
expect(page).not_to have_content "This was a mistake"
|
expect(page).not_to have_content "This was a mistake"
|
||||||
expect(page).not_to have_link "Delete comment"
|
expect(page).not_to have_button "Delete comment"
|
||||||
|
|
||||||
logout
|
logout
|
||||||
login_as(admin)
|
login_as(admin)
|
||||||
@@ -363,7 +363,7 @@ describe "Comments" do
|
|||||||
visit polymorphic_path(resource)
|
visit polymorphic_path(resource)
|
||||||
|
|
||||||
accept_confirm("Are you sure? This action will delete this comment. You can't undo this action.") do
|
accept_confirm("Are you sure? This action will delete this comment. You can't undo this action.") do
|
||||||
within(".comment-body", text: "Wrong comment") { click_link "Delete comment" }
|
within(".comment-body", text: "Wrong comment") { click_button "Delete comment" }
|
||||||
end
|
end
|
||||||
|
|
||||||
within "#comments > .comment-list > li", text: "Right reply" do
|
within "#comments > .comment-list > li", text: "Right reply" do
|
||||||
|
|||||||
Reference in New Issue
Block a user