diff --git a/spec/models/account_warning_preset_spec.rb b/spec/models/account_warning_preset_spec.rb index e7a98551751..0053302deb2 100644 --- a/spec/models/account_warning_preset_spec.rb +++ b/spec/models/account_warning_preset_spec.rb @@ -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 diff --git a/spec/system/admin/account_actions_spec.rb b/spec/system/admin/account_actions_spec.rb index abfd33dc272..1ebaecbb424 100644 --- a/spec/system/admin/account_actions_spec.rb +++ b/spec/system/admin/account_actions_spec.rb @@ -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)