discourse/spec/system/user_page/staff_info_spec.rb
Kelv 5f0bc4557f
FEATURE: Count only approved flagged posts in user pages (#22799)
FEATURE: Only approved flags for post counters

* Why was this change necessary?
The counters for flagged posts in the user's profile and user index from
the admin view include flags that were rejected, ignored or pending
review. This introduces unnecessary noise. Also the flagged posts
counter in the user's profile includes custom flags which add further
noise to this signal.

* How does it address the problem?

* Modifying User#flags_received_count to return posts with only approved
  standard flags
* Refactoring User#number_of_flagged_posts to alias to
  User#flags_received_count
* Updating the flagged post staff counter hyperlink to navigate to a
  filtered view of that user's approved flagged posts to maintain
  consistency with the counter
* Adding system tests for the profile page to cover the flagged posts
  staff counter
2023-07-31 13:33:10 +08:00

60 lines
1.8 KiB
Ruby

# frozen_string_literal: true
describe "Viewing user staff info as an admin", type: :system do
fab!(:user) { Fabricate(:user) }
fab!(:admin) { Fabricate(:admin) }
let(:user_page) { PageObjects::Pages::User.new }
before { sign_in(admin) }
context "for warnings" do
fab!(:topic) { Fabricate(:private_message_topic, user: admin, recipient: user) }
fab!(:user_warning) { UserWarning.create!(user: user, created_by: admin, topic: topic) }
it "should display the right link to user's warnings with the right count in text" do
user_page.visit(user).click_staff_info_warnings_link(user, warnings_count: 1)
expect(user_page).to have_warning_messages_path(user)
end
end
context "for flagged posts" do
before do
%i[disagree ignore delete_and_ignore].each do |review_action|
PostActionCreator
.off_topic(admin, Fabricate(:post, user: user))
.reviewable
.perform(admin, review_action)
end
end
context "when there are no approved flagged posts" do
it "should not display a flagged-posts staff counter" do
user_page.visit(user)
expect(user_page).to have_no_staff_info_flagged_posts_counter
end
end
context "when there are approved flagged posts" do
before do
2.times do
PostActionCreator
.off_topic(admin, Fabricate(:post, user: user))
.reviewable
.perform(admin, :agree_and_keep)
end
end
it "should display a flagged-posts staff counter with the right count and link to user's flagged posts" do
user_page.visit(user)
expect(user_page).to have_staff_info_flagged_posts_count(count: 2)
user_page.staff_info_flagged_posts_counter.click
expect(user_page).to have_reviewable_flagged_posts_path(user)
end
end
end
end