1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'User uses header search field', :js, :disable_rate_limiter, feature_category: :global_search do
include FilteredSearchHelpers
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
sign_in(user)
end
shared_examples 'search field examples' do
before do
visit(url)
wait_for_all_requests
end
it 'starts searching by pressing the enter key' do
submit_search('gitlab')
page.within('.page-title') do
expect(page).to have_content('Search')
end
end
context 'when using the keyboard shortcut' do
before do
find('#search')
find('body').native.send_keys('s')
wait_for_all_requests
end
it 'shows the category search dropdown', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/250285' do
expect(page).to have_selector('.dropdown-header', text: /#{scope_name}/i)
end
end
context 'when clicking the search field' do
before do
page.find('#search').click
wait_for_all_requests
end
it 'shows category search dropdown', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/250285' do
expect(page).to have_selector('.dropdown-header', text: /#{scope_name}/i)
end
context 'when clicking issues', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/332317' do
let!(:issue) { create(:issue, project: project, author: user, assignees: [user]) }
it 'shows assigned issues' do
find('[data-testid="header-search-dropdown-menu"]').click_link('Issues assigned to me')
expect(page).to have_selector('.issues-list .issue')
expect_tokens([assignee_token(user.name)])
expect_filtered_search_input_empty
end
it 'shows created issues' do
find('[data-testid="header-search-dropdown-menu"]').click_link("Issues I've created")
expect(page).to have_selector('.issues-list .issue')
expect_tokens([author_token(user.name)])
expect_filtered_search_input_empty
end
end
context 'when clicking merge requests', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/332317' do
let!(:merge_request) { create(:merge_request, source_project: project, author: user, assignees: [user]) }
it 'shows assigned merge requests' do
find('[data-testid="header-search-dropdown-menu"]').click_link('Merge requests assigned to me')
expect(page).to have_selector('.mr-list .merge-request')
expect_tokens([assignee_token(user.name)])
expect_filtered_search_input_empty
end
it 'shows created merge requests' do
find('[data-testid="header-search-dropdown-menu"]').click_link("Merge requests I've created")
expect(page).to have_selector('.mr-list .merge-request')
expect_tokens([author_token(user.name)])
expect_filtered_search_input_empty
end
end
end
context 'when entering text into the search field' do
it 'does not display the category search dropdown' do
fill_in_search(scope_name.first(4))
expect(page).not_to have_selector('.dropdown-header', text: /#{scope_name}/i)
end
end
end
context 'when user is in a global scope' do
include_examples 'search field examples' do
let(:url) { root_path }
let(:scope_name) { 'All GitLab' }
end
it 'displays search options', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/251076' do
fill_in_search('test')
expect(page).to have_selector(scoped_search_link('test'))
end
context 'when searching through the search field' do
before do
create(:issue, project: project, title: 'project issue')
submit_search('project')
end
it 'displays result counts for all categories' do
expect(page).to have_content('Projects 1')
expect(page).to have_content('Issues 1')
expect(page).to have_content('Merge requests 0')
expect(page).to have_content('Milestones 0')
expect(page).to have_content('Users 0')
end
end
end
context 'when user is in a project scope' do
context 'and it belongs to a group' 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 }
end
it 'displays search options' do
fill_in_search('test')
expect(page).to have_selector(scoped_search_link('test', search_code: true))
expect(page).to have_selector(scoped_search_link('test', group_id: group.id, search_code: true))
expect(page).to have_selector(scoped_search_link('test', project_id: project.id, group_id: group.id, search_code: true))
end
end
context 'and it belongs to a user' do
include_examples 'search field examples' do
let(:url) { project_path(project) }
let(:scope_name) { project.name }
end
it 'displays search options' do
fill_in_search('test')
sleep 0.5
expect(page).to have_selector(scoped_search_link('test', search_code: true, repository_ref: 'master'))
expect(page).not_to have_selector(scoped_search_link('test', search_code: true, group_id: project.namespace_id, repository_ref: 'master'))
expect(page).to have_selector(scoped_search_link('test', search_code: true, project_id: project.id, repository_ref: 'master'))
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
context 'when user is in a group scope' do
let(:group) { create(:group) }
let(:project) { create(:project, namespace: group) }
before do
group.add_maintainer(user)
end
include_examples 'search field examples' do
let(:url) { group_path(group) }
let(:scope_name) { group.name }
end
it 'displays search options' do
fill_in_search('test')
expect(page).to have_selector(scoped_search_link('test'))
expect(page).to have_selector(scoped_search_link('test', group_id: group.id))
expect(page).not_to have_selector(scoped_search_link('test', project_id: project.id))
end
end
context 'when user is in a subgroup scope' do
let(:group) { create(:group) }
let(:subgroup) { create(:group, :public, parent: group) }
let(:project) { create(:project, namespace: subgroup) }
before do
group.add_owner(user)
subgroup.add_owner(user)
end
include_examples 'search field examples' do
let(:url) { group_path(subgroup) }
let(:scope_name) { subgroup.name }
end
it 'displays search options' do
fill_in_search('test')
expect(page).to have_selector(scoped_search_link('test'))
expect(page).to have_selector(scoped_search_link('test', group_id: subgroup.id))
expect(page).not_to have_selector(scoped_search_link('test', project_id: project.id))
end
end
def scoped_search_link(term, project_id: nil, group_id: nil, search_code: nil, repository_ref: nil)
# search_path will accept group_id and project_id but the order does not match
# what is expected in the href, so the variable must be built manually
href = search_path(search: term)
href.concat("&nav_source=navbar")
href.concat("&project_id=#{project_id}") if project_id
href.concat("&group_id=#{group_id}") if group_id
href.concat("&search_code=true") if search_code
href.concat("&repository_ref=#{repository_ref}") if repository_ref
"[data-testid='header-search-dropdown-menu'] a[href='#{href}']"
end
def dashboard_search_options_popup_menu
"[data-testid='header-search-dropdown-menu'] .header-search-dropdown-content"
end
end
|