mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
Fix core unit tests
Fix core unit tests Fix core unit tests Fix core unit tests Fix core unit tests Fix core unit tests Fix core unit tests
This commit is contained in:
@@ -41,10 +41,21 @@ describe('AuthGuardService BPM', () => {
|
|||||||
imports: [
|
imports: [
|
||||||
TranslateModule.forRoot(),
|
TranslateModule.forRoot(),
|
||||||
CoreTestingModule
|
CoreTestingModule
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
provide: OidcAuthenticationService, useValue: {
|
||||||
|
ssoImplicitLogin: () => { },
|
||||||
|
isPublicUrl: () => false,
|
||||||
|
hasValidIdToken: () => false,
|
||||||
|
isLoggedIn: () => false
|
||||||
|
}
|
||||||
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
basicAlfrescoAuthService = TestBed.inject(BasicAlfrescoAuthService);
|
basicAlfrescoAuthService = TestBed.inject(BasicAlfrescoAuthService);
|
||||||
|
oidcAuthenticationService = TestBed.inject(OidcAuthenticationService);
|
||||||
authService = TestBed.inject(AuthenticationService);
|
authService = TestBed.inject(AuthenticationService);
|
||||||
authGuard = TestBed.inject(AuthGuardBpm);
|
authGuard = TestBed.inject(AuthGuardBpm);
|
||||||
router = TestBed.inject(Router);
|
router = TestBed.inject(Router);
|
||||||
|
|||||||
@@ -40,6 +40,16 @@ describe('AuthGuardService ECM', () => {
|
|||||||
imports: [
|
imports: [
|
||||||
TranslateModule.forRoot(),
|
TranslateModule.forRoot(),
|
||||||
CoreTestingModule
|
CoreTestingModule
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
provide: OidcAuthenticationService, useValue: {
|
||||||
|
ssoImplicitLogin: () => { },
|
||||||
|
isPublicUrl: () => false,
|
||||||
|
hasValidIdToken: () => false,
|
||||||
|
isLoggedIn: () => false
|
||||||
|
}
|
||||||
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
|
|||||||
@@ -41,6 +41,15 @@ describe('AuthGuardService', () => {
|
|||||||
imports: [
|
imports: [
|
||||||
TranslateModule.forRoot(),
|
TranslateModule.forRoot(),
|
||||||
CoreTestingModule
|
CoreTestingModule
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
provide: OidcAuthenticationService, useValue: {
|
||||||
|
ssoImplicitLogin: () => { },
|
||||||
|
isPublicUrl: () => false,
|
||||||
|
hasValidIdToken: () => false
|
||||||
|
}
|
||||||
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import { of } from 'rxjs';
|
|||||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
import { BasicAlfrescoAuthService } from '../../auth/basic-auth/basic-alfresco-auth.service';
|
import { BasicAlfrescoAuthService } from '../../auth/basic-auth/basic-alfresco-auth.service';
|
||||||
|
import { OidcAuthenticationService } from '../../auth/services/oidc-authentication.service';
|
||||||
|
|
||||||
describe('LoginDialogPanelComponent', () => {
|
describe('LoginDialogPanelComponent', () => {
|
||||||
let component: LoginDialogPanelComponent;
|
let component: LoginDialogPanelComponent;
|
||||||
@@ -35,9 +36,14 @@ describe('LoginDialogPanelComponent', () => {
|
|||||||
imports: [
|
imports: [
|
||||||
TranslateModule.forRoot(),
|
TranslateModule.forRoot(),
|
||||||
CoreTestingModule
|
CoreTestingModule
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
{ provide: OidcAuthenticationService, useValue: {}}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
fixture = TestBed.createComponent(LoginDialogPanelComponent);
|
fixture = TestBed.createComponent(LoginDialogPanelComponent);
|
||||||
|
basicAlfrescoAuthService = TestBed.inject(BasicAlfrescoAuthService);
|
||||||
|
|
||||||
element = fixture.nativeElement;
|
element = fixture.nativeElement;
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
|
|
||||||
|
|||||||
@@ -25,11 +25,11 @@ import { AuthenticationService } from '../../auth/services/authentication.servic
|
|||||||
import { LoginErrorEvent } from '../models/login-error.event';
|
import { LoginErrorEvent } from '../models/login-error.event';
|
||||||
import { LoginSuccessEvent } from '../models/login-success.event';
|
import { LoginSuccessEvent } from '../models/login-success.event';
|
||||||
import { LoginComponent } from './login.component';
|
import { LoginComponent } from './login.component';
|
||||||
import { of, throwError } from 'rxjs';
|
import { EMPTY, of, throwError } from 'rxjs';
|
||||||
import { AlfrescoApiService } from '../../services/alfresco-api.service';
|
|
||||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||||
import { LogService } from '../../common/services/log.service';
|
import { LogService } from '../../common/services/log.service';
|
||||||
import { BasicAlfrescoAuthService } from '../../auth/basic-auth/basic-alfresco-auth.service';
|
import { BasicAlfrescoAuthService } from '../../auth/basic-auth/basic-alfresco-auth.service';
|
||||||
|
import { OidcAuthenticationService } from '../../auth/services/oidc-authentication.service';
|
||||||
|
|
||||||
describe('LoginComponent', () => {
|
describe('LoginComponent', () => {
|
||||||
let component: LoginComponent;
|
let component: LoginComponent;
|
||||||
@@ -39,7 +39,6 @@ describe('LoginComponent', () => {
|
|||||||
let router: Router;
|
let router: Router;
|
||||||
let userPreferences: UserPreferencesService;
|
let userPreferences: UserPreferencesService;
|
||||||
let appConfigService: AppConfigService;
|
let appConfigService: AppConfigService;
|
||||||
let alfrescoApiService: AlfrescoApiService;
|
|
||||||
let basicAlfrescoAuthService: BasicAlfrescoAuthService;
|
let basicAlfrescoAuthService: BasicAlfrescoAuthService;
|
||||||
|
|
||||||
let usernameInput;
|
let usernameInput;
|
||||||
@@ -62,6 +61,16 @@ describe('LoginComponent', () => {
|
|||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [
|
imports: [
|
||||||
CoreTestingModule
|
CoreTestingModule
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
provide: OidcAuthenticationService, useValue: {
|
||||||
|
ssoImplicitLogin: () => { },
|
||||||
|
isPublicUrl: () => false,
|
||||||
|
hasValidIdToken: () => false,
|
||||||
|
isLoggedIn: () => false
|
||||||
|
}
|
||||||
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
fixture = TestBed.createComponent(LoginComponent);
|
fixture = TestBed.createComponent(LoginComponent);
|
||||||
@@ -76,7 +85,6 @@ describe('LoginComponent', () => {
|
|||||||
router = TestBed.inject(Router);
|
router = TestBed.inject(Router);
|
||||||
userPreferences = TestBed.inject(UserPreferencesService);
|
userPreferences = TestBed.inject(UserPreferencesService);
|
||||||
appConfigService = TestBed.inject(AppConfigService);
|
appConfigService = TestBed.inject(AppConfigService);
|
||||||
alfrescoApiService = TestBed.inject(AlfrescoApiService);
|
|
||||||
|
|
||||||
const logService = TestBed.inject(LogService);
|
const logService = TestBed.inject(LogService);
|
||||||
spyOn(logService, 'error');
|
spyOn(logService, 'error');
|
||||||
@@ -178,7 +186,6 @@ describe('LoginComponent', () => {
|
|||||||
it('should update user preferences upon login', async () => {
|
it('should update user preferences upon login', async () => {
|
||||||
spyOn(userPreferences, 'setStoragePrefix').and.callThrough();
|
spyOn(userPreferences, 'setStoragePrefix').and.callThrough();
|
||||||
spyOn(basicAlfrescoAuthService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' }));
|
spyOn(basicAlfrescoAuthService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' }));
|
||||||
spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.resolve());
|
|
||||||
|
|
||||||
component.success.subscribe(() => {
|
component.success.subscribe(() => {
|
||||||
expect(userPreferences.setStoragePrefix).toHaveBeenCalledWith('fake-username');
|
expect(userPreferences.setStoragePrefix).toHaveBeenCalledWith('fake-username');
|
||||||
@@ -472,7 +479,7 @@ describe('LoginComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return error with a wrong username', (done) => {
|
it('should return error with a wrong username', (done) => {
|
||||||
spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.reject());
|
spyOn(basicAlfrescoAuthService, 'login').and.returnValue(throwError(new Error()));
|
||||||
|
|
||||||
component.error.subscribe(() => {
|
component.error.subscribe(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
@@ -487,7 +494,7 @@ describe('LoginComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return error with a wrong password', (done) => {
|
it('should return error with a wrong password', (done) => {
|
||||||
spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.reject());
|
spyOn(basicAlfrescoAuthService, 'login').and.returnValue(throwError(new Error()));
|
||||||
|
|
||||||
component.error.subscribe(() => {
|
component.error.subscribe(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
@@ -503,7 +510,7 @@ describe('LoginComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return error with a wrong username and password', (done) => {
|
it('should return error with a wrong username and password', (done) => {
|
||||||
spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.reject());
|
spyOn(basicAlfrescoAuthService, 'login').and.returnValue(throwError(new Error()));
|
||||||
|
|
||||||
component.error.subscribe(() => {
|
component.error.subscribe(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
@@ -671,7 +678,7 @@ describe('LoginComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should emit only the username and not the password as part of the executeSubmit', fakeAsync(() => {
|
it('should emit only the username and not the password as part of the executeSubmit', fakeAsync(() => {
|
||||||
spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.resolve());
|
spyOn(basicAlfrescoAuthService, 'login').and.returnValue(EMPTY);
|
||||||
|
|
||||||
component.executeSubmit.subscribe((res) => {
|
component.executeSubmit.subscribe((res) => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
@@ -691,7 +698,6 @@ describe('LoginComponent', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
appConfigService.config.oauth2 = { implicitFlow: true, silentLogin: false };
|
appConfigService.config.oauth2 = { implicitFlow: true, silentLogin: false };
|
||||||
appConfigService.load();
|
appConfigService.load();
|
||||||
alfrescoApiService.reset();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not show login username and password if SSO implicit flow is active', fakeAsync(() => {
|
it('should not show login username and password if SSO implicit flow is active', fakeAsync(() => {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { LoginComponent } from '../components/login.component';
|
|||||||
import { LoginFooterDirective } from './login-footer.directive';
|
import { LoginFooterDirective } from './login-footer.directive';
|
||||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { OidcAuthenticationService } from '../../auth/services/oidc-authentication.service';
|
||||||
|
|
||||||
describe('LoginFooterDirective', () => {
|
describe('LoginFooterDirective', () => {
|
||||||
let fixture: ComponentFixture<LoginComponent>;
|
let fixture: ComponentFixture<LoginComponent>;
|
||||||
@@ -31,6 +32,11 @@ describe('LoginFooterDirective', () => {
|
|||||||
imports: [
|
imports: [
|
||||||
TranslateModule.forRoot(),
|
TranslateModule.forRoot(),
|
||||||
CoreTestingModule
|
CoreTestingModule
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
provide: OidcAuthenticationService, useValue: {}
|
||||||
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
fixture = TestBed.createComponent(LoginComponent);
|
fixture = TestBed.createComponent(LoginComponent);
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { LoginComponent } from '../components/login.component';
|
|||||||
import { LoginHeaderDirective } from './login-header.directive';
|
import { LoginHeaderDirective } from './login-header.directive';
|
||||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { OidcAuthenticationService } from '../../auth/services/oidc-authentication.service';
|
||||||
|
|
||||||
describe('LoginHeaderDirective', () => {
|
describe('LoginHeaderDirective', () => {
|
||||||
let fixture: ComponentFixture<LoginComponent>;
|
let fixture: ComponentFixture<LoginComponent>;
|
||||||
@@ -31,6 +32,9 @@ describe('LoginHeaderDirective', () => {
|
|||||||
imports: [
|
imports: [
|
||||||
TranslateModule.forRoot(),
|
TranslateModule.forRoot(),
|
||||||
CoreTestingModule
|
CoreTestingModule
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
{ provide: OidcAuthenticationService, useValue: {} }
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
fixture = TestBed.createComponent(LoginComponent);
|
fixture = TestBed.createComponent(LoginComponent);
|
||||||
|
|||||||
Reference in New Issue
Block a user