diff options
Diffstat (limited to 'spec/helpers/nav')
-rw-r--r-- | spec/helpers/nav/new_dropdown_helper_spec.rb | 2 | ||||
-rw-r--r-- | spec/helpers/nav/top_nav_helper_spec.rb | 240 |
2 files changed, 157 insertions, 85 deletions
diff --git a/spec/helpers/nav/new_dropdown_helper_spec.rb b/spec/helpers/nav/new_dropdown_helper_spec.rb index 45664a7e0bd..3a65131aab0 100644 --- a/spec/helpers/nav/new_dropdown_helper_spec.rb +++ b/spec/helpers/nav/new_dropdown_helper_spec.rb @@ -100,7 +100,7 @@ RSpec.describe Nav::NewDropdownHelper do id: 'general_new_group', title: 'New group', href: '/groups/new', - data: { track_action: 'click_link_new_group', track_label: 'plus_menu_dropdown' } + data: { qa_selector: 'global_new_group_link', track_action: 'click_link_new_group', track_label: 'plus_menu_dropdown' } ) ) ) diff --git a/spec/helpers/nav/top_nav_helper_spec.rb b/spec/helpers/nav/top_nav_helper_spec.rb index e4fa503b5ee..9c396d6bf25 100644 --- a/spec/helpers/nav/top_nav_helper_spec.rb +++ b/spec/helpers/nav/top_nav_helper_spec.rb @@ -27,9 +27,11 @@ RSpec.describe Nav::TopNavHelper do let(:subject) { helper.top_nav_view_model(project: current_project, group: current_group) } - let(:active_title) { 'Menu' } + let(:menu_title) { 'Menu' } before do + stub_feature_flags(new_navbar_layout: false) + allow(Gitlab::CurrentSettings).to receive(:admin_mode) { with_current_settings_admin_mode } allow(helper).to receive(:header_link?).with(:admin_mode) { with_header_link_admin_mode } @@ -44,12 +46,15 @@ RSpec.describe Nav::TopNavHelper do allow(helper).to receive(:dashboard_nav_link?).with(:activity) { with_activity } end - it 'has :activeTitle' do - expect(subject[:activeTitle]).to eq(active_title) + it 'has :menuTitle' do + expect(subject[:menuTitle]).to eq(menu_title) end context 'when current_user is nil (anonymous)' do it 'has expected :primary' do + expected_header = ::Gitlab::Nav::TopNavMenuHeader.build( + title: 'Explore' + ) expected_primary = [ { href: '/explore', icon: 'project', id: 'project', title: 'Projects' }, { href: '/explore/groups', icon: 'group', id: 'groups', title: 'Groups' }, @@ -58,7 +63,7 @@ RSpec.describe Nav::TopNavHelper do ::Gitlab::Nav::TopNavMenuItem.build(**item) end - expect(subject[:primary]).to eq(expected_primary) + expect(subject[:primary]).to eq([expected_header, *expected_primary]) end it 'has expected :shortcuts' do @@ -103,7 +108,7 @@ RSpec.describe Nav::TopNavHelper do let(:current_user) { user } it 'has no menu items or views by default' do - expect(subject).to eq({ activeTitle: active_title, + expect(subject).to eq({ menuTitle: menu_title, primary: [], secondary: [], shortcuts: [], @@ -115,6 +120,9 @@ RSpec.describe Nav::TopNavHelper do let(:projects_view) { subject[:views][:projects] } it 'has expected :primary' do + expected_header = ::Gitlab::Nav::TopNavMenuHeader.build( + title: 'Switch to' + ) expected_primary = ::Gitlab::Nav::TopNavMenuItem.build( css_class: 'qa-projects-dropdown', data: { @@ -126,7 +134,7 @@ RSpec.describe Nav::TopNavHelper do title: 'Projects', view: 'projects' ) - expect(subject[:primary]).to eq([expected_primary]) + expect(subject[:primary]).to eq([expected_header, expected_primary]) end it 'has expected :shortcuts' do @@ -153,61 +161,87 @@ RSpec.describe Nav::TopNavHelper do ::Gitlab::Nav::TopNavMenuItem.build( data: { qa_selector: 'menu_item_link', - qa_title: 'Your projects', - **menu_data_tracking_attrs('your_projects') + qa_title: 'View all projects', + **menu_data_tracking_attrs('view_all_projects') }, href: '/dashboard/projects', id: 'your', - title: 'Your projects' - ), - ::Gitlab::Nav::TopNavMenuItem.build( - data: { - qa_selector: 'menu_item_link', - qa_title: 'Starred projects', - **menu_data_tracking_attrs('starred_projects') - }, - href: '/dashboard/projects/starred', - id: 'starred', - title: 'Starred projects' - ), - ::Gitlab::Nav::TopNavMenuItem.build( - data: { - qa_selector: 'menu_item_link', - qa_title: 'Explore projects', - **menu_data_tracking_attrs('explore_projects') - }, - href: '/explore', - id: 'explore', - title: 'Explore projects' - ), - ::Gitlab::Nav::TopNavMenuItem.build( - data: { - qa_selector: 'menu_item_link', - qa_title: 'Explore topics', - **menu_data_tracking_attrs('explore_topics') - }, - href: '/explore/projects/topics', - id: 'topics', - title: 'Explore topics' + title: 'View all projects' ) ] expect(projects_view[:linksPrimary]).to eq(expected_links_primary) end - it 'has expected :linksSecondary' do - expected_links_secondary = [ - ::Gitlab::Nav::TopNavMenuItem.build( - data: { - qa_selector: 'menu_item_link', - qa_title: 'Create new project', - **menu_data_tracking_attrs('create_new_project') - }, - href: '/projects/new', - id: 'create', - title: 'Create new project' - ) - ] - expect(projects_view[:linksSecondary]).to eq(expected_links_secondary) + it 'does not have any :linksSecondary' do + expect(projects_view[:linksSecondary]).to eq([]) + end + + context 'when extra submenu options are not hidden' do + before do + stub_feature_flags(remove_extra_primary_submenu_options: false) + end + + it 'has expected :linksPrimary' do + expected_links_primary = [ + ::Gitlab::Nav::TopNavMenuItem.build( + data: { + qa_selector: 'menu_item_link', + qa_title: 'Your projects', + **menu_data_tracking_attrs('your_projects') + }, + href: '/dashboard/projects', + id: 'your', + title: 'Your projects' + ), + ::Gitlab::Nav::TopNavMenuItem.build( + data: { + qa_selector: 'menu_item_link', + qa_title: 'Starred projects', + **menu_data_tracking_attrs('starred_projects') + }, + href: '/dashboard/projects/starred', + id: 'starred', + title: 'Starred projects' + ), + ::Gitlab::Nav::TopNavMenuItem.build( + data: { + qa_selector: 'menu_item_link', + qa_title: 'Explore projects', + **menu_data_tracking_attrs('explore_projects') + }, + href: '/explore', + id: 'explore', + title: 'Explore projects' + ), + ::Gitlab::Nav::TopNavMenuItem.build( + data: { + qa_selector: 'menu_item_link', + qa_title: 'Explore topics', + **menu_data_tracking_attrs('explore_topics') + }, + href: '/explore/projects/topics', + id: 'topics', + title: 'Explore topics' + ) + ] + expect(projects_view[:linksPrimary]).to eq(expected_links_primary) + end + + it 'has expected :linksSecondary' do + expected_links_secondary = [ + ::Gitlab::Nav::TopNavMenuItem.build( + data: { + qa_selector: 'menu_item_link', + qa_title: 'Create new project', + **menu_data_tracking_attrs('create_new_project') + }, + href: '/projects/new', + id: 'create', + title: 'Create new project' + ) + ] + expect(projects_view[:linksSecondary]).to eq(expected_links_secondary) + end end context 'with current nav as project' do @@ -251,6 +285,9 @@ RSpec.describe Nav::TopNavHelper do let(:groups_view) { subject[:views][:groups] } it 'has expected :primary' do + expected_header = ::Gitlab::Nav::TopNavMenuHeader.build( + title: 'Switch to' + ) expected_primary = ::Gitlab::Nav::TopNavMenuItem.build( css_class: 'qa-groups-dropdown', data: { @@ -262,7 +299,7 @@ RSpec.describe Nav::TopNavHelper do title: 'Groups', view: 'groups' ) - expect(subject[:primary]).to eq([expected_primary]) + expect(subject[:primary]).to eq([expected_header, expected_primary]) end it 'has expected :shortcuts' do @@ -289,41 +326,67 @@ RSpec.describe Nav::TopNavHelper do ::Gitlab::Nav::TopNavMenuItem.build( data: { qa_selector: 'menu_item_link', - qa_title: 'Your groups', - **menu_data_tracking_attrs('your_groups') + qa_title: 'View all groups', + **menu_data_tracking_attrs('view_all_groups') }, href: '/dashboard/groups', id: 'your', - title: 'Your groups' - ), - ::Gitlab::Nav::TopNavMenuItem.build( - data: { - qa_selector: 'menu_item_link', - qa_title: 'Explore groups', - **menu_data_tracking_attrs('explore_groups') - }, - href: '/explore/groups', - id: 'explore', - title: 'Explore groups' + title: 'View all groups' ) ] expect(groups_view[:linksPrimary]).to eq(expected_links_primary) end - it 'has expected :linksSecondary' do - expected_links_secondary = [ - ::Gitlab::Nav::TopNavMenuItem.build( - data: { - qa_selector: 'menu_item_link', - qa_title: 'Create group', - **menu_data_tracking_attrs('create_group') - }, - href: '/groups/new', - id: 'create', - title: 'Create group' - ) - ] - expect(groups_view[:linksSecondary]).to eq(expected_links_secondary) + it 'does not have any :linksSecondary' do + expect(groups_view[:linksSecondary]).to eq([]) + end + + context 'when extra submenu options are not hidden' do + before do + stub_feature_flags(remove_extra_primary_submenu_options: false) + end + + it 'has expected :linksPrimary' do + expected_links_primary = [ + ::Gitlab::Nav::TopNavMenuItem.build( + data: { + qa_selector: 'menu_item_link', + qa_title: 'Your groups', + **menu_data_tracking_attrs('your_groups') + }, + href: '/dashboard/groups', + id: 'your', + title: 'Your groups' + ), + ::Gitlab::Nav::TopNavMenuItem.build( + data: { + qa_selector: 'menu_item_link', + qa_title: 'Explore groups', + **menu_data_tracking_attrs('explore_groups') + }, + href: '/explore/groups', + id: 'explore', + title: 'Explore groups' + ) + ] + expect(groups_view[:linksPrimary]).to eq(expected_links_primary) + end + + it 'has expected :linksSecondary' do + expected_links_secondary = [ + ::Gitlab::Nav::TopNavMenuItem.build( + data: { + qa_selector: 'menu_item_link', + qa_title: 'Create group', + **menu_data_tracking_attrs('create_group') + }, + href: '/groups/new', + id: 'create', + title: 'Create group' + ) + ] + expect(groups_view[:linksSecondary]).to eq(expected_links_secondary) + end end context 'with external user' do @@ -374,6 +437,9 @@ RSpec.describe Nav::TopNavHelper do let(:with_milestones) { true } it 'has expected :primary' do + expected_header = ::Gitlab::Nav::TopNavMenuHeader.build( + title: 'Explore' + ) expected_primary = ::Gitlab::Nav::TopNavMenuItem.build( data: { qa_selector: 'milestones_link', @@ -384,7 +450,7 @@ RSpec.describe Nav::TopNavHelper do id: 'milestones', title: 'Milestones' ) - expect(subject[:primary]).to eq([expected_primary]) + expect(subject[:primary]).to eq([expected_header, expected_primary]) end it 'has expected :shortcuts' do @@ -402,6 +468,9 @@ RSpec.describe Nav::TopNavHelper do let(:with_snippets) { true } it 'has expected :primary' do + expected_header = ::Gitlab::Nav::TopNavMenuHeader.build( + title: 'Explore' + ) expected_primary = ::Gitlab::Nav::TopNavMenuItem.build( data: { qa_selector: 'snippets_link', @@ -412,7 +481,7 @@ RSpec.describe Nav::TopNavHelper do id: 'snippets', title: 'Snippets' ) - expect(subject[:primary]).to eq([expected_primary]) + expect(subject[:primary]).to eq([expected_header, expected_primary]) end it 'has expected :shortcuts' do @@ -430,6 +499,9 @@ RSpec.describe Nav::TopNavHelper do let(:with_activity) { true } it 'has expected :primary' do + expected_header = ::Gitlab::Nav::TopNavMenuHeader.build( + title: 'Explore' + ) expected_primary = ::Gitlab::Nav::TopNavMenuItem.build( data: { qa_selector: 'activity_link', @@ -440,7 +512,7 @@ RSpec.describe Nav::TopNavHelper do id: 'activity', title: 'Activity' ) - expect(subject[:primary]).to eq([expected_primary]) + expect(subject[:primary]).to eq([expected_header, expected_primary]) end it 'has expected :shortcuts' do |