Files
nairobi/spec/system/comments/topics_spec.rb

327 lines
8.9 KiB
Ruby

require "rails_helper"
describe "Commenting topics from proposals" do
let(:proposal) { create(:proposal) }
it_behaves_like "flaggable", :topic_with_community_comment
describe "Administrators" do
scenario "can create comment as an administrator" do
community = proposal.community
topic = create(:topic, community: community)
admin = create(:administrator)
login_as(admin.user)
visit community_topic_path(community, topic)
fill_in "Leave your comment", with: "I am your Admin!"
check "comment-as-administrator-topic_#{topic.id}"
click_button "Publish comment"
within "#comments" do
expect(page).to have_content "I am your Admin!"
expect(page).to have_content "Administrator ##{admin.id}"
expect(page).to have_css "div.is-admin"
expect(page).to have_css "img.admin-avatar"
end
end
scenario "can create reply as an administrator" do
community = proposal.community
topic = create(:topic, community: community)
citizen = create(:user, username: "Ana")
manuela = create(:user, username: "Manuela")
admin = create(:administrator, user: manuela)
comment = create(:comment, commentable: topic, user: citizen)
login_as(manuela)
visit community_topic_path(community, topic)
click_link "Reply"
within "#js-comment-form-comment_#{comment.id}" do
fill_in "Leave your comment", with: "Top of the world!"
check "comment-as-administrator-comment_#{comment.id}"
click_button "Publish reply"
end
within "#comment_#{comment.id}" do
expect(page).to have_content "Top of the world!"
expect(page).to have_content "Administrator ##{admin.id}"
expect(page).to have_css "div.is-admin"
expect(page).to have_css "img.admin-avatar"
end
expect(page).not_to have_css "#js-comment-form-comment_#{comment.id}"
end
scenario "can not comment as a moderator", :admin do
community = proposal.community
topic = create(:topic, community: community)
visit community_topic_path(community, topic)
expect(page).not_to have_content "Comment as moderator"
end
end
describe "Voting comments" do
let(:verified) { create(:user, verified_at: Time.current) }
let(:unverified) { create(:user) }
let(:proposal) { create(:proposal) }
let(:topic) { create(:topic, community: proposal.community) }
let!(:comment) { create(:comment, commentable: topic) }
before do
login_as(verified)
end
scenario "Show" do
create(:vote, voter: verified, votable: comment, vote_flag: true)
create(:vote, voter: unverified, votable: comment, vote_flag: false)
visit community_topic_path(proposal.community, topic)
within("#comment_#{comment.id}_votes") do
within(".in-favor") do
expect(page).to have_content "1"
end
within(".against") do
expect(page).to have_content "1"
end
expect(page).to have_content "2 votes"
end
end
scenario "Create" do
visit community_topic_path(proposal.community, topic)
within("#comment_#{comment.id}_votes") do
click_button "I agree"
within(".in-favor") do
expect(page).to have_content "1"
end
within(".against") do
expect(page).to have_content "0"
end
expect(page).to have_content "1 vote"
end
end
scenario "Update" do
visit community_topic_path(proposal.community, topic)
within("#comment_#{comment.id}_votes") do
click_button "I agree"
within(".in-favor") do
expect(page).to have_content "1"
end
click_button "I disagree"
within(".in-favor") do
expect(page).to have_content "0"
end
within(".against") do
expect(page).to have_content "1"
end
expect(page).to have_content "1 vote"
end
end
scenario "Allow undoing votes" do
visit community_topic_path(proposal.community, topic)
within("#comment_#{comment.id}_votes") do
click_button "I agree"
within(".in-favor") do
expect(page).to have_content "1"
end
click_button "I agree"
within(".in-favor") do
expect(page).to have_content "0"
end
within(".against") do
expect(page).to have_content "0"
end
expect(page).to have_content "No votes"
end
end
end
end
describe "Commenting topics from budget investments" do
let(:user) { create(:user) }
let(:investment) { create(:budget_investment) }
describe "Administrators" do
scenario "can create comment as an administrator" do
community = investment.community
topic = create(:topic, community: community)
admin = create(:administrator)
login_as(admin.user)
visit community_topic_path(community, topic)
fill_in "Leave your comment", with: "I am your Admin!"
check "comment-as-administrator-topic_#{topic.id}"
click_button "Publish comment"
within "#comments" do
expect(page).to have_content "I am your Admin!"
expect(page).to have_content "Administrator ##{admin.id}"
expect(page).to have_css "div.is-admin"
expect(page).to have_css "img.admin-avatar"
end
end
scenario "can create reply as an administrator" do
community = investment.community
topic = create(:topic, community: community)
citizen = create(:user, username: "Ana")
manuela = create(:user, username: "Manuela")
admin = create(:administrator, user: manuela)
comment = create(:comment, commentable: topic, user: citizen)
login_as(manuela)
visit community_topic_path(community, topic)
click_link "Reply"
within "#js-comment-form-comment_#{comment.id}" do
fill_in "Leave your comment", with: "Top of the world!"
check "comment-as-administrator-comment_#{comment.id}"
click_button "Publish reply"
end
within "#comment_#{comment.id}" do
expect(page).to have_content "Top of the world!"
expect(page).to have_content "Administrator ##{admin.id}"
expect(page).to have_css "div.is-admin"
expect(page).to have_css "img.admin-avatar"
end
expect(page).not_to have_css "#js-comment-form-comment_#{comment.id}"
end
scenario "can not comment as a moderator", :admin do
community = investment.community
topic = create(:topic, community: community)
visit community_topic_path(community, topic)
expect(page).not_to have_content "Comment as moderator"
end
end
describe "Voting comments" do
let(:verified) { create(:user, verified_at: Time.current) }
let(:unverified) { create(:user) }
let(:investment) { create(:budget_investment) }
let(:topic) { create(:topic, community: investment.community) }
let!(:comment) { create(:comment, commentable: topic) }
before do
login_as(verified)
end
scenario "Show" do
create(:vote, voter: verified, votable: comment, vote_flag: true)
create(:vote, voter: unverified, votable: comment, vote_flag: false)
visit community_topic_path(investment.community, topic)
within("#comment_#{comment.id}_votes") do
within(".in-favor") do
expect(page).to have_content "1"
end
within(".against") do
expect(page).to have_content "1"
end
expect(page).to have_content "2 votes"
end
end
scenario "Create" do
visit community_topic_path(investment.community, topic)
within("#comment_#{comment.id}_votes") do
click_button "I agree"
within(".in-favor") do
expect(page).to have_content "1"
end
within(".against") do
expect(page).to have_content "0"
end
expect(page).to have_content "1 vote"
end
end
scenario "Update" do
visit community_topic_path(investment.community, topic)
within("#comment_#{comment.id}_votes") do
click_button "I agree"
within(".in-favor") do
expect(page).to have_content "1"
end
click_button "I disagree"
within(".in-favor") do
expect(page).to have_content "0"
end
within(".against") do
expect(page).to have_content "1"
end
expect(page).to have_content "1 vote"
end
end
scenario "Allow undoing votes" do
visit community_topic_path(investment.community, topic)
within("#comment_#{comment.id}_votes") do
click_button "I agree"
within(".in-favor") do
expect(page).to have_content "1"
end
click_button "I agree"
within(".in-favor") do
expect(page).to have_content "0"
end
within(".against") do
expect(page).to have_content "0"
end
expect(page).to have_content "No votes"
end
end
end
end