Commit 1752e1f3 authored by Jason Goodman's avatar Jason Goodman Committed by Lin Jen-Shin

Display feature flags link in header search bar results in CE

Hide feature flags link if user does not have permissions
Use let_it_be in search bar spec
parent 13e00158
......@@ -150,7 +150,7 @@ module SearchHelper
if @project && @project.repository.root_ref
ref = @ref || @project.repository.root_ref
[
result = [
{ category: "In this project", label: _("Files"), url: project_tree_path(@project, ref) },
{ category: "In this project", label: _("Commits"), url: project_commits_path(@project, ref) },
{ category: "In this project", label: _("Network"), url: project_network_path(@project, ref) },
......@@ -162,6 +162,12 @@ module SearchHelper
{ category: "In this project", label: _("Members"), url: project_project_members_path(@project) },
{ category: "In this project", label: _("Wiki"), url: project_wikis_path(@project) }
]
if can?(current_user, :read_feature_flag, @project)
result << { category: "In this project", label: _("Feature Flags"), url: project_feature_flags_path(@project) }
end
result
else
[]
end
......
......@@ -12,7 +12,7 @@
qa_selector: 'search_term_field' },
aria: { label: _('Search or jump to…') }
%button.hidden.js-dropdown-search-toggle{ type: 'button', data: { toggle: 'dropdown' } }
.dropdown-menu.dropdown-select.js-dashboard-search-options
.dropdown-menu.dropdown-select{ data: { testid: 'dashboard-search-options' } }
= dropdown_content do
%ul
%li.dropdown-menu-empty-item
......
---
title: Fix when Feature Flags link is shown in search bar results
merge_request: 45803
author:
type: fixed
......@@ -34,13 +34,6 @@ module EE
end
end
override :project_autocomplete
def project_autocomplete
return super unless @project && @project.feature_available?(:repository)
super + [{ category: "In this project", label: _("Feature Flags"), url: project_feature_flags_path(@project) }]
end
override :search_entries_scope_label
def search_entries_scope_label(scope, count)
case scope
......
......@@ -92,21 +92,6 @@ RSpec.describe SearchHelper do
end
end
describe '#project_autocomplete' do
let(:user) { create(:user) }
before do
@project = create(:project, :repository)
allow(self).to receive(:current_user).and_return(user)
end
context 'with a licensed user' do
it "does include feature flags" do
expect(project_autocomplete.find { |i| i[:label] == 'Feature Flags' }).to be_present
end
end
end
describe '#search_entries_info_template' do
let(:com_value) { true }
let(:elasticsearch_enabled) { true }
......
......@@ -36,15 +36,15 @@ RSpec.describe 'Global search' do
end
end
it 'closes the dropdown on blur', :js, quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/201841' do
it 'closes the dropdown on blur', :js do
find('#search').click
fill_in 'search', with: "a"
dropdown = find('.js-dashboard-search-options')
expect(dropdown[:class]).to include 'show'
expect(page).to have_selector("div[data-testid='dashboard-search-options'].show")
find('#search').send_keys(:backspace)
find('body').click
expect(dropdown[:class]).not_to include 'show'
expect(page).to have_no_selector("div[data-testid='dashboard-search-options'].show")
end
end
......@@ -5,11 +5,18 @@ require 'spec_helper'
RSpec.describe 'User uses header search field', :js do
include FilteredSearchHelpers
let(:project) { create(:project) }
let(:user) { create(:user) }
let_it_be(:project) { create(:project, :repository) }
let_it_be(:reporter) { create(:user) }
let_it_be(:developer) { create(:user) }
let(:user) { reporter }
before_all do
project.add_reporter(reporter)
project.add_developer(developer)
end
before do
project.add_reporter(user)
sign_in(user)
end
......@@ -132,6 +139,10 @@ RSpec.describe 'User uses header search field', :js do
let(:group) { create(:group) }
let(:project) { create(:project, namespace: group) }
before do
project.add_reporter(user)
end
include_examples 'search field examples' do
let(:url) { project_path(project) }
let(:scope_name) { project.name }
......@@ -159,6 +170,35 @@ RSpec.describe 'User uses header search field', :js do
expect(page).not_to have_selector(scoped_search_link('test', group_id: project.namespace_id))
expect(page).to have_selector(scoped_search_link('test', project_id: project.id))
end
it 'displays a link to project merge requests' do
fill_in_search('Merge')
within(dashboard_search_options_popup_menu) do
expect(page).to have_text('Merge Requests')
end
end
it 'does not display a link to project feature flags' do
fill_in_search('Feature')
within(dashboard_search_options_popup_menu) do
expect(page).to have_text('"Feature" in all GitLab')
expect(page).to have_no_text('Feature Flags')
end
end
context 'and user is a developer' do
let(:user) { developer }
it 'displays a link to project feature flags' do
fill_in_search('Feature')
within(dashboard_search_options_popup_menu) do
expect(page).to have_text('Feature Flags')
end
end
end
end
end
......@@ -217,4 +257,8 @@ RSpec.describe 'User uses header search field', :js do
".dropdown a[href='#{href}']"
end
def dashboard_search_options_popup_menu
"div[data-testid='dashboard-search-options']"
end
end
......@@ -143,6 +143,7 @@ RSpec.describe SearchHelper do
context "with a current project" do
before do
@project = create(:project, :repository)
allow(self).to receive(:can?).with(user, :read_feature_flag, @project).and_return(false)
end
it "includes project-specific sections", :aggregate_failures do
......@@ -162,6 +163,7 @@ RSpec.describe SearchHelper do
context 'when user has project access' do
before do
@project = create(:project, :repository, namespace: user.namespace)
allow(self).to receive(:can?).with(user, :read_feature_flag, @project).and_return(true)
end
it 'includes issues by iid', :aggregate_failures do
......
......@@ -3,6 +3,7 @@
module SearchHelpers
def fill_in_search(text)
page.within('.search-input-wrap') do
find('#search').click
fill_in('search', with: text)
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