Extract helper method for repeated form fill in admin/domain_blocks feature spec (#29128)

This commit is contained in:
Matt Jankowski 2024-02-08 05:02:53 -05:00 committed by GitHub
parent 52986f35b8
commit 5271131658
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -12,9 +12,7 @@ describe 'blocking domains through the moderation interface' do
it 'adds a new domain block' do
visit new_admin_domain_block_path
fill_in 'domain_block_domain', with: 'example.com'
select I18n.t('admin.domain_blocks.new.severity.silence'), from: 'domain_block_severity'
click_on I18n.t('admin.domain_blocks.new.create')
submit_domain_block('example.com', 'silence')
expect(DomainBlock.exists?(domain: 'example.com', severity: 'silence')).to be true
expect(DomainBlockWorker).to have_received(:perform_async)
@ -25,9 +23,7 @@ describe 'blocking domains through the moderation interface' do
it 'presents a confirmation screen before suspending the domain' do
visit new_admin_domain_block_path
fill_in 'domain_block_domain', with: 'example.com'
select I18n.t('admin.domain_blocks.new.severity.suspend'), from: 'domain_block_severity'
click_on I18n.t('admin.domain_blocks.new.create')
submit_domain_block('example.com', 'suspend')
# It doesn't immediately block but presents a confirmation screen
expect(page).to have_title(I18n.t('admin.domain_blocks.confirm_suspension.title', domain: 'example.com'))
@ -47,9 +43,7 @@ describe 'blocking domains through the moderation interface' do
visit new_admin_domain_block_path
fill_in 'domain_block_domain', with: 'example.com'
select I18n.t('admin.domain_blocks.new.severity.suspend'), from: 'domain_block_severity'
click_on I18n.t('admin.domain_blocks.new.create')
submit_domain_block('example.com', 'suspend')
# It doesn't immediately block but presents a confirmation screen
expect(page).to have_title(I18n.t('admin.domain_blocks.confirm_suspension.title', domain: 'example.com'))
@ -69,9 +63,7 @@ describe 'blocking domains through the moderation interface' do
visit new_admin_domain_block_path
fill_in 'domain_block_domain', with: 'subdomain.example.com'
select I18n.t('admin.domain_blocks.new.severity.suspend'), from: 'domain_block_severity'
click_on I18n.t('admin.domain_blocks.new.create')
submit_domain_block('subdomain.example.com', 'suspend')
# It doesn't immediately block but presents a confirmation screen
expect(page).to have_title(I18n.t('admin.domain_blocks.confirm_suspension.title', domain: 'subdomain.example.com'))
@ -84,8 +76,11 @@ describe 'blocking domains through the moderation interface' do
expect(DomainBlockWorker).to have_received(:perform_async)
# And leaves the previous block alone
expect(domain_block.reload.severity).to eq 'silence'
expect(domain_block.reload.domain).to eq 'example.com'
expect(domain_block.reload)
.to have_attributes(
severity: eq('silence'),
domain: eq('example.com')
)
end
end
@ -109,4 +104,12 @@ describe 'blocking domains through the moderation interface' do
expect(domain_block.reload.severity).to eq 'suspend'
end
end
private
def submit_domain_block(domain, severity)
fill_in 'domain_block_domain', with: domain
select I18n.t("admin.domain_blocks.new.severity.#{severity}"), from: 'domain_block_severity'
click_on I18n.t('admin.domain_blocks.new.create')
end
end