Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
7afcf455f0e3
Commit
76a40e74
authored
Aug 30, 2019
by
Lin Jen-Shin
Browse files
Merge branch '36383-improve-search-result-labels' into 'master'
Improve search result labels See merge request gitlab-org/gitlab-ce!32101
parents
ea559b85e015
6cc0acf06af4
Changes
22
Hide whitespace changes
Inline
Side-by-side
app/helpers/search_helper.rb
View file @
7afcf455
...
...
@@ -30,7 +30,46 @@ def search_entries_info(collection, scope, term)
to
=
collection
.
offset_value
+
collection
.
to_a
.
size
count
=
collection
.
total_count
s_
(
"SearchResults|Showing %{from} - %{to} of %{count} %{scope} for
\"
%{term}
\"
"
)
%
{
from:
from
,
to:
to
,
count:
count
,
scope:
scope
.
humanize
(
capitalize:
false
),
term:
term
}
search_entries_info_template
(
collection
)
%
{
from:
from
,
to:
to
,
count:
count
,
scope:
search_entries_info_label
(
scope
,
count
),
term:
term
}
end
def
search_entries_info_label
(
scope
,
count
)
case
scope
when
'blobs'
,
'snippet_blobs'
,
'wiki_blobs'
ns_
(
'SearchResults|result'
,
'SearchResults|results'
,
count
)
when
'commits'
ns_
(
'SearchResults|commit'
,
'SearchResults|commits'
,
count
)
when
'issues'
ns_
(
'SearchResults|issue'
,
'SearchResults|issues'
,
count
)
when
'merge_requests'
ns_
(
'SearchResults|merge request'
,
'SearchResults|merge requests'
,
count
)
when
'milestones'
ns_
(
'SearchResults|milestone'
,
'SearchResults|milestones'
,
count
)
when
'notes'
ns_
(
'SearchResults|comment'
,
'SearchResults|comments'
,
count
)
when
'projects'
ns_
(
'SearchResults|project'
,
'SearchResults|projects'
,
count
)
when
'snippet_titles'
ns_
(
'SearchResults|snippet'
,
'SearchResults|snippets'
,
count
)
when
'users'
ns_
(
'SearchResults|user'
,
'SearchResults|users'
,
count
)
else
raise
"Unrecognized search scope '
#{
scope
}
'"
end
end
def
search_entries_info_template
(
collection
)
if
collection
.
total_pages
>
1
s_
(
"SearchResults|Showing %{from} - %{to} of %{count} %{scope} for
\"
%{term}
\"
"
)
else
s_
(
"SearchResults|Showing %{count} %{scope} for
\"
%{term}
\"
"
)
end
end
def
find_project_for_result_blob
(
projects
,
result
)
...
...
app/views/layouts/_search.html.haml
View file @
7afcf455
...
...
@@ -47,6 +47,7 @@
=
hidden_field_tag
:snippets
,
true
=
hidden_field_tag
:repository_ref
,
@ref
=
hidden_field_tag
:nav_source
,
'navbar'
-# workaround for non-JS feature specs, for JS you need to use find('#search').send_keys(:enter)
=
button_tag
'Go'
if
ENV
[
'RAILS_ENV'
]
==
'test'
-# workaround for non-JS feature specs, see spec/support/helpers/search_helpers.rb
-
if
ENV
[
'RAILS_ENV'
]
==
'test'
%noscript
=
button_tag
'Search'
.search-autocomplete-opts.hide
{
:'data-autocomplete-path'
=>
search_autocomplete_path
,
:'data-autocomplete-project-id'
=>
@project
.
try
(
:id
),
:'data-autocomplete-project-ref'
=>
@ref
}
changelogs/unreleased/36383-improve-search-result-labels.yml
0 → 100644
View file @
7afcf455
---
title
:
Improve search result labels
merge_request
:
32101
author
:
type
:
changed
locale/gitlab.pot
View file @
7afcf455
...
...
@@ -10097,9 +10097,57 @@ msgstr ""
msgid "SearchCodeResults|of %{link_to_project}"
msgstr ""
msgid "SearchResults|Showing %{count} %{scope} for \"%{term}\""
msgstr ""
msgid "SearchResults|Showing %{from} - %{to} of %{count} %{scope} for \"%{term}\""
msgstr ""
msgid "SearchResults|comment"
msgid_plural "SearchResults|comments"
msgstr[0] ""
msgstr[1] ""
msgid "SearchResults|commit"
msgid_plural "SearchResults|commits"
msgstr[0] ""
msgstr[1] ""
msgid "SearchResults|issue"
msgid_plural "SearchResults|issues"
msgstr[0] ""
msgstr[1] ""
msgid "SearchResults|merge request"
msgid_plural "SearchResults|merge requests"
msgstr[0] ""
msgstr[1] ""
msgid "SearchResults|milestone"
msgid_plural "SearchResults|milestones"
msgstr[0] ""
msgstr[1] ""
msgid "SearchResults|project"
msgid_plural "SearchResults|projects"
msgstr[0] ""
msgstr[1] ""
msgid "SearchResults|result"
msgid_plural "SearchResults|results"
msgstr[0] ""
msgstr[1] ""
msgid "SearchResults|snippet"
msgid_plural "SearchResults|snippets"
msgstr[0] ""
msgstr[1] ""
msgid "SearchResults|user"
msgid_plural "SearchResults|users"
msgstr[0] ""
msgstr[1] ""
msgid "Secret"
msgstr ""
...
...
spec/features/global_search_spec.rb
View file @
7afcf455
...
...
@@ -16,8 +16,7 @@
it
'increases usage ping searches counter'
do
expect
(
Gitlab
::
UsageDataCounters
::
SearchCounter
).
to
receive
(
:increment_navbar_searches_count
)
fill_in
"search"
,
with:
"foobar"
click_button
"Go"
submit_search
(
'foobar'
)
end
describe
'I search through the issues and I see pagination'
do
...
...
@@ -27,10 +26,9 @@
end
it
"has a pagination"
do
fill_in
"search"
,
with:
"
initial
"
click_button
"Go"
submit_search
(
'
initial
'
)
select_search_scope
(
'Issues'
)
select_filter
(
"Issues"
)
expect
(
page
).
to
have_selector
(
'.gl-pagination .next'
)
end
end
...
...
spec/features/projects/files/user_searches_for_files_spec.rb
View file @
7afcf455
...
...
@@ -18,8 +18,7 @@
end
it
'does not show any result'
do
fill_in
(
'search'
,
with:
'coffee'
)
click_button
(
'Go'
)
submit_search
(
'coffee'
)
expect
(
page
).
to
have_content
(
"We couldn't find any"
)
end
...
...
@@ -50,8 +49,7 @@
it
'shows found files'
do
expect
(
page
).
to
have_selector
(
'.tree-controls .shortcuts-find-file'
)
fill_in
(
'search'
,
with:
'coffee'
)
click_button
(
'Go'
)
submit_search
(
'coffee'
)
expect
(
page
).
to
have_content
(
'coffee'
)
expect
(
page
).
to
have_content
(
'CONTRIBUTING.md'
)
...
...
spec/features/search/user_searches_for_code_spec.rb
View file @
7afcf455
...
...
@@ -6,21 +6,6 @@
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
:repository
,
namespace:
user
.
namespace
)
}
def
submit_search
(
search
,
with_send_keys:
false
)
page
.
within
(
'.search'
)
do
field
=
find_field
(
'search'
)
field
.
fill_in
(
with:
search
)
if
with_send_keys
field
.
send_keys
(
:enter
)
else
click_button
(
"Go"
)
end
end
click_link
(
'Code'
)
end
context
'when signed in'
do
before
do
project
.
add_maintainer
(
user
)
...
...
@@ -31,7 +16,9 @@ def submit_search(search, with_send_keys: false)
visit
(
project_path
(
project
))
submit_search
(
'application.js'
)
select_search_scope
(
'Code'
)
expect
(
page
).
to
have_selector
(
'.results'
,
text:
'application.js'
)
expect
(
page
).
to
have_selector
(
'.file-content .code'
)
expect
(
page
).
to
have_selector
(
"span.line[lang='javascript']"
)
end
...
...
@@ -52,9 +39,7 @@ def submit_search(search, with_send_keys: false)
fill_in
(
'dashboard_search'
,
with:
'rspec'
)
find
(
'.btn-search'
).
click
page
.
within
(
'.results'
)
do
expect
(
find
(
:css
,
'.search-results'
)).
to
have_content
(
'Update capybara, rspec-rails, poltergeist to recent versions'
)
end
expect
(
page
).
to
have_selector
(
'.results'
,
text:
'Update capybara, rspec-rails, poltergeist to recent versions'
)
end
it
'search mutiple words with refs switching'
do
...
...
@@ -64,16 +49,12 @@ def submit_search(search, with_send_keys: false)
fill_in
(
'dashboard_search'
,
with:
search
)
find
(
'.btn-search'
).
click
page
.
within
(
'.results'
)
do
expect
(
find
(
'.search-results'
)).
to
have_content
(
expected_result
)
end
expect
(
page
).
to
have_selector
(
'.results'
,
text:
expected_result
)
find
(
'.js-project-refs-dropdown'
).
click
find
(
'.dropdown-page-one .dropdown-content'
).
click_link
(
'v1.0.0'
)
page
.
within
(
'.results'
)
do
expect
(
find
(
:css
,
'.search-results'
)).
to
have_content
(
expected_result
)
end
expect
(
page
).
to
have_selector
(
'.results'
,
text:
expected_result
)
expect
(
find_field
(
'dashboard_search'
).
value
).
to
eq
(
search
)
end
...
...
@@ -84,7 +65,9 @@ def submit_search(search, with_send_keys: false)
before
do
visit
(
project_tree_path
(
project
,
ref_name
))
submit_search
(
'gitlab-grack'
,
with_send_keys:
true
)
submit_search
(
'gitlab-grack'
)
select_search_scope
(
'Code'
)
end
it
'shows ref switcher in code result summary'
do
...
...
@@ -104,22 +87,27 @@ def submit_search(search, with_send_keys: false)
end
it
'search result changes when refs switched'
do
expect
(
find
(
'.search-results'
)).
not_to
have_content
(
'path = gitlab-grack'
)
expect
(
find
(
'.results'
)).
not_to
have_content
(
'path = gitlab-grack'
)
find
(
'.js-project-refs-dropdown'
).
click
find
(
'.dropdown-page-one .dropdown-content'
).
click_link
(
'master'
)
expect
(
find
(
'.search-results'
)).
to
have_content
(
'path = gitlab-grack'
)
expect
(
page
).
to
have_selector
(
'.results'
,
text:
'path = gitlab-grack'
)
end
end
it
'no ref switcher shown in issue result summary'
,
:js
do
issue
=
create
(
:issue
,
title:
'test'
,
project:
project
)
visit
(
project_tree_path
(
project
))
submit_search
(
'test'
,
with_send_keys:
true
)
submit_search
(
'test'
)
select_search_scope
(
'Code'
)
expect
(
page
).
to
have_selector
(
'.js-project-refs-dropdown'
)
page
.
within
(
'.search-filter'
)
do
click_link
(
'Issues'
)
end
expect
(
find
(
:css
,
'.
search-
results'
)).
to
have_link
(
issue
.
title
)
select_search_scope
(
'Issues'
)
expect
(
find
(
:css
,
'.results'
)).
to
have_link
(
issue
.
title
)
expect
(
page
).
not_to
have_selector
(
'.js-project-refs-dropdown'
)
end
end
...
...
@@ -133,10 +121,9 @@ def submit_search(search, with_send_keys: false)
it
'finds code'
do
submit_search
(
'rspec'
)
select_search_scope
(
'Code'
)
page
.
within
(
'.results'
)
do
expect
(
find
(
:css
,
'.search-results'
)).
to
have_content
(
'Update capybara, rspec-rails, poltergeist to recent versions'
)
end
expect
(
page
).
to
have_selector
(
'.results'
,
text:
'Update capybara, rspec-rails, poltergeist to recent versions'
)
end
end
end
spec/features/search/user_searches_for_comments_spec.rb
View file @
7afcf455
...
...
@@ -18,15 +18,13 @@
let
(
:comment
)
{
create
(
:note_on_commit
,
author:
user
,
project:
project
,
commit_id:
12345678
,
note:
'Bug here'
)
}
it
'finds a commit'
do
page
.
within
(
'.search'
)
do
fill_in
(
'search'
,
with:
comment
.
note
)
click_button
(
'Go'
)
end
click_link
(
'Comments'
)
submit_search
(
comment
.
note
)
select_search_scope
(
'Comments'
)
expect
(
page
).
to
have_text
(
'Commit deleted'
)
expect
(
page
).
to
have_text
(
'12345678'
)
page
.
within
(
'.results'
)
do
expect
(
page
).
to
have_content
(
'Commit deleted'
)
expect
(
page
).
to
have_content
(
'12345678'
)
end
end
end
end
...
...
@@ -36,14 +34,10 @@
let
(
:comment
)
{
create
(
:note
,
noteable:
snippet
,
author:
user
,
note:
'Supercalifragilisticexpialidocious'
,
project:
project
)
}
it
'finds a snippet'
do
page
.
within
(
'.search'
)
do
fill_in
(
'search'
,
with:
comment
.
note
)
click_button
(
'Go'
)
end
click_link
(
'Comments'
)
submit_search
(
comment
.
note
)
select_search_scope
(
'Comments'
)
expect
(
page
).
to
have_
link
(
snippet
.
title
)
expect
(
page
).
to
have_
selector
(
'.results'
,
text:
snippet
.
title
)
end
end
end
spec/features/search/user_searches_for_commits_spec.rb
View file @
7afcf455
...
...
@@ -16,15 +16,13 @@
context
'when searching by SHA'
do
it
'finds a commit and redirects to its page'
do
fill_in
(
'search'
,
with:
sha
)
click_button
(
'Search'
)
submit_search
(
sha
)
expect
(
page
).
to
have_current_path
(
project_commit_path
(
project
,
sha
))
end
it
'finds a commit in uppercase and redirects to its page'
do
fill_in
(
'search'
,
with:
sha
.
upcase
)
click_button
(
'Search'
)
submit_search
(
sha
.
upcase
)
expect
(
page
).
to
have_current_path
(
project_commit_path
(
project
,
sha
))
end
...
...
@@ -34,16 +32,14 @@
it
'finds a commit and holds on /search page'
do
create_commit
(
'Message referencing another sha: "deadbeef"'
,
project
,
user
,
'master'
)
fill_in
(
'search'
,
with:
'deadbeef'
)
click_button
(
'Search'
)
submit_search
(
'deadbeef'
)
expect
(
page
).
to
have_current_path
(
'/search'
,
ignore_query:
true
)
end
it
'finds multiple commits'
do
fill_in
(
'search'
,
with:
'See merge request'
)
click_button
(
'Search'
)
click_link
(
'Commits'
)
submit_search
(
'See merge request'
)
select_search_scope
(
'Commits'
)
expect
(
page
).
to
have_selector
(
'.commit-row-description'
,
count:
9
)
end
...
...
spec/features/search/user_searches_for_issues_spec.rb
View file @
7afcf455
...
...
@@ -21,13 +21,11 @@
it
'finds an issue'
do
fill_in
(
'dashboard_search'
,
with:
issue1
.
title
)
find
(
'.btn-search'
).
click
page
.
within
(
'.search-filter'
)
do
click_link
(
'Issues'
)
end
select_search_scope
(
'Issues'
)
page
.
within
(
'.results'
)
do
expect
(
find
(
:css
,
'.search-results'
)).
to
have_link
(
issue1
.
title
).
and
have_no_link
(
issue2
.
title
)
expect
(
page
).
to
have_link
(
issue1
.
title
)
expect
(
page
).
not_to
have_link
(
issue2
.
title
)
end
end
...
...
@@ -41,13 +39,11 @@
fill_in
(
'dashboard_search'
,
with:
issue1
.
title
)
find
(
'.btn-search'
).
click
page
.
within
(
'.search-filter'
)
do
click_link
(
'Issues'
)
end
select_search_scope
(
'Issues'
)
page
.
within
(
'.results'
)
do
expect
(
find
(
:css
,
'.search-results'
)).
to
have_link
(
issue1
.
title
).
and
have_no_link
(
issue2
.
title
)
expect
(
page
).
to
have_link
(
issue1
.
title
)
expect
(
page
).
not_to
have_link
(
issue2
.
title
)
end
end
end
...
...
@@ -65,13 +61,11 @@
it
'finds an issue'
do
fill_in
(
'dashboard_search'
,
with:
issue1
.
title
)
find
(
'.btn-search'
).
click
page
.
within
(
'.search-filter'
)
do
click_link
(
'Issues'
)
end
select_search_scope
(
'Issues'
)
page
.
within
(
'.results'
)
do
expect
(
find
(
:css
,
'.search-results'
)).
to
have_link
(
issue1
.
title
).
and
have_no_link
(
issue2
.
title
)
expect
(
page
).
to
have_link
(
issue1
.
title
)
expect
(
page
).
not_to
have_link
(
issue2
.
title
)
end
end
end
...
...
spec/features/search/user_searches_for_merge_requests_spec.rb
View file @
7afcf455
...
...
@@ -20,13 +20,11 @@
it
'finds a merge request'
do
fill_in
(
'dashboard_search'
,
with:
merge_request1
.
title
)
find
(
'.btn-search'
).
click
page
.
within
(
'.search-filter'
)
do
click_link
(
'Merge requests'
)
end
select_search_scope
(
'Merge requests'
)
page
.
within
(
'.results'
)
do
expect
(
find
(
:css
,
'.search-results'
)).
to
have_link
(
merge_request1
.
title
).
and
have_no_link
(
merge_request2
.
title
)
expect
(
page
).
to
have_link
(
merge_request1
.
title
)
expect
(
page
).
not_to
have_link
(
merge_request2
.
title
)
end
end
...
...
@@ -40,13 +38,11 @@
fill_in
(
'dashboard_search'
,
with:
merge_request1
.
title
)
find
(
'.btn-search'
).
click
page
.
within
(
'.search-filter'
)
do
click_link
(
'Merge requests'
)
end
select_search_scope
(
'Merge requests'
)
page
.
within
(
'.results'
)
do
expect
(
find
(
:css
,
'.search-results'
)).
to
have_link
(
merge_request1
.
title
).
and
have_no_link
(
merge_request2
.
title
)
expect
(
page
).
to
have_link
(
merge_request1
.
title
)
expect
(
page
).
not_to
have_link
(
merge_request2
.
title
)
end
end
end
...
...
spec/features/search/user_searches_for_milestones_spec.rb
View file @
7afcf455
...
...
@@ -20,13 +20,11 @@
it
'finds a milestone'
do
fill_in
(
'dashboard_search'
,
with:
milestone1
.
title
)
find
(
'.btn-search'
).
click
page
.
within
(
'.search-filter'
)
do
click_link
(
'Milestones'
)
end
select_search_scope
(
'Milestones'
)
page
.
within
(
'.results'
)
do
expect
(
find
(
:css
,
'.search-results'
)).
to
have_link
(
milestone1
.
title
).
and
have_no_link
(
milestone2
.
title
)
expect
(
page
).
to
have_link
(
milestone1
.
title
)
expect
(
page
).
not_to
have_link
(
milestone2
.
title
)
end
end
...
...
@@ -40,13 +38,11 @@
fill_in
(
'dashboard_search'
,
with:
milestone1
.
title
)
find
(
'.btn-search'
).
click
page
.
within
(
'.search-filter'
)
do
click_link
(
'Milestones'
)
end
select_search_scope
(
'Milestones'
)
page
.
within
(
'.results'
)
do
expect
(
find
(
:css
,
'.search-results'
)).
to
have_link
(
milestone1
.
title
).
and
have_no_link
(
milestone2
.
title
)
expect
(
page
).
to
have_link
(
milestone1
.
title
)
expect
(
page
).
not_to
have_link
(
milestone2
.
title
)
end
end
end
...
...
spec/features/search/user_searches_for_projects_spec.rb
View file @
7afcf455
...
...
@@ -20,8 +20,7 @@
it
'preserves the group being searched in'
do
visit
(
search_path
(
group_id:
project
.
namespace
.
id
))
fill_in
(
'search'
,
with:
'foo'
)
click_button
(
'Search'
)
submit_search
(
'foo'
)
expect
(
find
(
'#group_id'
,
visible:
false
).
value
).
to
eq
(
project
.
namespace
.
id
.
to_s
)
end
...
...
@@ -29,8 +28,7 @@
it
'preserves the project being searched in'
do
visit
(
search_path
(
project_id:
project
.
id
))
fill_in
(
'search'
,
with:
'foo'
)
click_button
(
'Search'
)
submit_search
(
'foo'
)
expect
(
find
(
'#project_id'
,
visible:
false
).
value
).
to
eq
(
project
.
id
.
to_s
)
end
...
...
spec/features/search/user_searches_for_users_spec.rb
View file @
7afcf455
...
...
@@ -3,83 +3,81 @@
require
'spec_helper'
describe
'User searches for users'
do
context
'when on the dashboard'
do
it
'finds the user'
,
:js
do
create
(
:user
,
username:
'gob_
bluth
'
,
name:
'G
ob
Bluth'
)
let
(
:user1
)
{
create
(
:user
,
username:
'gob_bluth'
,
name:
'Gob Bluth'
)
}
let
(
:user2
)
{
create
(
:user
,
username:
'michael_bluth'
,
name:
'Michael Bluth'
)
}
let
(
:user3
)
{
create
(
:user
,
username:
'gob_
2018
'
,
name:
'G
eorge Oscar
Bluth'
)
}
sign_in
(
create
(
:user
))
before
do
sign_in
(
user1
)
end
context
'when on the dashboard'
do
it
'finds the user'
,
:js
do
visit
dashboard_projects_path
fill_in
'search'
,
with:
'gob'
find
(
'#search'
).
send_keys
(
:enter
)
submit_search
(
'gob'
)
select_search_scope
(
'Users'
)
expect
(
page
).
to
have_content
(
'Users 1'
)
click_on
(
'Users 1'
)
expect
(
page
).
to
have_content
(
'Gob Bluth'
)
expect
(
page
).
to
have_content
(
'@gob_bluth'
)
page
.
within
(
'.results'
)
do
expect
(
page
).
to
have_content
(
'Gob Bluth'
)
expect
(
page
).
to
have_content
(
'@gob_bluth'
)
end
end
end
context
'when on the project page'
do
it
'finds the user belonging to the project'
do
project
=
create
(
:project
)
let
(
:project
)
{
create
(
:project
)
}
user1
=
create
(
:user
,
username:
'gob_bluth'
,
name:
'Gob Bluth'
)
before
do
create
(
:project_member
,
:developer
,
user:
user1
,
project:
project
)
user2
=
create
(
:user
,
username:
'michael_bluth'
,
name:
'Michael Bluth'
)
create
(
:project_member
,
:developer
,
user:
user2
,
project:
project
)
user3
end
create
(
:user
,
username:
'gob_2018'
,
name:
'George Oscar Bluth'
)
sign_in
(
user1
)
visit
projects_path
(
project
)
it
'finds the user belonging to the project'
do
visit
project_path
(
project
)
fill_in
'search'
,
with:
'gob'
click_button
'Go'
submit_search
(
'gob'
)
select_search_scope
(
'Users'
)
expect
(
page
).
to
have_content
(
'Gob Bluth'
)
expect
(
page
).
to
have_content
(
'@gob_bluth'
)
page
.
within
(
'.results'
)
do
expect
(
page
).
to
have_content
(
'Gob Bluth'
)
expect
(
page
).
to
have_content
(
'@gob_bluth'
)
expect
(
page
).
not_to
have_content
(
'Michael Bluth'
)
expect
(
page
).
not_to
have_content
(
'@michael_bluth'
)
expect
(
page
).
not_to
have_content
(
'Michael Bluth'
)
expect
(
page
).
not_to
have_content
(
'@michael_bluth'
)
expect
(
page
).
not_to
have_content
(
'George Oscar Bluth'
)
expect
(
page
).
not_to
have_content
(
'@gob_2018'
)
expect
(
page
).
not_to
have_content
(
'George Oscar Bluth'
)
expect
(
page
).
not_to
have_content
(
'@gob_2018'
)
end
end
end
context
'when on the group page'
do
it
'finds the user belonging to the group'
do
group
=
create
(
:group
)
let
(
:group
)
{
create
(
:group
)
}
user1
=
create
(
:user
,