Commit 6a2abbf0 authored by Nikola Milojevic's avatar Nikola Milojevic

Merge branch 'fj-remove-harcoded-selector-from-sidebar' into 'master'

Remove hardcoded qa selector in sidebar and make it dynamic

See merge request gitlab-org/gitlab!65720
parents 88870dc4 49e24c9c
...@@ -2,25 +2,68 @@ ...@@ -2,25 +2,68 @@
module SidebarsHelper module SidebarsHelper
def sidebar_tracking_attributes_by_object(object) def sidebar_tracking_attributes_by_object(object)
sidebar_attributes_for_object(object).fetch(:tracking_attrs, {})
end
def sidebar_qa_selector(object)
sidebar_attributes_for_object(object).fetch(:sidebar_qa_selector, nil)
end
def scope_qa_menu_item(object)
sidebar_attributes_for_object(object).fetch(:scope_qa_menu_item, nil)
end
def scope_avatar_classes(object)
%w[avatar-container rect-avatar s32].tap do |klasses|
klass = sidebar_attributes_for_object(object).fetch(:scope_avatar_class, nil)
klasses << klass if klass
end
end
def project_sidebar_context(project, user, current_ref)
context_data = project_sidebar_context_data(project, user, current_ref)
Sidebars::Projects::Context.new(**context_data)
end
private
def sidebar_attributes_for_object(object)
case object case object
when Project when Project
sidebar_project_tracking_attrs sidebar_project_attributes
when Group when Group
sidebar_group_tracking_attrs sidebar_group_attributes
when User when User
sidebar_user_profile_tracking_attrs sidebar_user_attributes
else else
{} {}
end end
end end
def project_sidebar_context(project, user, current_ref) def sidebar_project_attributes
context_data = project_sidebar_context_data(project, user, current_ref) {
tracking_attrs: sidebar_project_tracking_attrs,
sidebar_qa_selector: 'project_sidebar',
scope_qa_menu_item: 'Project scope',
scope_avatar_class: 'project_avatar'
}
end
Sidebars::Projects::Context.new(**context_data) def sidebar_group_attributes
{
tracking_attrs: sidebar_group_tracking_attrs,
sidebar_qa_selector: 'group_sidebar',
scope_qa_menu_item: 'Group scope',
scope_avatar_class: 'group_avatar'
}
end end
private def sidebar_user_attributes
{
tracking_attrs: sidebar_user_profile_tracking_attrs
}
end
def sidebar_project_tracking_attrs def sidebar_project_tracking_attrs
tracking_attrs('projects_side_navigation', 'render', 'projects_side_navigation') tracking_attrs('projects_side_navigation', 'render', 'projects_side_navigation')
......
= nav_link(**scope_menu.active_routes, html_options: scope_menu.nav_link_html_options) do = nav_link(**scope_menu.active_routes, html_options: scope_menu.nav_link_html_options) do
= link_to scope_menu.link, **scope_menu.container_html_options, data: { qa_selector: 'project_scope_link' } do = link_to scope_menu.link, **scope_menu.container_html_options, data: { qa_selector: 'sidebar_menu_link', qa_menu_item: scope_qa_menu_item(scope_menu.container) } do
%span{ class: ['avatar-container', 'rect-avatar', 'project-avatar', 's32'] } %span{ class: scope_avatar_classes(scope_menu.container) }
= source_icon(scope_menu.container, alt: scope_menu.title, class: ['avatar', 'avatar-tile', 's32'], width: 32, height: 32) = source_icon(scope_menu.container, alt: scope_menu.title, class: ['avatar', 'avatar-tile', 's32'], width: 32, height: 32)
%span.sidebar-context-title %span.sidebar-context-title
= scope_menu.title = scope_menu.title
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
- if sidebar.render_raw_scope_menu_partial - if sidebar.render_raw_scope_menu_partial
= render sidebar.render_raw_scope_menu_partial = render sidebar.render_raw_scope_menu_partial
%ul.sidebar-top-level-items.qa-project-sidebar %ul.sidebar-top-level-items{ data: { qa_selector: sidebar_qa_selector(sidebar.container) } }
- if sidebar.scope_menu - if sidebar.scope_menu
= render partial: 'shared/nav/scope_menu', object: sidebar.scope_menu = render partial: 'shared/nav/scope_menu', object: sidebar.scope_menu
- if sidebar.renderable_menus.any? - if sidebar.renderable_menus.any?
......
...@@ -52,7 +52,7 @@ RSpec.describe 'Groups > Audit Events', :js do ...@@ -52,7 +52,7 @@ RSpec.describe 'Groups > Audit Events', :js do
click_button 'Maintainer' click_button 'Maintainer'
end end
page.within('.qa-group-sidebar') do page.within('.sidebar-top-level-items') do
find(:link, text: 'Security & Compliance').click find(:link, text: 'Security & Compliance').click
click_link 'Audit Events' click_link 'Audit Events'
end end
......
...@@ -34,7 +34,7 @@ RSpec.describe 'User views iteration' do ...@@ -34,7 +34,7 @@ RSpec.describe 'User views iteration' do
it 'shows iteration info' do it 'shows iteration info' do
aggregate_failures 'expect Iterations highlighted on left sidebar' do aggregate_failures 'expect Iterations highlighted on left sidebar' do
page.within '.qa-group-sidebar' do page.within '.sidebar-top-level-items' do
expect(page).to have_css('li.active > a', text: 'Iterations') expect(page).to have_css('li.active > a', text: 'Iterations')
end end
end end
......
...@@ -120,7 +120,7 @@ RSpec.describe 'Projects > Audit Events', :js do ...@@ -120,7 +120,7 @@ RSpec.describe 'Projects > Audit Events', :js do
click_button 'Maintainer' click_button 'Maintainer'
end end
page.within('.qa-project-sidebar') do page.within('.sidebar-top-level-items') do
find(:link, text: 'Security & Compliance').click find(:link, text: 'Security & Compliance').click
click_link 'Audit Events' click_link 'Audit Events'
end end
...@@ -149,7 +149,7 @@ RSpec.describe 'Projects > Audit Events', :js do ...@@ -149,7 +149,7 @@ RSpec.describe 'Projects > Audit Events', :js do
wait_for_all_requests wait_for_all_requests
page.within('.qa-project-sidebar') do page.within('.sidebar-top-level-items') do
click_link 'Security & Compliance' click_link 'Security & Compliance'
click_link 'Audit Events' click_link 'Audit Events'
end end
......
...@@ -12,17 +12,13 @@ module QA ...@@ -12,17 +12,13 @@ module QA
base.class_eval do base.class_eval do
include QA::Page::Project::SubMenus::Common include QA::Page::Project::SubMenus::Common
view 'app/views/shared/nav/_scope_menu.html.haml' do
element :project_scope_link
end
end end
end end
def click_project def click_project
retry_on_exception do retry_on_exception do
within_sidebar do within_sidebar do
click_element(:project_scope_link) click_element(:sidebar_menu_link, menu_item: 'Project scope')
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment