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
5c885486
Commit
5c885486
authored
Mar 05, 2018
by
Kushal Pandya
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
LabelsSelect DropdownButton Component
parent
7d58f0e0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
160 additions
and
0 deletions
+160
-0
app/assets/javascripts/vue_shared/components/sidebar/labels_select/dropdown_button.vue
...ared/components/sidebar/labels_select/dropdown_button.vue
+78
-0
spec/javascripts/vue_shared/components/sidebar/labels_select/dropdown_button_spec.js
.../components/sidebar/labels_select/dropdown_button_spec.js
+82
-0
No files found.
app/assets/javascripts/vue_shared/components/sidebar/labels_select/dropdown_button.vue
0 → 100644
View file @
5c885486
<
script
>
import
{
__
,
s__
,
sprintf
}
from
'
~/locale
'
;
export
default
{
props
:
{
abilityName
:
{
type
:
String
,
required
:
true
,
},
fieldName
:
{
type
:
String
,
required
:
true
,
},
updatePath
:
{
type
:
String
,
required
:
true
,
},
labelsPath
:
{
type
:
String
,
required
:
true
,
},
namespace
:
{
type
:
String
,
required
:
true
,
},
labels
:
{
type
:
Array
,
required
:
true
,
},
showExtraOptions
:
{
type
:
Boolean
,
required
:
true
,
},
},
computed
:
{
dropdownToggleText
()
{
if
(
this
.
labels
.
length
===
0
)
{
return
__
(
'
Label
'
);
}
if
(
this
.
labels
.
length
>
1
)
{
return
sprintf
(
s__
(
'
LabelSelect|%{firstLabelName} +%{remainingLabelCount} more
'
),
{
firstLabelName
:
this
.
labels
[
0
].
title
,
remainingLabelCount
:
this
.
labels
.
length
-
1
,
});
}
return
this
.
labels
[
0
].
title
;
},
},
};
</
script
>
<
template
>
<button
type=
"button"
ref=
"dropdownButton"
class=
"dropdown-menu-toggle wide js-label-select js-multiselect js-context-config-modal"
data-toggle=
"dropdown"
:class=
"
{ 'js-extra-options': showExtraOptions }"
:data-ability-name="abilityName"
:data-field-name="fieldName"
:data-issue-update="updatePath"
:data-labels="labelsPath"
:data-namespace-path="namespace"
:data-show-any="showExtraOptions"
>
<span
class=
"dropdown-toggle-text"
>
{{
dropdownToggleText
}}
</span>
<i
aria-hidden=
"true"
class=
"fa fa-chevron-down"
data-hidden=
"true"
>
</i>
</button>
</
template
>
spec/javascripts/vue_shared/components/sidebar/labels_select/dropdown_button_spec.js
0 → 100644
View file @
5c885486
import
Vue
from
'
vue
'
;
import
dropdownButtonComponent
from
'
~/vue_shared/components/sidebar/labels_select/dropdown_button.vue
'
;
import
{
mockConfig
,
mockLabels
}
from
'
./mock_data
'
;
import
mountComponent
from
'
../../../../helpers/vue_mount_component_helper
'
;
const
componentConfig
=
Object
.
assign
({},
mockConfig
,
{
fieldName
:
'
label_id[]
'
,
labels
:
mockLabels
,
showExtraOptions
:
false
,
});
const
createComponent
=
(
config
=
componentConfig
)
=>
{
const
Component
=
Vue
.
extend
(
dropdownButtonComponent
);
return
mountComponent
(
Component
,
config
);
};
describe
(
'
DropdownButtonComponent
'
,
()
=>
{
let
vm
;
beforeEach
(()
=>
{
vm
=
createComponent
();
});
afterEach
(()
=>
{
vm
.
$destroy
();
});
describe
(
'
computed
'
,
()
=>
{
describe
(
'
dropdownToggleText
'
,
()
=>
{
it
(
'
returns text as `Label` when `labels` prop is empty array
'
,
()
=>
{
const
mockEmptyLabels
=
Object
.
assign
({},
componentConfig
,
{
labels
:
[]
});
const
vmEmptyLabels
=
createComponent
(
mockEmptyLabels
);
expect
(
vmEmptyLabels
.
dropdownToggleText
).
toBe
(
'
Label
'
);
vmEmptyLabels
.
$destroy
();
});
it
(
'
returns first label name with remaining label count when `labels` prop has more than one item
'
,
()
=>
{
const
mockMoreLabels
=
Object
.
assign
({},
componentConfig
,
{
labels
:
mockLabels
.
concat
(
mockLabels
),
});
const
vmMoreLabels
=
createComponent
(
mockMoreLabels
);
expect
(
vmMoreLabels
.
dropdownToggleText
).
toBe
(
'
Foo Label +1 more
'
);
vmMoreLabels
.
$destroy
();
});
it
(
'
returns first label name when `labels` prop has only one item present
'
,
()
=>
{
expect
(
vm
.
dropdownToggleText
).
toBe
(
'
Foo Label
'
);
});
});
});
describe
(
'
template
'
,
()
=>
{
it
(
'
renders component container element of type `button`
'
,
()
=>
{
expect
(
vm
.
$el
.
nodeName
).
toBe
(
'
BUTTON
'
);
});
it
(
'
renders component container element with required data attributes
'
,
()
=>
{
expect
(
vm
.
$el
.
dataset
.
abilityName
).
toBe
(
vm
.
abilityName
);
expect
(
vm
.
$el
.
dataset
.
fieldName
).
toBe
(
vm
.
fieldName
);
expect
(
vm
.
$el
.
dataset
.
issueUpdate
).
toBe
(
vm
.
updatePath
);
expect
(
vm
.
$el
.
dataset
.
labels
).
toBe
(
vm
.
labelsPath
);
expect
(
vm
.
$el
.
dataset
.
namespacePath
).
toBe
(
vm
.
namespace
);
expect
(
vm
.
$el
.
dataset
.
showAny
).
not
.
toBeDefined
();
});
it
(
'
renders dropdown toggle text element
'
,
()
=>
{
const
dropdownToggleTextEl
=
vm
.
$el
.
querySelector
(
'
.dropdown-toggle-text
'
);
expect
(
dropdownToggleTextEl
).
not
.
toBeNull
();
expect
(
dropdownToggleTextEl
.
innerText
.
trim
()).
toBe
(
'
Foo Label
'
);
});
it
(
'
renders dropdown button icon
'
,
()
=>
{
const
dropdownIconEl
=
vm
.
$el
.
querySelector
(
'
i.fa
'
);
expect
(
dropdownIconEl
).
not
.
toBeNull
();
expect
(
dropdownIconEl
.
classList
.
contains
(
'
fa-chevron-down
'
)).
toBe
(
true
);
});
});
});
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