Files
nairobi/spec/features/admin/stats_spec.rb
2017-06-13 12:59:04 +02:00

166 lines
4.3 KiB
Ruby

require 'rails_helper'
feature 'Stats' do
background do
admin = create(:administrator)
login_as(admin.user)
visit root_path
end
context 'Summary' do
scenario 'General' do
create(:debate)
2.times { create(:proposal) }
3.times { create(:comment, commentable: Debate.first) }
4.times { create(:visit) }
visit admin_stats_path
expect(page).to have_content "Debates 1"
expect(page).to have_content "Proposals 2"
expect(page).to have_content "Comments 3"
expect(page).to have_content "Visits 4"
end
scenario 'Votes' do
debate = create(:debate)
create(:vote, votable: debate)
proposal = create(:proposal)
2.times { create(:vote, votable: proposal) }
comment = create(:comment)
3.times { create(:vote, votable: comment) }
visit admin_stats_path
expect(page).to have_content "Debate votes 1"
expect(page).to have_content "Proposal votes 2"
expect(page).to have_content "Comment votes 3"
expect(page).to have_content "Total votes 6"
end
end
context "Users" do
scenario 'Summary' do
1.times { create(:user, :level_three) }
2.times { create(:user, :level_two) }
3.times { create(:user) }
visit admin_stats_path
expect(page).to have_content "Level three users 1"
expect(page).to have_content "Level two users 2"
expect(page).to have_content "Verified users 3"
expect(page).to have_content "Unverified users 4"
expect(page).to have_content "Total users 7"
end
scenario "Do not count erased users" do
1.times { create(:user, :level_three, erased_at: Time.current) }
2.times { create(:user, :level_two, erased_at: Time.current) }
3.times { create(:user, erased_at: Time.current) }
visit admin_stats_path
expect(page).to have_content "Level three users 0"
expect(page).to have_content "Level two users 0"
expect(page).to have_content "Verified users 0"
expect(page).to have_content "Unverified users 1"
expect(page).to have_content "Total users 1"
end
scenario "Do not count hidden users" do
1.times { create(:user, :level_three, hidden_at: Time.current) }
2.times { create(:user, :level_two, hidden_at: Time.current) }
3.times { create(:user, hidden_at: Time.current) }
visit admin_stats_path
expect(page).to have_content "Level three users 0"
expect(page).to have_content "Level two users 0"
expect(page).to have_content "Verified users 0"
expect(page).to have_content "Unverified users 1"
expect(page).to have_content "Total users 1"
end
scenario 'Level 2 user Graph' do
create(:geozone)
visit account_path
click_link 'Verify my account'
verify_residence
confirm_phone
visit admin_stats_path
expect(page).to have_content "Level 2 User (1)"
end
end
context "Proposal notifications" do
scenario "Summary stats" do
proposal = create(:proposal)
create(:proposal_notification, proposal: proposal)
create(:proposal_notification, proposal: proposal)
create(:proposal_notification)
visit admin_stats_path
click_link "Proposal notifications"
within("#proposal_notifications_count") do
expect(page).to have_content "3"
end
within("#proposals_with_notifications_count") do
expect(page).to have_content "2"
end
end
scenario "Index" do
3.times { create(:proposal_notification) }
visit admin_stats_path
click_link "Proposal notifications"
expect(page).to have_css(".proposal_notification", count: 3)
ProposalNotification.all.each do |proposal_notification|
expect(page).to have_content proposal_notification.title
expect(page).to have_content proposal_notification.body
end
end
end
context "Direct messages" do
scenario "Summary stats" do
sender = create(:user, :level_two)
create(:direct_message, sender: sender)
create(:direct_message, sender: sender)
create(:direct_message)
visit admin_stats_path
click_link "Direct messages"
within("#direct_messages_count") do
expect(page).to have_content "3"
end
within("#users_who_have_sent_message_count") do
expect(page).to have_content "2"
end
end
end
end