Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
anis
anis-client
Commits
e3656f50
Commit
e3656f50
authored
Nov 10, 2020
by
François Agneray
Browse files
Fixed tests => done
parent
3f084a97
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/app/auth/store/auth.action.ts
View file @
e3656f50
import
{
Action
}
from
'
@ngrx/store
'
;
import
{
UserProfile
}
from
'
./user-profile.model
'
;
export
const
LOGIN
=
'
[Auth] Login
'
;
export
const
LOGOUT
=
'
[Auth] Logout
'
;
export
const
AUTH_SUCCESS
=
'
[Auth] Auth Success
'
;
...
...
@@ -27,7 +29,7 @@ export class AuthSuccessAction implements Action {
export
class
LoadUserProfileSuccessAction
implements
Action
{
readonly
type
=
LOAD_USER_PROFILE_SUCCESS
;
constructor
(
public
payload
:
Keycloak
.
Keycloak
Profile
)
{
}
constructor
(
public
payload
:
User
Profile
)
{
}
}
export
class
OpenEditProfileAction
implements
Action
{
...
...
src/app/auth/store/user-profile.model.ts
0 → 100644
View file @
e3656f50
export
interface
UserProfile
{
id
?:
string
;
username
?:
string
;
email
?:
string
;
firstName
?:
string
;
lastName
?:
string
;
enabled
?:
boolean
;
emailVerified
?:
boolean
;
totp
?:
boolean
;
createdTimestamp
?:
number
;
}
\ No newline at end of file
src/app/core/components/nav.component.ts
View file @
e3656f50
import
{
Component
,
Input
,
Output
,
EventEmitter
,
ChangeDetectionStrategy
}
from
'
@angular/core
'
;
import
{
Instance
}
from
'
../../metamodel/model
'
;
import
{
UserProfile
}
from
'
../../auth/store/user-profile.model
'
;
import
{
environment
}
from
'
../../../environments/environment
'
@
Component
({
...
...
@@ -11,7 +12,7 @@ import { environment } from '../../../environments/environment'
})
export
class
NavComponent
{
@
Input
()
isAuthenticated
:
boolean
;
@
Input
()
userProfile
:
Keycloak
.
Keycloak
Profile
;
@
Input
()
userProfile
:
User
Profile
;
@
Input
()
instance
:
Instance
;
@
Output
()
login
:
EventEmitter
<
any
>
=
new
EventEmitter
();
@
Output
()
logout
:
EventEmitter
<
any
>
=
new
EventEmitter
();
...
...
src/app/core/containers/app.component.spec.ts
View file @
e3656f50
...
...
@@ -3,11 +3,10 @@ import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import
{
RouterTestingModule
}
from
'
@angular/router/testing
'
;
import
{
provideMockStore
,
MockStore
}
from
'
@ngrx/store/testing
'
;
import
*
as
fromAuth
from
'
../../auth/store/auth.reducer
'
;
import
*
as
authActions
from
'
../../auth/store/auth.action
'
;
import
{
UserProfile
}
from
'
../../auth/store/user-profile.model
'
;
import
{
AppComponent
}
from
'
./app.component
'
;
import
*
as
fromLogin
from
'
../../login/store/login.reducer
'
;
import
*
as
loginActions
from
'
../../login/store/login.action
'
;
import
{
LoginToken
}
from
'
../../login/store/model
'
;
import
*
as
fromMetamodel
from
'
../../metamodel/reducers
'
;
import
*
as
instanceActions
from
'
../../metamodel/action/instance.action
'
;
...
...
@@ -15,14 +14,14 @@ describe('[Core] Container: AppComponent', () => {
@
Component
({
selector
:
'
app-nav
'
,
template
:
''
})
class
NavStubComponent
{
@
Input
()
isAuthenticated
:
boolean
;
@
Input
()
loginToken
:
LoginToken
;
@
Input
()
userProfile
:
UserProfile
;
}
let
component
:
AppComponent
;
let
fixture
:
ComponentFixture
<
AppComponent
>
;
let
store
:
MockStore
;
const
initialState
=
{
login
:
{
...
from
Login
.
initialState
},
auth
:
{
...
from
Auth
.
initialState
},
metamodel
:
{
...
fromMetamodel
}
};
...
...
@@ -47,17 +46,15 @@ describe('[Core] Container: AppComponent', () => {
});
it
(
'
should execute ngOnInit lifecycle
'
,
()
=>
{
const
loginLocalStorageAction
=
new
loginActions
.
LoginLocalStorageAction
();
const
loadInstanceMetaAction
=
new
instanceActions
.
LoadInstanceMetaAction
();
const
spy
=
spyOn
(
store
,
'
dispatch
'
);
component
.
ngOnInit
();
expect
(
spy
).
toHaveBeenCalledTimes
(
2
);
expect
(
spy
).
toHaveBeenCalledWith
(
loginLocalStorageAction
);
expect
(
spy
).
toHaveBeenCalledTimes
(
1
);
expect
(
spy
).
toHaveBeenCalledWith
(
loadInstanceMetaAction
);
});
it
(
'
#logout() should dispatch LogoutAction
'
,
()
=>
{
const
logoutAction
=
new
login
Actions
.
LogoutAction
();
const
logoutAction
=
new
auth
Actions
.
LogoutAction
();
const
spy
=
spyOn
(
store
,
'
dispatch
'
);
component
.
logout
();
expect
(
spy
).
toHaveBeenCalledTimes
(
1
);
...
...
src/app/core/containers/app.component.ts
View file @
e3656f50
...
...
@@ -9,6 +9,7 @@ import * as metamodelSelector from '../../metamodel/selectors';
import
*
as
fromAuth
from
'
../../auth/store/auth.reducer
'
;
import
*
as
authActions
from
'
../../auth/store/auth.action
'
;
import
*
as
authSelector
from
'
../../auth/store/auth.selector
'
;
import
{
UserProfile
}
from
'
../../auth/store/user-profile.model
'
;
import
{
Instance
}
from
'
../../metamodel/model
'
;
import
{
VERSIONS
}
from
'
../../../settings/settings
'
;
...
...
@@ -27,7 +28,7 @@ export class AppComponent implements OnInit {
public
anisClientVersion
:
string
=
VERSIONS
.
anisClient
;
public
year
=
(
new
Date
()).
getFullYear
();
public
isAuthenticated
:
Observable
<
boolean
>
;
public
userProfile
:
Observable
<
Keycloak
.
Keycloak
Profile
>
public
userProfile
:
Observable
<
User
Profile
>
public
instance
:
Observable
<
Instance
>
;
constructor
(
private
store
:
Store
<
StoreState
>
)
{
...
...
Write
Preview
Supports
Markdown
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