UNCLASSIFIED
Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
Platform One
P
Party Bus
Launchboard
launchboard-fe
Commits
3d0c7841
Commit
3d0c7841
authored
May 03, 2021
by
graham.smith
Browse files
fix tests
parent
8f3e85f9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
7 deletions
+18
-7
tests/unit/views/TrainingDetails.spec.js
tests/unit/views/TrainingDetails.spec.js
+18
-7
No files found.
tests/unit/views/TrainingDetails.spec.js
View file @
3d0c7841
...
@@ -17,6 +17,7 @@ describe("TrainingDetails", () => {
...
@@ -17,6 +17,7 @@ describe("TrainingDetails", () => {
trainingId
:
42
,
trainingId
:
42
,
},
},
};
};
const
mockCourse
=
{
instructors
:
[]
};
const
propsData
=
{
const
propsData
=
{
trainingCourse
:
{
trainingCourse
:
{
id
:
1
,
id
:
1
,
...
@@ -29,6 +30,10 @@ describe("TrainingDetails", () => {
...
@@ -29,6 +30,10 @@ describe("TrainingDetails", () => {
jest
.
resetAllMocks
();
jest
.
resetAllMocks
();
});
});
it
(
"
should fetch debounced
"
,
async
()
=>
{
it
(
"
should fetch debounced
"
,
async
()
=>
{
TrainingService
.
getCourse
=
jest
.
fn
().
mockResolvedValue
(
mockCourse
);
TrainingService
.
getCourseRegistrationsById
=
jest
.
fn
()
.
mockResolvedValue
({});
TrainingDetails
.
fetchData
=
jest
.
fn
();
TrainingDetails
.
fetchData
=
jest
.
fn
();
const
wrapper
=
shallowMount
(
TrainingDetails
,
{
const
wrapper
=
shallowMount
(
TrainingDetails
,
{
mocks
:
{
mocks
:
{
...
@@ -51,10 +56,12 @@ describe("TrainingDetails", () => {
...
@@ -51,10 +56,12 @@ describe("TrainingDetails", () => {
vuetify
,
vuetify
,
});
});
expect
(
wrapper
.
vm
.
fetchingData
).
toBe
(
false
);
expect
(
wrapper
.
vm
.
fetchingData
).
toBe
(
false
);
await
flushPromises
();
wrapper
.
vm
.
fetchDebounced
();
wrapper
.
vm
.
fetchDebounced
();
expect
(
wrapper
.
vm
.
fetchingData
).
toBe
(
true
);
expect
(
wrapper
.
vm
.
fetchingData
).
toBe
(
true
);
});
});
it
(
"
should fetchStudent data
"
,
async
()
=>
{
it
(
"
should fetchStudent data
"
,
async
()
=>
{
TrainingService
.
getCourse
=
jest
.
fn
().
mockResolvedValue
(
mockCourse
);
TrainingService
.
getCourseRegistrationsById
=
jest
.
fn
().
mockResolvedValue
({
TrainingService
.
getCourseRegistrationsById
=
jest
.
fn
().
mockResolvedValue
({
meta
:
{
total
:
2
},
meta
:
{
total
:
2
},
registrations
:
[
registrations
:
[
...
@@ -68,7 +75,6 @@ describe("TrainingDetails", () => {
...
@@ -68,7 +75,6 @@ describe("TrainingDetails", () => {
{},
{},
],
],
});
});
TrainingDetails
.
courseDates
=
jest
.
fn
().
mockReturnValue
([]);
const
wrapper
=
shallowMount
(
TrainingDetails
,
{
const
wrapper
=
shallowMount
(
TrainingDetails
,
{
mocks
:
{
mocks
:
{
$route
,
$route
,
...
@@ -93,13 +99,13 @@ describe("TrainingDetails", () => {
...
@@ -93,13 +99,13 @@ describe("TrainingDetails", () => {
});
});
await
wrapper
.
vm
.
fetchStudentData
();
await
wrapper
.
vm
.
fetchStudentData
();
await
flushPromises
();
await
flushPromises
();
expect
(
TrainingService
.
getCourseRegistrationsById
).
toBeCalledTimes
(
1
);
expect
(
TrainingService
.
getCourseRegistrationsById
).
toBeCalledTimes
(
2
);
});
});
it
(
"
should fetchStudent data with an empty string
"
,
async
()
=>
{
it
(
"
should fetchStudent data with an empty string
"
,
async
()
=>
{
TrainingService
.
getCourseRegistrationsById
=
jest
TrainingService
.
getCourseRegistrationsById
=
jest
.
fn
()
.
fn
()
.
mockResolvedValue
({});
.
mockResolvedValue
({});
Training
Details
.
courseDates
=
jest
.
fn
().
mockReturnValue
([]
);
Training
Service
.
getCourse
=
jest
.
fn
().
mockResolvedValue
(
mockCourse
);
const
wrapper
=
shallowMount
(
TrainingDetails
,
{
const
wrapper
=
shallowMount
(
TrainingDetails
,
{
mocks
:
{
mocks
:
{
$route
,
$route
,
...
@@ -124,14 +130,14 @@ describe("TrainingDetails", () => {
...
@@ -124,14 +130,14 @@ describe("TrainingDetails", () => {
});
});
await
wrapper
.
vm
.
fetchStudentData
();
await
wrapper
.
vm
.
fetchStudentData
();
await
flushPromises
();
await
flushPromises
();
expect
(
TrainingService
.
getCourseRegistrationsById
).
toBeCalledTimes
(
1
);
expect
(
TrainingService
.
getCourseRegistrationsById
).
toBeCalledTimes
(
2
);
expect
(
wrapper
.
vm
.
listItems
).
toStrictEqual
([]);
expect
(
wrapper
.
vm
.
listItems
).
toStrictEqual
([]);
});
});
it
(
"
should throw error in fetchStudent
"
,
async
()
=>
{
it
(
"
should throw error in fetchStudent
"
,
async
()
=>
{
TrainingService
.
getCourse
=
jest
.
fn
().
mockResolvedValue
(
mockCourse
);
TrainingService
.
getCourseRegistrationsById
=
jest
TrainingService
.
getCourseRegistrationsById
=
jest
.
fn
()
.
fn
()
.
mockRejectedValue
(
"
mock error
"
);
.
mockRejectedValue
(
"
mock error
"
);
TrainingDetails
.
courseDates
=
jest
.
fn
().
mockReturnValue
([]);
const
wrapper
=
shallowMount
(
TrainingDetails
,
{
const
wrapper
=
shallowMount
(
TrainingDetails
,
{
mocks
:
{
mocks
:
{
$route
,
$route
,
...
@@ -154,6 +160,7 @@ describe("TrainingDetails", () => {
...
@@ -154,6 +160,7 @@ describe("TrainingDetails", () => {
localVue
,
localVue
,
vuetify
,
vuetify
,
});
});
await
wrapper
.
vm
.
fetchStudentData
();
await
wrapper
.
vm
.
fetchStudentData
();
await
flushPromises
();
await
flushPromises
();
expect
(
wrapper
.
vm
.
$store
.
commit
).
toHaveBeenCalledWith
(
expect
(
wrapper
.
vm
.
$store
.
commit
).
toHaveBeenCalledWith
(
...
@@ -166,6 +173,7 @@ describe("TrainingDetails", () => {
...
@@ -166,6 +173,7 @@ describe("TrainingDetails", () => {
);
);
});
});
it
(
"
should add student
"
,
async
()
=>
{
it
(
"
should add student
"
,
async
()
=>
{
TrainingService
.
getCourse
=
jest
.
fn
().
mockResolvedValue
(
mockCourse
);
TrainingService
.
getCourseRegistrationsById
=
jest
TrainingService
.
getCourseRegistrationsById
=
jest
.
fn
()
.
fn
()
.
mockResolvedValue
({
registrations
:
[]
});
.
mockResolvedValue
({
registrations
:
[]
});
...
@@ -196,6 +204,8 @@ describe("TrainingDetails", () => {
...
@@ -196,6 +204,8 @@ describe("TrainingDetails", () => {
expect
(
TrainingService
.
addStudents
).
toHaveBeenCalledTimes
(
1
);
expect
(
TrainingService
.
addStudents
).
toHaveBeenCalledTimes
(
1
);
});
});
it
(
"
addStudent should catch error
"
,
async
()
=>
{
it
(
"
addStudent should catch error
"
,
async
()
=>
{
console
.
error
=
jest
.
fn
();
// mock console.error when expecting error messages
TrainingService
.
getCourse
=
jest
.
fn
().
mockResolvedValue
(
mockCourse
);
TrainingService
.
addStudents
=
jest
.
fn
().
mockRejectedValue
(
"
error
"
);
TrainingService
.
addStudents
=
jest
.
fn
().
mockRejectedValue
(
"
error
"
);
const
wrapper
=
shallowMount
(
TrainingDetails
,
{
const
wrapper
=
shallowMount
(
TrainingDetails
,
{
mocks
:
{
mocks
:
{
...
@@ -218,6 +228,7 @@ describe("TrainingDetails", () => {
...
@@ -218,6 +228,7 @@ describe("TrainingDetails", () => {
);
);
});
});
it
(
"
should cancel add student
"
,
async
()
=>
{
it
(
"
should cancel add student
"
,
async
()
=>
{
TrainingService
.
getCourse
=
jest
.
fn
().
mockResolvedValue
(
mockCourse
);
TrainingService
.
getCourseRegistrationsById
=
jest
TrainingService
.
getCourseRegistrationsById
=
jest
.
fn
()
.
fn
()
.
mockResolvedValue
({
registrations
:
[]
});
.
mockResolvedValue
({
registrations
:
[]
});
...
@@ -248,7 +259,7 @@ describe("TrainingDetails", () => {
...
@@ -248,7 +259,7 @@ describe("TrainingDetails", () => {
});
});
it
(
"
should not show error by default
"
,
()
=>
{
it
(
"
should not show error by default
"
,
()
=>
{
TrainingService
.
getCourse
=
jest
.
fn
().
mockResolvedValue
(
{}
);
TrainingService
.
getCourse
=
jest
.
fn
().
mockResolvedValue
(
mockCourse
);
// render the component
// render the component
const
wrapper
=
shallowMount
(
TrainingDetails
,
{
const
wrapper
=
shallowMount
(
TrainingDetails
,
{
mocks
:
{
mocks
:
{
...
@@ -273,7 +284,7 @@ describe("TrainingDetails", () => {
...
@@ -273,7 +284,7 @@ describe("TrainingDetails", () => {
});
});
it
(
"
should set training course snapshot and isEditingCourse on btnPushEditPoc
"
,
()
=>
{
it
(
"
should set training course snapshot and isEditingCourse on btnPushEditPoc
"
,
()
=>
{
TrainingService
.
getCourse
=
jest
.
fn
().
mockResolvedValue
(
{}
);
TrainingService
.
getCourse
=
jest
.
fn
().
mockResolvedValue
(
mockCourse
);
// render the component
// render the component
const
wrapper
=
shallowMount
(
TrainingDetails
,
{
const
wrapper
=
shallowMount
(
TrainingDetails
,
{
mocks
:
{
mocks
:
{
...
...
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