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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
00db4cb7
Commit
00db4cb7
authored
Mar 05, 2018
by
Kushal Pandya
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
LabelsSelect DropdownValueCollapsed Component
parent
c1ed7f3f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
122 additions
and
0 deletions
+122
-0
app/assets/javascripts/vue_shared/components/sidebar/labels_select/dropdown_value_collapsed.vue
...onents/sidebar/labels_select/dropdown_value_collapsed.vue
+48
-0
spec/javascripts/vue_shared/components/sidebar/labels_select/dropdown_value_collapsed_spec.js
...ts/sidebar/labels_select/dropdown_value_collapsed_spec.js
+74
-0
No files found.
app/assets/javascripts/vue_shared/components/sidebar/labels_select/dropdown_value_collapsed.vue
0 → 100644
View file @
00db4cb7
<
script
>
import
{
s__
,
sprintf
}
from
'
~/locale
'
;
import
tooltip
from
'
~/vue_shared/directives/tooltip
'
;
export
default
{
directives
:
{
tooltip
,
},
props
:
{
labels
:
{
type
:
Array
,
required
:
true
,
},
},
computed
:
{
labelsList
()
{
const
labelsString
=
this
.
labels
.
slice
(
0
,
5
).
map
(
label
=>
label
.
title
).
join
(
'
,
'
);
if
(
this
.
labels
.
length
>
5
)
{
return
sprintf
(
s__
(
'
LabelSelect|%{labelsString}, and %{remainingLabelCount} more
'
),
{
labelsString
,
remainingLabelCount
:
this
.
labels
.
length
-
5
,
});
}
return
labelsString
;
},
},
};
</
script
>
<
template
>
<div
v-tooltip
class=
"sidebar-collapsed-icon"
data-placement=
"left"
data-container=
"body"
:title=
"labelsList"
>
<i
aria-hidden=
"true"
data-hidden=
"true"
class=
"fa fa-tags"
>
</i>
<span>
{{
labels
.
length
}}
</span>
</div>
</
template
>
spec/javascripts/vue_shared/components/sidebar/labels_select/dropdown_value_collapsed_spec.js
0 → 100644
View file @
00db4cb7
import
Vue
from
'
vue
'
;
import
dropdownValueCollapsedComponent
from
'
~/vue_shared/components/sidebar/labels_select/dropdown_value_collapsed.vue
'
;
import
{
mockLabels
}
from
'
./mock_data
'
;
import
mountComponent
from
'
../../../../helpers/vue_mount_component_helper
'
;
const
createComponent
=
(
labels
=
mockLabels
)
=>
{
const
Component
=
Vue
.
extend
(
dropdownValueCollapsedComponent
);
return
mountComponent
(
Component
,
{
labels
,
});
};
describe
(
'
DropdownValueCollapsedComponent
'
,
()
=>
{
let
vm
;
beforeEach
(()
=>
{
vm
=
createComponent
();
});
afterEach
(()
=>
{
vm
.
$destroy
();
});
describe
(
'
computed
'
,
()
=>
{
describe
(
'
labelsList
'
,
()
=>
{
it
(
'
returns empty text when `labels` prop is empty array
'
,
()
=>
{
const
vmEmptyLabels
=
createComponent
([]);
expect
(
vmEmptyLabels
.
labelsList
).
toBe
(
''
);
vmEmptyLabels
.
$destroy
();
});
it
(
'
returns labels names separated by coma when `labels` prop has more than one item
'
,
()
=>
{
const
vmMoreLabels
=
createComponent
(
mockLabels
.
concat
(
mockLabels
));
expect
(
vmMoreLabels
.
labelsList
).
toBe
(
'
Foo Label, Foo Label
'
);
vmMoreLabels
.
$destroy
();
});
it
(
'
returns labels names separated by coma with remaining labels count and `and more` phrase when `labels` prop has more than five items
'
,
()
=>
{
const
mockMoreLabels
=
Object
.
assign
([],
mockLabels
);
for
(
let
i
=
0
;
i
<
6
;
i
+=
1
)
{
mockMoreLabels
.
unshift
(
mockLabels
[
0
]);
}
const
vmMoreLabels
=
createComponent
(
mockMoreLabels
);
expect
(
vmMoreLabels
.
labelsList
).
toBe
(
'
Foo Label, Foo Label, Foo Label, Foo Label, Foo Label, and 2 more
'
);
vmMoreLabels
.
$destroy
();
});
it
(
'
returns first label name when `labels` prop has only one item present
'
,
()
=>
{
expect
(
vm
.
labelsList
).
toBe
(
'
Foo Label
'
);
});
});
});
describe
(
'
template
'
,
()
=>
{
it
(
'
renders component container element with tooltip`
'
,
()
=>
{
expect
(
vm
.
$el
.
dataset
.
placement
).
toBe
(
'
left
'
);
expect
(
vm
.
$el
.
dataset
.
container
).
toBe
(
'
body
'
);
expect
(
vm
.
$el
.
dataset
.
originalTitle
).
toBe
(
vm
.
labelsList
);
});
it
(
'
renders tags icon element
'
,
()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.fa-tags
'
)).
not
.
toBeNull
();
});
it
(
'
renders labels count
'
,
()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
span
'
).
innerText
.
trim
()).
toBe
(
`
${
vm
.
labels
.
length
}
`
);
});
});
});
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