Skip to content

Commit

Permalink
Adiciona teste para showRenewTokenDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcosatc147 committed Dec 8, 2023
1 parent b543074 commit 41029a8
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/app/pages/profile/profile.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class AlertServiceMock {
class AuthServiceMock {
logout() { }
refreshToken() { }
showRenewTokenDialog() { }
}

class ConfirmationServiceMock {
Expand Down Expand Up @@ -134,7 +135,7 @@ describe('ProfileComponent', () => {
expect(authService.refreshToken).toHaveBeenCalled();
expect(localStorage.getItem('token')).toEqual('new_access_token');
});

it('should handle error when renewing token', () => {
spyOn(authService, 'refreshToken').and.returnValue(throwError('error'));
spyOn(console, 'error');
Expand All @@ -144,6 +145,30 @@ describe('ProfileComponent', () => {
expect(authService.refreshToken).toHaveBeenCalled();
expect(console.error).toHaveBeenCalledWith('Failed to refresh token:', 'error');
});
it('should show renew token dialog', () => {
const confirmSpy = spyOn(confirmationService, 'confirm').and.callFake((params: any) => {
params.accept();
params.reject();

// Return a mock ConfirmationService instance
return {} as ConfirmationService;
});
const renewTokenSpy = spyOn(component, 'renewToken');
const logoutSpy = spyOn(authService, 'logout');

component.showRenewTokenDialog();

expect(confirmSpy).toHaveBeenCalledWith({
message: 'Deseja se manter logado?',
header: 'Confirmação',
key: 'myDialog',
icon: 'pi pi-exclamation-triangle',
accept: jasmine.any(Function),
reject: jasmine.any(Function),
});
expect(renewTokenSpy).toHaveBeenCalled();
expect(logoutSpy).toHaveBeenCalled();
});

it('should call navigatorEdit when editUser is clicked', () => {
spyOn(component, 'navigatorEdit').and.callThrough();
Expand Down

0 comments on commit 41029a8

Please sign in to comment.