2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
RSpec.describe NavHelper, feature_category: :navigation do
|
2018-03-27 19:54:05 +05:30
|
|
|
describe '#header_links' do
|
2019-12-21 20:55:43 +05:30
|
|
|
include_context 'custom session'
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
before do
|
2019-12-21 20:55:43 +05:30
|
|
|
allow(helper).to receive(:session).and_return(session)
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user is logged in' do
|
2019-12-21 20:55:43 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:current_user_mode) { Gitlab::Auth::CurrentUserMode.new(user) }
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:current_user).and_return(user)
|
2019-12-21 20:55:43 +05:30
|
|
|
allow(helper).to receive(:current_user_mode).and_return(current_user_mode)
|
2018-03-27 19:54:05 +05:30
|
|
|
allow(helper).to receive(:can?) { true }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has all the expected links by default' do
|
|
|
|
menu_items = [:user_dropdown, :search, :issues, :merge_requests, :todos]
|
|
|
|
|
|
|
|
expect(helper.header_links).to contain_exactly(*menu_items)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains the impersonation link while impersonating' do
|
|
|
|
expect(helper).to receive(:session) { { impersonator_id: 1 } }
|
|
|
|
|
|
|
|
expect(helper.header_links).to include(:admin_impersonation)
|
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
context 'as admin' do
|
|
|
|
let(:user) { create(:user, :admin) }
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
context 'application setting :admin_mode is enabled' do
|
2019-12-21 20:55:43 +05:30
|
|
|
it 'does not contain the admin mode link by default' do
|
|
|
|
expect(helper.header_links).not_to include(:admin_mode)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with admin mode enabled' do
|
|
|
|
before do
|
2020-01-01 13:55:28 +05:30
|
|
|
current_user_mode.request_admin_mode!
|
2019-12-21 20:55:43 +05:30
|
|
|
current_user_mode.enable_admin_mode!(password: user.password)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains the admin mode link' do
|
|
|
|
expect(helper.header_links).to include(:admin_mode)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
context 'application setting :admin_mode is disabled' do
|
2019-12-21 20:55:43 +05:30
|
|
|
before do
|
2021-04-29 21:17:54 +05:30
|
|
|
stub_application_setting(admin_mode: false)
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not contain the admin mode link' do
|
|
|
|
expect(helper.header_links).not_to include(:admin_mode)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with admin mode enabled' do
|
|
|
|
before do
|
2020-01-01 13:55:28 +05:30
|
|
|
current_user_mode.request_admin_mode!
|
2019-12-21 20:55:43 +05:30
|
|
|
current_user_mode.enable_admin_mode!(password: user.password)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has no effect on header links' do
|
|
|
|
expect(helper.header_links).not_to include(:admin_mode)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
context 'when the user cannot read cross project' do
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:can?).with(user, :read_cross_project) { false }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not contain cross project elements when the user cannot read cross project' do
|
|
|
|
expect(helper.header_links).not_to include(:issues, :merge_requests, :todos, :search)
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
it 'shows the search box when the user cannot read cross project and they are visiting a project' do
|
2018-03-27 19:54:05 +05:30
|
|
|
helper.instance_variable_set(:@project, create(:project))
|
|
|
|
|
|
|
|
expect(helper.header_links).to include(:search)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
context 'when the user is not logged in' do
|
|
|
|
let(:current_user_mode) { Gitlab::Auth::CurrentUserMode.new(nil) }
|
2018-03-27 19:54:05 +05:30
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
before do
|
|
|
|
allow(helper).to receive(:current_user).and_return(nil)
|
|
|
|
allow(helper).to receive(:current_user_mode).and_return(current_user_mode)
|
|
|
|
allow(helper).to receive(:can?).with(nil, :read_cross_project) { true }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns only the sign in and search when the user is not logged in' do
|
|
|
|
expect(helper.header_links).to contain_exactly(:sign_in, :search)
|
|
|
|
end
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
describe '.admin_monitoring_nav_links' do
|
2019-09-04 21:01:54 +05:30
|
|
|
subject { helper.admin_monitoring_nav_links }
|
|
|
|
|
|
|
|
it { is_expected.to all(be_a(String)) }
|
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
describe '#page_has_markdown?' do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
where path: %w(
|
2022-11-25 23:54:43 +05:30
|
|
|
projects/merge_requests#show
|
2020-05-24 23:13:21 +05:30
|
|
|
projects/merge_requests/conflicts#show
|
|
|
|
issues#show
|
|
|
|
milestones#show
|
|
|
|
issues#designs
|
|
|
|
)
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:current_path?).and_call_original
|
|
|
|
allow(helper).to receive(:current_path?).with(path).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { helper.page_has_markdown? }
|
|
|
|
|
|
|
|
it { is_expected.to eq(true) }
|
|
|
|
end
|
|
|
|
end
|
2023-03-17 16:20:25 +05:30
|
|
|
|
|
|
|
describe '#show_super_sidebar?' do
|
2023-07-09 08:55:56 +05:30
|
|
|
shared_examples 'show_super_sidebar is supposed to' do
|
2023-03-17 16:20:25 +05:30
|
|
|
before do
|
|
|
|
stub_feature_flags(super_sidebar_nav: new_nav_ff)
|
|
|
|
user.update!(use_new_navigation: user_preference)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with feature flag off' do
|
|
|
|
let(:new_nav_ff) { false }
|
|
|
|
|
|
|
|
context 'when user has new nav disabled' do
|
|
|
|
let(:user_preference) { false }
|
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
specify { expect(subject).to eq false }
|
2023-03-17 16:20:25 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user has new nav enabled' do
|
|
|
|
let(:user_preference) { true }
|
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
specify { expect(subject).to eq false }
|
2023-03-17 16:20:25 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with feature flag on' do
|
|
|
|
let(:new_nav_ff) { true }
|
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
context 'when user has not interacted with the new nav toggle yet' do
|
|
|
|
let(:user_preference) { nil }
|
|
|
|
|
|
|
|
specify { expect(subject).to eq false }
|
|
|
|
|
|
|
|
context 'when the user was enrolled into the new nav via a special feature flag' do
|
|
|
|
before do
|
|
|
|
# this ff is disabled in globally to keep tests of the old nav working
|
|
|
|
stub_feature_flags(super_sidebar_nav_enrolled: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
specify { expect(subject).to eq true }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
context 'when user has new nav disabled' do
|
|
|
|
let(:user_preference) { false }
|
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
specify { expect(subject).to eq false }
|
2023-03-17 16:20:25 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user has new nav enabled' do
|
|
|
|
let(:user_preference) { true }
|
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
specify { expect(subject).to eq true }
|
2023-03-17 16:20:25 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-07-09 08:55:56 +05:30
|
|
|
|
|
|
|
context 'when nil is provided' do
|
|
|
|
specify { expect(helper.show_super_sidebar?(nil)).to eq false }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when no user is signed-in' do
|
|
|
|
specify do
|
|
|
|
allow(helper).to receive(:current_user).and_return(nil)
|
|
|
|
|
|
|
|
expect(helper.show_super_sidebar?).to eq false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is signed-in' do
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
|
|
|
|
context 'with current_user as a default' do
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:current_user).and_return(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { helper.show_super_sidebar? }
|
|
|
|
|
|
|
|
it_behaves_like 'show_super_sidebar is supposed to'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with user provided as an argument' do
|
|
|
|
subject { helper.show_super_sidebar?(user) }
|
|
|
|
|
|
|
|
it_behaves_like 'show_super_sidebar is supposed to'
|
|
|
|
end
|
|
|
|
end
|
2023-03-17 16:20:25 +05:30
|
|
|
end
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|