Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Spring2021-SellPoint
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TDT4140-Group 58
Spring2021-SellPoint
Commits
217f0882
Commit
217f0882
authored
4 years ago
by
Jonny Ngo Luong
Browse files
Options
Downloads
Patches
Plain Diff
test: Added mock tests on guest-profile (
#16
)
parent
d829f8e7
No related branches found
No related tags found
1 merge request
!21
Resolve "Gjesteside for profilen din"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
client/src/app/users/user-guest-profile/user-guest-profile.component.spec.ts
+46
-4
46 additions, 4 deletions
...s/user-guest-profile/user-guest-profile.component.spec.ts
with
46 additions
and
4 deletions
client/src/app/users/user-guest-profile/user-guest-profile.component.spec.ts
+
46
−
4
View file @
217f0882
import
{
HttpClientTestingModule
}
from
'
@angular/common/http/testing
'
;
import
{
ComponentFixture
,
TestBed
}
from
'
@angular/core/testing
'
;
import
{
ActivatedRoute
}
from
'
@angular/router
'
;
import
{
RouterTestingModule
}
from
'
@angular/router/testing
'
;
import
{
User
}
from
'
src/app/models/user.model
'
;
import
{
UserService
}
from
'
../user.service
'
;
import
{
UserGuestProfileComponent
}
from
'
./user-guest-profile.component
'
;
describe
(
'
UserGuestProfileComponent
'
,
()
=>
{
let
component
:
UserGuestProfileComponent
;
let
fixture
:
ComponentFixture
<
UserGuestProfileComponent
>
;
let
mockPostService
;
const
dateNow
=
new
Date
();
beforeEach
(
async
()
=>
{
// UserService mock setup
mockPostService
=
jasmine
.
createSpyObj
([
'
getUser
'
]);
mockPostService
.
getUser
.
and
.
returnValue
(
new
Promise
<
User
>
(
(
resolve
)
=>
{
resolve
(
new
User
({
userId
:
1
,
username
:
"
Test
"
,
email
:
"
test@email.com
"
,
password
:
"
testPassword
"
,
create_time
:
dateNow
,
}));
})
);
await
TestBed
.
configureTestingModule
({
declarations
:
[
UserGuestProfileComponent
]
declarations
:
[
UserGuestProfileComponent
],
imports
:
[
HttpClientTestingModule
,
RouterTestingModule
],
providers
:
[
{
provide
:
ActivatedRoute
,
useValue
:
{
snapshot
:
{
params
:
{
id
:
1
}}}},
{
provide
:
UserService
,
useValue
:
mockPostService
}
]
})
.
compileComponents
();
});
...
...
@@ -22,4 +48,20 @@ describe('UserGuestProfileComponent', () => {
it
(
'
should create
'
,
()
=>
{
expect
(
component
).
toBeTruthy
();
});
});
it
(
'
should get user with id from url parameter
'
,
async
()
=>
{
// Waits for ngOnInit and checks that we get user
expect
(
component
.
user
).
not
.
toBeNull
();
fixture
.
whenStable
().
then
(()
=>
{
expect
(
mockPostService
.
getUser
).
toHaveBeenCalledWith
(
1
);
expect
(
component
.
user
).
toEqual
(
new
User
({
userId
:
1
,
username
:
"
Test
"
,
email
:
"
test@email.com
"
,
password
:
"
testPassword
"
,
create_time
:
dateNow
,
}));
});
});
});
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment