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
Show 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
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
mountComponent
from
'
spec/helpers/vue_mount_component_helper
'
;
import
LoadingButton
from
'
~/vue_shared/components/loading_button.vue
'
;
import
loadingButton
from
'
~/vue_shared/components/loading_button.vue
'
;
const
LABEL
=
'
Hello
'
;
const
LABEL
=
'
Hello
'
;
describe
(
'
LoadingButton
'
,
function
()
{
describe
(
'
LoadingButton
'
,
()
=>
{
let
vm
;
let
wrapper
;
let
LoadingButton
;
before
Each
(()
=>
{
after
Each
(()
=>
{
LoadingButton
=
Vue
.
extend
(
loadingButton
);
wrapper
.
destroy
(
);
});
});
afterEach
(()
=>
{
const
buildWrapper
=
(
propsData
=
{})
=>
{
vm
.
$destroy
();
wrapper
=
shallowMount
(
LoadingButton
,
{
propsData
,
});
});
};
const
findButtonLabel
=
()
=>
wrapper
.
find
(
'
.js-loading-button-label
'
);
const
findButtonIcon
=
()
=>
wrapper
.
find
(
'
.js-loading-button-icon
'
);
describe
(
'
loading spinner
'
,
()
=>
{
describe
(
'
loading spinner
'
,
()
=>
{
it
(
'
shown when loading
'
,
()
=>
{
it
(
'
shown when loading
'
,
()
=>
{
vm
=
mountComponent
(
LoadingButton
,
{
buildWrapper
({
loading
:
true
});
loading
:
true
,
});
expect
(
vm
.
$el
.
querySelector
(
'
.js-loading-button-icon
'
)).
toBeDefined
(
);
expect
(
findButtonIcon
().
exists
()).
toBe
(
true
);
});
});
});
});
describe
(
'
disabled state
'
,
()
=>
{
describe
(
'
disabled state
'
,
()
=>
{
it
(
'
disabled when loading
'
,
()
=>
{
it
(
'
disabled when loading
'
,
()
=>
{
vm
=
mountComponent
(
LoadingButton
,
{
buildWrapper
({
loading
:
true
});
loading
:
true
,
expect
(
wrapper
.
attributes
(
'
disabled
'
)).
toBe
(
'
disabled
'
);
});
expect
(
vm
.
$el
.
disabled
).
toEqual
(
true
);
});
});
it
(
'
not disabled when normal
'
,
()
=>
{
it
(
'
not disabled when normal
'
,
()
=>
{
vm
=
mountComponent
(
LoadingButton
,
{
buildWrapper
({
loading
:
false
});
loading
:
false
,
});
expect
(
vm
.
$el
.
disabled
).
toEqual
(
false
);
expect
(
wrapper
.
attributes
(
'
disabled
'
)).
toBe
(
undefined
);
});
});
});
});
describe
(
'
label
'
,
()
=>
{
describe
(
'
label
'
,
()
=>
{
it
(
'
shown when normal
'
,
()
=>
{
it
(
'
shown when normal
'
,
()
=>
{
vm
=
mountComponent
(
LoadingButton
,
{
buildWrapper
({
loading
:
false
,
label
:
LABEL
});
loading
:
false
,
expect
(
findButtonLabel
().
text
()).
toBe
(
LABEL
);
label
:
LABEL
,
});
const
label
=
vm
.
$el
.
querySelector
(
'
.js-loading-button-label
'
);
expect
(
label
.
textContent
.
trim
()).
toEqual
(
LABEL
);
});
});
it
(
'
shown when loading
'
,
()
=>
{
it
(
'
shown when loading
'
,
()
=>
{
vm
=
mountComponent
(
LoadingButton
,
{
buildWrapper
({
loading
:
false
,
label
:
LABEL
});
loading
:
true
,
expect
(
findButtonLabel
().
text
()).
toBe
(
LABEL
);
label
:
LABEL
,
});
const
label
=
vm
.
$el
.
querySelector
(
'
.js-loading-button-label
'
);
expect
(
label
.
textContent
.
trim
()).
toEqual
(
LABEL
);
});
});
});
});
describe
(
'
container class
'
,
()
=>
{
describe
(
'
container class
'
,
()
=>
{
it
(
'
should default to btn btn-align-content
'
,
()
=>
{
it
(
'
should default to btn btn-align-content
'
,
()
=>
{
vm
=
mountComponent
(
LoadingButton
,
{}
);
buildWrapper
(
);
expect
(
vm
.
$el
.
classList
.
contains
(
'
btn
'
)).
toEqual
(
true
);
expect
(
wrapper
.
classes
()).
toContain
(
'
btn
'
);
expect
(
vm
.
$el
.
classList
.
contains
(
'
btn-align-content
'
)).
toEqual
(
true
);
expect
(
wrapper
.
classes
()).
toContain
(
'
btn-align-content
'
);
});
});
it
(
'
should be configurable through props
'
,
()
=>
{
it
(
'
should be configurable through props
'
,
()
=>
{
vm
=
mountComponent
(
LoadingButton
,
{
const
containerClass
=
'
test-class
'
;
containerClass
:
'
test-class
'
,
buildWrapper
({
containerClass
,
});
});
expect
(
vm
.
$el
.
classList
.
contains
(
'
btn
'
)).
toEqual
(
false
);
expect
(
wrapper
.
classes
()).
not
.
toContain
(
'
btn
'
);
expect
(
vm
.
$el
.
classList
.
contains
(
'
btn-align-content
'
)).
toEqual
(
false
);
expect
(
wrapper
.
classes
()).
not
.
toContain
(
'
btn-align-content
'
);
expect
(
vm
.
$el
.
classList
.
contains
(
'
test-class
'
)).
toEqual
(
true
);
expect
(
wrapper
.
classes
()).
toContain
(
containerClass
);
});
});
});
});
describe
(
'
click callback prop
'
,
()
=>
{
describe
(
'
click callback prop
'
,
()
=>
{
it
(
'
calls given callback when normal
'
,
()
=>
{
it
(
'
calls given callback when normal
'
,
()
=>
{
vm
=
mountComponent
(
LoadingButton
,
{
buildWrapper
(
{
loading
:
false
,
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
'
,
()
=>
{
it
(
'
does not call given callback when disabled because of loading
'
,
()
=>
{
vm
=
mountComponent
(
LoadingButton
,
{
buildWrapper
(
{
loading
:
true
,
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