diff options
Diffstat (limited to 'spec/models/appearance_spec.rb')
-rw-r--r-- | spec/models/appearance_spec.rb | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/spec/models/appearance_spec.rb b/spec/models/appearance_spec.rb index 54dc280d7ac..b5f47c950b9 100644 --- a/spec/models/appearance_spec.rb +++ b/spec/models/appearance_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' RSpec.describe Appearance do + using RSpec::Parameterized::TableSyntax subject { build(:appearance) } it { include(CacheableAttributes) } @@ -14,8 +15,10 @@ RSpec.describe Appearance do subject(:appearance) { described_class.new } it { expect(appearance.title).to eq('') } - it { expect(appearance.pwa_short_name).to eq('') } it { expect(appearance.description).to eq('') } + it { expect(appearance.pwa_name).to eq('') } + it { expect(appearance.pwa_short_name).to eq('') } + it { expect(appearance.pwa_description).to eq('') } it { expect(appearance.new_project_guidelines).to eq('') } it { expect(appearance.profile_image_guidelines).to eq('') } it { expect(appearance.header_message).to eq('') } @@ -23,6 +26,7 @@ RSpec.describe Appearance do it { expect(appearance.message_background_color).to eq('#E75E40') } it { expect(appearance.message_font_color).to eq('#FFFFFF') } it { expect(appearance.email_header_and_footer_enabled).to eq(false) } + it { expect(Appearance::ALLOWED_PWA_ICON_SCALER_WIDTHS).to match_array([192, 512]) } end describe '#single_appearance_row' do @@ -81,6 +85,19 @@ RSpec.describe Appearance do it_behaves_like 'logo paths', logo_type end + shared_examples 'icon paths sized' do |width| + let_it_be(:appearance) { create(:appearance, :with_pwa_icon) } + let_it_be(:filename) { 'dk.png' } + let_it_be(:expected_path) { "/uploads/-/system/appearance/pwa_icon/#{appearance.id}/#{filename}?width=#{width}" } + + it 'returns icon path with size parameter' do + expect(appearance.pwa_icon_path_scaled(width)).to eq(expected_path) + end + end + + it_behaves_like 'icon paths sized', 192 + it_behaves_like 'icon paths sized', 512 + describe 'validations' do let(:triplet) { '#000' } let(:hex) { '#AABBCC' } @@ -96,6 +113,41 @@ RSpec.describe Appearance do it { is_expected.not_to allow_value('000').for(:message_font_color) } end + shared_examples 'validation allows' do + it { is_expected.to allow_value(value).for(attribute) } + end + + shared_examples 'validation permits with message' do + it { is_expected.not_to allow_value(value).for(attribute).with_message(message) } + end + + context 'valid pwa attributes' do + where(:attribute, :value) do + :pwa_name | nil + :pwa_name | "G" * 255 + :pwa_short_name | nil + :pwa_short_name | "S" * 255 + :pwa_description | nil + :pwa_description | "T" * 2048 + end + + with_them do + it_behaves_like 'validation allows' + end + end + + context 'invalid pwa attributes' do + where(:attribute, :value, :message) do + :pwa_name | "G" * 256 | 'is too long (maximum is 255 characters)' + :pwa_short_name | "S" * 256 | 'is too long (maximum is 255 characters)' + :pwa_description | "T" * 2049 | 'is too long (maximum is 2048 characters)' + end + + with_them do + it_behaves_like 'validation permits with message' + end + end + describe 'email_header_and_footer_enabled' do context 'default email_header_and_footer_enabled flag value' do it 'returns email_header_and_footer_enabled as true' do |