Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
6785cdb4
Commit
6785cdb4
authored
Sep 10, 2020
by
Dmitry Gruzd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add filter by state for merge requests
parent
223b51be
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
226 additions
and
77 deletions
+226
-77
app/assets/javascripts/search/state_filter/components/state_filter.vue
...vascripts/search/state_filter/components/state_filter.vue
+19
-16
app/assets/javascripts/search/state_filter/constants.js
app/assets/javascripts/search/state_filter/constants.js
+19
-0
changelogs/unreleased/237938-merge-requests-filter-by-state.yml
...logs/unreleased/237938-merge-requests-filter-by-state.yml
+5
-0
ee/lib/elastic/latest/issue_class_proxy.rb
ee/lib/elastic/latest/issue_class_proxy.rb
+2
-12
ee/lib/elastic/latest/merge_request_class_proxy.rb
ee/lib/elastic/latest/merge_request_class_proxy.rb
+3
-0
ee/lib/elastic/latest/state_filter.rb
ee/lib/elastic/latest/state_filter.rb
+21
-0
ee/lib/gitlab/elastic/search_results.rb
ee/lib/gitlab/elastic/search_results.rb
+4
-1
ee/spec/lib/gitlab/elastic/group_search_results_spec.rb
ee/spec/lib/gitlab/elastic/group_search_results_spec.rb
+20
-3
ee/spec/lib/gitlab/elastic/project_search_results_spec.rb
ee/spec/lib/gitlab/elastic/project_search_results_spec.rb
+22
-5
ee/spec/lib/gitlab/elastic/search_results_spec.rb
ee/spec/lib/gitlab/elastic/search_results_spec.rb
+19
-3
spec/frontend/search/components/state_filter_spec.js
spec/frontend/search/components/state_filter_spec.js
+27
-4
spec/lib/gitlab/group_search_results_spec.rb
spec/lib/gitlab/group_search_results_spec.rb
+20
-5
spec/lib/gitlab/project_search_results_spec.rb
spec/lib/gitlab/project_search_results_spec.rb
+15
-9
spec/lib/gitlab/search_results_spec.rb
spec/lib/gitlab/search_results_spec.rb
+14
-3
spec/support/shared_examples/lib/gitlab/search_issue_state_filter_shared_examples.rb
...s/lib/gitlab/search_issue_state_filter_shared_examples.rb
+16
-16
No files found.
app/assets/javascripts/search/state_filter/components/state_filter.vue
View file @
6785cdb4
<
script
>
<
script
>
import
{
GlDropdown
,
GlDropdownItem
,
GlDropdownDivider
}
from
'
@gitlab/ui
'
;
import
{
GlDropdown
,
GlDropdownItem
,
GlDropdownDivider
}
from
'
@gitlab/ui
'
;
import
{
FILTER_STATES
,
FILTER_HEADER
,
FILTER_TEXT
}
from
'
../constants
'
;
import
{
FILTER_STATES
,
SCOPES
,
FILTER_STATES_BY_SCOPE
,
FILTER_HEADER
,
FILTER_TEXT
,
}
from
'
../constants
'
;
import
{
setUrlParams
,
visitUrl
}
from
'
~/lib/utils/url_utility
'
;
import
{
setUrlParams
,
visitUrl
}
from
'
~/lib/utils/url_utility
'
;
const
FILTERS_ARRAY
=
Object
.
values
(
FILTER_STATES
);
const
FILTERS_ARRAY
=
Object
.
values
(
FILTER_STATES
);
...
@@ -26,13 +32,15 @@ export default {
...
@@ -26,13 +32,15 @@ export default {
},
},
computed
:
{
computed
:
{
selectedFilterText
()
{
selectedFilterText
()
{
let
filterText
=
FILTER_TEXT
;
const
filter
=
FILTERS_ARRAY
.
find
(({
value
})
=>
value
===
this
.
selectedFilter
);
if
(
this
.
selectedFilter
===
FILTER_STATES
.
CLOSED
.
value
)
{
if
(
!
filter
||
filter
===
FILTER_STATES
.
ANY
)
{
filterText
=
FILTER_STATES
.
CLOSED
.
label
;
return
FILTER_TEXT
;
}
else
if
(
this
.
selectedFilter
===
FILTER_STATES
.
OPEN
.
value
)
{
filterText
=
FILTER_STATES
.
OPEN
.
label
;
}
}
return
filterText
;
return
filter
.
label
;
},
showDropdown
()
{
return
Object
.
values
(
SCOPES
).
includes
(
this
.
scope
);
},
},
selectedFilter
:
{
selectedFilter
:
{
get
()
{
get
()
{
...
@@ -63,29 +71,24 @@ export default {
...
@@ -63,29 +71,24 @@ export default {
},
},
filterStates
:
FILTER_STATES
,
filterStates
:
FILTER_STATES
,
filterHeader
:
FILTER_HEADER
,
filterHeader
:
FILTER_HEADER
,
filters
Array
:
FILTERS_ARRAY
,
filters
ByScope
:
FILTER_STATES_BY_SCOPE
,
};
};
</
script
>
</
script
>
<
template
>
<
template
>
<gl-dropdown
<gl-dropdown
v-if=
"showDropdown"
:text=
"selectedFilterText"
class=
"col-sm-3 gl-pt-4 gl-pl-0"
>
v-if=
"scope === 'issues'"
:text=
"selectedFilterText"
class=
"col-sm-3 gl-pt-4 gl-pl-0"
>
<header
class=
"gl-text-center gl-font-weight-bold gl-font-lg"
>
<header
class=
"gl-text-center gl-font-weight-bold gl-font-lg"
>
{{
$options
.
filterHeader
}}
{{
$options
.
filterHeader
}}
</header>
</header>
<gl-dropdown-divider
/>
<gl-dropdown-divider
/>
<gl-dropdown-item
<gl-dropdown-item
v-for=
"filter in $options.filters
Array
"
v-for=
"filter in $options.filters
ByScope[scope]
"
:key=
"filter.value"
:key=
"filter.value"
:is-check-item=
"true"
:is-check-item=
"true"
:is-checked=
"isFilterSelected(filter.value)"
:is-checked=
"isFilterSelected(filter.value)"
:class=
"dropDownItemClass(filter)"
:class=
"dropDownItemClass(filter)"
@
click=
"handleFilterChange(filter.value)"
@
click=
"handleFilterChange(filter.value)"
>
{{
filter
.
label
}}
</gl-dropdown-item
>
>
{{
filter
.
label
}}
</gl-dropdown-item>
</gl-dropdown>
</gl-dropdown>
</
template
>
</
template
>
app/assets/javascripts/search/state_filter/constants.js
View file @
6785cdb4
...
@@ -17,4 +17,23 @@ export const FILTER_STATES = {
...
@@ -17,4 +17,23 @@ export const FILTER_STATES = {
label
:
__
(
'
Closed
'
),
label
:
__
(
'
Closed
'
),
value
:
'
closed
'
,
value
:
'
closed
'
,
},
},
MERGED
:
{
label
:
__
(
'
Merged
'
),
value
:
'
merged
'
,
},
};
export
const
SCOPES
=
{
ISSUES
:
'
issues
'
,
MERGE_REQUESTS
:
'
merge_requests
'
,
};
export
const
FILTER_STATES_BY_SCOPE
=
{
[
SCOPES
.
ISSUES
]:
[
FILTER_STATES
.
ANY
,
FILTER_STATES
.
OPEN
,
FILTER_STATES
.
CLOSED
],
[
SCOPES
.
MERGE_REQUESTS
]:
[
FILTER_STATES
.
ANY
,
FILTER_STATES
.
OPEN
,
FILTER_STATES
.
MERGED
,
FILTER_STATES
.
CLOSED
,
],
};
};
changelogs/unreleased/237938-merge-requests-filter-by-state.yml
0 → 100644
View file @
6785cdb4
---
title
:
Search UI - Implement Merge Request scope results filter by state
merge_request
:
41282
author
:
type
:
added
ee/lib/elastic/latest/issue_class_proxy.rb
View file @
6785cdb4
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
module
Elastic
module
Elastic
module
Latest
module
Latest
class
IssueClassProxy
<
ApplicationClassProxy
class
IssueClassProxy
<
ApplicationClassProxy
include
StateFilter
def
elastic_search
(
query
,
options:
{})
def
elastic_search
(
query
,
options:
{})
query_hash
=
query_hash
=
if
query
=~
/#(\d+)\z/
if
query
=~
/#(\d+)\z/
...
@@ -28,18 +30,6 @@ module Elastic
...
@@ -28,18 +30,6 @@ module Elastic
private
private
def
state_filter
(
query_hash
,
options
)
state
=
options
[
:state
]
return
query_hash
if
state
.
blank?
||
state
==
'all'
return
query_hash
unless
%w(all opened closed)
.
include?
(
state
)
filter
=
{
match:
{
state:
state
}
}
query_hash
[
:query
][
:bool
][
:filter
]
<<
filter
query_hash
end
def
confidentiality_filter
(
query_hash
,
options
)
def
confidentiality_filter
(
query_hash
,
options
)
current_user
=
options
[
:current_user
]
current_user
=
options
[
:current_user
]
project_ids
=
options
[
:project_ids
]
project_ids
=
options
[
:project_ids
]
...
...
ee/lib/elastic/latest/merge_request_class_proxy.rb
View file @
6785cdb4
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
module
Elastic
module
Elastic
module
Latest
module
Latest
class
MergeRequestClassProxy
<
ApplicationClassProxy
class
MergeRequestClassProxy
<
ApplicationClassProxy
include
StateFilter
def
elastic_search
(
query
,
options:
{})
def
elastic_search
(
query
,
options:
{})
query_hash
=
query_hash
=
if
query
=~
/\!(\d+)\z/
if
query
=~
/\!(\d+)\z/
...
@@ -20,6 +22,7 @@ module Elastic
...
@@ -20,6 +22,7 @@ module Elastic
options
[
:features
]
=
'merge_requests'
options
[
:features
]
=
'merge_requests'
query_hash
=
project_ids_filter
(
query_hash
,
options
)
query_hash
=
project_ids_filter
(
query_hash
,
options
)
query_hash
=
state_filter
(
query_hash
,
options
)
search
(
query_hash
,
options
)
search
(
query_hash
,
options
)
end
end
...
...
ee/lib/elastic/latest/state_filter.rb
0 → 100644
View file @
6785cdb4
# frozen_string_literal: true
module
Elastic
module
Latest
module
StateFilter
private
def
state_filter
(
query_hash
,
options
)
state
=
options
[
:state
]
return
query_hash
if
state
.
blank?
||
state
==
'all'
return
query_hash
unless
%w(all opened closed merged)
.
include?
(
state
)
filter
=
{
match:
{
state:
state
}
}
query_hash
[
:query
][
:bool
][
:filter
]
<<
filter
query_hash
end
end
end
end
ee/lib/gitlab/elastic/search_results.rb
View file @
6785cdb4
...
@@ -244,7 +244,10 @@ module Gitlab
...
@@ -244,7 +244,10 @@ module Gitlab
def
merge_requests
def
merge_requests
strong_memoize
(
:merge_requests
)
do
strong_memoize
(
:merge_requests
)
do
MergeRequest
.
elastic_search
(
query
,
options:
base_options
)
options
=
base_options
options
[
:state
]
=
filters
[
:state
]
if
filters
.
key?
(
:state
)
MergeRequest
.
elastic_search
(
query
,
options:
options
)
end
end
end
end
...
...
ee/spec/lib/gitlab/elastic/group_search_results_spec.rb
View file @
6785cdb4
...
@@ -17,11 +17,28 @@ RSpec.describe Gitlab::Elastic::GroupSearchResults, :elastic do
...
@@ -17,11 +17,28 @@ RSpec.describe Gitlab::Elastic::GroupSearchResults, :elastic do
context
'issues search'
,
:sidekiq_inline
do
context
'issues search'
,
:sidekiq_inline
do
let!
(
:project
)
{
create
(
:project
,
:public
,
group:
group
)
}
let!
(
:project
)
{
create
(
:project
,
:public
,
group:
group
)
}
let!
(
:closed_issue
)
{
create
(
:issue
,
:closed
,
project:
project
,
title:
'foo closed'
)
}
let!
(
:closed_result
)
{
create
(
:issue
,
:closed
,
project:
project
,
title:
'foo closed'
)
}
let!
(
:opened_issue
)
{
create
(
:issue
,
:opened
,
project:
project
,
title:
'foo opened'
)
}
let!
(
:opened_result
)
{
create
(
:issue
,
:opened
,
project:
project
,
title:
'foo opened'
)
}
let
(
:query
)
{
'foo'
}
let
(
:scope
)
{
'issues'
}
include_examples
'search results filtered by state'
do
before
do
ensure_elasticsearch_index!
end
end
end
context
'merge_requests search'
,
:sidekiq_inline
do
let!
(
:project
)
{
create
(
:project
,
:public
,
group:
group
)
}
let!
(
:opened_result
)
{
create
(
:merge_request
,
:opened
,
source_project:
project
,
title:
'foo opened'
)
}
let!
(
:closed_result
)
{
create
(
:merge_request
,
:closed
,
source_project:
project
,
title:
'foo closed'
)
}
let
(
:query
)
{
'foo'
}
let
(
:query
)
{
'foo'
}
let
(
:scope
)
{
'merge_requests'
}
include_examples
'search
issues scope filters
by state'
do
include_examples
'search
results filtered
by state'
do
before
do
before
do
ensure_elasticsearch_index!
ensure_elasticsearch_index!
end
end
...
...
ee/spec/lib/gitlab/elastic/project_search_results_spec.rb
View file @
6785cdb4
...
@@ -70,14 +70,31 @@ RSpec.describe Gitlab::Elastic::ProjectSearchResults, :elastic do
...
@@ -70,14 +70,31 @@ RSpec.describe Gitlab::Elastic::ProjectSearchResults, :elastic do
end
end
context
'filtering'
do
context
'filtering'
do
include_examples
'search issues scope filters by state
'
do
context
'issues
'
do
let!
(
:project
)
{
create
(
:project
,
:public
)
}
let!
(
:project
)
{
create
(
:project
,
:public
)
}
let!
(
:closed_
issue
)
{
create
(
:issue
,
:closed
,
project:
project
,
title:
'foo closed'
)
}
let!
(
:closed_
result
)
{
create
(
:issue
,
:closed
,
project:
project
,
title:
'foo closed'
)
}
let!
(
:opened_
issue
)
{
create
(
:issue
,
:opened
,
project:
project
,
title:
'foo opened'
)
}
let!
(
:opened_
result
)
{
create
(
:issue
,
:opened
,
project:
project
,
title:
'foo opened'
)
}
let
(
:query
)
{
'foo'
}
let
(
:query
)
{
'foo'
}
let
(
:scope
)
{
'issues'
}
before
do
include_examples
'search results filtered by state'
do
ensure_elasticsearch_index!
before
do
ensure_elasticsearch_index!
end
end
end
context
'merge_requests'
do
let!
(
:project
)
{
create
(
:project
,
:public
)
}
let!
(
:opened_result
)
{
create
(
:merge_request
,
:opened
,
source_project:
project
,
title:
'foo opened'
)
}
let!
(
:closed_result
)
{
create
(
:merge_request
,
:closed
,
source_project:
project
,
title:
'foo closed'
)
}
let
(
:query
)
{
'foo'
}
let
(
:scope
)
{
'merge_requests'
}
include_examples
'search results filtered by state'
do
before
do
ensure_elasticsearch_index!
end
end
end
end
end
end
end
...
...
ee/spec/lib/gitlab/elastic/search_results_spec.rb
View file @
6785cdb4
...
@@ -174,12 +174,13 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
...
@@ -174,12 +174,13 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
context
'filtering'
do
context
'filtering'
do
let!
(
:project
)
{
create
(
:project
,
:public
)
}
let!
(
:project
)
{
create
(
:project
,
:public
)
}
let!
(
:closed_
issue
)
{
create
(
:issue
,
:closed
,
project:
project
,
title:
'foo closed'
)
}
let!
(
:closed_
result
)
{
create
(
:issue
,
:closed
,
project:
project
,
title:
'foo closed'
)
}
let!
(
:opened_
issue
)
{
create
(
:issue
,
:opened
,
project:
project
,
title:
'foo opened'
)
}
let!
(
:opened_
result
)
{
create
(
:issue
,
:opened
,
project:
project
,
title:
'foo opened'
)
}
let
(
:scope
)
{
'issues'
}
let
(
:results
)
{
described_class
.
new
(
user
,
'foo'
,
[
project
],
filters:
filters
)
}
let
(
:results
)
{
described_class
.
new
(
user
,
'foo'
,
[
project
],
filters:
filters
)
}
include_examples
'search
issues scope filters
by state'
do
include_examples
'search
results filtered
by state'
do
before
do
before
do
ensure_elasticsearch_index!
ensure_elasticsearch_index!
end
end
...
@@ -493,6 +494,21 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
...
@@ -493,6 +494,21 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
expect
(
results
.
objects
(
'merge_requests'
)).
to
be_empty
expect
(
results
.
objects
(
'merge_requests'
)).
to
be_empty
expect
(
results
.
merge_requests_count
).
to
eq
0
expect
(
results
.
merge_requests_count
).
to
eq
0
end
end
context
'filtering'
do
let!
(
:project
)
{
create
(
:project
,
:public
)
}
let!
(
:opened_result
)
{
create
(
:merge_request
,
:opened
,
source_project:
project
,
title:
'foo opened'
)
}
let!
(
:closed_result
)
{
create
(
:merge_request
,
:closed
,
source_project:
project
,
title:
'foo closed'
)
}
let
(
:scope
)
{
'merge_requests'
}
let
(
:results
)
{
described_class
.
new
(
user
,
'foo'
,
[
project
],
filters:
filters
)
}
include_examples
'search results filtered by state'
do
before
do
ensure_elasticsearch_index!
end
end
end
end
end
describe
'project scoping'
do
describe
'project scoping'
do
...
...
spec/frontend/search/components/state_filter_spec.js
View file @
6785cdb4
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
{
GlDropdown
,
GlDropdownItem
}
from
'
@gitlab/ui
'
;
import
{
GlDropdown
,
GlDropdownItem
}
from
'
@gitlab/ui
'
;
import
StateFilter
from
'
~/search/state_filter/components/state_filter.vue
'
;
import
StateFilter
from
'
~/search/state_filter/components/state_filter.vue
'
;
import
{
FILTER_STATES
}
from
'
~/search/state_filter/constants
'
;
import
{
FILTER_STATES
,
SCOPES
,
FILTER_STATES_BY_SCOPE
,
FILTER_TEXT
,
}
from
'
~/search/state_filter/constants
'
;
import
*
as
urlUtils
from
'
~/lib/utils/url_utility
'
;
import
*
as
urlUtils
from
'
~/lib/utils/url_utility
'
;
jest
.
mock
(
'
~/lib/utils/url_utility
'
,
()
=>
({
jest
.
mock
(
'
~/lib/utils/url_utility
'
,
()
=>
({
...
@@ -38,10 +43,10 @@ describe('StateFilter', () => {
...
@@ -38,10 +43,10 @@ describe('StateFilter', () => {
describe
.
each
`
describe
.
each
`
scope | showStateDropdown
scope | showStateDropdown
${
'
issues
'
}
|
${
true
}
${
'
issues
'
}
|
${
true
}
${
'
merge_requests
'
}
|
${
true
}
${
'
projects
'
}
|
${
false
}
${
'
projects
'
}
|
${
false
}
${
'
milestones
'
}
|
${
false
}
${
'
milestones
'
}
|
${
false
}
${
'
users
'
}
|
${
false
}
${
'
users
'
}
|
${
false
}
${
'
merge_requests
'
}
|
${
false
}
${
'
notes
'
}
|
${
false
}
${
'
notes
'
}
|
${
false
}
${
'
wiki_blobs
'
}
|
${
false
}
${
'
wiki_blobs
'
}
|
${
false
}
${
'
blobs
'
}
|
${
false
}
${
'
blobs
'
}
|
${
false
}
...
@@ -55,11 +60,29 @@ describe('StateFilter', () => {
...
@@ -55,11 +60,29 @@ describe('StateFilter', () => {
});
});
});
});
describe
.
each
`
state | label
${
FILTER_STATES
.
ANY
.
value
}
|
${
FILTER_TEXT
}
${
FILTER_STATES
.
OPEN
.
value
}
|
${
FILTER_STATES
.
OPEN
.
label
}
${
FILTER_STATES
.
CLOSED
.
value
}
|
${
FILTER_STATES
.
CLOSED
.
label
}
${
FILTER_STATES
.
MERGED
.
value
}
|
${
FILTER_STATES
.
MERGED
.
label
}
`
(
`filter text`
,
({
state
,
label
})
=>
{
describe
(
`when state is
${
state
}
`
,
()
=>
{
beforeEach
(()
=>
{
wrapper
=
createComponent
({
scope
:
'
issues
'
,
state
});
});
it
(
`sets dropdown label to
${
label
}
`
,
()
=>
{
expect
(
findGlDropdown
().
attributes
(
'
text
'
)).
toBe
(
label
);
});
});
});
describe
(
'
Filter options
'
,
()
=>
{
describe
(
'
Filter options
'
,
()
=>
{
it
(
'
renders a dropdown item for each filterOption
'
,
()
=>
{
it
(
'
renders a dropdown item for each filterOption
'
,
()
=>
{
expect
(
findDropdownItemsText
()).
toStrictEqual
(
expect
(
findDropdownItemsText
()).
toStrictEqual
(
Object
.
keys
(
FILTER_STATES
).
map
(
key
=>
{
FILTER_STATES_BY_SCOPE
[
SCOPES
.
ISSUES
].
map
(
v
=>
{
return
FILTER_STATES
[
key
]
.
label
;
return
v
.
label
;
}),
}),
);
);
});
});
...
...
spec/lib/gitlab/group_search_results_spec.rb
View file @
6785cdb4
...
@@ -7,6 +7,7 @@ RSpec.describe Gitlab::GroupSearchResults do
...
@@ -7,6 +7,7 @@ RSpec.describe Gitlab::GroupSearchResults do
# before so expect(GroupsFinder) check works
# before so expect(GroupsFinder) check works
let_it_be
(
:group
)
{
create
(
:group
)
}
let_it_be
(
:group
)
{
create
(
:group
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
,
:public
,
group:
group
)
}
let
(
:filters
)
{
{}
}
let
(
:filters
)
{
{}
}
let
(
:limit_projects
)
{
Project
.
all
}
let
(
:limit_projects
)
{
Project
.
all
}
let
(
:query
)
{
'gob'
}
let
(
:query
)
{
'gob'
}
...
@@ -14,13 +15,27 @@ RSpec.describe Gitlab::GroupSearchResults do
...
@@ -14,13 +15,27 @@ RSpec.describe Gitlab::GroupSearchResults do
subject
(
:results
)
{
described_class
.
new
(
user
,
query
,
limit_projects
,
group:
group
,
filters:
filters
)
}
subject
(
:results
)
{
described_class
.
new
(
user
,
query
,
limit_projects
,
group:
group
,
filters:
filters
)
}
describe
'issues search'
do
describe
'issues search'
do
let_it_be
(
:project
)
{
create
(
:project
,
:public
,
group:
group
)
}
let_it_be
(
:opened_result
)
{
create
(
:issue
,
:opened
,
project:
project
,
title:
'foo opened'
)
}
let_it_be
(
:opened_issue
)
{
create
(
:issue
,
:opened
,
project:
project
,
title:
'foo opened'
)
}
let_it_be
(
:closed_result
)
{
create
(
:issue
,
:closed
,
project:
project
,
title:
'foo closed'
)
}
let_it_be
(
:closed_issue
)
{
create
(
:issue
,
:closed
,
project:
project
,
title:
'foo closed'
)
}
let
(
:query
)
{
'foo'
}
let
(
:query
)
{
'foo'
}
let
(
:
filters
)
{
{
state:
'opened'
}
}
let
(
:
scope
)
{
'issues'
}
include_examples
'search issues scope filters by state'
include_examples
'search results filtered by state'
end
describe
'merge_requests search'
do
let
(
:opened_result
)
{
create
(
:merge_request
,
:opened
,
source_project:
project
,
title:
'foo opened'
)
}
let
(
:closed_result
)
{
create
(
:merge_request
,
:closed
,
source_project:
project
,
title:
'foo closed'
)
}
let
(
:query
)
{
'foo'
}
let
(
:scope
)
{
'merge_requests'
}
before
do
# we're creating those instances in before block because otherwise factory for MRs will fail on after(:build)
opened_result
closed_result
end
include_examples
'search results filtered by state'
end
end
describe
'user search'
do
describe
'user search'
do
...
...
spec/lib/gitlab/project_search_results_spec.rb
View file @
6785cdb4
...
@@ -249,8 +249,9 @@ RSpec.describe Gitlab::ProjectSearchResults do
...
@@ -249,8 +249,9 @@ RSpec.describe Gitlab::ProjectSearchResults do
describe
'issues search'
do
describe
'issues search'
do
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:query
)
{
issue
.
title
}
let
(
:query
)
{
issue
.
title
}
let
(
:scope
)
{
'issues'
}
subject
(
:objects
)
{
results
.
objects
(
'issues'
)
}
subject
(
:objects
)
{
results
.
objects
(
scope
)
}
it
'does not list issues on private projects'
do
it
'does not list issues on private projects'
do
expect
(
objects
).
not_to
include
issue
expect
(
objects
).
not_to
include
issue
...
@@ -262,20 +263,25 @@ RSpec.describe Gitlab::ProjectSearchResults do
...
@@ -262,20 +263,25 @@ RSpec.describe Gitlab::ProjectSearchResults do
context
'filtering'
do
context
'filtering'
do
let_it_be
(
:project
)
{
create
(
:project
,
:public
)
}
let_it_be
(
:project
)
{
create
(
:project
,
:public
)
}
let_it_be
(
:closed_
issue
)
{
create
(
:issue
,
:closed
,
project:
project
,
title:
'foo closed'
)
}
let_it_be
(
:closed_
result
)
{
create
(
:issue
,
:closed
,
project:
project
,
title:
'foo closed'
)
}
let_it_be
(
:opened_
issue
)
{
create
(
:issue
,
:opened
,
project:
project
,
title:
'foo opened'
)
}
let_it_be
(
:opened_
result
)
{
create
(
:issue
,
:opened
,
project:
project
,
title:
'foo opened'
)
}
let
(
:query
)
{
'foo'
}
let
(
:query
)
{
'foo'
}
include_examples
'search
issues scope filters
by state'
include_examples
'search
results filtered
by state'
end
end
end
it
'filters issues when state is provided'
,
:aggregate_failures
do
describe
'merge requests search'
do
closed_issue
=
create
(
:issue
,
:closed
,
project:
project
,
title:
"Revert:
#{
issue
.
title
}
"
)
let
(
:scope
)
{
'merge_requests'
}
let
(
:project
)
{
create
(
:project
,
:public
)
}
results
=
described_class
.
new
(
project
.
creator
,
query
,
project:
project
,
filters:
{
state:
'opened'
})
context
'filtering'
do
let!
(
:project
)
{
create
(
:project
,
:public
)
}
let!
(
:opened_result
)
{
create
(
:merge_request
,
:opened
,
source_project:
project
,
title:
'foo opened'
)
}
let!
(
:closed_result
)
{
create
(
:merge_request
,
:closed
,
source_project:
project
,
title:
'foo closed'
)
}
let
(
:query
)
{
'foo'
}
expect
(
results
.
objects
(
'issues'
)).
not_to
include
closed_issue
include_examples
'search results filtered by state'
expect
(
results
.
objects
(
'issues'
)).
to
include
issue
end
end
end
end
...
...
spec/lib/gitlab/search_results_spec.rb
View file @
6785cdb4
...
@@ -150,6 +150,15 @@ RSpec.describe Gitlab::SearchResults do
...
@@ -150,6 +150,15 @@ RSpec.describe Gitlab::SearchResults do
results
.
objects
(
'merge_requests'
)
results
.
objects
(
'merge_requests'
)
end
end
context
'filtering'
do
let!
(
:opened_result
)
{
create
(
:merge_request
,
:opened
,
source_project:
project
,
title:
'foo opened'
)
}
let!
(
:closed_result
)
{
create
(
:merge_request
,
:closed
,
source_project:
project
,
title:
'foo closed'
)
}
let
(
:scope
)
{
'merge_requests'
}
let
(
:query
)
{
'foo'
}
include_examples
'search results filtered by state'
end
end
end
describe
'#issues'
do
describe
'#issues'
do
...
@@ -168,10 +177,12 @@ RSpec.describe Gitlab::SearchResults do
...
@@ -168,10 +177,12 @@ RSpec.describe Gitlab::SearchResults do
end
end
context
'filtering'
do
context
'filtering'
do
let_it_be
(
:closed_issue
)
{
create
(
:issue
,
:closed
,
project:
project
,
title:
'foo closed'
)
}
let
(
:scope
)
{
'issues'
}
let_it_be
(
:opened_issue
)
{
create
(
:issue
,
:opened
,
project:
project
,
title:
'foo open'
)
}
let_it_be
(
:closed_result
)
{
create
(
:issue
,
:closed
,
project:
project
,
title:
'foo closed'
)
}
let_it_be
(
:opened_result
)
{
create
(
:issue
,
:opened
,
project:
project
,
title:
'foo open'
)
}
include_examples
'search
issues scope filters
by state'
include_examples
'search
results filtered
by state'
end
end
end
end
...
...
spec/support/shared_examples/lib/gitlab/search_issue_state_filter_shared_examples.rb
View file @
6785cdb4
# frozen_string_literal: true
# frozen_string_literal: true
RSpec
.
shared_examples
'search
issues scope filters
by state'
do
RSpec
.
shared_examples
'search
results filtered
by state'
do
context
'state not provided'
do
context
'state not provided'
do
let
(
:filters
)
{
{}
}
let
(
:filters
)
{
{}
}
it
'returns opened and closed
issue
s'
,
:aggregate_failures
do
it
'returns opened and closed
result
s'
,
:aggregate_failures
do
expect
(
results
.
objects
(
'issues'
)).
to
include
opened_issue
expect
(
results
.
objects
(
scope
)).
to
include
opened_result
expect
(
results
.
objects
(
'issues'
)).
to
include
closed_issue
expect
(
results
.
objects
(
scope
)).
to
include
closed_result
end
end
end
end
context
'all state'
do
context
'all state'
do
let
(
:filters
)
{
{
state:
'all'
}
}
let
(
:filters
)
{
{
state:
'all'
}
}
it
'returns opened and closed
issue
s'
,
:aggregate_failures
do
it
'returns opened and closed
result
s'
,
:aggregate_failures
do
expect
(
results
.
objects
(
'issues'
)).
to
include
opened_issue
expect
(
results
.
objects
(
scope
)).
to
include
opened_result
expect
(
results
.
objects
(
'issues'
)).
to
include
closed_issue
expect
(
results
.
objects
(
scope
)).
to
include
closed_result
end
end
end
end
context
'closed state'
do
context
'closed state'
do
let
(
:filters
)
{
{
state:
'closed'
}
}
let
(
:filters
)
{
{
state:
'closed'
}
}
it
'returns only closed
issue
s'
,
:aggregate_failures
do
it
'returns only closed
result
s'
,
:aggregate_failures
do
expect
(
results
.
objects
(
'issues'
)).
not_to
include
opened_issue
expect
(
results
.
objects
(
scope
)).
not_to
include
opened_result
expect
(
results
.
objects
(
'issues'
)).
to
include
closed_issue
expect
(
results
.
objects
(
scope
)).
to
include
closed_result
end
end
end
end
context
'opened state'
do
context
'opened state'
do
let
(
:filters
)
{
{
state:
'opened'
}
}
let
(
:filters
)
{
{
state:
'opened'
}
}
it
'returns only opened
issue
s'
,
:aggregate_failures
do
it
'returns only opened
result
s'
,
:aggregate_failures
do
expect
(
results
.
objects
(
'issues'
)).
to
include
opened_issue
expect
(
results
.
objects
(
scope
)).
to
include
opened_result
expect
(
results
.
objects
(
'issues'
)).
not_to
include
closed_issue
expect
(
results
.
objects
(
scope
)).
not_to
include
closed_result
end
end
end
end
context
'unsupported state'
do
context
'unsupported state'
do
let
(
:filters
)
{
{
state:
'hello'
}
}
let
(
:filters
)
{
{
state:
'hello'
}
}
it
'returns only opened
issue
s'
,
:aggregate_failures
do
it
'returns only opened
result
s'
,
:aggregate_failures
do
expect
(
results
.
objects
(
'issues'
)).
to
include
opened_issue
expect
(
results
.
objects
(
scope
)).
to
include
opened_result
expect
(
results
.
objects
(
'issues'
)).
to
include
closed_issue
expect
(
results
.
objects
(
scope
)).
to
include
closed_result
end
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment