From a9a8b6b701026e41b2ee8edb897834b9c799cd2e Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 14 Jan 2025 05:27:21 -0500 Subject: [PATCH] Expand coverage of admin/trends/* areas (#33581) --- .../links/preview_card_providers_spec.rb | 49 +++++++++-- spec/system/admin/trends/links_spec.rb | 85 +++++++++++++++++-- spec/system/admin/trends/statuses_spec.rb | 83 ++++++++++++++++-- spec/system/admin/trends/tags_spec.rb | 46 ++++++++-- 4 files changed, 232 insertions(+), 31 deletions(-) diff --git a/spec/system/admin/trends/links/preview_card_providers_spec.rb b/spec/system/admin/trends/links/preview_card_providers_spec.rb index 0a5b5a7581b..159a5b720ae 100644 --- a/spec/system/admin/trends/links/preview_card_providers_spec.rb +++ b/spec/system/admin/trends/links/preview_card_providers_spec.rb @@ -5,20 +5,49 @@ require 'rails_helper' RSpec.describe 'Admin::Trends::Links::PreviewCardProviders' do let(:current_user) { Fabricate(:admin_user) } - before do - sign_in current_user - end + before { sign_in current_user } describe 'Performing batch updates' do - before do - visit admin_trends_links_preview_card_providers_path - end - context 'without selecting any records' do it 'displays a notice about selection' do + visit admin_trends_links_preview_card_providers_path + click_on button_for_allow - expect(page).to have_content(selection_error_text) + expect(page) + .to have_content(selection_error_text) + end + end + + context 'with providers that are not trendable' do + let!(:provider) { Fabricate :preview_card_provider, trendable: false } + + it 'allows the providers' do + visit admin_trends_links_preview_card_providers_path + + check_item + + expect { click_on button_for_allow } + .to change { provider.reload.trendable? }.from(false).to(true) + end + end + + context 'with providers that are trendable' do + let!(:provider) { Fabricate :preview_card_provider, trendable: true } + + it 'disallows the providers' do + visit admin_trends_links_preview_card_providers_path + + check_item + + expect { click_on button_for_disallow } + .to change { provider.reload.trendable? }.from(true).to(false) + end + end + + def check_item + within '.batch-table__row' do + find('input[type=checkbox]').check end end @@ -26,6 +55,10 @@ RSpec.describe 'Admin::Trends::Links::PreviewCardProviders' do I18n.t('admin.trends.allow') end + def button_for_disallow + I18n.t('admin.trends.disallow') + end + def selection_error_text I18n.t('admin.trends.links.publishers.no_publisher_selected') end diff --git a/spec/system/admin/trends/links_spec.rb b/spec/system/admin/trends/links_spec.rb index 15138f42d11..879bbe8ad9f 100644 --- a/spec/system/admin/trends/links_spec.rb +++ b/spec/system/admin/trends/links_spec.rb @@ -5,20 +5,77 @@ require 'rails_helper' RSpec.describe 'Admin::Trends::Links' do let(:current_user) { Fabricate(:admin_user) } - before do - sign_in current_user - end + before { sign_in current_user } describe 'Performing batch updates' do - before do - visit admin_trends_links_path - end - context 'without selecting any records' do it 'displays a notice about selection' do + visit admin_trends_links_path + click_on button_for_allow - expect(page).to have_content(selection_error_text) + expect(page) + .to have_content(selection_error_text) + end + end + + context 'with links that are not trendable' do + let!(:preview_card_trend) { Fabricate :preview_card_trend, preview_card: Fabricate(:preview_card, trendable: false) } + + it 'allows the links' do + visit admin_trends_links_path + + check_item + + expect { click_on button_for_allow } + .to change { preview_card_trend.preview_card.reload.trendable? }.from(false).to(true) + end + end + + context 'with links whose providers are not trendable' do + let(:preview_card_provider) { Fabricate :preview_card_provider, trendable: false } + let!(:preview_card_trend) { Fabricate :preview_card_trend, preview_card: Fabricate(:preview_card, url: "https://#{preview_card_provider.domain}/page") } + + it 'allows the providers of the links' do + visit admin_trends_links_path + + check_item + + expect { click_on button_for_allow_providers } + .to change { preview_card_trend.preview_card.provider.reload.trendable? }.from(false).to(true) + end + end + + context 'with links that are trendable' do + let!(:preview_card_trend) { Fabricate :preview_card_trend, preview_card: Fabricate(:preview_card, trendable: true) } + + it 'disallows the links' do + visit admin_trends_links_path + + check_item + + expect { click_on button_for_disallow } + .to change { preview_card_trend.preview_card.reload.trendable? }.from(true).to(false) + end + end + + context 'with links whose providers are trendable' do + let(:preview_card_provider) { Fabricate :preview_card_provider, trendable: true } + let!(:preview_card_trend) { Fabricate :preview_card_trend, preview_card: Fabricate(:preview_card, url: "https://#{preview_card_provider.domain}/page") } + + it 'disallows the links' do + visit admin_trends_links_path + + check_item + + expect { click_on button_for_disallow_providers } + .to change { preview_card_trend.preview_card.provider.reload.trendable? }.from(true).to(false) + end + end + + def check_item + within '.batch-table__row' do + find('input[type=checkbox]').check end end @@ -26,6 +83,18 @@ RSpec.describe 'Admin::Trends::Links' do I18n.t('admin.trends.links.allow') end + def button_for_allow_providers + I18n.t('admin.trends.links.allow_provider') + end + + def button_for_disallow + I18n.t('admin.trends.links.disallow') + end + + def button_for_disallow_providers + I18n.t('admin.trends.links.disallow_provider') + end + def selection_error_text I18n.t('admin.trends.links.no_link_selected') end diff --git a/spec/system/admin/trends/statuses_spec.rb b/spec/system/admin/trends/statuses_spec.rb index 45c048afb07..be081df9893 100644 --- a/spec/system/admin/trends/statuses_spec.rb +++ b/spec/system/admin/trends/statuses_spec.rb @@ -5,20 +5,75 @@ require 'rails_helper' RSpec.describe 'Admin::Trends::Statuses' do let(:current_user) { Fabricate(:admin_user) } - before do - sign_in current_user - end + before { sign_in current_user } describe 'Performing batch updates' do - before do - visit admin_trends_statuses_path - end - context 'without selecting any records' do it 'displays a notice about selection' do + visit admin_trends_statuses_path + click_on button_for_allow - expect(page).to have_content(selection_error_text) + expect(page) + .to have_content(selection_error_text) + end + end + + context 'with statuses that are not trendable' do + let!(:status_trend) { Fabricate :status_trend, status: Fabricate(:status, trendable: false) } + + it 'allows the statuses' do + visit admin_trends_statuses_path + + check_item + + expect { click_on button_for_allow } + .to change { status_trend.status.reload.trendable? }.from(false).to(true) + end + end + + context 'with statuses whose accounts are not trendable' do + let!(:status_trend) { Fabricate :status_trend, status: Fabricate(:status, account: Fabricate(:account, trendable: false)) } + + it 'allows the accounts of the statuses' do + visit admin_trends_statuses_path + + check_item + + expect { click_on button_for_allow_accounts } + .to change { status_trend.status.account.reload.trendable? }.from(false).to(true) + end + end + + context 'with statuses that are trendable' do + let!(:status_trend) { Fabricate :status_trend, status: Fabricate(:status, trendable: true) } + + it 'disallows the statuses' do + visit admin_trends_statuses_path + + check_item + + expect { click_on button_for_disallow } + .to change { status_trend.status.reload.trendable? }.from(true).to(false) + end + end + + context 'with statuses whose accounts are trendable' do + let!(:status_trend) { Fabricate :status_trend, status: Fabricate(:status, account: Fabricate(:account, trendable: true)) } + + it 'disallows the statuses' do + visit admin_trends_statuses_path + + check_item + + expect { click_on button_for_disallow_accounts } + .to change { status_trend.status.reload.trendable? }.from(true).to(false) + end + end + + def check_item + within '.batch-table__row' do + find('input[type=checkbox]').check end end @@ -26,6 +81,18 @@ RSpec.describe 'Admin::Trends::Statuses' do I18n.t('admin.trends.statuses.allow') end + def button_for_allow_accounts + I18n.t('admin.trends.statuses.allow_account') + end + + def button_for_disallow + I18n.t('admin.trends.statuses.disallow') + end + + def button_for_disallow_accounts + I18n.t('admin.trends.statuses.disallow_account') + end + def selection_error_text I18n.t('admin.trends.statuses.no_status_selected') end diff --git a/spec/system/admin/trends/tags_spec.rb b/spec/system/admin/trends/tags_spec.rb index 30b0850b938..a71d9ba8cad 100644 --- a/spec/system/admin/trends/tags_spec.rb +++ b/spec/system/admin/trends/tags_spec.rb @@ -5,27 +5,59 @@ require 'rails_helper' RSpec.describe 'Admin::Trends::Tags' do let(:current_user) { Fabricate(:admin_user) } - before do - sign_in current_user - end + before { sign_in current_user } describe 'Performing batch updates' do - before do - visit admin_trends_tags_path - end - context 'without selecting any records' do it 'displays a notice about selection' do + visit admin_trends_tags_path + click_on button_for_allow expect(page).to have_content(selection_error_text) end end + context 'with tags that are not trendable' do + let!(:tag_trend) { Fabricate :tag_trend, tag: Fabricate(:tag, trendable: false) } + + it 'allows the tags' do + visit admin_trends_tags_path + + check_item + + expect { click_on button_for_allow } + .to change { tag_trend.tag.reload.trendable? }.from(false).to(true) + end + end + + context 'with tags that are trendable' do + let!(:tag_trend) { Fabricate :tag_trend, tag: Fabricate(:tag, trendable: true) } + + it 'disallows the tags' do + visit admin_trends_tags_path + + check_item + + expect { click_on button_for_disallow } + .to change { tag_trend.tag.reload.trendable? }.from(true).to(false) + end + end + + def check_item + within '.batch-table__row' do + find('input[type=checkbox]').check + end + end + def button_for_allow I18n.t('admin.trends.allow') end + def button_for_disallow + I18n.t('admin.trends.disallow') + end + def selection_error_text I18n.t('admin.trends.tags.no_tag_selected') end