docbrown/spec/system/internal/admin_awards_badges_spec.rb
Vaidehi Joshi b1de4cb1cf
Add Percy 🦔 (#7783) [deploy]
* Add Percy to Gemfile, rails helper

* Percy snapshots for using the editor

* Add PERCY_TOKEN to sample_application.yml

* Percy snapshots for visiting the homepage

* Percy snapshots for viewing an article's comments

* Percy snapshots for creating an article

* Percy snapshots for editing an article

* Percy snapshots for logged in/out user

* Remove empty spec file

* Percy snapshots for settings page

* Percy snapshots for reading list

* Percy snapshots for admin view

* Percy snapshots for moderator view

* Percy snapshots for authentication views

* Percy snapshots for article and tag views

* Percy snapshots for editing/deleting comment views

* Percy snapshots for admin views

* Percy snapshots for comment views

* Percy snapshots for organization views

* Percy snapshots for pro membership views

* Percy snapshots for podcast views

* Percy snapshots for user views

* Percy snapshots for dashboard views

* Percy snapshots for homepage views

* Percy snapshots for video views

* Add js: true in tests that require it for Percy

* Percy dependency cleanup

* Add the Percy agent
* Remove the PERCY_TOKEN from sample_application.yml
* Move the Percy gem into the "test" group in the Gemfile

* Remove duplicate snapshots, provide unique names to snapshots

* Set seed on Faker::Config for deterministic Percy snapshots

* Freeze time in js: true tests for determinstic snapshots

* Upgrade Percy to v0.26.3

* Add percy: true flag for Percy snapshotting tests

* Add more percy: true flags
2020-05-18 11:35:53 -07:00

67 lines
2 KiB
Ruby

require "rails_helper"
RSpec.describe "Admin awards badges", type: :system do
let(:admin) { create(:user, :super_admin) }
let(:user) { create(:user) }
let(:user2) { create(:user) }
let(:badges) { Badge.pluck(:title) }
def award_two_badges
find(:xpath, "//option[contains(text(), \"#{badges.last}\")]").select_option
fill_in "usernames", with: "#{user.username}, #{user2.username}"
fill_in "message_markdown", with: "He who controls the spice controls the universe."
click_on "Award Badges"
end
def award_no_badges
fill_in "usernames", with: "#{user.username}, #{user2.username}"
fill_in "message_markdown", with: "He who controls the spice controls the universe."
click_on "Award Badges"
end
before do
create_list :badge, 5
sign_in admin
visit "/internal/badges"
end
it "renders the page", js: true, percy: true do
Percy.snapshot(page, name: "Admin: /internal/badges")
end
it "loads the view" do
expect(page).to have_content("Badges")
end
it "lists the badges" do
badges.each do |badge|
expect(page).to have_content(badge)
end
end
it "awards badges" do
expect { award_two_badges }.to change { user.badges.count }.by(1).
and change { user2.badges.count }.by(1)
expect(page).to have_content("BadgeRewarder task ran!")
visit "/#{user.username}/"
expect(page).to have_link(href: "/badge/#{Badge.last.slug}")
end
it "notifies users of new badges" do
sidekiq_assert_enqueued_jobs(2, only: BadgeAchievements::SendEmailNotificationWorker) do
sidekiq_assert_enqueued_jobs(2, only: Notifications::NewBadgeAchievementWorker) do
award_two_badges
end
end
end
it "does not award badges if no badge is selected", js: true, percy: true do
expect { award_no_badges }.to change { user.badges.count }.by(0)
Percy.snapshot(page, name: "Admin: /internal/badges error")
expect(page).to have_content("Please choose a badge to award")
end
end