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
6ebc082e
Commit
6ebc082e
authored
Feb 10, 2021
by
Jose Vargas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor delayed_job_mixin_spec to use shallowMount
parent
0dbe4c2d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
52 deletions
+46
-52
spec/frontend/jobs/mixins/delayed_job_mixin_spec.js
spec/frontend/jobs/mixins/delayed_job_mixin_spec.js
+46
-52
No files found.
spec/frontend/jobs/mixins/delayed_job_mixin_spec.js
View file @
6ebc082e
import
Vue
from
'
vue
'
;
import
mountComponent
from
'
helpers/vue_mount_component_helper
'
;
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
delayedJobMixin
from
'
~/jobs/mixins/delayed_job_mixin
'
;
describe
(
'
DelayedJobMixin
'
,
()
=>
{
let
wrapper
;
const
delayedJobFixture
=
getJSONFixture
(
'
jobs/delayed.json
'
);
const
dummyComponent
=
Vue
.
extend
({
mixins
:
[
delayedJobMixin
],
const
dummyComponent
=
{
props
:
{
job
:
{
type
:
Object
,
required
:
true
,
},
},
render
(
createElement
)
{
return
createElement
(
'
div
'
,
this
.
remainingTime
);
},
});
let
vm
;
mixins
:
[
delayedJobMixin
],
template
:
'
<div>{{remainingTime}}</div>
'
,
};
afterEach
(()
=>
{
vm
.
$
destroy
();
jest
.
clearAllTimers
()
;
wrapper
.
destroy
();
wrapper
=
null
;
});
describe
(
'
if job is empty object
'
,
()
=>
{
beforeEach
(()
=>
{
vm
=
mountComponent
(
dummyComponent
,
{
job
:
{},
wrapper
=
shallowMount
(
dummyComponent
,
{
propsData
:
{
job
:
{},
},
});
});
it
(
'
sets remaining time to 00:00:00
'
,
()
=>
{
expect
(
vm
.
$el
.
innerText
).
toBe
(
'
00:00:00
'
);
expect
(
wrapper
.
text
()
).
toBe
(
'
00:00:00
'
);
});
describe
(
'
after mounting
'
,
()
=>
{
beforeEach
(()
=>
vm
.
$nextTick
()
);
it
(
'
does not update remaining time after mounting
'
,
async
()
=>
{
await
wrapper
.
vm
.
$nextTick
(
);
it
(
'
does not update remaining time
'
,
()
=>
{
expect
(
vm
.
$el
.
innerText
).
toBe
(
'
00:00:00
'
);
});
expect
(
wrapper
.
text
()).
toBe
(
'
00:00:00
'
);
});
});
...
...
@@ -48,33 +44,32 @@ describe('DelayedJobMixin', () => {
describe
(
'
if job is delayed job
'
,
()
=>
{
let
remainingTimeInMilliseconds
=
42000
;
beforeEach
(()
=>
{
beforeEach
(
async
()
=>
{
jest
.
spyOn
(
Date
,
'
now
'
)
.
mockImplementation
(
()
=>
new
Date
(
delayedJobFixture
.
scheduled_at
).
getTime
()
-
remainingTimeInMilliseconds
,
);
vm
=
mountComponent
(
dummyComponent
,
{
job
:
delayedJobFixture
,
wrapper
=
shallowMount
(
dummyComponent
,
{
propsData
:
{
job
:
delayedJobFixture
,
},
});
});
describe
(
'
after mounting
'
,
()
=>
{
beforeEach
(()
=>
vm
.
$nextTick
()
);
await
wrapper
.
vm
.
$nextTick
();
}
);
it
(
'
sets remaining time
'
,
()
=>
{
expect
(
vm
.
$el
.
innerText
).
toBe
(
'
00:00:42
'
);
});
it
(
'
sets remaining time
'
,
()
=>
{
expect
(
wrapper
.
text
()
).
toBe
(
'
00:00:42
'
);
});
it
(
'
updates remaining time
'
,
()
=>
{
remainingTimeInMilliseconds
=
41000
;
jest
.
advanceTimersByTime
(
1000
);
it
(
'
updates remaining time
'
,
async
()
=>
{
remainingTimeInMilliseconds
=
41000
;
jest
.
advanceTimersByTime
(
1000
);
return
vm
.
$nextTick
().
then
(()
=>
{
expect
(
vm
.
$el
.
innerText
).
toBe
(
'
00:00:41
'
);
});
});
await
wrapper
.
vm
.
$nextTick
();
expect
(
wrapper
.
text
()).
toBe
(
'
00:00:41
'
);
});
});
});
...
...
@@ -96,33 +91,32 @@ describe('DelayedJobMixin', () => {
describe
(
'
if job is delayed job
'
,
()
=>
{
let
remainingTimeInMilliseconds
=
42000
;
beforeEach
(()
=>
{
beforeEach
(
async
()
=>
{
jest
.
spyOn
(
Date
,
'
now
'
)
.
mockImplementation
(
()
=>
mockGraphQlJob
.
scheduledAt
.
getTime
()
-
remainingTimeInMilliseconds
,
);
vm
=
mountComponent
(
dummyComponent
,
{
job
:
mockGraphQlJob
,
wrapper
=
shallowMount
(
dummyComponent
,
{
propsData
:
{
job
:
mockGraphQlJob
,
},
});
});
describe
(
'
after mounting
'
,
()
=>
{
beforeEach
(()
=>
vm
.
$nextTick
()
);
await
wrapper
.
vm
.
$nextTick
();
}
);
it
(
'
sets remaining time
'
,
()
=>
{
expect
(
vm
.
$el
.
innerText
).
toBe
(
'
00:00:42
'
);
});
it
(
'
sets remaining time
'
,
()
=>
{
expect
(
wrapper
.
text
()
).
toBe
(
'
00:00:42
'
);
});
it
(
'
updates remaining time
'
,
()
=>
{
remainingTimeInMilliseconds
=
41000
;
jest
.
advanceTimersByTime
(
1000
);
it
(
'
updates remaining time
'
,
async
()
=>
{
remainingTimeInMilliseconds
=
41000
;
jest
.
advanceTimersByTime
(
1000
);
return
vm
.
$nextTick
().
then
(()
=>
{
expect
(
vm
.
$el
.
innerText
).
toBe
(
'
00:00:41
'
);
});
});
await
wrapper
.
vm
.
$nextTick
();
expect
(
wrapper
.
text
()).
toBe
(
'
00:00:41
'
);
});
});
});
...
...
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