diff options
Diffstat (limited to 'spec/helpers/sidebars_helper_spec.rb')
-rw-r--r-- | spec/helpers/sidebars_helper_spec.rb | 186 |
1 files changed, 165 insertions, 21 deletions
diff --git a/spec/helpers/sidebars_helper_spec.rb b/spec/helpers/sidebars_helper_spec.rb index dbb6f9bd9f3..5323b041a9e 100644 --- a/spec/helpers/sidebars_helper_spec.rb +++ b/spec/helpers/sidebars_helper_spec.rb @@ -65,14 +65,16 @@ RSpec.describe SidebarsHelper, feature_category: :navigation do let_it_be(:user) { build(:user) } let_it_be(:group) { build(:group) } let_it_be(:panel) { {} } + let_it_be(:panel_type) { 'project' } subject do - helper.super_sidebar_context(user, group: group, project: nil, panel: panel) + helper.super_sidebar_context(user, group: group, project: nil, panel: panel, panel_type: panel_type) end before do allow(helper).to receive(:current_user) { user } allow(helper).to receive(:can?).and_return(true) + allow(helper).to receive(:header_search_context).and_return({ some: "search data" }) allow(panel).to receive(:super_sidebar_menu_items).and_return(nil) allow(panel).to receive(:super_sidebar_context_header).and_return(nil) allow(user).to receive(:assigned_open_issues_count).and_return(1) @@ -80,6 +82,7 @@ RSpec.describe SidebarsHelper, feature_category: :navigation do allow(user).to receive(:review_requested_open_merge_requests_count).and_return(0) allow(user).to receive(:todos_pending_count).and_return(3) allow(user).to receive(:total_merge_requests_count).and_return(4) + allow(user).to receive(:pinned_nav_items).and_return({ panel_type => %w[foo bar], 'another_panel' => %w[baz] }) end it 'returns sidebar values from user', :use_clean_rails_memory_store_caching do @@ -111,12 +114,12 @@ RSpec.describe SidebarsHelper, feature_category: :navigation do }, can_sign_out: helper.current_user_menu?(:sign_out), sign_out_link: destroy_user_session_path, - assigned_open_issues_count: 1, + assigned_open_issues_count: "1", todos_pending_count: 3, issues_dashboard_path: issues_dashboard_path(assignee_username: user.username), - total_merge_requests_count: 4, - projects_path: projects_path, - groups_path: groups_path, + total_merge_requests_count: "4", + projects_path: dashboard_projects_path, + groups_path: dashboard_groups_path, support_path: helper.support_url, display_whats_new: helper.display_whats_new?, whats_new_most_recent_release_items_count: helper.whats_new_most_recent_release_items_count, @@ -126,7 +129,34 @@ RSpec.describe SidebarsHelper, feature_category: :navigation do gitlab_version_check: helper.gitlab_version_check, gitlab_com_but_not_canary: Gitlab.com_but_not_canary?, gitlab_com_and_canary: Gitlab.com_and_canary?, - canary_toggle_com_url: Gitlab::Saas.canary_toggle_com_url + canary_toggle_com_url: Gitlab::Saas.canary_toggle_com_url, + search: { + search_path: search_path, + issues_path: issues_dashboard_path, + mr_path: merge_requests_dashboard_path, + autocomplete_path: search_autocomplete_path, + search_context: helper.header_search_context + }, + pinned_items: %w[foo bar], + panel_type: panel_type, + update_pins_url: pins_url, + 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' + } + ] }) end @@ -138,12 +168,24 @@ RSpec.describe SidebarsHelper, feature_category: :navigation do { text: _('Assigned'), href: merge_requests_dashboard_path(assignee_username: user.username), - count: 4 + count: 4, + extraAttrs: { + 'data-track-action': 'click_link', + 'data-track-label': 'merge_requests_assigned', + 'data-track-property': 'nav_core_menu', + class: 'dashboard-shortcuts-merge_requests' + } }, { text: _('Review requests'), href: merge_requests_dashboard_path(reviewer_username: user.username), - count: 0 + count: 0, + extraAttrs: { + 'data-track-action': 'click_link', + 'data-track-label': 'merge_requests_to_review', + 'data-track-property': 'nav_core_menu', + class: 'dashboard-shortcuts-review_requests' + } } ] } @@ -151,19 +193,42 @@ RSpec.describe SidebarsHelper, feature_category: :navigation do end it 'returns "Create new" menu groups without headers', :use_clean_rails_memory_store_caching do + extra_attrs = ->(id) { + { + "data-track-label": id, + "data-track-action": "click_link", + "data-track-property": "nav_create_menu", + "data-qa-selector": 'create_menu_item', + "data-qa-create-menu-item": id + } + } + expect(subject[:create_new_menu_groups]).to eq([ { name: "", items: [ - { href: "/projects/new", text: "New project/repository" }, - { href: "/groups/new", text: "New group" }, - { href: "/-/snippets/new", text: "New snippet" } + { href: "/projects/new", text: "New project/repository", + extraAttrs: extra_attrs.call("general_new_project") }, + { href: "/groups/new", text: "New group", + extraAttrs: extra_attrs.call("general_new_group") }, + { href: "/-/snippets/new", text: "New snippet", + extraAttrs: extra_attrs.call("general_new_snippet") } ] } ]) end it 'returns "Create new" menu groups with headers', :use_clean_rails_memory_store_caching do + extra_attrs = ->(id) { + { + "data-track-label": id, + "data-track-action": "click_link", + "data-track-property": "nav_create_menu", + "data-qa-selector": 'create_menu_item', + "data-qa-create-menu-item": id + } + } + allow(group).to receive(:persisted?).and_return(true) allow(helper).to receive(:can?).and_return(true) @@ -171,28 +236,49 @@ RSpec.describe SidebarsHelper, feature_category: :navigation do a_hash_including( name: "In this group", items: array_including( - { href: "/projects/new", text: "New project/repository" }, - { href: "/groups/new#create-group-pane", text: "New subgroup" }, - { href: '', text: "Invite members" } + { href: "/projects/new", text: "New project/repository", + extraAttrs: extra_attrs.call("new_project") }, + { href: "/groups/new#create-group-pane", text: "New subgroup", + extraAttrs: extra_attrs.call("new_subgroup") }, + { href: "", text: "Invite members", + extraAttrs: extra_attrs.call("invite") } ) ), a_hash_including( name: "In GitLab", items: array_including( - { href: "/projects/new", text: "New project/repository" }, - { href: "/groups/new", text: "New group" }, - { href: "/-/snippets/new", text: "New snippet" } + { href: "/projects/new", text: "New project/repository", + extraAttrs: extra_attrs.call("general_new_project") }, + { href: "/groups/new", text: "New group", + extraAttrs: extra_attrs.call("general_new_group") }, + { href: "/-/snippets/new", text: "New snippet", + extraAttrs: extra_attrs.call("general_new_snippet") } ) ) ) end + context 'when counts are high' do + before do + allow(user).to receive(:assigned_open_issues_count).and_return(1000) + allow(user).to receive(:assigned_open_merge_requests_count).and_return(50) + allow(user).to receive(:review_requested_open_merge_requests_count).and_return(50) + end + + it 'caps counts to USER_BAR_COUNT_LIMIT and appends a "+" to them' do + expect(subject).to include( + assigned_open_issues_count: "99+", + total_merge_requests_count: "99+" + ) + end + end + describe 'current context' do context 'when current context is a project' do let_it_be(:project) { build(:project) } subject do - helper.super_sidebar_context(user, group: nil, project: project, panel: panel) + helper.super_sidebar_context(user, group: nil, project: project, panel: panel, panel_type: panel_type) end before do @@ -215,7 +301,7 @@ RSpec.describe SidebarsHelper, feature_category: :navigation do context 'when current context is a group' do subject do - helper.super_sidebar_context(user, group: group, project: nil, panel: panel) + helper.super_sidebar_context(user, group: group, project: nil, panel: panel, panel_type: panel_type) end before do @@ -238,7 +324,7 @@ RSpec.describe SidebarsHelper, feature_category: :navigation do context 'when current context is not tracked' do subject do - helper.super_sidebar_context(user, group: nil, project: nil, panel: panel) + helper.super_sidebar_context(user, group: nil, project: nil, panel: panel, panel_type: panel_type) end it 'returns no context' do @@ -246,6 +332,55 @@ RSpec.describe SidebarsHelper, feature_category: :navigation do end end end + + describe 'context switcher persistent links' do + let_it_be(:public_link) do + [ + { title: s_('Navigation|Your work'), link: '/', icon: 'work' }, + { title: s_('Navigation|Explore'), link: '/explore', icon: 'compass' } + ] + end + + subject do + helper.super_sidebar_context(user, group: nil, project: nil, panel: panel, panel_type: panel_type) + end + + context 'when user is not an admin' do + it 'returns only the public links' do + expect(subject[:context_switcher_links]).to eq(public_link) + end + end + + context 'when user is an admin' do + before do + allow(user).to receive(:can_admin_all_resources?).and_return(true) + end + + it 'returns public links and admin area link' do + expect(subject[:context_switcher_links]).to eq([ + *public_link, + { title: s_('Navigation|Admin'), link: '/admin', icon: 'admin' } + ]) + end + end + end + + describe 'impersonation data' do + it 'sets is_impersonating to `false` when not impersonating' do + expect(subject[:is_impersonating]).to be(false) + end + + it 'passes the stop_impersonation_path property' do + expect(subject[:stop_impersonation_path]).to eq(admin_impersonation_path) + end + + describe 'when impersonating' do + it 'sets is_impersonating to `true`' do + expect(helper).to receive(:session).and_return({ impersonator_id: 1 }) + expect(subject[:is_impersonating]).to be(true) + end + end + end end describe '#super_sidebar_nav_panel' do @@ -256,7 +391,8 @@ RSpec.describe SidebarsHelper, feature_category: :navigation do before do allow(helper).to receive(:project_sidebar_context_data).and_return( { current_user: nil, container: project, can_view_pipeline_editor: false, learn_gitlab_enabled: false }) - allow(helper).to receive(:group_sidebar_context_data).and_return({ current_user: nil, container: group }) + allow(helper).to receive(:group_sidebar_context_data).and_return( + { 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) @@ -282,10 +418,18 @@ RSpec.describe SidebarsHelper, feature_category: :navigation do expect(helper.super_sidebar_nav_panel(nav: 'user_profile')).to be_a(Sidebars::UserProfile::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 "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 Search Panel for search nav' do + expect(helper.super_sidebar_nav_panel(nav: 'search', user: user)).to be_a(Sidebars::Search::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 |