From 6f7615ba86afda56e1d661442286a1d68467a525 Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 27 Feb 2024 16:18:06 +0100 Subject: [PATCH] Add basic end-to-end test for admin moderation interface (#29424) --- spec/support/stories/profile_stories.rb | 6 +++++ spec/support/streaming_server_manager.rb | 3 +++ spec/system/report_interface_spec.rb | 31 ++++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 spec/system/report_interface_spec.rb diff --git a/spec/support/stories/profile_stories.rb b/spec/support/stories/profile_stories.rb index 74342c337d6..f5fc9a441fd 100644 --- a/spec/support/stories/profile_stories.rb +++ b/spec/support/stories/profile_stories.rb @@ -21,6 +21,12 @@ module ProfileStories click_on I18n.t('auth.login') end + def as_a_logged_in_admin + # This is a bit awkward, but this avoids code duplication. + as_a_logged_in_user + bob.update!(role: UserRole.find_by!(name: 'Admin')) + end + def with_alice_as_local_user @alice_bio = '@alice and @bob are fictional characters commonly used as' \ 'placeholder names in #cryptology, as well as #science and' \ diff --git a/spec/support/streaming_server_manager.rb b/spec/support/streaming_server_manager.rb index 33819182990..b702fc77cef 100644 --- a/spec/support/streaming_server_manager.rb +++ b/spec/support/streaming_server_manager.rb @@ -109,6 +109,9 @@ RSpec.configure do |config| # Also needs to be set per-example here because of the database cleaner. Setting.registrations_mode = 'open' + # Load seeds so we have the default roles otherwise cleared by `DatabaseCleaner` + Rails.application.load_seed + example.run end diff --git a/spec/system/report_interface_spec.rb b/spec/system/report_interface_spec.rb new file mode 100644 index 00000000000..6eba5525594 --- /dev/null +++ b/spec/system/report_interface_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'report interface', :paperclip_processing do + include ProfileStories + + let(:email) { 'admin@example.com' } + let(:password) { 'password' } + let(:confirmed_at) { Time.zone.now } + let(:finished_onboarding) { true } + + let(:reported_account) { Fabricate(:account) } + let(:reported_status) { Fabricate(:status, account: reported_account) } + let(:media_attachment) { Fabricate(:media_attachment, account: reported_account, status: reported_status, file: attachment_fixture('attachment.jpg')) } + let!(:report) { Fabricate(:report, target_account: reported_account, status_ids: [media_attachment.status.id]) } + + before do + as_a_logged_in_admin + visit admin_report_path(report) + end + + it 'displays the report interface, including the javascript bits' do + # The report category selector React component is properly rendered + expect(page).to have_css('.report-reason-selector') + + # The media React component is properly rendered + page.scroll_to(page.find('.batch-table__row')) + expect(page).to have_css('.spoiler-button__overlay__label') + end +end