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
37cfca2c
Commit
37cfca2c
authored
May 08, 2018
by
Dennis Tang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tests for resuable dropdown components
parent
aa7e55f2
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
169 additions
and
0 deletions
+169
-0
spec/javascripts/vue_shared/components/dropdown/dropdown_button_spec.js
...ts/vue_shared/components/dropdown/dropdown_button_spec.js
+69
-0
spec/javascripts/vue_shared/components/dropdown/dropdown_hidden_input_spec.js
..._shared/components/dropdown/dropdown_hidden_input_spec.js
+37
-0
spec/javascripts/vue_shared/components/dropdown/dropdown_search_input_spec.js
..._shared/components/dropdown/dropdown_search_input_spec.js
+52
-0
spec/javascripts/vue_shared/components/dropdown/mock_data.js
spec/javascripts/vue_shared/components/dropdown/mock_data.js
+11
-0
No files found.
spec/javascripts/vue_shared/components/dropdown/dropdown_button_spec.js
0 → 100644
View file @
37cfca2c
import
Vue
from
'
vue
'
;
import
dropdownButtonComponent
from
'
~/vue_shared/components/dropdown/dropdown_button.vue
'
;
import
mountComponent
from
'
spec/helpers/vue_mount_component_helper
'
;
const
defaultLabel
=
'
Select
'
;
const
customLabel
=
'
Select project
'
;
const
createComponent
=
config
=>
{
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 default toggle text
'
,
()
=>
{
expect
(
vm
.
toggleText
).
toBe
(
defaultLabel
);
});
it
(
'
returns custom toggle text when provided via props
'
,
()
=>
{
const
vmEmptyLabels
=
createComponent
({
toggleText
:
customLabel
});
expect
(
vmEmptyLabels
.
toggleText
).
toBe
(
customLabel
);
vmEmptyLabels
.
$destroy
();
});
});
});
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
(
defaultLabel
);
});
it
(
'
renders dropdown button icon
'
,
()
=>
{
const
dropdownIconEl
=
vm
.
$el
.
querySelector
(
'
.dropdown-toggle-icon i.fa
'
);
expect
(
dropdownIconEl
).
not
.
toBeNull
();
expect
(
dropdownIconEl
.
classList
.
contains
(
'
fa-chevron-down
'
)).
toBe
(
true
);
});
});
});
spec/javascripts/vue_shared/components/dropdown/dropdown_hidden_input_spec.js
0 → 100644
View file @
37cfca2c
import
Vue
from
'
vue
'
;
import
dropdownHiddenInputComponent
from
'
~/vue_shared/components/dropdown/dropdown_hidden_input.vue
'
;
import
mountComponent
from
'
spec/helpers/vue_mount_component_helper
'
;
import
{
mockLabels
}
from
'
./mock_data
'
;
const
createComponent
=
(
name
=
'
label_id[]
'
,
value
=
mockLabels
[
0
].
id
)
=>
{
const
Component
=
Vue
.
extend
(
dropdownHiddenInputComponent
);
return
mountComponent
(
Component
,
{
name
,
value
,
});
};
describe
(
'
DropdownHiddenInputComponent
'
,
()
=>
{
let
vm
;
beforeEach
(()
=>
{
vm
=
createComponent
();
});
afterEach
(()
=>
{
vm
.
$destroy
();
});
describe
(
'
template
'
,
()
=>
{
it
(
'
renders input element of type `hidden`
'
,
()
=>
{
expect
(
vm
.
$el
.
nodeName
).
toBe
(
'
INPUT
'
);
expect
(
vm
.
$el
.
getAttribute
(
'
type
'
)).
toBe
(
'
hidden
'
);
expect
(
vm
.
$el
.
getAttribute
(
'
name
'
)).
toBe
(
vm
.
name
);
expect
(
vm
.
$el
.
getAttribute
(
'
value
'
)).
toBe
(
`
${
vm
.
value
}
`
);
});
});
});
spec/javascripts/vue_shared/components/dropdown/dropdown_search_input_spec.js
0 → 100644
View file @
37cfca2c
import
Vue
from
'
vue
'
;
import
dropdownSearchInputComponent
from
'
~/vue_shared/components/dropdown/dropdown_search_input.vue
'
;
import
mountComponent
from
'
spec/helpers/vue_mount_component_helper
'
;
const
componentConfig
=
{
placeholderText
:
'
Search something
'
,
};
const
createComponent
=
(
config
=
componentConfig
)
=>
{
const
Component
=
Vue
.
extend
(
dropdownSearchInputComponent
);
return
mountComponent
(
Component
,
config
);
};
describe
(
'
DropdownSearchInputComponent
'
,
()
=>
{
let
vm
;
beforeEach
(()
=>
{
vm
=
createComponent
();
});
afterEach
(()
=>
{
vm
.
$destroy
();
});
describe
(
'
template
'
,
()
=>
{
it
(
'
renders input element with type `search`
'
,
()
=>
{
const
inputEl
=
vm
.
$el
.
querySelector
(
'
input.dropdown-input-field
'
);
expect
(
inputEl
).
not
.
toBeNull
();
expect
(
inputEl
.
getAttribute
(
'
type
'
)).
toBe
(
'
search
'
);
});
it
(
'
renders search icon element
'
,
()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.fa-search.dropdown-input-search
'
)).
not
.
toBeNull
();
});
it
(
'
renders clear search icon element
'
,
()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.fa-times.dropdown-input-clear.js-dropdown-input-clear
'
),
).
not
.
toBeNull
();
});
it
(
'
displays custom placeholder text
'
,
()
=>
{
const
inputEl
=
vm
.
$el
.
querySelector
(
'
input.dropdown-input-field
'
);
expect
(
inputEl
.
getAttribute
(
'
placeholder
'
)).
toBe
(
componentConfig
.
placeholderText
);
});
});
});
spec/javascripts/vue_shared/components/dropdown/mock_data.js
0 → 100644
View file @
37cfca2c
export
const
mockLabels
=
[
{
id
:
26
,
title
:
'
Foo Label
'
,
description
:
'
Foobar
'
,
color
:
'
#BADA55
'
,
text_color
:
'
#FFFFFF
'
,
},
];
export
default
mockLabels
;
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