diff options
Diffstat (limited to 'spec/helpers/sidebars_helper_spec.rb')
-rw-r--r-- | spec/helpers/sidebars_helper_spec.rb | 229 |
1 files changed, 147 insertions, 82 deletions
diff --git a/spec/helpers/sidebars_helper_spec.rb b/spec/helpers/sidebars_helper_spec.rb index 4109eb01caa..3e5ee714b32 100644 --- a/spec/helpers/sidebars_helper_spec.rb +++ b/spec/helpers/sidebars_helper_spec.rb @@ -71,6 +71,36 @@ RSpec.describe SidebarsHelper, feature_category: :navigation do let(:project) { nil } let(:current_user_mode) { Gitlab::Auth::CurrentUserMode.new(user) } + let(:global_shortcut_links) do + [ + { + title: _('Milestones'), + href: dashboard_milestones_path, + css_class: 'dashboard-shortcuts-milestones' + }, + { + title: _('Snippets'), + href: dashboard_snippets_path, + css_class: 'dashboard-shortcuts-snippets' + }, + { + title: _('Activity'), + href: activity_dashboard_path, + css_class: 'dashboard-shortcuts-activity' + }, + { + title: _('Groups'), + href: dashboard_groups_path, + css_class: 'dashboard-shortcuts-groups' + }, + { + title: _('Projects'), + href: dashboard_projects_path, + css_class: 'dashboard-shortcuts-projects' + } + ] + end + subject do helper.super_sidebar_context(user, group: group, project: project, panel: panel, panel_type: panel_type) end @@ -139,65 +169,65 @@ RSpec.describe SidebarsHelper, feature_category: :navigation do canary_toggle_com_url: Gitlab::Saas.canary_toggle_com_url, pinned_items: %w[foo bar], update_pins_url: pins_path, - shortcut_links: [ - { - title: _('Milestones'), - href: dashboard_milestones_path, - css_class: 'dashboard-shortcuts-milestones' - }, - { - title: _('Snippets'), - href: dashboard_snippets_path, - css_class: 'dashboard-shortcuts-snippets' - }, - { - title: _('Activity'), - href: activity_dashboard_path, - css_class: 'dashboard-shortcuts-activity' - } - ] + shortcut_links: global_shortcut_links, + track_visits_path: track_namespace_visits_path }) end describe "shortcut links" do - let(:global_shortcut_links) do - [ - { - title: _('Milestones'), - href: dashboard_milestones_path, - css_class: 'dashboard-shortcuts-milestones' - }, - { - title: _('Snippets'), - href: dashboard_snippets_path, - css_class: 'dashboard-shortcuts-snippets' - }, - { - title: _('Activity'), - href: activity_dashboard_path, - css_class: 'dashboard-shortcuts-activity' - } - ] - end + describe "as the anonymous user" do + let_it_be(:user) { nil } + let(:global_shortcut_links) do + [ + { + title: _('Snippets'), + href: explore_snippets_path, + css_class: 'dashboard-shortcuts-snippets' + }, + { + title: _('Groups'), + href: explore_groups_path, + css_class: 'dashboard-shortcuts-groups' + }, + { + title: _('Projects'), + href: explore_projects_path, + css_class: 'dashboard-shortcuts-projects' + } + ] + end + + it 'returns global shortcut links' do + expect(subject[:shortcut_links]).to eq(global_shortcut_links) + end + + context 'in a project' do + let_it_be(:project) { build_stubbed(:project) } - it 'returns global shortcut links' do - expect(subject[:shortcut_links]).to eq(global_shortcut_links) + it 'returns project-specific shortcut links' do + expect(subject[:shortcut_links]).to eq(global_shortcut_links) + end + end end - context 'in a project' do - # rubocop: disable RSpec/FactoryBot/AvoidCreate - let_it_be(:project) { create(:project) } - # rubocop: enable RSpec/FactoryBot/AvoidCreate + describe "as logged-in user" do + it 'returns global shortcut links' do + expect(subject[:shortcut_links]).to eq(global_shortcut_links) + end - it 'returns project-specific shortcut links' do - expect(subject[:shortcut_links]).to eq([ - *global_shortcut_links, - { - title: _('Create a new issue'), - href: new_project_issue_path(project), - css_class: 'shortcuts-new-issue' - } - ]) + context 'in a project' do + let_it_be(:project) { build_stubbed(:project) } + + it 'returns project-specific shortcut links' do + expect(subject[:shortcut_links]).to eq([ + *global_shortcut_links, + { + title: _('Create a new issue'), + href: new_project_issue_path(project), + css_class: 'shortcuts-new-issue' + } + ]) + end end end end @@ -488,7 +518,6 @@ RSpec.describe SidebarsHelper, feature_category: :navigation do end describe '#super_sidebar_nav_panel' do - let(:user) { build(:user) } let(:group) { build(:group) } let(:project) { build(:project) } let(:organization) { build(:organization) } @@ -500,48 +529,84 @@ RSpec.describe SidebarsHelper, feature_category: :navigation do { current_user: nil, container: group, show_discover_group_security: false }) allow(group).to receive(:to_global_id).and_return(5) - Rails.cache.write(['users', user.id, 'assigned_open_issues_count'], 1) - Rails.cache.write(['users', user.id, 'assigned_open_merge_requests_count'], 4) - Rails.cache.write(['users', user.id, 'review_requested_open_merge_requests_count'], 0) - Rails.cache.write(['users', user.id, 'todos_pending_count'], 3) end - it 'returns Project Panel for project nav' do - expect(helper.super_sidebar_nav_panel(nav: 'project')).to be_a(Sidebars::Projects::SuperSidebarPanel) - end + shared_examples 'nav panels available to logged-out users' do + it 'returns Project Panel for project nav' do + expect(helper.super_sidebar_nav_panel(nav: 'project', + user: user)).to be_a(Sidebars::Projects::SuperSidebarPanel) + end - it 'returns Group Panel for group nav' do - expect(helper.super_sidebar_nav_panel(nav: 'group')).to be_a(Sidebars::Groups::SuperSidebarPanel) - end + it 'returns Group Panel for group nav' do + expect(helper.super_sidebar_nav_panel(nav: 'group', user: user)).to be_a(Sidebars::Groups::SuperSidebarPanel) + end - it 'returns User Settings Panel for profile nav' do - expect(helper.super_sidebar_nav_panel(nav: 'profile')).to be_a(Sidebars::UserSettings::Panel) - end + it 'returns User profile Panel for user profile nav' do + viewed_user = build(:user) + expect(helper.super_sidebar_nav_panel(nav: 'user_profile', user: user, + viewed_user: viewed_user)).to be_a(Sidebars::UserProfile::Panel) + end - it 'returns User profile Panel for user profile nav' do - expect(helper.super_sidebar_nav_panel(nav: 'user_profile')).to be_a(Sidebars::UserProfile::Panel) - end + it 'returns Explore Panel for explore nav' do + expect(helper.super_sidebar_nav_panel(nav: 'explore', user: user)).to be_a(Sidebars::Explore::Panel) + end - it 'returns Admin Panel for admin nav' do - expect(helper.super_sidebar_nav_panel(nav: 'admin')).to be_a(Sidebars::Admin::Panel) - end + it 'returns Organization Panel for organization nav' do + expect( + helper.super_sidebar_nav_panel(nav: 'organization', organization: organization, user: user) + ).to be_a(Sidebars::Organizations::SuperSidebarPanel) + end - it 'returns Organization Panel for organization nav' do - expect( - helper.super_sidebar_nav_panel(nav: 'organization', organization: organization) - ).to be_a(Sidebars::Organizations::SuperSidebarPanel) + it 'returns Search Panel for search nav' do + expect(helper.super_sidebar_nav_panel(nav: 'search', user: user)).to be_a(Sidebars::Search::Panel) + end end - it 'returns "Your Work" Panel for your_work nav', :use_clean_rails_memory_store_caching do - expect(helper.super_sidebar_nav_panel(nav: 'your_work', user: user)).to be_a(Sidebars::YourWork::Panel) - end + describe 'when logged-in' do + let(:user) { build(:user) } + + before do + Rails.cache.write(['users', user.id, 'assigned_open_issues_count'], 1) + Rails.cache.write(['users', user.id, 'assigned_open_merge_requests_count'], 4) + Rails.cache.write(['users', user.id, 'review_requested_open_merge_requests_count'], 0) + Rails.cache.write(['users', user.id, 'todos_pending_count'], 3) + end + + it 'returns User Settings Panel for profile nav' do + expect(helper.super_sidebar_nav_panel(nav: 'profile', user: user)).to be_a(Sidebars::UserSettings::Panel) + end + + describe 'admin user' do + it 'returns Admin Panel for admin nav', :aggregate_failures do + allow(user).to receive(:can_admin_all_resources?).and_return(true) + + expect(helper.super_sidebar_nav_panel(nav: 'admin', user: user)).to be_a(Sidebars::Admin::Panel) + end + end + + it 'returns Your Work Panel for admin nav' do + expect(helper.super_sidebar_nav_panel(nav: 'admin', user: user)).to be_a(Sidebars::YourWork::Panel) + end + + it 'returns "Your Work" Panel for your_work nav', :use_clean_rails_memory_store_caching do + expect(helper.super_sidebar_nav_panel(nav: 'your_work', user: user)).to be_a(Sidebars::YourWork::Panel) + end + + it 'returns "Your Work" Panel as a fallback', :use_clean_rails_memory_store_caching do + expect(helper.super_sidebar_nav_panel(user: user)).to be_a(Sidebars::YourWork::Panel) + end - it 'returns Search Panel for search nav' do - expect(helper.super_sidebar_nav_panel(nav: 'search', user: user)).to be_a(Sidebars::Search::Panel) + it_behaves_like 'nav panels available to logged-out users' end - it 'returns "Your Work" Panel as a fallback', :use_clean_rails_memory_store_caching do - expect(helper.super_sidebar_nav_panel(user: user)).to be_a(Sidebars::YourWork::Panel) + describe 'when logged-out' do + let(:user) { nil } + + it_behaves_like 'nav panels available to logged-out users' + + it 'returns "Explore" Panel as a fallback' do + expect(helper.super_sidebar_nav_panel(user: user)).to be_a(Sidebars::Explore::Panel) + end end end |