2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe AppearancesHelper do
|
2022-11-25 23:54:43 +05:30
|
|
|
let_it_be(:gitlab_logo) { ActionController::Base.helpers.image_path('logo.svg') }
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
before do
|
|
|
|
user = create(:user)
|
|
|
|
allow(helper).to receive(:current_user).and_return(user)
|
|
|
|
end
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
describe '.current_appearance' do
|
|
|
|
it 'memoizes empty appearance' do
|
|
|
|
expect(Appearance).to receive(:current).once
|
|
|
|
|
|
|
|
2.times { helper.current_appearance }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'memoizes custom appearance' do
|
|
|
|
create(:appearance)
|
|
|
|
|
|
|
|
expect(Appearance).to receive(:current).once.and_call_original
|
|
|
|
|
|
|
|
2.times { helper.current_appearance }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
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
|
|
|
|
context 'when there is a logo' do
|
2022-11-25 23:54:43 +05:30
|
|
|
let!(:appearance) { create(:appearance, :with_logo) }
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
it 'returns a path' do
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(helper.brand_image).to match(%r(img .* data-src="/uploads/-/system/appearance/.*png))
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is 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
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
context 'when there is no logo' do
|
|
|
|
it 'returns path of GitLab logo' do
|
|
|
|
expect(helper.brand_image).to match(%r(img .* data-src="#{gitlab_logo}))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a title' do
|
|
|
|
let!(:appearance) { create(:appearance, title: 'My title') }
|
|
|
|
|
|
|
|
it 'returns the title' do
|
|
|
|
expect(helper.brand_image).to match(%r(img alt="My title"))
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
2022-11-25 23:54:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is no title' do
|
|
|
|
it 'returns the default title' do
|
|
|
|
expect(helper.brand_image).to match(%r(img alt="GitLab))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#brand_image_path' do
|
|
|
|
context 'with a custom logo' do
|
|
|
|
let!(:appearance) { create(:appearance, :with_logo) }
|
|
|
|
|
|
|
|
it 'returns path of custom logo' do
|
|
|
|
expect(helper.brand_image_path).to match(%r(/uploads/-/system/appearance/.*/dk.png))
|
|
|
|
end
|
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
context 'with no custom logo' do
|
|
|
|
it 'returns path of GitLab logo' do
|
|
|
|
expect(helper.brand_image_path).to eq(gitlab_logo)
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
describe '#brand_header_logo' do
|
|
|
|
let(:options) { {} }
|
|
|
|
|
|
|
|
subject do
|
|
|
|
helper.brand_header_logo(options)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with header logo' do
|
|
|
|
let!(:appearance) { create(:appearance, :with_header_logo) }
|
|
|
|
|
|
|
|
it 'renders image tag' do
|
|
|
|
expect(helper).to receive(:image_tag).with(appearance.header_logo_path, class: 'brand-header-logo')
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with add_gitlab_white_text option' do
|
|
|
|
let(:options) { { add_gitlab_white_text: true } }
|
|
|
|
|
|
|
|
it 'renders shared/logo_with_white_text partial' do
|
|
|
|
expect(helper).to receive(:render).with(partial: 'shared/logo_with_white_text', formats: :svg)
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with add_gitlab_black_text option' do
|
|
|
|
let(:options) { { add_gitlab_black_text: true } }
|
|
|
|
|
|
|
|
it 'renders shared/logo_with_black_text partial' do
|
|
|
|
expect(helper).to receive(:render).with(partial: 'shared/logo_with_black_text', formats: :svg)
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders shared/logo by default' do
|
|
|
|
expect(helper).to receive(:render).with(partial: 'shared/logo', formats: :svg)
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
describe '#brand_title' do
|
|
|
|
it 'returns the default title when no appearance is present' do
|
|
|
|
allow(helper).to receive(:current_appearance).and_return(nil)
|
|
|
|
|
|
|
|
expect(helper.brand_title).to eq(helper.default_brand_title)
|
|
|
|
end
|
|
|
|
end
|
2023-01-13 00:05:48 +05:30
|
|
|
|
|
|
|
describe '#default_brand_title' do
|
|
|
|
it 'returns the default title' do
|
|
|
|
edition = Gitlab.ee? ? 'Enterprise' : 'Community'
|
|
|
|
expected_default_brand_title = "GitLab #{edition} Edition"
|
|
|
|
|
|
|
|
expect(helper.default_brand_title).to eq _(expected_default_brand_title)
|
|
|
|
end
|
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|