0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-08 17:53:55 +08:00
discourse/spec/system/flagging_post_spec.rb
Krzysztof Kotlarek 5e46fd35f9
UX: enable refreshed review page (#36711)
This is a small PR just enabling the refreshed review page for everyone.
At this stage, I don't want to remove the site setting so we can
potentially quickly revert that change.

I will create a follow-up PR that will remove the hidden site setting
and all legacy code.

Some tests were irrelevant. For example, in the old layout, long posts
were collapsed. In the new layout, we have an inline scroll.

<img width="1143" height="679" alt="Screenshot 2025-12-16 at 12 37
37 pm"
src="https://github.com/user-attachments/assets/3020dfd1-f84b-44ca-906f-385536bdce3d"
/>
2025-12-16 13:51:48 +08:00

166 lines
5.8 KiB
Ruby
Vendored

# frozen_string_literal: true
describe "Flagging post", type: :system do
fab!(:current_user, :admin)
fab!(:category)
fab!(:topic) { Fabricate(:topic, category: category) }
fab!(:first_post) { Fabricate(:post, topic: topic) }
fab!(:post_to_flag) { Fabricate(:post, topic: topic) }
let(:topic_page) { PageObjects::Pages::Topic.new }
let(:flag_modal) { PageObjects::Modals::Flag.new }
let(:silence_user_modal) { PageObjects::Modals::PenalizeUser.new("silence") }
let(:refreshed_review_page) { PageObjects::Pages::RefreshedReview.new }
describe "Using Take Action" do
before { sign_in(current_user) }
it "can select the default action to hide the post, agree with other flags, and reach the flag threshold" do
other_flag = Fabricate(:flag_post_action, post: post_to_flag, user: Fabricate(:moderator))
other_flag_reviewable =
Fabricate(:reviewable_flagged_post, target: post_to_flag, created_by: other_flag.user)
expect(other_flag.reload.agreed_at).to be_nil
topic_page.visit_topic(topic)
topic_page.expand_post_actions(post_to_flag)
topic_page.click_post_action_button(post_to_flag, :flag)
flag_modal.choose_type(:off_topic)
flag_modal.take_action(:agree_and_hide)
expect(
topic_page.post_by_number(post_to_flag).ancestor(".topic-post.post-hidden"),
).to be_present
visit "/review/#{other_flag_reviewable.id}"
expect(refreshed_review_page).to have_reviewable_with_approved_status(other_flag_reviewable)
end
it "can choose to immediately silence the user" do
expect(Reviewable.count).to eq(0)
topic_page.visit_topic(topic)
topic_page.expand_post_actions(post_to_flag)
topic_page.click_post_action_button(post_to_flag, :flag)
flag_modal.choose_type(:off_topic)
flag_modal.take_action(:agree_and_silence)
silence_user_modal.fill_in_silence_reason("spamming")
silence_user_modal.set_future_date("tomorrow")
silence_user_modal.perform
expect(silence_user_modal).to be_closed
expect(
topic_page.post_by_number(post_to_flag).ancestor(".topic-post.post-hidden"),
).to be_present
visit "/review/#{Reviewable.sole.id}"
expect(refreshed_review_page).to have_reviewable_with_approved_status(Reviewable.sole)
end
end
describe "As Illegal" do
before { sign_in(current_user) }
it do
topic_page.visit_topic(topic)
topic_page.expand_post_actions(post_to_flag)
topic_page.click_post_action_button(post_to_flag, :flag)
flag_modal.choose_type(:illegal)
expect(flag_modal).to have_css(".illegal .description")
expect(flag_modal).to have_css(".flag-confirmation")
flag_modal.fill_message("This looks totally illegal to me.")
flag_modal.check_confirmation
flag_modal.confirm_flag
expect(page).to have_content(I18n.t("js.post.actions.by_you.illegal"))
end
end
describe "As send a message to user" do
before do
SiteSetting.allow_user_locale = true
current_user.update!(locale: "en_GB")
sign_in(current_user)
end
it do
topic_page.visit_topic(topic)
topic_page.expand_post_actions(post_to_flag)
topic_page.click_post_action_button(post_to_flag, :flag)
flag_modal.choose_type(:notify_user)
flag_modal.fill_message("This looks totally illegal to me.")
flag_modal.confirm_flag
expect(page).to have_content(I18n.t("js.post.actions.by_you.notify_user"))
end
end
context "when tl0" do
fab!(:tl0_user) { Fabricate(:user, trust_level: TrustLevel[0]) }
before { sign_in(tl0_user) }
it "does not allow to mark posts as illegal" do
topic_page.visit_topic(topic)
expect(topic_page).to have_no_flag_button
end
it "allows to mark posts as illegal when allow_all_users_to_flag_illegal_content setting is enabled" do
SiteSetting.email_address_to_report_illegal_content = "illegal@example.com"
SiteSetting.allow_all_users_to_flag_illegal_content = true
topic_page.visit_topic(topic).open_flag_topic_modal
expect(flag_modal.body).to have_content(
ActionView::Base.full_sanitizer.sanitize(I18n.t("js.flagging.review_process_description")),
)
expect(flag_modal).to have_choices(I18n.t("js.flagging.formatted_name.illegal"))
end
end
context "when anonymous" do
let(:anonymous_flag_modal) { PageObjects::Modals::AnonymousFlag.new }
it "does not allow to mark posts as illegal" do
topic_page.visit_topic(topic)
expect(topic_page).to have_no_post_more_actions(post_to_flag)
end
it "allows to mark posts as illegal when allow_all_users_to_flag_illegal_content setting is enabled" do
SiteSetting.contact_email = "contact@example.com"
SiteSetting.allow_all_users_to_flag_illegal_content = true
topic_page.visit_topic(topic, post_number: post_to_flag.post_number)
topic_page.find_post_action_button(post_to_flag, :flag).click
expect(anonymous_flag_modal.body).to have_content(
ActionView::Base.full_sanitizer.sanitize(I18n.t("js.flagging.review_process_description")),
)
expect(anonymous_flag_modal.body).to have_content(
ActionView::Base.full_sanitizer.sanitize(
I18n.t(
"js.anonymous_flagging.description",
{ email: "contact@example.com", topic_title: topic.title, url: current_url },
),
),
)
SiteSetting.email_address_to_report_illegal_content = "illegal@example.com"
topic_page.visit_topic(topic)
topic_page.find_post_action_button(post_to_flag, :flag).click
expect(anonymous_flag_modal.body).to have_content(
ActionView::Base.full_sanitizer.sanitize(
I18n.t(
"js.anonymous_flagging.description",
{ email: "illegal@example.com", topic_title: topic.title, url: current_url },
),
),
)
end
end
end