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
af0e2b21
Commit
af0e2b21
authored
May 03, 2021
by
graham.smith
Committed by
luke.glasscock
May 03, 2021
Browse files
LB-201 test tweaks
parent
e462e481
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
11 deletions
+19
-11
tests/unit/components/Training/TrainingAttendance.spec.js
tests/unit/components/Training/TrainingAttendance.spec.js
+1
-4
tests/unit/views/TrainingDetails.spec.js
tests/unit/views/TrainingDetails.spec.js
+18
-7
No files found.
tests/unit/components/Training/TrainingAttendance.spec.js
View file @
af0e2b21
...
@@ -548,10 +548,7 @@ describe("TrainingAttendance", () => {
...
@@ -548,10 +548,7 @@ describe("TrainingAttendance", () => {
wrapper
.
vm
.
fetchDebounced
=
jest
.
fn
();
wrapper
.
vm
.
fetchDebounced
=
jest
.
fn
();
// trigger the watch for wrapper.vm.options
// trigger the watch for wrapper.vm.options
const
mockOptions
=
2
;
await
wrapper
.
setProps
({
reload
:
1
});
wrapper
.
vm
.
reload
=
mockOptions
;
await
wrapper
.
vm
.
$nextTick
();
expect
(
wrapper
.
vm
.
fetchDebounced
).
toHaveBeenCalledTimes
(
1
);
expect
(
wrapper
.
vm
.
fetchDebounced
).
toHaveBeenCalledTimes
(
1
);
});
});
...
...
tests/unit/views/TrainingDetails.spec.js
View file @
af0e2b21
...
@@ -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