discourse/spec/system/admin_user_spec.rb
Joffrey JAFFEUX 33fbf19d05
FIX: ensure we can lookup identical ip addresses (#32725)
This has been broken in
b6aad28ccf

We correctly access the users object and added a test to prevent future
regressions.
2025-05-14 11:48:01 +02:00

85 lines
3 KiB
Ruby
Vendored

# frozen_string_literal: true
describe "Admin User Page", type: :system do
fab!(:current_user) { Fabricate(:admin) }
let(:admin_user_page) { PageObjects::Pages::AdminUser.new }
let(:suspend_user_modal) { PageObjects::Modals::PenalizeUser.new("suspend") }
let(:silence_user_modal) { PageObjects::Modals::PenalizeUser.new("silence") }
before { sign_in(current_user) }
context "when visiting an admin's page" do
fab!(:admin)
before { admin_user_page.visit(admin) }
it "doesn't display the suspend or silence buttons" do
expect(admin_user_page).to have_no_suspend_button
expect(admin_user_page).to have_no_silence_button
end
end
context "when visiting a moderator's page" do
fab!(:moderator)
before { admin_user_page.visit(moderator) }
it "doesn't display the suspend or silence buttons" do
expect(admin_user_page).to have_no_suspend_button
expect(admin_user_page).to have_no_silence_button
end
end
context "when visting a regular user's page" do
fab!(:user) { Fabricate(:user, ip_address: "93.123.44.90") }
fab!(:similar_user) { Fabricate(:user, ip_address: user.ip_address) }
fab!(:another_mod) { Fabricate(:moderator, ip_address: user.ip_address) }
fab!(:another_admin) { Fabricate(:admin, ip_address: user.ip_address) }
before { admin_user_page.visit(user) }
it "can list accounts with identical IPs" do
find(".ip-lookup-trigger").click
expect(page).to have_content("#{I18n.t("js.ip_lookup.other_accounts")}\n3")
table = page.find(".other-accounts table")
expect(table).to have_content(similar_user.username)
expect(table).to have_content(another_mod.username)
expect(table).to have_content(another_admin.username)
end
it "displays the suspend and silence buttons" do
expect(admin_user_page).to have_suspend_button
expect(admin_user_page).to have_silence_button
end
it "displays username in the title" do
expect(page).to have_css(".display-row.username")
expect(page.title).to eq("#{user.username} - Users - Admin - Discourse")
end
describe "the suspend user modal" do
it "displays the list of users who share the same IP but are not mods or admins" do
admin_user_page.click_suspend_button
expect(suspend_user_modal.similar_users).to contain_exactly(similar_user.username)
expect(admin_user_page.similar_users_warning).to include(
I18n.t("admin_js.admin.user.other_matches", count: 1, username: user.username),
)
end
end
describe "the silence user modal" do
it "displays the list of users who share the same IP but are not mods or admins" do
admin_user_page.click_silence_button
expect(silence_user_modal.similar_users).to contain_exactly(similar_user.username)
expect(admin_user_page.similar_users_warning).to include(
I18n.t("admin_js.admin.user.other_matches", count: 1, username: user.username),
)
end
end
end
end