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
2ea16b66
Commit
2ea16b66
authored
Sep 01, 2017
by
Bryce Johnson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add JS unit tests and shush eslint.
parent
7d4e83fe
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
9 deletions
+66
-9
app/assets/javascripts/filtered_search/filtered_search_manager.js
...ts/javascripts/filtered_search/filtered_search_manager.js
+4
-5
app/assets/javascripts/service_desk_issues/filtered_search.js
...assets/javascripts/service_desk_issues/filtered_search.js
+4
-4
spec/javascripts/filtered_search/filtered_search_manager_spec.js
...vascripts/filtered_search/filtered_search_manager_spec.js
+58
-0
No files found.
app/assets/javascripts/filtered_search/filtered_search_manager.js
View file @
2ea16b66
...
...
@@ -337,7 +337,7 @@ class FilteredSearchManager {
removalValidator
(
token
)
{
const
isToken
=
token
.
classList
.
contains
(
'
js-visual-token
'
);
return
this
.
customRemovalValidator
?
(
isToken
&&
this
.
customRemovalValidator
(
token
)
)
:
isToken
;
return
this
.
customRemovalValidator
?
(
this
.
customRemovalValidator
(
token
)
&&
isToken
)
:
isToken
;
}
clearSearch
()
{
...
...
@@ -426,14 +426,13 @@ class FilteredSearchManager {
}
// allows for modifying params array when a param can't be included in the URL (e.g. Service Desk)
getAllParams
()
{
let
urlParams
=
gl
.
utils
.
getUrlParamsArray
();
getAllParams
(
urlParams
)
{
return
this
.
modifyUrlParams
?
this
.
modifyUrlParams
(
urlParams
)
:
urlParams
;
}
loadSearchParamsFromURL
()
{
const
params
=
this
.
getAllParams
();
const
urlParams
=
gl
.
utils
.
getUrlParamsArray
();
const
params
=
this
.
getAllParams
(
urlParams
);
const
usernameParams
=
this
.
getUsernameParams
();
let
hasFilteredSearch
=
false
;
...
...
app/assets/javascripts/service_desk_issues/filtered_search.js
View file @
2ea16b66
/* eslint-disable class-methods-use-this */
export
default
class
FilteredSearchServiceDesk
extends
gl
.
FilteredSearchManager
{
constructor
()
{
super
(
'
service_desk
'
);
...
...
@@ -5,7 +7,7 @@ export default class FilteredSearchServiceDesk extends gl.FilteredSearchManager
customRemovalValidator
(
token
)
{
return
token
.
querySelector
(
'
.value-container
'
).
getAttribute
(
'
data-original-value
'
)
!==
'
@support-bot
'
;
}
;
}
canEdit
(
tokenName
)
{
return
tokenName
!==
'
author
'
;
...
...
@@ -16,9 +18,7 @@ export default class FilteredSearchServiceDesk extends gl.FilteredSearchManager
// FIXME: Need to grab the value from a data attribute
const
supportBotParamPair
=
`
${
authorParamKey
}
=support-bot`
;
const
onlyValidParams
=
paramsArray
.
filter
((
param
)
=>
{
return
param
.
indexOf
(
authorParamKey
)
===
-
1
;
});
const
onlyValidParams
=
paramsArray
.
filter
(
param
=>
param
.
indexOf
(
authorParamKey
)
===
-
1
);
// unshift ensures author param is always first token element
onlyValidParams
.
unshift
(
supportBotParamPair
);
...
...
spec/javascripts/filtered_search/filtered_search_manager_spec.js
View file @
2ea16b66
...
...
@@ -411,4 +411,62 @@ describe('Filtered Search Manager', () => {
expect
(
document
.
querySelector
(
'
.filtered-search-box
'
).
classList
.
contains
(
'
focus
'
)).
toEqual
(
false
);
});
});
describe
(
'
removalValidator
'
,
()
=>
{
beforeEach
(()
=>
{
Object
.
assign
(
gl
.
FilteredSearchManager
.
prototype
,
{
customRemovalValidator
:
()
=>
true
,
});
spyOn
(
gl
.
FilteredSearchManager
.
prototype
,
'
removalValidator
'
).
and
.
callThrough
();
spyOn
(
gl
.
FilteredSearchManager
.
prototype
,
'
customRemovalValidator
'
).
and
.
callThrough
();
initializeManager
();
});
it
(
'
is called on clearSearch
'
,
()
=>
{
manager
.
clearSearch
();
expect
(
manager
.
removalValidator
).
toHaveBeenCalled
();
});
it
(
'
calls the customRemovalValidator when present
'
,
()
=>
{
manager
.
clearSearch
();
expect
(
manager
.
customRemovalValidator
).
toHaveBeenCalled
();
});
});
describe
(
'
getAllParams
'
,
()
=>
{
beforeEach
(()
=>
{
this
.
paramsArr
=
[
'
key=value
'
,
'
otherkey=othervalue
'
];
Object
.
assign
(
gl
.
FilteredSearchManager
.
prototype
,
{
modifyUrlParams
:
paramsArr
=>
paramsArr
.
reverse
(),
});
spyOn
(
gl
.
FilteredSearchManager
.
prototype
,
'
modifyUrlParams
'
).
and
.
callThrough
();
initializeManager
();
});
it
(
'
calls modifyUrlParams when present
'
,
()
=>
{
manager
.
getAllParams
(
this
.
paramsArr
);
expect
(
manager
.
modifyUrlParams
).
toHaveBeenCalled
();
});
it
(
'
correctly modifies params when custom modifier is passed
'
,
()
=>
{
const
modifedParams
=
manager
.
getAllParams
(
this
.
paramsArr
);
expect
(
modifedParams
[
0
]).
toBe
(
'
otherkey=othervalue
'
);
});
it
(
'
does not modify params when no custom modifier is passed
'
,
()
=>
{
Object
.
assign
(
gl
.
FilteredSearchManager
.
prototype
,
{
modifyUrlParams
:
undefined
});
const
modifedParams
=
manager
.
getAllParams
(
this
.
paramsArr
);
expect
(
modifedParams
[
1
]).
toBe
(
'
otherkey=othervalue
'
);
});
});
});
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