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
805e1aee
Commit
805e1aee
authored
Dec 18, 2019
by
Enrique Alcantara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate loading button spec to jest
parent
bc1e39fd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
96 additions
and
0 deletions
+96
-0
spec/frontend/vue_shared/components/loading_button_spec.js
spec/frontend/vue_shared/components/loading_button_spec.js
+96
-0
No files found.
spec/
javascripts
/vue_shared/components/loading_button_spec.js
→
spec/
frontend
/vue_shared/components/loading_button_spec.js
View file @
805e1aee
import
Vue
from
'
vue
'
;
import
mountComponent
from
'
spec/helpers/vue_mount_component_helper
'
;
import
loadingButton
from
'
~/vue_shared/components/loading_button.vue
'
;
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
LoadingButton
from
'
~/vue_shared/components/loading_button.vue
'
;
const
LABEL
=
'
Hello
'
;
describe
(
'
LoadingButton
'
,
function
()
{
let
vm
;
let
LoadingButton
;
beforeEach
(()
=>
{
LoadingButton
=
Vue
.
extend
(
loadingButton
);
});
describe
(
'
LoadingButton
'
,
()
=>
{
let
wrapper
;
afterEach
(()
=>
{
vm
.
$
destroy
();
wrapper
.
destroy
();
});
const
buildWrapper
=
(
propsData
=
{})
=>
{
wrapper
=
shallowMount
(
LoadingButton
,
{
propsData
,
});
};
const
findButtonLabel
=
()
=>
wrapper
.
find
(
'
.js-loading-button-label
'
);
const
findButtonIcon
=
()
=>
wrapper
.
find
(
'
.js-loading-button-icon
'
);
describe
(
'
loading spinner
'
,
()
=>
{
it
(
'
shown when loading
'
,
()
=>
{
vm
=
mountComponent
(
LoadingButton
,
{
loading
:
true
,
});
buildWrapper
({
loading
:
true
});
expect
(
vm
.
$el
.
querySelector
(
'
.js-loading-button-icon
'
)).
toBeDefined
(
);
expect
(
findButtonIcon
().
exists
()).
toBe
(
true
);
});
});
describe
(
'
disabled state
'
,
()
=>
{
it
(
'
disabled when loading
'
,
()
=>
{
vm
=
mountComponent
(
LoadingButton
,
{
loading
:
true
,
});
expect
(
vm
.
$el
.
disabled
).
toEqual
(
true
);
buildWrapper
({
loading
:
true
});
expect
(
wrapper
.
attributes
(
'
disabled
'
)).
toBe
(
'
disabled
'
);
});
it
(
'
not disabled when normal
'
,
()
=>
{
vm
=
mountComponent
(
LoadingButton
,
{
loading
:
false
,
});
buildWrapper
({
loading
:
false
});
expect
(
vm
.
$el
.
disabled
).
toEqual
(
false
);
expect
(
wrapper
.
attributes
(
'
disabled
'
)).
toBe
(
undefined
);
});
});
describe
(
'
label
'
,
()
=>
{
it
(
'
shown when normal
'
,
()
=>
{
vm
=
mountComponent
(
LoadingButton
,
{
loading
:
false
,
label
:
LABEL
,
});
const
label
=
vm
.
$el
.
querySelector
(
'
.js-loading-button-label
'
);
expect
(
label
.
textContent
.
trim
()).
toEqual
(
LABEL
);
buildWrapper
({
loading
:
false
,
label
:
LABEL
});
expect
(
findButtonLabel
().
text
()).
toBe
(
LABEL
);
});
it
(
'
shown when loading
'
,
()
=>
{
vm
=
mountComponent
(
LoadingButton
,
{
loading
:
true
,
label
:
LABEL
,
});
const
label
=
vm
.
$el
.
querySelector
(
'
.js-loading-button-label
'
);
expect
(
label
.
textContent
.
trim
()).
toEqual
(
LABEL
);
buildWrapper
({
loading
:
false
,
label
:
LABEL
});
expect
(
findButtonLabel
().
text
()).
toBe
(
LABEL
);
});
});
describe
(
'
container class
'
,
()
=>
{
it
(
'
should default to btn btn-align-content
'
,
()
=>
{
vm
=
mountComponent
(
LoadingButton
,
{}
);
buildWrapper
(
);
expect
(
vm
.
$el
.
classList
.
contains
(
'
btn
'
)).
toEqual
(
true
);
expect
(
vm
.
$el
.
classList
.
contains
(
'
btn-align-content
'
)).
toEqual
(
true
);
expect
(
wrapper
.
classes
()).
toContain
(
'
btn
'
);
expect
(
wrapper
.
classes
()).
toContain
(
'
btn-align-content
'
);
});
it
(
'
should be configurable through props
'
,
()
=>
{
vm
=
mountComponent
(
LoadingButton
,
{
containerClass
:
'
test-class
'
,
const
containerClass
=
'
test-class
'
;
buildWrapper
({
containerClass
,
});
expect
(
vm
.
$el
.
classList
.
contains
(
'
btn
'
)).
toEqual
(
false
);
expect
(
vm
.
$el
.
classList
.
contains
(
'
btn-align-content
'
)).
toEqual
(
false
);
expect
(
vm
.
$el
.
classList
.
contains
(
'
test-class
'
)).
toEqual
(
true
);
expect
(
wrapper
.
classes
()).
not
.
toContain
(
'
btn
'
);
expect
(
wrapper
.
classes
()).
not
.
toContain
(
'
btn-align-content
'
);
expect
(
wrapper
.
classes
()).
toContain
(
containerClass
);
});
});
describe
(
'
click callback prop
'
,
()
=>
{
it
(
'
calls given callback when normal
'
,
()
=>
{
vm
=
mountComponent
(
LoadingButton
,
{
buildWrapper
(
{
loading
:
false
,
});
spyOn
(
vm
,
'
$emit
'
);
vm
.
$el
.
click
(
);
wrapper
.
trigger
(
'
click
'
);
expect
(
vm
.
$emit
).
toHaveBeenCalledWith
(
'
click
'
,
jasmine
.
any
(
Object
)
);
expect
(
wrapper
.
emitted
(
'
click
'
)).
toBeTruthy
(
);
});
it
(
'
does not call given callback when disabled because of loading
'
,
()
=>
{
vm
=
mountComponent
(
LoadingButton
,
{
buildWrapper
(
{
loading
:
true
,
});
spyOn
(
vm
,
'
$emit
'
);
vm
.
$el
.
click
(
);
wrapper
.
trigger
(
'
click
'
);
expect
(
vm
.
$emit
).
not
.
toHaveBeenCalled
();
expect
(
wrapper
.
emitted
(
'
click
'
)).
toBeFalsy
();
});
});
});
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