diff options
author | Sean McGivern <sean@gitlab.com> | 2019-02-22 13:46:00 +0300 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2019-02-22 13:46:00 +0300 |
commit | 695df38fce2893becfd858d9e96f2f4d648af2f2 (patch) | |
tree | 9f695eba7dbf063b1aa8e7e594fd0211e8a0ed8f /spec | |
parent | 6fa88ed77e1693cda845efe49bf2c9a77aed2e4f (diff) | |
parent | 28e1739a3fd8c93e4805fe0053faf820cec4e1bc (diff) |
Merge branch '55057-system-message-to-core' into 'master'
Port EE System Header And Footer feature to CE
Closes #55057
See merge request gitlab-org/gitlab-ce!25241
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/admin/appearances_controller_spec.rb | 55 | ||||
-rw-r--r-- | spec/features/admin/admin_appearance_spec.rb | 32 | ||||
-rw-r--r-- | spec/features/display_system_header_and_footer_bar_spec.rb | 137 | ||||
-rw-r--r-- | spec/helpers/appearances_helper_spec.rb | 76 | ||||
-rw-r--r-- | spec/models/appearance_spec.rb | 15 |
5 files changed, 315 insertions, 0 deletions
diff --git a/spec/controllers/admin/appearances_controller_spec.rb b/spec/controllers/admin/appearances_controller_spec.rb new file mode 100644 index 00000000000..4ddd0953267 --- /dev/null +++ b/spec/controllers/admin/appearances_controller_spec.rb @@ -0,0 +1,55 @@ +require 'spec_helper' + +describe Admin::AppearancesController do + let(:admin) { create(:admin) } + let(:header_message) { "Header message" } + let(:footer_message) { "Footer" } + + describe 'POST #create' do + let(:create_params) do + { + title: "Foo", + description: "Bar", + header_message: header_message, + footer_message: footer_message + } + end + + before do + sign_in(admin) + end + + it 'creates appearance with footer and header message' do + post :create, params: { appearance: create_params } + + expect(Appearance.current).to have_attributes( + header_message: header_message, + footer_message: footer_message + ) + end + end + + describe 'PUT #update' do + let(:update_params) do + { + header_message: header_message, + footer_message: footer_message + } + end + + before do + create(:appearance) + + sign_in(admin) + end + + it 'updates appearance with footer and header message' do + put :update, params: { appearance: update_params } + + expect(Appearance.current).to have_attributes( + header_message: header_message, + footer_message: footer_message + ) + end + end +end diff --git a/spec/features/admin/admin_appearance_spec.rb b/spec/features/admin/admin_appearance_spec.rb index 57215c0d1e9..83cd686818c 100644 --- a/spec/features/admin/admin_appearance_spec.rb +++ b/spec/features/admin/admin_appearance_spec.rb @@ -39,6 +39,38 @@ describe 'Admin Appearance' do expect_custom_new_project_appearance(appearance) end + context 'Custom system header and footer' do + before do + sign_in(create(:admin)) + end + + context 'when system header and footer messages are empty' do + it 'shows custom system header and footer fields' do + visit admin_appearances_path + + expect(page).to have_field('appearance_header_message', with: '') + expect(page).to have_field('appearance_footer_message', with: '') + expect(page).to have_field('appearance_message_background_color') + expect(page).to have_field('appearance_message_font_color') + end + end + + context 'when system header and footer messages are not empty' do + before do + appearance.update(header_message: 'Foo', footer_message: 'Bar') + end + + it 'shows custom system header and footer fields' do + visit admin_appearances_path + + expect(page).to have_field('appearance_header_message', with: appearance.header_message) + expect(page).to have_field('appearance_footer_message', with: appearance.footer_message) + expect(page).to have_field('appearance_message_background_color') + expect(page).to have_field('appearance_message_font_color') + end + end + end + it 'Custom sign-in page' do visit new_user_session_path diff --git a/spec/features/display_system_header_and_footer_bar_spec.rb b/spec/features/display_system_header_and_footer_bar_spec.rb new file mode 100644 index 00000000000..af9d9a5834f --- /dev/null +++ b/spec/features/display_system_header_and_footer_bar_spec.rb @@ -0,0 +1,137 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'Display system header and footer bar' do + let(:header_message) { "Foo" } + let(:footer_message) { "Bar" } + + shared_examples 'system header is configured' do + it 'shows system header' do + expect(page).to have_css('.header-message') + end + + it 'shows the correct content' do + page.within('.header-message') do + expect(page).to have_content(header_message) + end + end + end + + shared_examples 'system footer is configured' do + it 'shows system footer' do + expect(page).to have_css('.footer-message') + end + + it 'shows the correct content' do + page.within('.footer-message') do + expect(page).to have_content(footer_message) + end + end + end + + shared_examples 'system header is not configured' do + it 'does not show system header' do + expect(page).not_to have_css('.header-message') + end + end + + shared_examples 'system footer is not configured' do + it 'does not show system footer' do + expect(page).not_to have_css('.footer-message') + end + end + + context 'when authenticated' do + context 'when system header and footer are not configured' do + before do + sign_in(create(:user)) + + visit root_path + end + + it_behaves_like 'system header is not configured' + it_behaves_like 'system footer is not configured' + end + + context 'when only system header is defined' do + before do + create(:appearance, header_message: header_message) + + sign_in(create(:user)) + visit root_path + end + + it_behaves_like 'system header is configured' + it_behaves_like 'system footer is not configured' + end + + context 'when only system footer is defined' do + before do + create(:appearance, footer_message: footer_message) + + sign_in(create(:user)) + visit root_path + end + + it_behaves_like 'system header is not configured' + it_behaves_like 'system footer is configured' + end + + context 'when system header and footer are defined' do + before do + create(:appearance, header_message: header_message, footer_message: footer_message) + + sign_in(create(:user)) + visit root_path + end + + it_behaves_like 'system header is configured' + it_behaves_like 'system footer is configured' + end + end + + context 'when not authenticated' do + context 'when system header and footer are not configured' do + before do + visit root_path + end + + it_behaves_like 'system header is not configured' + it_behaves_like 'system footer is not configured' + end + + context 'when only system header is defined' do + before do + create(:appearance, header_message: header_message) + + visit root_path + end + + it_behaves_like 'system header is configured' + it_behaves_like 'system footer is not configured' + end + + context 'when only system footer is defined' do + before do + create(:appearance, footer_message: footer_message) + + visit root_path + end + + it_behaves_like 'system header is not configured' + it_behaves_like 'system footer is configured' + end + + context 'when system header and footer are defined' do + before do + create(:appearance, header_message: header_message, footer_message: footer_message) + + visit root_path + end + + it_behaves_like 'system header is configured' + it_behaves_like 'system footer is configured' + end + end +end diff --git a/spec/helpers/appearances_helper_spec.rb b/spec/helpers/appearances_helper_spec.rb new file mode 100644 index 00000000000..8d717b968dd --- /dev/null +++ b/spec/helpers/appearances_helper_spec.rb @@ -0,0 +1,76 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe AppearancesHelper do + before do + user = create(:user) + allow(helper).to receive(:current_user).and_return(user) + end + + describe '#header_message' do + it 'returns nil when header message field is not set' do + create(:appearance) + + expect(helper.header_message).to be_nil + end + + context 'when header message is set' do + it 'includes current message' do + message = "Foo bar" + create(:appearance, header_message: message) + + expect(helper.header_message).to include(message) + end + end + end + + describe '#footer_message' do + it 'returns nil when footer message field is not set' do + create(:appearance) + + expect(helper.footer_message).to be_nil + end + + context 'when footer message is set' do + it 'includes current message' do + message = "Foo bar" + create(:appearance, footer_message: message) + + expect(helper.footer_message).to include(message) + end + end + end + + describe '#brand_image' do + let!(:appearance) { create(:appearance, :with_logo) } + + context 'when there is a logo' do + it 'returns a path' do + expect(helper.brand_image).to match(%r(img data-src="/uploads/-/system/appearance/.*png)) + end + end + + context 'when there is a logo but no associated upload' do + before do + # Legacy attachments were not tracked in the uploads table + appearance.logo.upload.destroy + appearance.reload + end + + it 'falls back to using the original path' do + expect(helper.brand_image).to match(%r(img data-src="/uploads/-/system/appearance/.*png)) + end + end + end + + describe '#brand_title' do + it 'returns the default CE title when no appearance is present' do + allow(helper) + .to receive(:current_appearance) + .and_return(nil) + + expect(helper.brand_title).to eq('GitLab Community Edition') + end + end +end diff --git a/spec/models/appearance_spec.rb b/spec/models/appearance_spec.rb index cc76a2019ec..28d482adebf 100644 --- a/spec/models/appearance_spec.rb +++ b/spec/models/appearance_spec.rb @@ -63,4 +63,19 @@ describe Appearance do %i(logo header_logo favicon).each do |logo_type| it_behaves_like 'logo paths', logo_type end + + describe 'validations' do + let(:triplet) { '#000' } + let(:hex) { '#AABBCC' } + + it { is_expected.to allow_value(nil).for(:message_background_color) } + it { is_expected.to allow_value(triplet).for(:message_background_color) } + it { is_expected.to allow_value(hex).for(:message_background_color) } + it { is_expected.not_to allow_value('000').for(:message_background_color) } + + it { is_expected.to allow_value(nil).for(:message_font_color) } + it { is_expected.to allow_value(triplet).for(:message_font_color) } + it { is_expected.to allow_value(hex).for(:message_font_color) } + it { is_expected.not_to allow_value('000').for(:message_font_color) } + end end |