-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from fga-eps-mds/details-login-social
Details login social
- Loading branch information
Showing
7 changed files
with
68 additions
and
93 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
import { ComponentFixture, TestBed, tick, fakeAsync } from '@angular/core/testing'; | ||
import { | ||
ComponentFixture, | ||
TestBed, | ||
tick, | ||
fakeAsync, | ||
} from '@angular/core/testing'; | ||
import { LoginComponent } from './login.component'; | ||
import { FormBuilder, ReactiveFormsModule } from '@angular/forms'; | ||
import { HttpClientTestingModule } from '@angular/common/http/testing'; | ||
|
@@ -13,22 +18,22 @@ import { VideoComponent } from '../video/video.component'; | |
import { HttpErrorResponse } from '@angular/common/http'; | ||
import { ActiveAccountComponent } from '../active-account/active-account.component'; | ||
|
||
|
||
const mockUserReturn = { | ||
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJqb2FvMTV2aWN0b3IwOEBnbWFpbC5jb20iLCJleHAiOjE2OTkzMTI5MzV9.1B9qBJt8rErwBKyD5JCdsPozsw86oQ38tdfDuMM2HFI", | ||
"token_type": "bearer" | ||
access_token: | ||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJqb2FvMTV2aWN0b3IwOEBnbWFpbC5jb20iLCJleHAiOjE2OTkzMTI5MzV9.1B9qBJt8rErwBKyD5JCdsPozsw86oQ38tdfDuMM2HFI', | ||
token_type: 'bearer', | ||
}; | ||
|
||
class AuthServiceMock { | ||
constructor() { } | ||
constructor() {} | ||
|
||
loginUser() { | ||
return of({ success: true }); | ||
} | ||
} | ||
|
||
class AlertServiceMock { | ||
constructor() { } | ||
constructor() {} | ||
showMessage() { | ||
return of({ success: true }); | ||
} | ||
|
@@ -45,21 +50,26 @@ describe('LoginComponent', () => { | |
|
||
beforeEach(async () => { | ||
TestBed.configureTestingModule({ | ||
imports: [HttpClientTestingModule, ReactiveFormsModule, RouterTestingModule.withRoutes( | ||
[ | ||
imports: [ | ||
HttpClientTestingModule, | ||
ReactiveFormsModule, | ||
RouterTestingModule.withRoutes([ | ||
{ path: 'profile', component: ProfileComponent }, | ||
{ path: 'sendCodeResetPassword', component: CheckCodeRestPasswordComponent }, | ||
{ | ||
path: 'sendCodeResetPassword', | ||
component: CheckCodeRestPasswordComponent, | ||
}, | ||
{ path: 'register', component: RegisterComponent }, | ||
{ path: 'videos', component: VideoComponent }, | ||
{ path: 'activeAccount', component: ActiveAccountComponent } | ||
] | ||
)], | ||
{ path: 'activeAccount', component: ActiveAccountComponent }, | ||
]), | ||
], | ||
providers: [ | ||
FormBuilder, | ||
AuthService, | ||
AlertService, | ||
{ provide: AlertService, useValue: new AlertServiceMock() }, // Provide the mock class | ||
{ provide: AuthService, useValue: new AuthServiceMock() } | ||
{ provide: AuthService, useValue: new AuthServiceMock() }, | ||
], | ||
declarations: [LoginComponent], | ||
}).compileComponents(); | ||
|
@@ -85,7 +95,9 @@ describe('LoginComponent', () => { | |
const form = component.userForm; | ||
form.setValue({ email: '[email protected]', password: 'password' }); | ||
|
||
const submitButton = fixture.nativeElement.querySelector('button[type="submit"]'); | ||
const submitButton = fixture.nativeElement.querySelector( | ||
'button[type="submit"]' | ||
); | ||
submitButton.click(); | ||
tick(); | ||
|
||
|
@@ -97,38 +109,60 @@ describe('LoginComponent', () => { | |
const alertSpy = spyOn(alertService, 'showMessage'); | ||
fixture.detectChanges(); | ||
|
||
const submitButton = fixture.nativeElement.querySelector('button[type="submit"]'); | ||
const submitButton = fixture.nativeElement.querySelector( | ||
'button[type="submit"]' | ||
); | ||
submitButton.click(); | ||
tick(); | ||
|
||
expect(alertSpy).toHaveBeenCalledWith('info', 'Alerta', 'Preencha todos os campos corretamente!'); | ||
expect(alertSpy).toHaveBeenCalledWith( | ||
'info', | ||
'Alerta', | ||
'Preencha todos os campos corretamente!' | ||
); | ||
})); | ||
|
||
it('should call navigator method when "Esqueceu a senha?" is clicked', () => { | ||
spyOn(component, 'navigator').and.callThrough(); | ||
const forgotPasswordLink = fixture.nativeElement.querySelector('.text-gray-400'); | ||
const forgotPasswordLink = | ||
fixture.nativeElement.querySelector('.text-gray-400'); | ||
forgotPasswordLink.click(); | ||
|
||
expect(component.navigator).toHaveBeenCalledWith('/sendCodeResetPassword'); | ||
}); | ||
|
||
it('should call navigator method when "Cadastre-se" is clicked', () => { | ||
spyOn(component, 'navigator').and.callThrough(); | ||
const registerLink = fixture.nativeElement.querySelector('.text-blue-brand'); | ||
const registerLink = | ||
fixture.nativeElement.querySelector('.text-blue-brand'); | ||
registerLink.click(); | ||
|
||
expect(component.navigator).toHaveBeenCalledWith('/register'); | ||
}); | ||
|
||
it('should call navigator method when "Login com redes sociais" is clicked', () => { | ||
const navigatorSpy = spyOn(component, 'navigator').and.callThrough(); | ||
const loginSocial = fixture.nativeElement.querySelector('#loginSocialButton'); | ||
loginSocial.click(); | ||
|
||
expect(navigatorSpy).toHaveBeenCalledWith('/loginsocial'); | ||
}); | ||
|
||
it('should call login and return an error', () => { | ||
fixture.detectChanges(); | ||
const form = component.userForm; | ||
form.setValue({ email: '[email protected]', password: 'password' }); | ||
const mySpy = spyOn(authService, 'loginUser').and.returnValue(throwError(() => new HttpErrorResponse({ error: { detail: 'A sua conta ainda não foi ativada.' } }))); | ||
const mySpy = spyOn(authService, 'loginUser').and.returnValue( | ||
throwError( | ||
() => | ||
new HttpErrorResponse({ | ||
error: { detail: 'A sua conta ainda não foi ativada.' }, | ||
}) | ||
) | ||
); | ||
spyOn(component, 'navigator').and.callThrough(); | ||
component.login(); | ||
expect(mySpy).toHaveBeenCalled(); | ||
expect(component.navigator).toHaveBeenCalledWith('/activeAccount'); | ||
}); | ||
|
||
}); |