Use buttons to agree/disagree with comments

As mentioned in commits 5311daadf and bb958daf0, using links combined
with JavaScript to generate POST requests to the server has a few
issues.
This commit is contained in:
Javi Martín
2021-09-30 22:56:21 +02:00
parent 7a25c61ae6
commit ba0d21b469
10 changed files with 63 additions and 68 deletions

View File

@@ -1887,7 +1887,7 @@ table {
display: inline-block; display: inline-block;
} }
form { .comment-form form {
margin-top: $line-height / 2; margin-top: $line-height / 2;
} }
} }
@@ -2004,17 +2004,18 @@ table {
.comment-votes { .comment-votes {
a, button,
form {
display: inline-block;
}
.icon-like, .icon-like,
.icon-unlike { .icon-unlike {
color: $text-light; color: $text-light;
display: inline-block;
vertical-align: top;
} }
a:hover { button:hover {
color: $text-medium; cursor: pointer;
text-decoration: none;
.icon-like { .icon-like {
color: $like; color: $like;

View File

@@ -3,14 +3,11 @@
 |   | 
<span class="in_favor"> <span class="in_favor">
<% if can?(:vote, comment) %> <%= button_to vote_comment_path(comment, value: "yes"),
<%= link_to vote_comment_path(comment, value: "yes"), method: "post",
method: "post", remote: true, title: t("votes.agree") do %> remote: true,
<span class="icon-like"> title: t("votes.agree"),
<span class="show-for-sr"><%= t("votes.agree") %></span> disabled: !can?(:vote, comment) do %>
</span>
<% end %>
<% else %>
<span class="icon-like"> <span class="icon-like">
<span class="show-for-sr"><%= t("votes.agree") %></span> <span class="show-for-sr"><%= t("votes.agree") %></span>
</span> </span>
@@ -19,14 +16,11 @@
</span> </span>
<span class="against"> <span class="against">
<% if can?(:vote, comment) %> <%= button_to vote_comment_path(comment, value: "no"),
<%= link_to vote_comment_path(comment, value: "no"), method: "post",
method: "post", remote: true, title: t("votes.disagree") do %> remote: true,
<span class="icon-unlike"> title: t("votes.disagree"),
<span class="show-for-sr"><%= t("votes.disagree") %></span> disabled: !can?(:vote, comment) do %>
</span>
<% end %>
<% else %>
<span class="icon-unlike"> <span class="icon-unlike">
<span class="show-for-sr"><%= t("votes.disagree") %></span> <span class="show-for-sr"><%= t("votes.disagree") %></span>
</span> </span>

View File

@@ -177,7 +177,7 @@ describe "Ballots" do
end end
within(".budget-investment", text: "More bridges") do within(".budget-investment", text: "More bridges") do
click_link "Remove vote" click_button "Remove vote"
end end
within("#sidebar") do within("#sidebar") do
@@ -464,7 +464,7 @@ describe "Ballots" do
hover_over_ballot hover_over_ballot
expect(page).to have_content "Only verified users can vote on investments" expect(page).to have_content "Only verified users can vote on investments"
expect(page).to have_selector(".in-favor a", obscured: true) expect(page).to have_button "Vote", disabled: true, obscured: true
end end
end end
@@ -575,8 +575,8 @@ describe "Ballots" do
end end
within("#budget_investment_#{bi1.id}") do within("#budget_investment_#{bi1.id}") do
find(".remove a").click click_button "Remove vote"
expect(page).to have_css ".add a" expect(page).to have_button "Vote"
end end
within("#budget_investment_#{bi2.id}") do within("#budget_investment_#{bi2.id}") do

View File

@@ -525,7 +525,7 @@ describe "Commenting Budget::Investments" do
visit budget_investment_path(budget, investment) visit budget_investment_path(budget, investment)
within("#comment_#{comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
@@ -543,13 +543,13 @@ describe "Commenting Budget::Investments" do
visit budget_investment_path(budget, investment) visit budget_investment_path(budget, investment)
within("#comment_#{comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
end end
find(".against a").click click_button "I disagree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "0" expect(page).to have_content "0"
@@ -567,13 +567,13 @@ describe "Commenting Budget::Investments" do
visit budget_investment_path(budget, investment) visit budget_investment_path(budget, investment)
within("#comment_#{comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
end end
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"

View File

@@ -331,7 +331,7 @@ describe "Commenting debates" do
fill_in "Leave your comment", with: "Probably if government approves." fill_in "Leave your comment", with: "Probably if government approves."
click_button "Publish reply" click_button "Publish reply"
expect(page).not_to have_selector("form") expect(page).not_to have_css ".comment-form"
within ".comment" do within ".comment" do
expect(page).to have_content "Probably if government approves." expect(page).to have_content "Probably if government approves."
@@ -574,7 +574,7 @@ describe "Commenting debates" do
visit debate_path(debate) visit debate_path(debate)
within("#comment_#{comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
@@ -592,13 +592,13 @@ describe "Commenting debates" do
visit debate_path(debate) visit debate_path(debate)
within("#comment_#{comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
end end
find(".against a").click click_button "I disagree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "0" expect(page).to have_content "0"
@@ -616,12 +616,12 @@ describe "Commenting debates" do
visit debate_path(debate) visit debate_path(debate)
within("#comment_#{comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
end end
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).not_to have_content "2" expect(page).not_to have_content "2"
expect(page).to have_content "1" expect(page).to have_content "1"

View File

@@ -541,7 +541,7 @@ describe "Commenting legislation questions" do
annotation) annotation)
within("#comment_#{comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
@@ -561,13 +561,13 @@ describe "Commenting legislation questions" do
annotation) annotation)
within("#comment_#{comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
end end
find(".against a").click click_button "I disagree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "0" expect(page).to have_content "0"
@@ -587,12 +587,12 @@ describe "Commenting legislation questions" do
annotation) annotation)
within("#comment_#{comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
end end
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).not_to have_content "2" expect(page).not_to have_content "2"
expect(page).to have_content "1" expect(page).to have_content "1"

View File

@@ -491,7 +491,7 @@ describe "Commenting legislation questions" do
visit legislation_process_question_path(question.process, question) visit legislation_process_question_path(question.process, question)
within("#comment_#{comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
@@ -509,13 +509,13 @@ describe "Commenting legislation questions" do
visit legislation_process_question_path(question.process, question) visit legislation_process_question_path(question.process, question)
within("#comment_#{comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
end end
find(".against a").click click_button "I disagree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "0" expect(page).to have_content "0"
@@ -533,12 +533,12 @@ describe "Commenting legislation questions" do
visit legislation_process_question_path(question.process, question) visit legislation_process_question_path(question.process, question)
within("#comment_#{comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
end end
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).not_to have_content "2" expect(page).not_to have_content "2"
expect(page).to have_content "1" expect(page).to have_content "1"

View File

@@ -469,7 +469,7 @@ describe "Commenting polls" do
visit poll_path(poll) visit poll_path(poll)
within("#comment_#{comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
@@ -487,13 +487,13 @@ describe "Commenting polls" do
visit poll_path(poll) visit poll_path(poll)
within("#comment_#{comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
end end
find(".against a").click click_button "I disagree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "0" expect(page).to have_content "0"
@@ -511,13 +511,13 @@ describe "Commenting polls" do
visit poll_path(poll) visit poll_path(poll)
within("#comment_#{comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
end end
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"

View File

@@ -457,7 +457,7 @@ describe "Commenting proposals" do
visit proposal_path(proposal) visit proposal_path(proposal)
within("#comment_#{comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
@@ -475,13 +475,13 @@ describe "Commenting proposals" do
visit proposal_path(proposal) visit proposal_path(proposal)
within("#comment_#{comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
end end
find(".against a").click click_button "I disagree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "0" expect(page).to have_content "0"
@@ -499,13 +499,13 @@ describe "Commenting proposals" do
visit proposal_path(proposal) visit proposal_path(proposal)
within("#comment_#{comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
end end
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"

View File

@@ -507,7 +507,7 @@ describe "Commenting topics from proposals" do
visit community_topic_path(proposal.community, topic) visit community_topic_path(proposal.community, topic)
within("#comment_#{comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
@@ -525,13 +525,13 @@ describe "Commenting topics from proposals" do
visit community_topic_path(proposal.community, topic) visit community_topic_path(proposal.community, topic)
within("#comment_#{comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
end end
find(".against a").click click_button "I disagree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "0" expect(page).to have_content "0"
@@ -549,13 +549,13 @@ describe "Commenting topics from proposals" do
visit community_topic_path(proposal.community, topic) visit community_topic_path(proposal.community, topic)
within("#comment_#{comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
end end
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
@@ -1018,7 +1018,7 @@ describe "Commenting topics from budget investments" do
visit community_topic_path(investment.community, topic) visit community_topic_path(investment.community, topic)
within("#comment_#{comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
@@ -1036,13 +1036,13 @@ describe "Commenting topics from budget investments" do
visit community_topic_path(investment.community, topic) visit community_topic_path(investment.community, topic)
within("#comment_#{comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
end end
find(".against a").click click_button "I disagree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "0" expect(page).to have_content "0"
@@ -1060,13 +1060,13 @@ describe "Commenting topics from budget investments" do
visit community_topic_path(investment.community, topic) visit community_topic_path(investment.community, topic)
within("#comment_#{comment.id}_votes") do within("#comment_#{comment.id}_votes") do
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"
end end
find(".in_favor a").click click_button "I agree"
within(".in_favor") do within(".in_favor") do
expect(page).to have_content "1" expect(page).to have_content "1"