Select preset warning in spec

This commit is contained in:
Matt Jankowski 2025-07-22 10:10:19 -04:00
parent 25f1a515f8
commit 18a045e221
2 changed files with 32 additions and 1 deletions

View File

@ -3,7 +3,11 @@
require 'rails_helper'
RSpec.describe AccountWarningPreset do
describe 'alphabetical' do
describe 'Validations' do
it { is_expected.to validate_presence_of(:text) }
end
describe '.alphabetical' do
let(:first) { Fabricate(:account_warning_preset, title: 'aaa', text: 'aaa') }
let(:second) { Fabricate(:account_warning_preset, title: 'bbb', text: 'aaa') }
let(:third) { Fabricate(:account_warning_preset, title: 'bbb', text: 'bbb') }
@ -14,4 +18,29 @@ RSpec.describe AccountWarningPreset do
expect(results).to eq([first, second, third])
end
end
describe '#to_label' do
subject { Fabricate.build(:account_warning_preset, title:, text:).to_label }
let(:title) { nil }
let(:text) { 'Preset text' }
context 'when title is blank' do
it { is_expected.to eq('Preset text') }
end
context 'when title is present' do
let(:title) { 'Title' }
it { is_expected.to eq('Title - Preset text') }
end
context 'when text is longer than limit' do
let(:title) { 'Title' }
before { stub_const('AccountWarningPreset::LABEL_TEXT_LENGTH', 10) }
it { is_expected.to eq('Title - Preset ...') }
end
end
end

View File

@ -9,6 +9,7 @@ RSpec.describe 'Admin Account Actions' do
describe 'Creating a new account action on an account' do
let(:account) { Fabricate(:account) }
let!(:account_warning_preset) { Fabricate :account_warning_preset }
it 'creates the action and redirects to the account page' do
visit new_admin_account_action_path(account_id: account.id)
@ -23,6 +24,7 @@ RSpec.describe 'Admin Account Actions' do
# Valid submission
choose(option: 'silence')
select account_warning_preset.to_label, from: 'admin_account_action_warning_preset_id'
expect { submit_form }
.to change { account.strikes.count }.by(1)
expect(page)