Remove hardcoded qa selectors in sidebar and make them dynamic

In this commit we remove some hardcoded values related to projects
that we have on general sidebar views. Those values
should be dynamic in order to reuse them with other resources
like projects.
parent 6eb99551
......@@ -2,25 +2,68 @@
module SidebarsHelper
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
when Project
sidebar_project_tracking_attrs
sidebar_project_attributes
when Group
sidebar_group_tracking_attrs
sidebar_group_attributes
when User
sidebar_user_profile_tracking_attrs
sidebar_user_attributes
else
{}
end
end
def project_sidebar_context(project, user, current_ref)
context_data = project_sidebar_context_data(project, user, current_ref)
def sidebar_project_attributes
{
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
private
def sidebar_user_attributes
{
tracking_attrs: sidebar_user_profile_tracking_attrs
}
end
def sidebar_project_tracking_attrs
tracking_attrs('projects_side_navigation', 'render', 'projects_side_navigation')
......
= 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
%span{ class: ['avatar-container', 'rect-avatar', 'project-avatar', 's32'] }
= 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: scope_avatar_classes(scope_menu.container) }
= source_icon(scope_menu.container, alt: scope_menu.title, class: ['avatar', 'avatar-tile', 's32'], width: 32, height: 32)
%span.sidebar-context-title
= scope_menu.title
......@@ -3,7 +3,7 @@
- if 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
= render partial: 'shared/nav/scope_menu', object: sidebar.scope_menu
- if sidebar.renderable_menus.any?
......
......@@ -52,7 +52,7 @@ RSpec.describe 'Groups > Audit Events', :js do
click_button 'Maintainer'
end
page.within('.qa-group-sidebar') do
page.within('.sidebar-top-level-items') do
find(:link, text: 'Security & Compliance').click
click_link 'Audit Events'
end
......
......@@ -34,7 +34,7 @@ RSpec.describe 'User views iteration' do
it 'shows iteration info' 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')
end
end
......
......@@ -120,7 +120,7 @@ RSpec.describe 'Projects > Audit Events', :js do
click_button 'Maintainer'
end
page.within('.qa-project-sidebar') do
page.within('.sidebar-top-level-items') do
find(:link, text: 'Security & Compliance').click
click_link 'Audit Events'
end
......@@ -149,7 +149,7 @@ RSpec.describe 'Projects > Audit Events', :js do
wait_for_all_requests
page.within('.qa-project-sidebar') do
page.within('.sidebar-top-level-items') do
click_link 'Security & Compliance'
click_link 'Audit Events'
end
......
......@@ -12,17 +12,13 @@ module QA
base.class_eval do
include QA::Page::Project::SubMenus::Common
view 'app/views/shared/nav/_scope_menu.html.haml' do
element :project_scope_link
end
end
end
def click_project
retry_on_exception do
within_sidebar do
click_element(:project_scope_link)
click_element(:sidebar_menu_link, menu_item: 'Project scope')
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