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
7b973da3
Commit
7b973da3
authored
Jun 06, 2020
by
Himanshu Kapoor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate filtered_search specs to Jest
Migrate all remaining specs in spec/javascripts/filtered_search to Jest
parent
38a08da5
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
43 deletions
+57
-43
app/assets/javascripts/filtered_search/filtered_search_visual_tokens.js
...ascripts/filtered_search/filtered_search_visual_tokens.js
+16
-16
spec/frontend/filtered_search/filtered_search_dropdown_manager_spec.js
.../filtered_search/filtered_search_dropdown_manager_spec.js
+20
-16
spec/frontend/filtered_search/filtered_search_visual_tokens_spec.js
...end/filtered_search/filtered_search_visual_tokens_spec.js
+21
-11
No files found.
app/assets/javascripts/filtered_search/filtered_search_visual_tokens.js
View file @
7b973da3
...
...
@@ -95,7 +95,7 @@ export default class FilteredSearchVisualTokens {
const
tokenType
=
tokenName
.
toLowerCase
();
const
tokenValueContainer
=
parentElement
.
querySelector
(
'
.value-container
'
);
const
tokenValueElement
=
tokenValueContainer
.
querySelector
(
'
.value
'
);
tokenValueElement
.
innerTex
t
=
tokenValue
;
tokenValueElement
.
textConten
t
=
tokenValue
;
const
visualTokenValue
=
new
VisualTokenValue
(
tokenValue
,
tokenType
,
tokenOperator
);
...
...
@@ -140,9 +140,9 @@ export default class FilteredSearchVisualTokens {
li
.
innerHTML
=
nameHTML
+
operatorHTML
;
}
li
.
querySelector
(
'
.name
'
).
innerTex
t
=
name
;
li
.
querySelector
(
'
.name
'
).
textConten
t
=
name
;
if
(
hasOperator
)
{
li
.
querySelector
(
'
.operator
'
).
innerTex
t
=
operator
;
li
.
querySelector
(
'
.operator
'
).
textConten
t
=
operator
;
}
const
tokensContainer
=
FilteredSearchContainer
.
container
.
querySelector
(
'
.tokens-container
'
);
...
...
@@ -162,8 +162,8 @@ export default class FilteredSearchVisualTokens {
lastVisualToken
.
innerHTML
=
FilteredSearchVisualTokens
.
createVisualTokenElementHTML
({
hasOperator
:
Boolean
(
operator
),
});
lastVisualToken
.
querySelector
(
'
.name
'
).
innerTex
t
=
name
;
lastVisualToken
.
querySelector
(
'
.operator
'
).
innerTex
t
=
operator
;
lastVisualToken
.
querySelector
(
'
.name
'
).
textConten
t
=
name
;
lastVisualToken
.
querySelector
(
'
.operator
'
).
textConten
t
=
operator
;
FilteredSearchVisualTokens
.
renderVisualTokenValue
(
lastVisualToken
,
name
,
value
,
operator
);
}
}
...
...
@@ -208,8 +208,8 @@ export default class FilteredSearchVisualTokens {
},
});
}
else
{
const
previousTokenName
=
lastVisualToken
.
querySelector
(
'
.name
'
).
innerTex
t
;
const
previousTokenOperator
=
lastVisualToken
.
querySelector
(
'
.operator
'
).
innerTex
t
;
const
previousTokenName
=
lastVisualToken
.
querySelector
(
'
.name
'
).
textConten
t
;
const
previousTokenOperator
=
lastVisualToken
.
querySelector
(
'
.operator
'
).
textConten
t
;
const
tokensContainer
=
FilteredSearchContainer
.
container
.
querySelector
(
'
.tokens-container
'
);
tokensContainer
.
removeChild
(
lastVisualToken
);
...
...
@@ -234,7 +234,7 @@ export default class FilteredSearchVisualTokens {
const
{
lastVisualToken
}
=
FilteredSearchVisualTokens
.
getLastVisualTokenBeforeInput
();
if
(
lastVisualToken
&&
lastVisualToken
.
classList
.
contains
(
'
filtered-search-term
'
))
{
lastVisualToken
.
querySelector
(
'
.name
'
).
innerTex
t
+=
`
${
searchTerm
}
`
;
lastVisualToken
.
querySelector
(
'
.name
'
).
textConten
t
+=
`
${
searchTerm
}
`
;
}
else
{
FilteredSearchVisualTokens
.
addVisualTokenElement
({
name
:
searchTerm
,
...
...
@@ -261,12 +261,12 @@ export default class FilteredSearchVisualTokens {
const
value
=
lastVisualToken
.
querySelector
(
'
.value
'
);
const
name
=
lastVisualToken
.
querySelector
(
'
.name
'
);
const
valueText
=
value
?
value
.
innerTex
t
:
''
;
const
nameText
=
name
?
name
.
innerTex
t
:
''
;
const
valueText
=
value
?
value
.
textConten
t
:
''
;
const
nameText
=
name
?
name
.
textConten
t
:
''
;
if
(
includeOperator
)
{
const
operator
=
lastVisualToken
.
querySelector
(
'
.operator
'
);
const
operatorText
=
operator
?
operator
.
innerTex
t
:
''
;
const
operatorText
=
operator
?
operator
.
textConten
t
:
''
;
return
valueText
||
operatorText
||
nameText
;
}
...
...
@@ -278,7 +278,7 @@ export default class FilteredSearchVisualTokens {
const
operator
=
lastVisualToken
&&
lastVisualToken
.
querySelector
(
'
.operator
'
);
return
operator
?.
innerTex
t
;
return
operator
?.
textConten
t
;
}
static
removeLastTokenPartial
()
{
...
...
@@ -346,8 +346,8 @@ export default class FilteredSearchVisualTokens {
if
(
token
.
classList
.
contains
(
'
filtered-search-token
'
))
{
FilteredSearchVisualTokens
.
addFilterVisualToken
(
nameElement
.
innerTex
t
,
operatorElement
.
innerTex
t
,
nameElement
.
textConten
t
,
operatorElement
.
textConten
t
,
null
,
{
uppercaseTokenName
:
nameElement
.
classList
.
contains
(
'
text-uppercase
'
),
...
...
@@ -359,13 +359,13 @@ export default class FilteredSearchVisualTokens {
if
(
!
value
)
{
const
valueElement
=
valueContainerElement
.
querySelector
(
'
.value
'
);
value
=
valueElement
.
innerTex
t
;
value
=
valueElement
.
textConten
t
;
}
}
// token is a search term
if
(
!
value
)
{
value
=
nameElement
.
innerTex
t
;
value
=
nameElement
.
textConten
t
;
}
input
.
value
=
value
;
...
...
spec/
javascripts
/filtered_search/filtered_search_dropdown_manager_spec.js
→
spec/
frontend
/filtered_search/filtered_search_dropdown_manager_spec.js
View file @
7b973da3
import
$
from
'
jquery
'
;
import
axios
from
'
axios
'
;
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
FilteredSearchDropdownManager
from
'
~/filtered_search/filtered_search_dropdown_manager
'
;
describe
(
'
Filtered Search Dropdown Manager
'
,
()
=>
{
let
mock
;
beforeEach
(()
=>
{
spyOn
(
$
,
'
ajax
'
);
mock
=
new
MockAdapter
(
axios
);
mock
.
onGet
().
reply
(
200
);
});
describe
(
'
addWordToInput
'
,
()
=>
{
...
...
@@ -32,7 +36,7 @@ describe('Filtered Search Dropdown Manager', () => {
const
token
=
document
.
querySelector
(
'
.tokens-container .js-visual-token
'
);
expect
(
token
.
classList
.
contains
(
'
filtered-search-token
'
)).
toEqual
(
true
);
expect
(
token
.
querySelector
(
'
.name
'
).
innerTex
t
).
toBe
(
'
milestone
'
);
expect
(
token
.
querySelector
(
'
.name
'
).
textConten
t
).
toBe
(
'
milestone
'
);
expect
(
getInputValue
()).
toBe
(
''
);
});
...
...
@@ -42,7 +46,7 @@ describe('Filtered Search Dropdown Manager', () => {
let
token
=
document
.
querySelector
(
'
.tokens-container .js-visual-token
'
);
expect
(
token
.
classList
.
contains
(
'
filtered-search-token
'
)).
toEqual
(
true
);
expect
(
token
.
querySelector
(
'
.name
'
).
innerTex
t
).
toBe
(
'
label
'
);
expect
(
token
.
querySelector
(
'
.name
'
).
textConten
t
).
toBe
(
'
label
'
);
expect
(
getInputValue
()).
toBe
(
''
);
FilteredSearchDropdownManager
.
addWordToInput
({
tokenName
:
'
label
'
,
tokenOperator
:
'
=
'
});
...
...
@@ -50,8 +54,8 @@ describe('Filtered Search Dropdown Manager', () => {
token
=
document
.
querySelector
(
'
.tokens-container .js-visual-token
'
);
expect
(
token
.
classList
.
contains
(
'
filtered-search-token
'
)).
toEqual
(
true
);
expect
(
token
.
querySelector
(
'
.name
'
).
innerTex
t
).
toBe
(
'
label
'
);
expect
(
token
.
querySelector
(
'
.operator
'
).
innerTex
t
).
toBe
(
'
=
'
);
expect
(
token
.
querySelector
(
'
.name
'
).
textConten
t
).
toBe
(
'
label
'
);
expect
(
token
.
querySelector
(
'
.operator
'
).
textConten
t
).
toBe
(
'
=
'
);
expect
(
getInputValue
()).
toBe
(
''
);
FilteredSearchDropdownManager
.
addWordToInput
({
...
...
@@ -64,9 +68,9 @@ describe('Filtered Search Dropdown Manager', () => {
token
=
document
.
querySelector
(
'
.tokens-container .js-visual-token
'
);
expect
(
token
.
classList
.
contains
(
'
filtered-search-token
'
)).
toEqual
(
true
);
expect
(
token
.
querySelector
(
'
.name
'
).
innerTex
t
).
toBe
(
'
label
'
);
expect
(
token
.
querySelector
(
'
.operator
'
).
innerTex
t
).
toBe
(
'
=
'
);
expect
(
token
.
querySelector
(
'
.value
'
).
innerTex
t
).
toBe
(
'
none
'
);
expect
(
token
.
querySelector
(
'
.name
'
).
textConten
t
).
toBe
(
'
label
'
);
expect
(
token
.
querySelector
(
'
.operator
'
).
textConten
t
).
toBe
(
'
=
'
);
expect
(
token
.
querySelector
(
'
.value
'
).
textConten
t
).
toBe
(
'
none
'
);
expect
(
getInputValue
()).
toBe
(
''
);
});
});
...
...
@@ -79,7 +83,7 @@ describe('Filtered Search Dropdown Manager', () => {
const
token
=
document
.
querySelector
(
'
.tokens-container .js-visual-token
'
);
expect
(
token
.
classList
.
contains
(
'
filtered-search-token
'
)).
toEqual
(
true
);
expect
(
token
.
querySelector
(
'
.name
'
).
innerTex
t
).
toBe
(
'
author
'
);
expect
(
token
.
querySelector
(
'
.name
'
).
textConten
t
).
toBe
(
'
author
'
);
expect
(
getInputValue
()).
toBe
(
''
);
});
...
...
@@ -97,9 +101,9 @@ describe('Filtered Search Dropdown Manager', () => {
const
token
=
document
.
querySelector
(
'
.tokens-container .js-visual-token
'
);
expect
(
token
.
classList
.
contains
(
'
filtered-search-token
'
)).
toEqual
(
true
);
expect
(
token
.
querySelector
(
'
.name
'
).
innerTex
t
).
toBe
(
'
author
'
);
expect
(
token
.
querySelector
(
'
.operator
'
).
innerTex
t
).
toBe
(
'
=
'
);
expect
(
token
.
querySelector
(
'
.value
'
).
innerTex
t
).
toBe
(
'
@root
'
);
expect
(
token
.
querySelector
(
'
.name
'
).
textConten
t
).
toBe
(
'
author
'
);
expect
(
token
.
querySelector
(
'
.operator
'
).
textConten
t
).
toBe
(
'
=
'
);
expect
(
token
.
querySelector
(
'
.value
'
).
textConten
t
).
toBe
(
'
@root
'
);
expect
(
getInputValue
()).
toBe
(
''
);
});
...
...
@@ -116,9 +120,9 @@ describe('Filtered Search Dropdown Manager', () => {
const
token
=
document
.
querySelector
(
'
.tokens-container .js-visual-token
'
);
expect
(
token
.
classList
.
contains
(
'
filtered-search-token
'
)).
toEqual
(
true
);
expect
(
token
.
querySelector
(
'
.name
'
).
innerTex
t
).
toBe
(
'
label
'
);
expect
(
token
.
querySelector
(
'
.operator
'
).
innerTex
t
).
toBe
(
'
=
'
);
expect
(
token
.
querySelector
(
'
.value
'
).
innerTex
t
).
toBe
(
'
~
\'
"test me"
\'
'
);
expect
(
token
.
querySelector
(
'
.name
'
).
textConten
t
).
toBe
(
'
label
'
);
expect
(
token
.
querySelector
(
'
.operator
'
).
textConten
t
).
toBe
(
'
=
'
);
expect
(
token
.
querySelector
(
'
.value
'
).
textConten
t
).
toBe
(
'
~
\'
"test me"
\'
'
);
expect
(
getInputValue
()).
toBe
(
''
);
});
});
...
...
spec/
javascripts
/filtered_search/filtered_search_visual_tokens_spec.js
→
spec/
frontend
/filtered_search/filtered_search_visual_tokens_spec.js
View file @
7b973da3
import
axios
from
'
axios
'
;
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
FilteredSearchVisualTokens
from
'
~/filtered_search/filtered_search_visual_tokens
'
;
import
FilteredSearchSpecHelper
from
'
../helpers/filtered_search_spec_helper
'
;
describe
(
'
Filtered Search Visual Tokens
'
,
()
=>
{
let
mock
;
const
subject
=
FilteredSearchVisualTokens
;
const
findElements
=
tokenElement
=>
{
...
...
@@ -17,6 +20,9 @@ describe('Filtered Search Visual Tokens', () => {
let
bugLabelToken
;
beforeEach
(()
=>
{
mock
=
new
MockAdapter
(
axios
);
mock
.
onGet
().
reply
(
200
);
setFixtures
(
`
<ul class="tokens-container">
${
FilteredSearchSpecHelper
.
createInputHTML
()}
...
...
@@ -248,15 +254,15 @@ describe('Filtered Search Visual Tokens', () => {
});
it
(
'
contains name div
'
,
()
=>
{
expect
(
tokenElement
.
querySelector
(
'
.name
'
)).
toEqual
(
jasmine
.
anything
());
expect
(
tokenElement
.
querySelector
(
'
.name
'
)).
toEqual
(
expect
.
anything
());
});
it
(
'
contains value container div
'
,
()
=>
{
expect
(
tokenElement
.
querySelector
(
'
.value-container
'
)).
toEqual
(
jasmine
.
anything
());
expect
(
tokenElement
.
querySelector
(
'
.value-container
'
)).
toEqual
(
expect
.
anything
());
});
it
(
'
contains value div
'
,
()
=>
{
expect
(
tokenElement
.
querySelector
(
'
.value-container .value
'
)).
toEqual
(
jasmine
.
anything
());
expect
(
tokenElement
.
querySelector
(
'
.value-container .value
'
)).
toEqual
(
expect
.
anything
());
});
it
(
'
contains selectable class
'
,
()
=>
{
...
...
@@ -270,12 +276,12 @@ describe('Filtered Search Visual Tokens', () => {
describe
(
'
remove token
'
,
()
=>
{
it
(
'
contains remove-token button
'
,
()
=>
{
expect
(
tokenElement
.
querySelector
(
'
.value-container .remove-token
'
)).
toEqual
(
jasmine
.
anything
(),
expect
.
anything
(),
);
});
it
(
'
contains fa-close icon
'
,
()
=>
{
expect
(
tokenElement
.
querySelector
(
'
.remove-token .fa-close
'
)).
toEqual
(
jasmine
.
anything
());
expect
(
tokenElement
.
querySelector
(
'
.remove-token .fa-close
'
)).
toEqual
(
expect
.
anything
());
});
});
});
...
...
@@ -453,7 +459,7 @@ describe('Filtered Search Visual Tokens', () => {
valueContainer
.
dataset
.
originalValue
=
originalValue
;
const
avatar
=
document
.
createElement
(
'
img
'
);
const
valueElement
=
valueContainer
.
querySelector
(
'
.value
'
);
valueElement
.
insertAdjacentElement
(
'
afterbegin
'
,
avatar
);
valueElement
.
appendChild
(
avatar
);
tokensContainer
.
innerHTML
=
FilteredSearchSpecHelper
.
createTokensContainerHTML
(
authorToken
.
outerHTML
,
);
...
...
@@ -573,7 +579,7 @@ describe('Filtered Search Visual Tokens', () => {
it
(
"
tokenize's existing input
"
,
()
=>
{
input
.
value
=
'
some text
'
;
spyOn
(
subject
,
'
tokenizeInput
'
).
and
.
callThrough
(
);
jest
.
spyOn
(
subject
,
'
tokenizeInput
'
);
subject
.
editToken
(
token
);
...
...
@@ -635,8 +641,8 @@ describe('Filtered Search Visual Tokens', () => {
FilteredSearchSpecHelper
.
createFilterVisualTokenHTML
(
'
label
'
,
'
=
'
,
'
none
'
),
);
spyOn
(
subject
,
'
tokenizeInput
'
).
and
.
callFake
(()
=>
{});
spyOn
(
subject
,
'
getLastVisualTokenBeforeInput
'
).
and
.
callThrough
(
);
jest
.
spyOn
(
subject
,
'
tokenizeInput
'
).
mockImplementation
(()
=>
{});
jest
.
spyOn
(
subject
,
'
getLastVisualTokenBeforeInput
'
);
subject
.
moveInputToTheRight
();
...
...
@@ -711,12 +717,16 @@ describe('Filtered Search Visual Tokens', () => {
it
(
'
renders a author token value element
'
,
()
=>
{
const
{
tokenNameElement
,
tokenValueElement
}
=
findElements
(
authorToken
);
const
tokenName
=
tokenNameElement
.
innerTex
t
;
const
tokenName
=
tokenNameElement
.
textConten
t
;
const
tokenValue
=
'
new value
'
;
subject
.
renderVisualTokenValue
(
authorToken
,
tokenName
,
tokenValue
);
expect
(
tokenValueElement
.
innerText
).
toBe
(
tokenValue
);
jest
.
runOnlyPendingTimers
();
setImmediate
(()
=>
{
expect
(
tokenValueElement
.
textContent
).
toBe
(
tokenValue
);
});
});
});
});
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