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
e4f60986
Commit
e4f60986
authored
Jun 17, 2020
by
Ezekiel Kigbo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds specs for prepareTokens
Minor cleanup the prepareTokens method and adds additional specs
parent
a8f27410
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
20 deletions
+44
-20
ee/app/assets/javascripts/analytics/cycle_analytics/components/filter_bar.vue
...ripts/analytics/cycle_analytics/components/filter_bar.vue
+20
-19
ee/spec/frontend/analytics/cycle_analytics/components/filter_bar_spec.js
...d/analytics/cycle_analytics/components/filter_bar_spec.js
+24
-1
No files found.
ee/app/assets/javascripts/analytics/cycle_analytics/components/filter_bar.vue
View file @
e4f60986
...
...
@@ -6,27 +6,22 @@ import MilestoneToken from '../../shared/components/tokens/milestone_token.vue';
import
LabelToken
from
'
../../shared/components/tokens/label_token.vue
'
;
import
UserToken
from
'
../../shared/components/tokens/user_token.vue
'
;
const
prepareTokens
=
({
selectedMilestone
=
null
,
selectedAuthor
=
null
,
selectedAssignees
=
[],
selectedLabels
,
})
=>
{
const
authorToken
=
selectedAuthor
?
{
type
:
'
author
'
,
value
:
{
data
:
selectedAuthor
}
}
:
null
;
const
milestoneToken
=
selectedMilestone
?
{
type
:
'
milestone
'
,
value
:
{
data
:
selectedMilestone
}
}
:
null
;
const
assigneeTokens
=
selectedAssignees
.
length
?
selectedAssignees
.
map
(
data
=>
({
type
:
'
assignees
'
,
value
:
{
data
}
}))
export
const
prepareTokens
=
({
milestone
=
null
,
author
=
null
,
assignees
=
[],
labels
=
[],
}
=
{})
=>
{
const
authorToken
=
author
?
[{
type
:
'
author
'
,
value
:
{
data
:
author
}
}]
:
[];
const
milestoneToken
=
milestone
?
[{
type
:
'
milestone
'
,
value
:
{
data
:
milestone
}
}]
:
[];
const
assigneeTokens
=
assignees
?.
length
?
assignees
.
map
(
data
=>
({
type
:
'
assignees
'
,
value
:
{
data
}
}))
:
[];
const
labelTokens
=
selectedLabels
.
length
?
selectedL
abels
.
map
(
data
=>
({
type
:
'
labels
'
,
value
:
{
data
}
}))
const
labelTokens
=
labels
?
.
length
?
l
abels
.
map
(
data
=>
({
type
:
'
labels
'
,
value
:
{
data
}
}))
:
[];
let
initTokens
=
[...
assigneeTokens
,
...
labelTokens
];
if
(
authorToken
)
initTokens
=
[...
initTokens
,
authorToken
];
if
(
milestoneToken
)
initTokens
=
[...
initTokens
,
milestoneToken
];
return
initTokens
;
return
[...
authorToken
,
...
milestoneToken
,
...
assigneeTokens
,
...
labelTokens
];
};
export
default
{
...
...
@@ -111,7 +106,13 @@ export default {
methods
:
{
...
mapActions
(
'
filters
'
,
[
'
setFilters
'
]),
initializeTokens
()
{
const
preparedTokens
=
prepareTokens
(
this
.
initialTokens
);
const
{
selectedMilestone
:
milestone
=
null
,
selectedAuthor
:
author
=
null
,
selectedAssignees
:
assignees
=
[],
selectedLabels
:
labels
=
[],
}
=
this
.
initialTokens
;
const
preparedTokens
=
prepareTokens
({
milestone
,
author
,
assignees
,
labels
});
this
.
value
=
preparedTokens
;
},
processFilters
(
filters
)
{
...
...
ee/spec/frontend/analytics/cycle_analytics/components/filter_bar_spec.js
View file @
e4f60986
import
{
createLocalVue
,
shallowMount
}
from
'
@vue/test-utils
'
;
import
Vuex
from
'
vuex
'
;
import
{
GlFilteredSearch
}
from
'
@gitlab/ui
'
;
import
FilterBar
from
'
ee/analytics/cycle_analytics/components/filter_bar.vue
'
;
import
FilterBar
,
{
prepareTokens
}
from
'
ee/analytics/cycle_analytics/components/filter_bar.vue
'
;
import
initialFiltersState
from
'
ee/analytics/cycle_analytics/store/modules/filters/state
'
;
import
{
filterMilestones
,
filterLabels
}
from
'
../mock_data
'
;
...
...
@@ -176,4 +176,27 @@ describe('Filter bar', () => {
);
});
});
describe
(
'
prepareTokens
'
,
()
=>
{
describe
(
'
with empty data
'
,
()
=>
{
it
(
'
returns an empty array
'
,
()
=>
{
expect
(
prepareTokens
()).
toEqual
([]);
expect
(
prepareTokens
({})).
toEqual
([]);
expect
(
prepareTokens
({
milestone
:
null
,
author
:
null
,
assignees
:
[],
labels
:
[]
})).
toEqual
(
[],
);
});
});
it
.
each
`
token | value | result
${
'
milestone
'
}
|
${
'
v1.0
'
}
|
${[{
type
:
'
milestone
'
,
value
:
{
data
:
'
v1.0
'
}
}]}
$
{
'
author
'
}
|
${
'
mr.popo
'
}
|
${[{
type
:
'
author
'
,
value
:
{
data
:
'
mr.popo
'
}
}]}
$
{
'
labels
'
}
|
${[
'
z-fighters
'
]}
|
${[{
type
:
'
labels
'
,
value
:
{
data
:
'
z-fighters
'
}
}]}
$
{
'
assignees
'
}
|
${[
'
krillin
'
,
'
piccolo
'
]}
|
${[{
type
:
'
assignees
'
,
value
:
{
data
:
'
krillin
'
}
},
{
type
:
'
assignees
'
,
value
:
{
data
:
'
piccolo
'
}
}]}
`('with $token=$value sets the $token key', ({ token, value, result }) => {
const res = prepareTokens({ [token]: value });
expect(res).toEqual(result);
});
});
});
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