mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACS-7688] Reduce the usage of LogService and TranslateModule (tests) (#9567)
This commit is contained in:
@@ -19,7 +19,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { AboutGithubLinkComponent } from './about-github-link.component';
|
||||
import { aboutGithubDetails } from '../about.mock';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('AboutGithubLinkComponent', () => {
|
||||
let fixture: ComponentFixture<AboutGithubLinkComponent>;
|
||||
@@ -27,7 +26,7 @@ describe('AboutGithubLinkComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), CoreTestingModule]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(AboutGithubLinkComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
@@ -20,7 +20,6 @@ import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { AboutServerSettingsComponent } from './about-server-settings.component';
|
||||
import { AppConfigService } from '../../app-config/app-config.service';
|
||||
import { aboutGithubDetails } from '../about.mock';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('AboutServerSettingsComponent', () => {
|
||||
let fixture: ComponentFixture<AboutServerSettingsComponent>;
|
||||
@@ -29,10 +28,7 @@ describe('AboutServerSettingsComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(AboutServerSettingsComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
@@ -25,7 +25,6 @@ import { catchError, map } from 'rxjs/operators';
|
||||
import { from, Observable } from 'rxjs';
|
||||
import { RedirectionModel } from '../models/redirection.model';
|
||||
import { BaseAuthenticationService } from '../services/base-authentication.service';
|
||||
import { LogService } from '../../common';
|
||||
import { HttpHeaders } from '@angular/common/http';
|
||||
|
||||
const REMEMBER_ME_COOKIE_KEY = 'ALFRESCO_REMEMBER_ME';
|
||||
@@ -35,7 +34,6 @@ const REMEMBER_ME_UNTIL = 1000 * 60 * 60 * 24 * 30;
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class BasicAlfrescoAuthService extends BaseAuthenticationService {
|
||||
|
||||
protected redirectUrl: RedirectionModel = null;
|
||||
|
||||
authentications: Authentication = {
|
||||
@@ -45,45 +43,52 @@ export class BasicAlfrescoAuthService extends BaseAuthenticationService {
|
||||
type: 'basic'
|
||||
};
|
||||
|
||||
constructor(
|
||||
logService: LogService,
|
||||
appConfig: AppConfigService,
|
||||
cookie: CookieService,
|
||||
private contentAuth: ContentAuth,
|
||||
private processAuth: ProcessAuth
|
||||
) {
|
||||
super(appConfig, cookie, logService);
|
||||
constructor(appConfig: AppConfigService, cookie: CookieService, private contentAuth: ContentAuth, private processAuth: ProcessAuth) {
|
||||
super(appConfig, cookie);
|
||||
|
||||
this.appConfig.onLoad
|
||||
.subscribe(() => {
|
||||
if (!this.isOauth() && this.isLoggedIn()) {
|
||||
this.requireAlfTicket().then(() => {
|
||||
this.appConfig.onLoad.subscribe(() => {
|
||||
if (!this.isOauth() && this.isLoggedIn()) {
|
||||
this.requireAlfTicket()
|
||||
.then(() => {
|
||||
this.onLogin.next('logged-in');
|
||||
}).catch(() => {
|
||||
})
|
||||
.catch(() => {
|
||||
this.contentAuth.invalidateSession();
|
||||
this.onLogout.next('logout');
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
this.contentAuth.onLogout.pipe(map((event) => {
|
||||
this.onLogout.next(event);
|
||||
}));
|
||||
this.contentAuth.onLogin.pipe(map((event) => {
|
||||
this.onLogin.next(event);
|
||||
}));
|
||||
this.contentAuth.onError.pipe(map((event) => {
|
||||
this.onError.next(event);
|
||||
}));
|
||||
this.processAuth.onLogout.pipe(map((event) => {
|
||||
this.onLogout.next(event);
|
||||
}));
|
||||
this.processAuth.onLogin.pipe(map((event) => {
|
||||
this.onLogin.next(event);
|
||||
}));
|
||||
this.processAuth.onError.pipe(map((event) => {
|
||||
this.onError.next(event);
|
||||
}));
|
||||
this.contentAuth.onLogout.pipe(
|
||||
map((event) => {
|
||||
this.onLogout.next(event);
|
||||
})
|
||||
);
|
||||
this.contentAuth.onLogin.pipe(
|
||||
map((event) => {
|
||||
this.onLogin.next(event);
|
||||
})
|
||||
);
|
||||
this.contentAuth.onError.pipe(
|
||||
map((event) => {
|
||||
this.onError.next(event);
|
||||
})
|
||||
);
|
||||
this.processAuth.onLogout.pipe(
|
||||
map((event) => {
|
||||
this.onLogout.next(event);
|
||||
})
|
||||
);
|
||||
this.processAuth.onLogin.pipe(
|
||||
map((event) => {
|
||||
this.onLogin.next(event);
|
||||
})
|
||||
);
|
||||
this.processAuth.onError.pipe(
|
||||
map((event) => {
|
||||
this.onError.next(event);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,20 +135,17 @@ export class BasicAlfrescoAuthService extends BaseAuthenticationService {
|
||||
} catch (e) {
|
||||
return Promise.reject(e);
|
||||
}
|
||||
|
||||
} else if (this.isECMProvider()) {
|
||||
try {
|
||||
return await this.contentAuth.login(username, password);
|
||||
} catch (e) {
|
||||
return Promise.reject(e);
|
||||
}
|
||||
|
||||
} else if (this.isALLProvider()) {
|
||||
return this.loginBPMECM(username, password);
|
||||
} else {
|
||||
return Promise.reject(new Error('Unknown configuration'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private loginBPMECM(username: string, password: string): Promise<any> {
|
||||
@@ -165,7 +167,8 @@ export class BasicAlfrescoAuthService extends BaseAuthenticationService {
|
||||
}
|
||||
this.onError.next('error');
|
||||
reject(error);
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -243,7 +246,7 @@ export class BasicAlfrescoAuthService extends BaseAuthenticationService {
|
||||
} else if (this.isECMProvider()) {
|
||||
return authWithCredentials ? true : this.contentAuth.isLoggedIn();
|
||||
} else if (this.isALLProvider()) {
|
||||
return authWithCredentials ? true : (this.contentAuth.isLoggedIn() && this.processAuth.isLoggedIn());
|
||||
return authWithCredentials ? true : this.contentAuth.isLoggedIn() && this.processAuth.isLoggedIn();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -281,12 +284,13 @@ export class BasicAlfrescoAuthService extends BaseAuthenticationService {
|
||||
}
|
||||
this.onError.next('error');
|
||||
reject(error);
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
reset(): void {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -22,12 +22,10 @@ import { AuthenticationService } from '../services/authentication.service';
|
||||
import { RouterStateSnapshot, Router } from '@angular/router';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { BasicAlfrescoAuthService } from '../basic-auth/basic-alfresco-auth.service';
|
||||
import { OidcAuthenticationService } from '../services/oidc-authentication.service';
|
||||
|
||||
describe('AuthGuardService BPM', () => {
|
||||
|
||||
let authGuard: AuthGuardBpm;
|
||||
let authService: AuthenticationService;
|
||||
let basicAlfrescoAuthService: BasicAlfrescoAuthService;
|
||||
@@ -38,14 +36,12 @@ describe('AuthGuardService BPM', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
imports: [CoreTestingModule],
|
||||
providers: [
|
||||
{
|
||||
provide: OidcAuthenticationService, useValue: {
|
||||
ssoLogin: () => { },
|
||||
provide: OidcAuthenticationService,
|
||||
useValue: {
|
||||
ssoLogin: () => {},
|
||||
isPublicUrl: () => false,
|
||||
hasValidIdToken: () => false,
|
||||
isLoggedIn: () => false
|
||||
@@ -154,7 +150,8 @@ describe('AuthGuardService BPM', () => {
|
||||
authGuard.canActivate(null, route);
|
||||
|
||||
expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
|
||||
provider: 'BPM', url: 'some-url'
|
||||
provider: 'BPM',
|
||||
url: 'some-url'
|
||||
});
|
||||
expect(basicAlfrescoAuthService.getRedirect()).toEqual('some-url');
|
||||
});
|
||||
@@ -167,7 +164,8 @@ describe('AuthGuardService BPM', () => {
|
||||
authGuard.canActivate(null, route);
|
||||
|
||||
expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
|
||||
provider: 'BPM', url: 'some-url;q=123'
|
||||
provider: 'BPM',
|
||||
url: 'some-url;q=123'
|
||||
});
|
||||
expect(basicAlfrescoAuthService.getRedirect()).toEqual('some-url;q=123');
|
||||
});
|
||||
@@ -180,7 +178,8 @@ describe('AuthGuardService BPM', () => {
|
||||
authGuard.canActivate(null, route);
|
||||
|
||||
expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
|
||||
provider: 'BPM', url: '/'
|
||||
provider: 'BPM',
|
||||
url: '/'
|
||||
});
|
||||
expect(basicAlfrescoAuthService.getRedirect()).toEqual('/');
|
||||
});
|
||||
@@ -194,7 +193,8 @@ describe('AuthGuardService BPM', () => {
|
||||
authGuard.canActivate(null, route);
|
||||
|
||||
expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
|
||||
provider: 'BPM', url: 'some-url'
|
||||
provider: 'BPM',
|
||||
url: 'some-url'
|
||||
});
|
||||
expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/fakeLoginRoute?redirectUrl=some-url'));
|
||||
});
|
||||
@@ -211,7 +211,8 @@ describe('AuthGuardService BPM', () => {
|
||||
authGuard.canActivate(null, route);
|
||||
|
||||
expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
|
||||
provider: 'BPM', url: 'some-url'
|
||||
provider: 'BPM',
|
||||
url: 'some-url'
|
||||
});
|
||||
|
||||
expect(materialDialog.closeAll).toHaveBeenCalled();
|
||||
|
@@ -22,12 +22,10 @@ import { AuthenticationService } from '../services/authentication.service';
|
||||
import { RouterStateSnapshot, Router } from '@angular/router';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { OidcAuthenticationService } from '../services/oidc-authentication.service';
|
||||
import { BasicAlfrescoAuthService } from '../basic-auth/basic-alfresco-auth.service';
|
||||
|
||||
describe('AuthGuardService ECM', () => {
|
||||
|
||||
let authGuard: AuthGuardEcm;
|
||||
let authService: AuthenticationService;
|
||||
let basicAlfrescoAuthService: BasicAlfrescoAuthService;
|
||||
@@ -37,14 +35,12 @@ describe('AuthGuardService ECM', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
imports: [CoreTestingModule],
|
||||
providers: [
|
||||
{
|
||||
provide: OidcAuthenticationService, useValue: {
|
||||
ssoLogin: () => { },
|
||||
provide: OidcAuthenticationService,
|
||||
useValue: {
|
||||
ssoLogin: () => {},
|
||||
isPublicUrl: () => false,
|
||||
hasValidIdToken: () => false,
|
||||
isLoggedIn: () => false
|
||||
@@ -67,7 +63,7 @@ describe('AuthGuardService ECM', () => {
|
||||
|
||||
it('if the alfresco js api is logged in should canActivate be true', async () => {
|
||||
spyOn(authService, 'isEcmLoggedIn').and.returnValue(true);
|
||||
const route = {url : 'some-url'} as RouterStateSnapshot;
|
||||
const route = { url: 'some-url' } as RouterStateSnapshot;
|
||||
|
||||
expect(await authGuard.canActivate(null, route)).toBeTruthy();
|
||||
});
|
||||
@@ -76,7 +72,7 @@ describe('AuthGuardService ECM', () => {
|
||||
spyOn(authService, 'isBpmLoggedIn').and.returnValue(true);
|
||||
appConfigService.config.auth.withCredentials = true;
|
||||
|
||||
const route = {url : 'some-url'} as RouterStateSnapshot;
|
||||
const route = { url: 'some-url' } as RouterStateSnapshot;
|
||||
|
||||
expect(await authGuard.canActivate(null, route)).toBeTruthy();
|
||||
});
|
||||
@@ -94,7 +90,7 @@ describe('AuthGuardService ECM', () => {
|
||||
|
||||
spyOn(router, 'navigateByUrl');
|
||||
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
|
||||
const route = {url : 'some-url'} as RouterStateSnapshot;
|
||||
const route = { url: 'some-url' } as RouterStateSnapshot;
|
||||
|
||||
expect(await authGuard.canActivate(null, route)).toBeFalsy();
|
||||
expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/login?redirectUrl=some-url'));
|
||||
@@ -105,7 +101,7 @@ describe('AuthGuardService ECM', () => {
|
||||
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
|
||||
spyOn(authService, 'isOauth').and.returnValue(true);
|
||||
appConfigService.config.oauth2.silentLogin = false;
|
||||
const route = {url : 'some-url'} as RouterStateSnapshot;
|
||||
const route = { url: 'some-url' } as RouterStateSnapshot;
|
||||
|
||||
expect(await authGuard.canActivate(null, route)).toBeFalsy();
|
||||
expect(router.navigateByUrl).toHaveBeenCalled();
|
||||
@@ -126,7 +122,7 @@ describe('AuthGuardService ECM', () => {
|
||||
scope: 'openid'
|
||||
};
|
||||
|
||||
const route = {url : 'abc'} as RouterStateSnapshot;
|
||||
const route = { url: 'abc' } as RouterStateSnapshot;
|
||||
|
||||
expect(await authGuard.canActivate(null, route)).toBeFalsy();
|
||||
expect(oidcAuthenticationService.ssoLogin).toHaveBeenCalledTimes(1);
|
||||
@@ -137,7 +133,7 @@ describe('AuthGuardService ECM', () => {
|
||||
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
|
||||
spyOn(authService, 'isOauth').and.returnValue(true);
|
||||
appConfigService.config.oauth2.silentLogin = undefined;
|
||||
const route = {url : 'some-url'} as RouterStateSnapshot;
|
||||
const route = { url: 'some-url' } as RouterStateSnapshot;
|
||||
|
||||
expect(await authGuard.canActivate(null, route)).toBeFalsy();
|
||||
expect(router.navigateByUrl).toHaveBeenCalled();
|
||||
@@ -151,7 +147,8 @@ describe('AuthGuardService ECM', () => {
|
||||
authGuard.canActivate(null, route);
|
||||
|
||||
expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
|
||||
provider: 'ECM', url: 'some-url'
|
||||
provider: 'ECM',
|
||||
url: 'some-url'
|
||||
});
|
||||
expect(basicAlfrescoAuthService.getRedirect()).toEqual('some-url');
|
||||
});
|
||||
@@ -164,7 +161,8 @@ describe('AuthGuardService ECM', () => {
|
||||
authGuard.canActivate(null, route);
|
||||
|
||||
expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
|
||||
provider: 'ECM', url: 'some-url;q=123'
|
||||
provider: 'ECM',
|
||||
url: 'some-url;q=123'
|
||||
});
|
||||
expect(basicAlfrescoAuthService.getRedirect()).toEqual('some-url;q=123');
|
||||
});
|
||||
@@ -177,7 +175,8 @@ describe('AuthGuardService ECM', () => {
|
||||
authGuard.canActivate(null, route);
|
||||
|
||||
expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
|
||||
provider: 'ECM', url: '/'
|
||||
provider: 'ECM',
|
||||
url: '/'
|
||||
});
|
||||
expect(basicAlfrescoAuthService.getRedirect()).toEqual('/');
|
||||
});
|
||||
@@ -191,7 +190,8 @@ describe('AuthGuardService ECM', () => {
|
||||
authGuard.canActivate(null, route);
|
||||
|
||||
expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
|
||||
provider: 'ECM', url: 'some-url'
|
||||
provider: 'ECM',
|
||||
url: 'some-url'
|
||||
});
|
||||
expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/fakeLoginRoute?redirectUrl=some-url'));
|
||||
});
|
||||
@@ -208,7 +208,8 @@ describe('AuthGuardService ECM', () => {
|
||||
authGuard.canActivate(null, route);
|
||||
|
||||
expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
|
||||
provider: 'ECM', url: 'some-url'
|
||||
provider: 'ECM',
|
||||
url: 'some-url'
|
||||
});
|
||||
|
||||
expect(materialDialog.closeAll).toHaveBeenCalled();
|
||||
|
@@ -21,20 +21,15 @@ import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { AuthGuardSsoRoleService } from './auth-guard-sso-role.service';
|
||||
import { JwtHelperService } from '../services/jwt-helper.service';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('Auth Guard SSO role service', () => {
|
||||
|
||||
let authGuard: AuthGuardSsoRoleService;
|
||||
let jwtHelperService: JwtHelperService;
|
||||
let routerService: Router;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
localStorage.clear();
|
||||
authGuard = TestBed.inject(AuthGuardSsoRoleService);
|
||||
@@ -192,6 +187,5 @@ describe('Auth Guard SSO role service', () => {
|
||||
router.data = { roles: ['MOCK_USER_ROLE', 'MOCK_ADMIN_ROLE'], excludedRoles: ['MOCK_ROOT_USER_ROLE'] };
|
||||
expect(authGuard.canActivate(router)).toBeTruthy();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
@@ -21,7 +21,6 @@ import { AppConfigService } from '../../app-config/app-config.service';
|
||||
import { AuthGuard } from './auth-guard.service';
|
||||
import { AuthenticationService } from '../services/authentication.service';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { StorageService } from '../../common/services/storage.service';
|
||||
import { OidcAuthenticationService } from '../services/oidc-authentication.service';
|
||||
import { BasicAlfrescoAuthService } from '../basic-auth/basic-alfresco-auth.service';
|
||||
@@ -38,14 +37,12 @@ describe('AuthGuardService', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
imports: [CoreTestingModule],
|
||||
providers: [
|
||||
{
|
||||
provide: OidcAuthenticationService, useValue: {
|
||||
ssoLogin: () => { },
|
||||
provide: OidcAuthenticationService,
|
||||
useValue: {
|
||||
ssoLogin: () => {},
|
||||
isPublicUrl: () => false,
|
||||
hasValidIdToken: () => false
|
||||
}
|
||||
@@ -144,7 +141,8 @@ describe('AuthGuardService', () => {
|
||||
await authGuard.canActivate(null, state);
|
||||
|
||||
expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
|
||||
provider: 'ALL', url: 'some-url'
|
||||
provider: 'ALL',
|
||||
url: 'some-url'
|
||||
});
|
||||
expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/login?redirectUrl=some-url'));
|
||||
});
|
||||
@@ -160,7 +158,8 @@ describe('AuthGuardService', () => {
|
||||
await authGuard.canActivate(null, state);
|
||||
|
||||
expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
|
||||
provider: 'ALL', url: 'some-url;q=query'
|
||||
provider: 'ALL',
|
||||
url: 'some-url;q=query'
|
||||
});
|
||||
expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/login?redirectUrl=some-url;q=query'));
|
||||
});
|
||||
@@ -175,7 +174,8 @@ describe('AuthGuardService', () => {
|
||||
await authGuard.canActivate(null, state);
|
||||
|
||||
expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
|
||||
provider: 'ALL', url: 'some-url'
|
||||
provider: 'ALL',
|
||||
url: 'some-url'
|
||||
});
|
||||
expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/fakeLoginRoute?redirectUrl=some-url'));
|
||||
});
|
||||
@@ -189,7 +189,8 @@ describe('AuthGuardService', () => {
|
||||
await authGuard.canActivate(null, state);
|
||||
|
||||
expect(basicAlfrescoAuthService.setRedirect).toHaveBeenCalledWith({
|
||||
provider: 'ALL', url: '/'
|
||||
provider: 'ALL',
|
||||
url: '/'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -21,7 +21,6 @@ import { CookieService } from '../../common/services/cookie.service';
|
||||
import { AppConfigService } from '../../app-config/app-config.service';
|
||||
import { setupTestBed } from '../../testing/setup-test-bed';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { BasicAlfrescoAuthService } from '../basic-auth/basic-alfresco-auth.service';
|
||||
import { OidcAuthenticationService } from './oidc-authentication.service';
|
||||
|
||||
@@ -35,10 +34,7 @@ describe('AuthenticationService', () => {
|
||||
let oidcAuthenticationService: OidcAuthenticationService;
|
||||
|
||||
setupTestBed({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -69,7 +65,7 @@ describe('AuthenticationService', () => {
|
||||
appConfigService.config.auth = { withCredentials: true };
|
||||
});
|
||||
|
||||
it('should emit login event for kerberos', (done) => {
|
||||
it('should emit login event for kerberos', (done) => {
|
||||
spyOn(basicAlfrescoAuthService, 'requireAlfTicket').and.returnValue(Promise.resolve());
|
||||
const disposableLogin = authService.onLogin.subscribe(() => {
|
||||
disposableLogin.unsubscribe();
|
||||
@@ -97,7 +93,6 @@ describe('AuthenticationService', () => {
|
||||
});
|
||||
|
||||
describe('when the setting is ECM', () => {
|
||||
|
||||
const fakeECMLoginResponse = { type: 'ECM', ticket: 'fake-post-ticket' };
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -216,7 +211,6 @@ describe('AuthenticationService', () => {
|
||||
});
|
||||
|
||||
describe('when the setting is BPM', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
appConfigService.config.providers = 'BPM';
|
||||
appConfigService.load();
|
||||
@@ -278,13 +272,13 @@ describe('AuthenticationService', () => {
|
||||
|
||||
it('[BPM] should return an error when the logout return error', (done) => {
|
||||
authService.logout().subscribe(
|
||||
() => {
|
||||
},
|
||||
() => {},
|
||||
(err: any) => {
|
||||
expect(err).toBeDefined();
|
||||
expect(authService.getToken()).toBe(null);
|
||||
done();
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 403
|
||||
@@ -323,7 +317,6 @@ describe('AuthenticationService', () => {
|
||||
});
|
||||
|
||||
describe('remember me', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
appConfigService.config.providers = 'ECM';
|
||||
appConfigService.load();
|
||||
@@ -367,7 +360,8 @@ describe('AuthenticationService', () => {
|
||||
expect(cookie['ALFRESCO_REMEMBER_ME']).toBeUndefined();
|
||||
disposableLogin.unsubscribe();
|
||||
done();
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 403,
|
||||
@@ -386,7 +380,6 @@ describe('AuthenticationService', () => {
|
||||
});
|
||||
|
||||
describe('when the setting is both ECM and BPM ', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
appConfigService.config.providers = 'ALL';
|
||||
appConfigService.load();
|
||||
@@ -426,7 +419,8 @@ describe('AuthenticationService', () => {
|
||||
expect(authService.isEcmLoggedIn()).toBe(false, 'isEcmLoggedIn');
|
||||
disposableLogin.unsubscribe();
|
||||
done();
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
jasmine.Ajax.requests.at(0).respondWith({
|
||||
status: 403
|
||||
@@ -447,7 +441,8 @@ describe('AuthenticationService', () => {
|
||||
expect(authService.isBpmLoggedIn()).toBe(false);
|
||||
disposableLogin.unsubscribe();
|
||||
done();
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
jasmine.Ajax.requests.at(0).respondWith({
|
||||
status: 201,
|
||||
@@ -471,7 +466,8 @@ describe('AuthenticationService', () => {
|
||||
expect(authService.isEcmLoggedIn()).toBe(false);
|
||||
disposableLogin.unsubscribe();
|
||||
done();
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
jasmine.Ajax.requests.at(0).respondWith({
|
||||
status: 403
|
||||
@@ -510,6 +506,5 @@ describe('AuthenticationService', () => {
|
||||
const username = authService.getUsername();
|
||||
expect(username).toEqual('john.petrucci');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
@@ -20,12 +20,10 @@ import { RedirectionModel } from '../models/redirection.model';
|
||||
import { Observable, Observer, ReplaySubject, throwError } from 'rxjs';
|
||||
import { AppConfigService, AppConfigValues } from '../../app-config/app-config.service';
|
||||
import { CookieService } from '../../common/services/cookie.service';
|
||||
import { LogService } from '../../common/services/log.service';
|
||||
import { AuthenticationServiceInterface } from '../interfaces/authentication-service.interface';
|
||||
import ee from 'event-emitter';
|
||||
|
||||
export abstract class BaseAuthenticationService implements AuthenticationServiceInterface, ee.Emitter {
|
||||
|
||||
on: ee.EmitterMethod;
|
||||
off: ee.EmitterMethod;
|
||||
once: ee.EmitterMethod;
|
||||
@@ -37,11 +35,7 @@ export abstract class BaseAuthenticationService implements AuthenticationService
|
||||
onLogin = new ReplaySubject<any>(1);
|
||||
onLogout = new ReplaySubject<any>(1);
|
||||
|
||||
constructor(
|
||||
protected appConfig: AppConfigService,
|
||||
protected cookie: CookieService,
|
||||
private logService: LogService
|
||||
) {
|
||||
protected constructor(protected appConfig: AppConfigService, protected cookie: CookieService) {
|
||||
ee(this);
|
||||
}
|
||||
|
||||
@@ -77,7 +71,6 @@ export abstract class BaseAuthenticationService implements AuthenticationService
|
||||
headers = new HttpHeaders();
|
||||
}
|
||||
try {
|
||||
|
||||
const header = this.getAuthHeaders(requestUrl, headers);
|
||||
|
||||
observer.next(header);
|
||||
@@ -130,7 +123,6 @@ export abstract class BaseAuthenticationService implements AuthenticationService
|
||||
*/
|
||||
handleError(error: any): Observable<any> {
|
||||
this.onError.next(error || 'Server error');
|
||||
this.logService.error('Error when logging in', error);
|
||||
return throwError(error || 'Server error');
|
||||
}
|
||||
|
||||
|
@@ -28,7 +28,6 @@ import {
|
||||
roleMappingMock
|
||||
} from '../mock/identity-group.mock';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { AdfHttpClient } from '../../../../api/src';
|
||||
|
||||
describe('IdentityGroupService', () => {
|
||||
@@ -38,10 +37,7 @@ describe('IdentityGroupService', () => {
|
||||
|
||||
beforeEach(fakeAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
service = TestBed.inject(IdentityGroupService);
|
||||
adfHttpClient = TestBed.inject(AdfHttpClient);
|
||||
@@ -50,7 +46,7 @@ describe('IdentityGroupService', () => {
|
||||
|
||||
it('should be able to fetch groups based on group name', (done) => {
|
||||
requestSpy.and.returnValue(Promise.resolve(mockIdentityGroups));
|
||||
service.findGroupsByName({name: 'mock'}).subscribe((res) => {
|
||||
service.findGroupsByName({ name: 'mock' }).subscribe((res) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).not.toBeNull();
|
||||
expect(res.length).toBe(5);
|
||||
@@ -84,142 +80,126 @@ describe('IdentityGroupService', () => {
|
||||
|
||||
it('should able to fetch group roles by groupId', (done) => {
|
||||
spyOn(service, 'getGroupRoles').and.returnValue(of(mockIdentityRoles));
|
||||
service.getGroupRoles('mock-group-id').subscribe(
|
||||
(res: any) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.length).toEqual(3);
|
||||
expect(res[0].name).toEqual('MOCK-ADMIN-ROLE');
|
||||
expect(res[1].name).toEqual('MOCK-USER-ROLE');
|
||||
expect(res[2].name).toEqual('MOCK-ROLE-1');
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.getGroupRoles('mock-group-id').subscribe((res: any) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.length).toEqual(3);
|
||||
expect(res[0].name).toEqual('MOCK-ADMIN-ROLE');
|
||||
expect(res[1].name).toEqual('MOCK-USER-ROLE');
|
||||
expect(res[2].name).toEqual('MOCK-ROLE-1');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Should not able to fetch group roles if error occurred', (done) => {
|
||||
const errorResponse = new HttpErrorResponse({
|
||||
error: 'Mock Error',
|
||||
status: 404, statusText: 'Not Found'
|
||||
status: 404,
|
||||
statusText: 'Not Found'
|
||||
});
|
||||
|
||||
spyOn(service, 'getGroupRoles').and.returnValue(throwError(errorResponse));
|
||||
|
||||
service.getGroupRoles('mock-group-id')
|
||||
.subscribe(
|
||||
() => {
|
||||
fail('expected an error, not group roles');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.getGroupRoles('mock-group-id').subscribe(
|
||||
() => {
|
||||
fail('expected an error, not group roles');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should return true if group has given role', (done) => {
|
||||
spyOn(service, 'getGroupRoles').and.returnValue(of(mockIdentityRoles));
|
||||
service.checkGroupHasRole('mock-group-id', ['MOCK-ADMIN-ROLE']).subscribe(
|
||||
(res: boolean) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).toBeTruthy();
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.checkGroupHasRole('mock-group-id', ['MOCK-ADMIN-ROLE']).subscribe((res: boolean) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false if group does not have given role', (done) => {
|
||||
spyOn(service, 'getGroupRoles').and.returnValue(of(mockIdentityRoles));
|
||||
service.checkGroupHasRole('mock-group-id', ['MOCK-ADMIN-MODELER']).subscribe(
|
||||
(res: boolean) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).toBeFalsy();
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.checkGroupHasRole('mock-group-id', ['MOCK-ADMIN-MODELER']).subscribe((res: boolean) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).toBeFalsy();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fetch client roles by groupId and clientId', (done) => {
|
||||
spyOn(service, 'getClientRoles').and.returnValue(of(clientRoles));
|
||||
service.getClientRoles('mock-group-id', 'mock-client-id').subscribe(
|
||||
(res: any) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.length).toEqual(2);
|
||||
expect(res).toEqual(clientRoles);
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.getClientRoles('mock-group-id', 'mock-client-id').subscribe((res: any) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.length).toEqual(2);
|
||||
expect(res).toEqual(clientRoles);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Should not fetch client roles if error occurred', (done) => {
|
||||
const errorResponse = new HttpErrorResponse({
|
||||
error: 'Mock Error',
|
||||
status: 404, statusText: 'Not Found'
|
||||
status: 404,
|
||||
statusText: 'Not Found'
|
||||
});
|
||||
|
||||
spyOn(service, 'getClientRoles').and.returnValue(throwError(errorResponse));
|
||||
|
||||
service.getClientRoles('mock-group-id', 'mock-client-id')
|
||||
.subscribe(
|
||||
() => {
|
||||
fail('expected an error, not client roles');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.getClientRoles('mock-group-id', 'mock-client-id').subscribe(
|
||||
() => {
|
||||
fail('expected an error, not client roles');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should return true if group has client access', (done) => {
|
||||
spyOn(service, 'getClientRoles').and.returnValue(of(clientRoles));
|
||||
service.checkGroupHasClientApp('mock-group-id', 'mock-client-id').subscribe(
|
||||
(res: boolean) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).toBeTruthy();
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.checkGroupHasClientApp('mock-group-id', 'mock-client-id').subscribe((res: boolean) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false if group does not have client access', (done) => {
|
||||
spyOn(service, 'getClientRoles').and.returnValue(of([]));
|
||||
service.checkGroupHasClientApp('mock-group-id', 'mock-client-id').subscribe(
|
||||
(res: boolean) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).toBeFalsy();
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.checkGroupHasClientApp('mock-group-id', 'mock-client-id').subscribe((res: boolean) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).toBeFalsy();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return true if group has any client role', (done) => {
|
||||
spyOn(service, 'checkGroupHasAnyClientAppRole').and.returnValue(of(true));
|
||||
service.checkGroupHasAnyClientAppRole('mock-group-id', 'mock-client-id', ['MOCK-USER-ROLE']).subscribe(
|
||||
(res: boolean) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).toBeTruthy();
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.checkGroupHasAnyClientAppRole('mock-group-id', 'mock-client-id', ['MOCK-USER-ROLE']).subscribe((res: boolean) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false if group does not have any client role', (done) => {
|
||||
spyOn(service, 'getClientRoles').and.returnValue(of([]));
|
||||
service.checkGroupHasAnyClientAppRole('mock-group-id', 'mock-client-id', ['MOCK-ADMIN-MODELER']).subscribe(
|
||||
(res: boolean) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).toBeFalsy();
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.checkGroupHasAnyClientAppRole('mock-group-id', 'mock-client-id', ['MOCK-ADMIN-MODELER']).subscribe((res: boolean) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).toBeFalsy();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to fetch the client id', (done) => {
|
||||
requestSpy.and.returnValue(Promise.resolve([{id: 'mock-app-id', name: 'mock-app-name'}]));
|
||||
requestSpy.and.returnValue(Promise.resolve([{ id: 'mock-app-id', name: 'mock-app-name' }]));
|
||||
service.getClientIdByApplicationName('mock-app-name').subscribe((clientId) => {
|
||||
expect(clientId).toBeDefined();
|
||||
expect(clientId).not.toBeNull();
|
||||
@@ -245,29 +225,29 @@ describe('IdentityGroupService', () => {
|
||||
it('Should not able to fetch all group if error occurred', (done) => {
|
||||
const errorResponse = new HttpErrorResponse({
|
||||
error: 'Mock Error',
|
||||
status: 404, statusText: 'Not Found'
|
||||
status: 404,
|
||||
statusText: 'Not Found'
|
||||
});
|
||||
|
||||
spyOn(service, 'getGroups').and.returnValue(throwError(errorResponse));
|
||||
|
||||
service.getGroups()
|
||||
.subscribe(
|
||||
() => {
|
||||
fail('expected an error, not groups');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.getGroups().subscribe(
|
||||
() => {
|
||||
fail('expected an error, not groups');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should be able to query groups based on first & max params', (done) => {
|
||||
spyOn(service, 'getTotalGroupsCount').and.returnValue(of(mockIdentityGroupsCount));
|
||||
requestSpy.and.returnValue(Promise.resolve(mockIdentityGroups));
|
||||
service.queryGroups({first: 0, max: 5}).subscribe((res) => {
|
||||
service.queryGroups({ first: 0, max: 5 }).subscribe((res) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).not.toBeNull();
|
||||
expect(res.entries.length).toBe(5);
|
||||
@@ -287,23 +267,23 @@ describe('IdentityGroupService', () => {
|
||||
it('Should not able to query groups if error occurred', (done) => {
|
||||
const errorResponse = new HttpErrorResponse({
|
||||
error: 'Mock Error',
|
||||
status: 404, statusText: 'Not Found'
|
||||
status: 404,
|
||||
statusText: 'Not Found'
|
||||
});
|
||||
|
||||
spyOn(service, 'queryGroups').and.returnValue(throwError(errorResponse));
|
||||
|
||||
service.queryGroups({first: 0, max: 5})
|
||||
.subscribe(
|
||||
() => {
|
||||
fail('expected an error, not query groups');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.queryGroups({ first: 0, max: 5 }).subscribe(
|
||||
() => {
|
||||
fail('expected an error, not query groups');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should be able to create group', (done) => {
|
||||
@@ -317,23 +297,23 @@ describe('IdentityGroupService', () => {
|
||||
it('Should not able to create group if error occurred', (done) => {
|
||||
const errorResponse = new HttpErrorResponse({
|
||||
error: 'Mock Error',
|
||||
status: 404, statusText: 'Not Found'
|
||||
status: 404,
|
||||
statusText: 'Not Found'
|
||||
});
|
||||
|
||||
spyOn(service, 'createGroup').and.returnValue(throwError(errorResponse));
|
||||
|
||||
service.createGroup(mockIdentityGroup1)
|
||||
.subscribe(
|
||||
() => {
|
||||
fail('expected an error, not to create group');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.createGroup(mockIdentityGroup1).subscribe(
|
||||
() => {
|
||||
fail('expected an error, not to create group');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should be able to update group', (done) => {
|
||||
@@ -347,23 +327,23 @@ describe('IdentityGroupService', () => {
|
||||
it('Should not able to update group if error occurred', (done) => {
|
||||
const errorResponse = new HttpErrorResponse({
|
||||
error: 'Mock Error',
|
||||
status: 404, statusText: 'Not Found'
|
||||
status: 404,
|
||||
statusText: 'Not Found'
|
||||
});
|
||||
|
||||
spyOn(service, 'updateGroup').and.returnValue(throwError(errorResponse));
|
||||
|
||||
service.updateGroup('mock-group-id', mockIdentityGroup1)
|
||||
.subscribe(
|
||||
() => {
|
||||
fail('expected an error, not to update group');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.updateGroup('mock-group-id', mockIdentityGroup1).subscribe(
|
||||
() => {
|
||||
fail('expected an error, not to update group');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should be able to delete group', (done) => {
|
||||
@@ -377,22 +357,22 @@ describe('IdentityGroupService', () => {
|
||||
it('Should not able to delete group if error occurred', (done) => {
|
||||
const errorResponse = new HttpErrorResponse({
|
||||
error: 'Mock Error',
|
||||
status: 404, statusText: 'Not Found'
|
||||
status: 404,
|
||||
statusText: 'Not Found'
|
||||
});
|
||||
|
||||
spyOn(service, 'deleteGroup').and.returnValue(throwError(errorResponse));
|
||||
|
||||
service.deleteGroup('mock-group-id')
|
||||
.subscribe(
|
||||
() => {
|
||||
fail('expected an error, not to delete group');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.deleteGroup('mock-group-id').subscribe(
|
||||
() => {
|
||||
fail('expected an error, not to delete group');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@@ -17,17 +17,16 @@
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { throwError as observableThrowError, Observable, of } from 'rxjs';
|
||||
import { catchError, map } from 'rxjs/operators';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { PaginationModel } from '../../models/pagination.model';
|
||||
import { IdentityRoleModel } from '../models/identity-role.model';
|
||||
import { AppConfigService } from '../../app-config/app-config.service';
|
||||
import { LogService } from '../../common/services/log.service';
|
||||
|
||||
export interface IdentityRoleResponseModel {
|
||||
entries: IdentityRoleModel[];
|
||||
pagination: PaginationModel;
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -36,11 +35,7 @@ export class IdentityRoleService {
|
||||
contextRoot = '';
|
||||
identityHost = '';
|
||||
|
||||
constructor(
|
||||
protected http: HttpClient,
|
||||
protected appConfig: AppConfigService,
|
||||
protected logService: LogService
|
||||
) {
|
||||
constructor(protected http: HttpClient, protected appConfig: AppConfigService) {
|
||||
this.contextRoot = this.appConfig.get('apiHost', '');
|
||||
this.identityHost = this.appConfig.get('identityHost');
|
||||
}
|
||||
@@ -52,21 +47,11 @@ export class IdentityRoleService {
|
||||
* @param size page size
|
||||
* @returns List of roles
|
||||
*/
|
||||
getRoles(
|
||||
skipCount: number = 0,
|
||||
size: number = 5
|
||||
): Observable<IdentityRoleResponseModel> {
|
||||
return this.http.get<any>(`${this.identityHost}/roles`).pipe(
|
||||
map(res => this.preparePaginationWithRoles(res, skipCount, size)),
|
||||
catchError(error => this.handleError(error))
|
||||
);
|
||||
getRoles(skipCount: number = 0, size: number = 5): Observable<IdentityRoleResponseModel> {
|
||||
return this.http.get<any>(`${this.identityHost}/roles`).pipe(map((res) => this.preparePaginationWithRoles(res, skipCount, size)));
|
||||
}
|
||||
|
||||
private preparePaginationWithRoles(
|
||||
roles: IdentityRoleModel[],
|
||||
skipCount: number = 0,
|
||||
size: number = 5
|
||||
): IdentityRoleResponseModel {
|
||||
private preparePaginationWithRoles(roles: IdentityRoleModel[], skipCount: number = 0, size: number = 5): IdentityRoleResponseModel {
|
||||
return {
|
||||
entries: roles.slice(skipCount, skipCount + size),
|
||||
pagination: {
|
||||
@@ -87,10 +72,7 @@ export class IdentityRoleService {
|
||||
*/
|
||||
addRole(newRole: IdentityRoleModel): Observable<any> {
|
||||
if (newRole) {
|
||||
const request = newRole;
|
||||
return this.http
|
||||
.post(`${this.identityHost}/roles`, request)
|
||||
.pipe(catchError(error => this.handleError(error)));
|
||||
return this.http.post(`${this.identityHost}/roles`, newRole);
|
||||
}
|
||||
return of();
|
||||
}
|
||||
@@ -102,9 +84,7 @@ export class IdentityRoleService {
|
||||
* @returns Server result payload
|
||||
*/
|
||||
deleteRole(deletedRole: IdentityRoleModel): Observable<any> {
|
||||
return this.http
|
||||
.delete(`${this.identityHost}/roles-by-id/${deletedRole.id}`)
|
||||
.pipe(catchError(error => this.handleError(error)));
|
||||
return this.http.delete(`${this.identityHost}/roles-by-id/${deletedRole.id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,21 +94,10 @@ export class IdentityRoleService {
|
||||
* @param roleId Role id
|
||||
* @returns Server result payload
|
||||
*/
|
||||
updateRole(
|
||||
updatedRole: IdentityRoleModel,
|
||||
roleId: string
|
||||
): Observable<any> {
|
||||
updateRole(updatedRole: IdentityRoleModel, roleId: string): Observable<any> {
|
||||
if (updatedRole && roleId) {
|
||||
const request = updatedRole;
|
||||
return this.http
|
||||
.put(`${this.identityHost}/roles-by-id/${roleId}`, request)
|
||||
.pipe(catchError(error => this.handleError(error)));
|
||||
return this.http.put(`${this.identityHost}/roles-by-id/${roleId}`, updatedRole);
|
||||
}
|
||||
return of();
|
||||
}
|
||||
|
||||
private handleError(error: any) {
|
||||
this.logService.error(error);
|
||||
return observableThrowError(error || 'Server error');
|
||||
}
|
||||
}
|
||||
|
@@ -33,18 +33,16 @@ import { JwtHelperService } from './jwt-helper.service';
|
||||
import { mockToken } from '../mock/jwt-helper.service.spec';
|
||||
import { IdentityRoleModel } from '../models/identity-role.model';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { AdfHttpClient } from '../../../../api/src';
|
||||
import { StorageService } from '../../common/services/storage.service';
|
||||
|
||||
describe('IdentityUserService', () => {
|
||||
|
||||
const mockRoles = [
|
||||
{ id: 'id-1', name: 'MOCK-ADMIN-ROLE'},
|
||||
{ id: 'id-2', name: 'MOCK-USER-ROLE'},
|
||||
{ id: 'id-1', name: 'MOCK-ADMIN-ROLE' },
|
||||
{ id: 'id-2', name: 'MOCK-USER-ROLE' },
|
||||
{ id: 'id-3', name: 'MOCK_MODELER-ROLE' },
|
||||
{ id: 'id-4', name: 'MOCK-ROLE-1' },
|
||||
{ id: 'id-5', name: 'MOCK-ROLE-2'}
|
||||
{ id: 'id-5', name: 'MOCK-ROLE-2' }
|
||||
];
|
||||
|
||||
let storageService: StorageService;
|
||||
@@ -54,10 +52,7 @@ describe('IdentityUserService', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
storageService = TestBed.inject(StorageService);
|
||||
service = TestBed.inject(IdentityUserService);
|
||||
@@ -87,111 +82,103 @@ describe('IdentityUserService', () => {
|
||||
|
||||
it('should fetch users ', (done) => {
|
||||
spyOn(service, 'getUsers').and.returnValue(of(mockIdentityUsers));
|
||||
service.getUsers().subscribe(
|
||||
res => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res[0].id).toEqual('mock-user-id-1');
|
||||
expect(res[0].username).toEqual('userName1');
|
||||
expect(res[1].id).toEqual('mock-user-id-2');
|
||||
expect(res[1].username).toEqual('userName2');
|
||||
expect(res[2].id).toEqual('mock-user-id-3');
|
||||
expect(res[2].username).toEqual('userName3');
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.getUsers().subscribe((res) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res[0].id).toEqual('mock-user-id-1');
|
||||
expect(res[0].username).toEqual('userName1');
|
||||
expect(res[1].id).toEqual('mock-user-id-2');
|
||||
expect(res[1].username).toEqual('userName2');
|
||||
expect(res[2].id).toEqual('mock-user-id-3');
|
||||
expect(res[2].username).toEqual('userName3');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Should not fetch users if error occurred', (done) => {
|
||||
const errorResponse = new HttpErrorResponse({
|
||||
error: 'Mock Error',
|
||||
status: 404, statusText: 'Not Found'
|
||||
status: 404,
|
||||
statusText: 'Not Found'
|
||||
});
|
||||
|
||||
spyOn(service, 'getUsers').and.returnValue(throwError(errorResponse));
|
||||
service.getUsers()
|
||||
.subscribe(
|
||||
() => {
|
||||
fail('expected an error, not users');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should fetch roles by userId', (done) => {
|
||||
spyOn(service, 'getUserRoles').and.returnValue(of(mockRoles));
|
||||
service.getUserRoles('mock-user-id').subscribe(
|
||||
(res: IdentityRoleModel[]) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res[0].name).toEqual('MOCK-ADMIN-ROLE');
|
||||
expect(res[1].name).toEqual('MOCK-USER-ROLE');
|
||||
expect(res[4].name).toEqual('MOCK-ROLE-2');
|
||||
service.getUsers().subscribe(
|
||||
() => {
|
||||
fail('expected an error, not users');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should fetch roles by userId', (done) => {
|
||||
spyOn(service, 'getUserRoles').and.returnValue(of(mockRoles));
|
||||
service.getUserRoles('mock-user-id').subscribe((res: IdentityRoleModel[]) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res[0].name).toEqual('MOCK-ADMIN-ROLE');
|
||||
expect(res[1].name).toEqual('MOCK-USER-ROLE');
|
||||
expect(res[4].name).toEqual('MOCK-ROLE-2');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Should not fetch roles if error occurred', (done) => {
|
||||
const errorResponse = new HttpErrorResponse({
|
||||
error: 'Mock Error',
|
||||
status: 404, statusText: 'Not Found'
|
||||
status: 404,
|
||||
statusText: 'Not Found'
|
||||
});
|
||||
|
||||
spyOn(service, 'getUserRoles').and.returnValue(throwError(errorResponse));
|
||||
|
||||
service.getUserRoles('mock-user-id')
|
||||
.subscribe(
|
||||
() => {
|
||||
fail('expected an error, not users');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.getUserRoles('mock-user-id').subscribe(
|
||||
() => {
|
||||
fail('expected an error, not users');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should fetch users by roles', (done) => {
|
||||
spyOn(service, 'getUsers').and.returnValue(of(mockIdentityUsers));
|
||||
spyOn(service, 'getUserRoles').and.returnValue(of(mockRoles));
|
||||
|
||||
service.getUsersByRolesWithCurrentUser([mockRoles[0].name]).then(
|
||||
res => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res[0].id).toEqual('mock-user-id-1');
|
||||
expect(res[0].username).toEqual('userName1');
|
||||
expect(res[1].id).toEqual('mock-user-id-2');
|
||||
expect(res[1].username).toEqual('userName2');
|
||||
expect(res[2].id).toEqual('mock-user-id-3');
|
||||
expect(res[2].username).toEqual('userName3');
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.getUsersByRolesWithCurrentUser([mockRoles[0].name]).then((res) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res[0].id).toEqual('mock-user-id-1');
|
||||
expect(res[0].username).toEqual('userName1');
|
||||
expect(res[1].id).toEqual('mock-user-id-2');
|
||||
expect(res[1].username).toEqual('userName2');
|
||||
expect(res[2].id).toEqual('mock-user-id-3');
|
||||
expect(res[2].username).toEqual('userName3');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Should not fetch users by roles if error occurred', (done) => {
|
||||
const errorResponse = new HttpErrorResponse({
|
||||
error: 'Mock Error',
|
||||
status: 404, statusText: 'Not Found'
|
||||
status: 404,
|
||||
statusText: 'Not Found'
|
||||
});
|
||||
|
||||
spyOn(service, 'getUsers').and.returnValue(throwError(errorResponse));
|
||||
|
||||
service.getUsersByRolesWithCurrentUser([mockRoles[0].name])
|
||||
.catch(
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.getUsersByRolesWithCurrentUser([mockRoles[0].name]).catch((error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fetch users by roles without current user', (done) => {
|
||||
@@ -199,91 +186,77 @@ describe('IdentityUserService', () => {
|
||||
spyOn(service, 'getUserRoles').and.returnValue(of(mockRoles));
|
||||
spyOn(service, 'getCurrentUserInfo').and.returnValue(mockIdentityUsers[0]);
|
||||
|
||||
service.getUsersByRolesWithoutCurrentUser([mockRoles[0].name]).then(
|
||||
res => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res[0].id).toEqual('mock-user-id-2');
|
||||
expect(res[0].username).toEqual('userName2');
|
||||
expect(res[1].id).toEqual('mock-user-id-3');
|
||||
expect(res[1].username).toEqual('userName3');
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.getUsersByRolesWithoutCurrentUser([mockRoles[0].name]).then((res) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res[0].id).toEqual('mock-user-id-2');
|
||||
expect(res[0].username).toEqual('userName2');
|
||||
expect(res[1].id).toEqual('mock-user-id-3');
|
||||
expect(res[1].username).toEqual('userName3');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return true when user has access to an application', (done) => {
|
||||
spyOn(service, 'getClientIdByApplicationName').and.returnValue(of('mock-client'));
|
||||
spyOn(service, 'getClientRoles').and.returnValue(of(mockRoles));
|
||||
|
||||
service.checkUserHasClientApp('user-id', 'app-name').subscribe(
|
||||
(res: boolean) => {
|
||||
expect(res).toBeTruthy();
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.checkUserHasClientApp('user-id', 'app-name').subscribe((res: boolean) => {
|
||||
expect(res).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false when user does not have access to an application', (done) => {
|
||||
spyOn(service, 'getClientIdByApplicationName').and.returnValue(of('mock-client'));
|
||||
spyOn(service, 'getClientRoles').and.returnValue(of([]));
|
||||
|
||||
service.checkUserHasClientApp('user-id', 'app-name').subscribe(
|
||||
(res: boolean) => {
|
||||
expect(res).toBeFalsy();
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.checkUserHasClientApp('user-id', 'app-name').subscribe((res: boolean) => {
|
||||
expect(res).toBeFalsy();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return true when user has any given application role', (done) => {
|
||||
spyOn(service, 'getClientIdByApplicationName').and.returnValue(of('mock-client'));
|
||||
spyOn(service, 'getClientRoles').and.returnValue(of(mockRoles));
|
||||
|
||||
service.checkUserHasAnyClientAppRole('user-id', 'app-name', [mockRoles[1].name] ).subscribe(
|
||||
(res: boolean) => {
|
||||
expect(res).toBeTruthy();
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.checkUserHasAnyClientAppRole('user-id', 'app-name', [mockRoles[1].name]).subscribe((res: boolean) => {
|
||||
expect(res).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false when user does not have any given application role', (done) => {
|
||||
spyOn(service, 'getClientIdByApplicationName').and.returnValue(of('mock-client'));
|
||||
spyOn(service, 'getClientRoles').and.returnValue(of([]));
|
||||
|
||||
service.checkUserHasAnyClientAppRole('user-id', 'app-name', [mockRoles[1].name]).subscribe(
|
||||
(res: boolean) => {
|
||||
expect(res).toBeFalsy();
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.checkUserHasAnyClientAppRole('user-id', 'app-name', [mockRoles[1].name]).subscribe((res: boolean) => {
|
||||
expect(res).toBeFalsy();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return true if user has given role', (done) => {
|
||||
spyOn(service, 'getUserRoles').and.returnValue(of(mockRoles));
|
||||
service.checkUserHasRole('mock-user-id', ['MOCK-ROLE-1']).subscribe(
|
||||
(res: boolean) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).toBeTruthy();
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.checkUserHasRole('mock-user-id', ['MOCK-ROLE-1']).subscribe((res: boolean) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false if user does not have given role', (done) => {
|
||||
spyOn(service, 'getUserRoles').and.returnValue(of(mockRoles));
|
||||
service.checkUserHasRole('mock-user-id', ['MOCK-ROLE-10']).subscribe(
|
||||
(res: boolean) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).toBeFalsy();
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.checkUserHasRole('mock-user-id', ['MOCK-ROLE-10']).subscribe((res: boolean) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).toBeFalsy();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to query users based on query params (first & max params)', (done) => {
|
||||
requestSpy.and.returnValue(Promise.resolve(mockIdentityUsers));
|
||||
service.queryUsers({first: 0, max: 5}).subscribe((res) => {
|
||||
service.queryUsers({ first: 0, max: 5 }).subscribe((res) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).not.toBeNull();
|
||||
expect(res.entries.length).toBe(5);
|
||||
@@ -300,23 +273,23 @@ describe('IdentityUserService', () => {
|
||||
it('Should not be able to query users if error occurred', (done) => {
|
||||
const errorResponse = new HttpErrorResponse({
|
||||
error: 'Mock Error',
|
||||
status: 404, statusText: 'Not Found'
|
||||
status: 404,
|
||||
statusText: 'Not Found'
|
||||
});
|
||||
|
||||
spyOn(service, 'queryUsers').and.returnValue(throwError(errorResponse));
|
||||
|
||||
service.queryUsers({first: 0, max: 5})
|
||||
.subscribe(
|
||||
() => {
|
||||
fail('expected an error, not users');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.queryUsers({ first: 0, max: 5 }).subscribe(
|
||||
() => {
|
||||
fail('expected an error, not users');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should be able to create user', (done) => {
|
||||
@@ -330,23 +303,23 @@ describe('IdentityUserService', () => {
|
||||
it('Should not able to create user if error occurred', (done) => {
|
||||
const errorResponse = new HttpErrorResponse({
|
||||
error: 'Mock Error',
|
||||
status: 404, statusText: 'Not Found'
|
||||
status: 404,
|
||||
statusText: 'Not Found'
|
||||
});
|
||||
|
||||
spyOn(service, 'createUser').and.returnValue(throwError(errorResponse));
|
||||
|
||||
service.createUser(mockIdentityUser1)
|
||||
.subscribe(
|
||||
() => {
|
||||
fail('expected an error, not to create user');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.createUser(mockIdentityUser1).subscribe(
|
||||
() => {
|
||||
fail('expected an error, not to create user');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should be able to update user', (done) => {
|
||||
@@ -360,23 +333,23 @@ describe('IdentityUserService', () => {
|
||||
it('Should not able to update user if error occurred', (done) => {
|
||||
const errorResponse = new HttpErrorResponse({
|
||||
error: 'Mock Error',
|
||||
status: 404, statusText: 'Not Found'
|
||||
status: 404,
|
||||
statusText: 'Not Found'
|
||||
});
|
||||
|
||||
spyOn(service, 'updateUser').and.returnValue(throwError(errorResponse));
|
||||
|
||||
service.updateUser('mock-id-2', mockIdentityUser2)
|
||||
.subscribe(
|
||||
() => {
|
||||
fail('expected an error, not to update user');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.updateUser('mock-id-2', mockIdentityUser2).subscribe(
|
||||
() => {
|
||||
fail('expected an error, not to update user');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should be able to delete group', (done) => {
|
||||
@@ -390,23 +363,23 @@ describe('IdentityUserService', () => {
|
||||
it('Should not able to delete user if error occurred', (done) => {
|
||||
const errorResponse = new HttpErrorResponse({
|
||||
error: 'Mock Error',
|
||||
status: 404, statusText: 'Not Found'
|
||||
status: 404,
|
||||
statusText: 'Not Found'
|
||||
});
|
||||
|
||||
spyOn(service, 'deleteUser').and.returnValue(throwError(errorResponse));
|
||||
|
||||
service.deleteUser('mock-user-id')
|
||||
.subscribe(
|
||||
() => {
|
||||
fail('expected an error, not to delete user');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.deleteUser('mock-user-id').subscribe(
|
||||
() => {
|
||||
fail('expected an error, not to delete user');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should be able to fetch involved groups based on user id', (done) => {
|
||||
@@ -426,23 +399,23 @@ describe('IdentityUserService', () => {
|
||||
it('Should not be able to fetch involved groups if error occurred', (done) => {
|
||||
const errorResponse = new HttpErrorResponse({
|
||||
error: 'Mock Error',
|
||||
status: 404, statusText: 'Not Found'
|
||||
status: 404,
|
||||
statusText: 'Not Found'
|
||||
});
|
||||
|
||||
spyOn(service, 'getInvolvedGroups').and.returnValue(throwError(errorResponse));
|
||||
|
||||
service.getInvolvedGroups('mock-user-id')
|
||||
.subscribe(
|
||||
() => {
|
||||
fail('expected an error, not involved groups');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.getInvolvedGroups('mock-user-id').subscribe(
|
||||
() => {
|
||||
fail('expected an error, not involved groups');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should be able to join the group', (done) => {
|
||||
@@ -456,23 +429,23 @@ describe('IdentityUserService', () => {
|
||||
it('Should not able to join group if error occurred', (done) => {
|
||||
const errorResponse = new HttpErrorResponse({
|
||||
error: 'Mock Error',
|
||||
status: 404, statusText: 'Not Found'
|
||||
status: 404,
|
||||
statusText: 'Not Found'
|
||||
});
|
||||
|
||||
spyOn(service, 'joinGroup').and.returnValue(throwError(errorResponse));
|
||||
|
||||
service.joinGroup(mockJoinGroupRequest)
|
||||
.subscribe(
|
||||
() => {
|
||||
fail('expected an error, not to join group');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.joinGroup(mockJoinGroupRequest).subscribe(
|
||||
() => {
|
||||
fail('expected an error, not to join group');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should be able to leave the group', (done) => {
|
||||
@@ -486,23 +459,23 @@ describe('IdentityUserService', () => {
|
||||
it('Should not able to leave group if error occurred', (done) => {
|
||||
const errorResponse = new HttpErrorResponse({
|
||||
error: 'Mock Error',
|
||||
status: 404, statusText: 'Not Found'
|
||||
status: 404,
|
||||
statusText: 'Not Found'
|
||||
});
|
||||
|
||||
spyOn(service, 'leaveGroup').and.returnValue(throwError(errorResponse));
|
||||
|
||||
service.leaveGroup('mock-user-id', 'mock-group-id')
|
||||
.subscribe(
|
||||
() => {
|
||||
fail('expected an error, not to leave group');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.leaveGroup('mock-user-id', 'mock-group-id').subscribe(
|
||||
() => {
|
||||
fail('expected an error, not to leave group');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should be able to fetch available roles based on user id', (done) => {
|
||||
@@ -524,23 +497,23 @@ describe('IdentityUserService', () => {
|
||||
it('Should not be able to fetch available roles based on user id if error occurred', (done) => {
|
||||
const errorResponse = new HttpErrorResponse({
|
||||
error: 'Mock Error',
|
||||
status: 404, statusText: 'Not Found'
|
||||
status: 404,
|
||||
statusText: 'Not Found'
|
||||
});
|
||||
|
||||
spyOn(service, 'getAvailableRoles').and.returnValue(throwError(errorResponse));
|
||||
|
||||
service.getAvailableRoles('mock-user-id')
|
||||
.subscribe(
|
||||
() => {
|
||||
fail('expected an error, not available roles');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.getAvailableRoles('mock-user-id').subscribe(
|
||||
() => {
|
||||
fail('expected an error, not available roles');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should be able to fetch assigned roles based on user id', (done) => {
|
||||
@@ -562,23 +535,23 @@ describe('IdentityUserService', () => {
|
||||
it('Should not be able to fetch assigned roles based on user id if error occurred', (done) => {
|
||||
const errorResponse = new HttpErrorResponse({
|
||||
error: 'Mock Error',
|
||||
status: 404, statusText: 'Not Found'
|
||||
status: 404,
|
||||
statusText: 'Not Found'
|
||||
});
|
||||
|
||||
spyOn(service, 'getAssignedRoles').and.returnValue(throwError(errorResponse));
|
||||
|
||||
service.getAssignedRoles('mock-user-id')
|
||||
.subscribe(
|
||||
() => {
|
||||
fail('expected an error, not assigned roles');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.getAssignedRoles('mock-user-id').subscribe(
|
||||
() => {
|
||||
fail('expected an error, not assigned roles');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should be able to fetch effective roles based on user id', (done) => {
|
||||
@@ -600,23 +573,23 @@ describe('IdentityUserService', () => {
|
||||
it('Should not be able to fetch effective roles based on user id if error occurred', (done) => {
|
||||
const errorResponse = new HttpErrorResponse({
|
||||
error: 'Mock Error',
|
||||
status: 404, statusText: 'Not Found'
|
||||
status: 404,
|
||||
statusText: 'Not Found'
|
||||
});
|
||||
|
||||
spyOn(service, 'getEffectiveRoles').and.returnValue(throwError(errorResponse));
|
||||
|
||||
service.getEffectiveRoles('mock-user-id')
|
||||
.subscribe(
|
||||
() => {
|
||||
fail('expected an error, not effective roles');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.getEffectiveRoles('mock-user-id').subscribe(
|
||||
() => {
|
||||
fail('expected an error, not effective roles');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should be able to assign roles to the user', (done) => {
|
||||
@@ -630,23 +603,23 @@ describe('IdentityUserService', () => {
|
||||
it('Should not able to assign roles to the user if error occurred', (done) => {
|
||||
const errorResponse = new HttpErrorResponse({
|
||||
error: 'Mock Error',
|
||||
status: 404, statusText: 'Not Found'
|
||||
status: 404,
|
||||
statusText: 'Not Found'
|
||||
});
|
||||
|
||||
spyOn(service, 'assignRoles').and.returnValue(throwError(errorResponse));
|
||||
|
||||
service.assignRoles('mock-user-id', [mockIdentityRole])
|
||||
.subscribe(
|
||||
() => {
|
||||
fail('expected an error, not to assigen roles to the user');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.assignRoles('mock-user-id', [mockIdentityRole]).subscribe(
|
||||
() => {
|
||||
fail('expected an error, not to assigen roles to the user');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should be able to remove roles', (done) => {
|
||||
@@ -660,22 +633,22 @@ describe('IdentityUserService', () => {
|
||||
it('Should not able to remove roles if error occurred', (done) => {
|
||||
const errorResponse = new HttpErrorResponse({
|
||||
error: 'Mock Error',
|
||||
status: 404, statusText: 'Not Found'
|
||||
status: 404,
|
||||
statusText: 'Not Found'
|
||||
});
|
||||
|
||||
spyOn(service, 'removeRoles').and.returnValue(throwError(errorResponse));
|
||||
|
||||
service.removeRoles('mock-user-id', [mockIdentityRole])
|
||||
.subscribe(
|
||||
() => {
|
||||
fail('expected an error, not to remove roles');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
service.removeRoles('mock-user-id', [mockIdentityRole]).subscribe(
|
||||
() => {
|
||||
fail('expected an error, not to remove roles');
|
||||
},
|
||||
(error) => {
|
||||
expect(error.status).toEqual(404);
|
||||
expect(error.statusText).toEqual('Not Found');
|
||||
expect(error.error).toEqual('Mock Error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@@ -24,7 +24,6 @@ import { OauthConfigModel } from '../models/oauth-config.model';
|
||||
import { BaseAuthenticationService } from './base-authentication.service';
|
||||
import { CookieService } from '../../common/services/cookie.service';
|
||||
import { JwtHelperService } from './jwt-helper.service';
|
||||
import { LogService } from '../../common/services/log.service';
|
||||
import { AuthConfigService } from '../oidc/auth-config.service';
|
||||
import { AuthService } from '../oidc/auth.service';
|
||||
import { Minimatch } from 'minimatch';
|
||||
@@ -34,18 +33,16 @@ import { HttpHeaders } from '@angular/common/http';
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class OidcAuthenticationService extends BaseAuthenticationService {
|
||||
|
||||
constructor(
|
||||
appConfig: AppConfigService,
|
||||
cookie: CookieService,
|
||||
logService: LogService,
|
||||
private jwtHelperService: JwtHelperService,
|
||||
private authStorage: OAuthStorage,
|
||||
private oauthService: OAuthService,
|
||||
private readonly authConfig: AuthConfigService,
|
||||
private readonly auth: AuthService
|
||||
) {
|
||||
super(appConfig, cookie, logService);
|
||||
super(appConfig, cookie);
|
||||
}
|
||||
|
||||
isEcmLoggedIn(): boolean {
|
||||
@@ -53,7 +50,6 @@ export class OidcAuthenticationService extends BaseAuthenticationService {
|
||||
return this.isLoggedIn();
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
isBpmLoggedIn(): boolean {
|
||||
@@ -118,7 +114,7 @@ export class OidcAuthenticationService extends BaseAuthenticationService {
|
||||
});
|
||||
}
|
||||
|
||||
getUsername(){
|
||||
getUsername() {
|
||||
return this.jwtHelperService.getValueFromLocalToken<string>(JwtHelperService.USER_PREFERRED_USERNAME);
|
||||
}
|
||||
|
||||
@@ -169,11 +165,13 @@ export class OidcAuthenticationService extends BaseAuthenticationService {
|
||||
const oauth2 = this.appConfig.get<OauthConfigModel>(AppConfigValues.OAUTHCONFIG, null);
|
||||
|
||||
if (Array.isArray(oauth2.publicUrls)) {
|
||||
return oauth2.publicUrls.length > 0 &&
|
||||
return (
|
||||
oauth2.publicUrls.length > 0 &&
|
||||
oauth2.publicUrls.some((urlPattern: string) => {
|
||||
const minimatch = new Minimatch(urlPattern);
|
||||
return minimatch.match(window.location.href);
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -219,5 +217,4 @@ export class OidcAuthenticationService extends BaseAuthenticationService {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -19,20 +19,16 @@ import { TestBed, ComponentFixture } from '@angular/core/testing';
|
||||
import { MaterialModule } from '../material.module';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { CUSTOM_ELEMENTS_SCHEMA, Component } from '@angular/core';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-custom-container',
|
||||
template: `
|
||||
<adf-buttons-action-menu>
|
||||
<button mat-menu-item (click)="assignValue()">
|
||||
<mat-icon>settings</mat-icon><span> Button </span>
|
||||
</button>
|
||||
<button mat-menu-item (click)="assignValue()"><mat-icon>settings</mat-icon><span> Button </span></button>
|
||||
</adf-buttons-action-menu>
|
||||
`
|
||||
})
|
||||
export class CustomContainerComponent {
|
||||
|
||||
value: number;
|
||||
|
||||
assignValue() {
|
||||
@@ -42,35 +38,21 @@ export class CustomContainerComponent {
|
||||
|
||||
@Component({
|
||||
selector: 'adf-custom-empty-container',
|
||||
template: `
|
||||
<adf-buttons-action-menu>
|
||||
</adf-buttons-action-menu>
|
||||
`
|
||||
template: `<adf-buttons-action-menu></adf-buttons-action-menu>`
|
||||
})
|
||||
export class CustomEmptyContainerComponent {
|
||||
}
|
||||
export class CustomEmptyContainerComponent {}
|
||||
|
||||
describe('ButtonsMenuComponent', () => {
|
||||
|
||||
describe('When Buttons are injected', () => {
|
||||
|
||||
let fixture: ComponentFixture<CustomContainerComponent>;
|
||||
let component: CustomContainerComponent;
|
||||
let element: HTMLElement;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule,
|
||||
MaterialModule
|
||||
],
|
||||
declarations: [
|
||||
CustomContainerComponent
|
||||
],
|
||||
schemas: [
|
||||
CUSTOM_ELEMENTS_SCHEMA
|
||||
]
|
||||
imports: [CoreTestingModule, MaterialModule],
|
||||
declarations: [CustomContainerComponent],
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
});
|
||||
fixture = TestBed.createComponent(CustomContainerComponent);
|
||||
element = fixture.debugElement.nativeElement;
|
||||
@@ -111,17 +93,9 @@ describe('ButtonsMenuComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule,
|
||||
MaterialModule
|
||||
],
|
||||
declarations: [
|
||||
CustomEmptyContainerComponent
|
||||
],
|
||||
schemas: [
|
||||
CUSTOM_ELEMENTS_SCHEMA
|
||||
]
|
||||
imports: [CoreTestingModule, MaterialModule],
|
||||
declarations: [CustomEmptyContainerComponent],
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
});
|
||||
fixture = TestBed.createComponent(CustomEmptyContainerComponent);
|
||||
element = fixture.nativeElement;
|
||||
|
@@ -21,7 +21,6 @@ import { CoreTestingModule } from '../../../testing/core.testing.module';
|
||||
import { CardViewArrayItemComponent } from './card-view-arrayitem.component';
|
||||
import { CardViewArrayItemModel, CardViewArrayItem } from '../../models/card-view-arrayitem.model';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { CardViewUpdateService } from '../../services/card-view-update.service';
|
||||
import { HarnessLoader } from '@angular/cdk/testing';
|
||||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||
@@ -52,7 +51,7 @@ describe('CardViewArrayItemComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), CoreTestingModule]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(CardViewArrayItemComponent);
|
||||
service = TestBed.inject(CardViewUpdateService);
|
||||
|
@@ -22,19 +22,14 @@ import { CardViewUpdateService } from '../../services/card-view-update.service';
|
||||
import { CardViewBoolItemComponent } from './card-view-boolitem.component';
|
||||
import { CardViewBoolItemModel } from '../../models/card-view-boolitem.model';
|
||||
import { CoreTestingModule } from '../../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('CardViewBoolItemComponent', () => {
|
||||
|
||||
let fixture: ComponentFixture<CardViewBoolItemComponent>;
|
||||
let component: CardViewBoolItemComponent;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(CardViewBoolItemComponent);
|
||||
component = fixture.componentInstance;
|
||||
@@ -52,7 +47,6 @@ describe('CardViewBoolItemComponent', () => {
|
||||
});
|
||||
|
||||
describe('Rendering', () => {
|
||||
|
||||
it('should render the label and value if the property is editable', () => {
|
||||
component.editable = true;
|
||||
component.property.editable = true;
|
||||
@@ -169,7 +163,6 @@ describe('CardViewBoolItemComponent', () => {
|
||||
});
|
||||
|
||||
describe('Update', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
component.editable = true;
|
||||
component.property.editable = true;
|
||||
@@ -180,7 +173,7 @@ describe('CardViewBoolItemComponent', () => {
|
||||
it('should trigger the update event when changing the checkbox', () => {
|
||||
const cardViewUpdateService = TestBed.inject(CardViewUpdateService);
|
||||
spyOn(cardViewUpdateService, 'update');
|
||||
const property = { ... component.property };
|
||||
const property = { ...component.property };
|
||||
|
||||
component.changed({ checked: true } as MatCheckboxChange);
|
||||
|
||||
@@ -204,14 +197,12 @@ describe('CardViewBoolItemComponent', () => {
|
||||
fixture.detectChanges();
|
||||
const property = { ...component.property };
|
||||
|
||||
const disposableUpdate = cardViewUpdateService.itemUpdated$.subscribe(
|
||||
(updateNotification) => {
|
||||
expect(updateNotification.target).toEqual(property);
|
||||
expect(updateNotification.changed).toEqual({ boolKey: true });
|
||||
disposableUpdate.unsubscribe();
|
||||
done();
|
||||
}
|
||||
);
|
||||
const disposableUpdate = cardViewUpdateService.itemUpdated$.subscribe((updateNotification) => {
|
||||
expect(updateNotification.target).toEqual(property);
|
||||
expect(updateNotification.changed).toEqual({ boolKey: true });
|
||||
disposableUpdate.unsubscribe();
|
||||
done();
|
||||
});
|
||||
|
||||
const labelElement = fixture.debugElement.query(By.directive(MatCheckbox)).nativeElement.querySelector('label');
|
||||
labelElement.click();
|
||||
|
@@ -24,6 +24,7 @@ import { CoreTestingModule } from '../../../testing/core.testing.module';
|
||||
import { ClipboardService } from '../../../clipboard/clipboard.service';
|
||||
import { CardViewDatetimeItemModel } from '../../models/card-view-datetimeitem.model';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { AppConfigService } from '../../../app-config/app-config.service';
|
||||
import { MatDatetimepickerInputEvent } from '@mat-datetimepicker/core';
|
||||
import { HarnessLoader } from '@angular/cdk/testing';
|
||||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||
@@ -33,11 +34,18 @@ describe('CardViewDateItemComponent', () => {
|
||||
let loader: HarnessLoader;
|
||||
let fixture: ComponentFixture<CardViewDateItemComponent>;
|
||||
let component: CardViewDateItemComponent;
|
||||
let appConfigService: AppConfigService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), CoreTestingModule]
|
||||
});
|
||||
appConfigService = TestBed.inject(AppConfigService);
|
||||
appConfigService.config.dateValues = {
|
||||
defaultDateFormat: 'shortDate',
|
||||
defaultDateTimeFormat: 'M/d/yy, h:mm a',
|
||||
defaultLocale: 'uk'
|
||||
};
|
||||
|
||||
fixture = TestBed.createComponent(CardViewDateItemComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
@@ -21,10 +21,8 @@ import { CardViewKeyValuePairsItemModel } from '../../models/card-view-keyvaluep
|
||||
import { CardViewKeyValuePairsItemComponent } from './card-view-keyvaluepairsitem.component';
|
||||
import { CoreTestingModule } from '../../../testing/core.testing.module';
|
||||
import { CardViewUpdateService } from '../../services/card-view-update.service';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('CardViewKeyValuePairsItemComponent', () => {
|
||||
|
||||
let fixture: ComponentFixture<CardViewKeyValuePairsItemComponent>;
|
||||
let component: CardViewKeyValuePairsItemComponent;
|
||||
let cardViewUpdateService: CardViewUpdateService;
|
||||
@@ -33,10 +31,7 @@ describe('CardViewKeyValuePairsItemComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(CardViewKeyValuePairsItemComponent);
|
||||
cardViewUpdateService = TestBed.inject(CardViewUpdateService);
|
||||
@@ -55,7 +50,6 @@ describe('CardViewKeyValuePairsItemComponent', () => {
|
||||
});
|
||||
|
||||
describe('Component', () => {
|
||||
|
||||
it('should render the label', () => {
|
||||
fixture.detectChanges();
|
||||
|
||||
@@ -122,5 +116,5 @@ describe('CardViewKeyValuePairsItemComponent', () => {
|
||||
expect(cardViewUpdateService.update).toHaveBeenCalled();
|
||||
expect(component.property.value.length).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -22,7 +22,6 @@ import { CardViewMapItemModel } from '../../models/card-view-mapitem.model';
|
||||
import { CardViewUpdateService } from '../../services/card-view-update.service';
|
||||
import { CardViewMapItemComponent } from './card-view-mapitem.component';
|
||||
import { CoreTestingModule } from '../../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('CardViewMapItemComponent', () => {
|
||||
let service: CardViewUpdateService;
|
||||
@@ -34,10 +33,7 @@ describe('CardViewMapItemComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(CardViewMapItemComponent);
|
||||
service = TestBed.inject(CardViewUpdateService);
|
||||
|
@@ -21,7 +21,6 @@ import { CardViewSelectItemModel } from '../../models/card-view-selectitem.model
|
||||
import { CardViewSelectItemComponent } from './card-view-selectitem.component';
|
||||
import { CoreTestingModule } from '../../../testing/core.testing.module';
|
||||
import { of } from 'rxjs';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { AppConfigService } from '../../../app-config/app-config.service';
|
||||
import { HarnessLoader } from '@angular/cdk/testing';
|
||||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||
@@ -60,7 +59,7 @@ describe('CardViewSelectItemComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), CoreTestingModule]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(CardViewSelectItemComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
@@ -17,7 +17,6 @@
|
||||
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { CoreTestingModule } from '../../../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { SelectFilterInputComponent } from './select-filter-input.component';
|
||||
import { MatSelect } from '@angular/material/select';
|
||||
|
||||
@@ -28,7 +27,7 @@ describe('SelectFilterInputComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), CoreTestingModule],
|
||||
imports: [CoreTestingModule],
|
||||
providers: [MatSelect]
|
||||
});
|
||||
|
||||
|
@@ -28,7 +28,6 @@ import { CardViewFloatItemModel } from '../../models/card-view-floatitem.model';
|
||||
import { MatChipInputEvent, MatChipsModule } from '@angular/material/chips';
|
||||
import { ClipboardService } from '../../../clipboard/clipboard.service';
|
||||
import { DebugElement, SimpleChange } from '@angular/core';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { CardViewItemValidator } from '../../interfaces/card-view-item-validator.interface';
|
||||
import { HarnessLoader } from '@angular/cdk/testing';
|
||||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||
@@ -113,7 +112,7 @@ describe('CardViewTextItemComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), CoreTestingModule, MatChipsModule]
|
||||
imports: [CoreTestingModule, MatChipsModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(CardViewTextItemComponent);
|
||||
component = fixture.componentInstance;
|
||||
@@ -536,7 +535,9 @@ describe('CardViewTextItemComponent', () => {
|
||||
component.ngOnChanges({});
|
||||
|
||||
loader = TestbedHarnessEnvironment.loader(fixture);
|
||||
const inputHarness = await loader.getHarness(MatInputHarness.with({selector: `[data-automation-id="card-textitem-value-${component.property.key}"]`}));
|
||||
const inputHarness = await loader.getHarness(
|
||||
MatInputHarness.with({ selector: `[data-automation-id="card-textitem-value-${component.property.key}"]` })
|
||||
);
|
||||
|
||||
expect(component.isEditable).toBe(false);
|
||||
expect(await inputHarness.isReadonly()).toBe(true);
|
||||
|
@@ -21,7 +21,6 @@ import { CardViewDateItemModel } from '../../models/card-view-dateitem.model';
|
||||
import { CardViewTextItemModel } from '../../models/card-view-textitem.model';
|
||||
import { CardViewComponent } from './card-view.component';
|
||||
import { CoreTestingModule } from '../../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { CardViewSelectItemModel } from '../../models/card-view-selectitem.model';
|
||||
import { of } from 'rxjs';
|
||||
import { CardViewSelectItemOption } from '../../interfaces/card-view-selectitem-properties.interface';
|
||||
@@ -38,7 +37,7 @@ describe('CardViewComponent', () => {
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), CoreTestingModule]
|
||||
imports: [CoreTestingModule]
|
||||
}).compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(CardViewComponent);
|
||||
|
@@ -20,19 +20,14 @@ import { ComponentFixture, TestBed, tick, fakeAsync } from '@angular/core/testin
|
||||
import { ClipboardService } from './clipboard.service';
|
||||
import { ClipboardDirective } from './clipboard.directive';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-test-component',
|
||||
template: `
|
||||
<button
|
||||
clipboard-notification="copy success"
|
||||
[adf-clipboard] [target]="ref">
|
||||
copy
|
||||
</button>
|
||||
selector: 'adf-test-component',
|
||||
template: `
|
||||
<button clipboard-notification="copy success" [adf-clipboard] [target]="ref">copy</button>
|
||||
|
||||
<input #ref />
|
||||
`
|
||||
`
|
||||
})
|
||||
class TestTargetClipboardComponent {}
|
||||
|
||||
@@ -42,13 +37,8 @@ describe('ClipboardDirective', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
declarations: [
|
||||
TestTargetClipboardComponent
|
||||
]
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [TestTargetClipboardComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(TestTargetClipboardComponent);
|
||||
clipboardService = TestBed.inject(ClipboardService);
|
||||
@@ -66,20 +56,18 @@ describe('ClipboardDirective', () => {
|
||||
it('should notify copy target value on keydown event', () => {
|
||||
spyOn(clipboardService, 'copyToClipboard');
|
||||
fixture.nativeElement.querySelector('input').value = 'some value';
|
||||
fixture.nativeElement.querySelector('button').dispatchEvent(new KeyboardEvent('keydown', {code: 'Enter', key: 'Enter'}));
|
||||
fixture.nativeElement.querySelector('button').dispatchEvent(new KeyboardEvent('keydown', { code: 'Enter', key: 'Enter' }));
|
||||
|
||||
expect(clipboardService.copyToClipboard).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('CopyClipboardDirective', () => {
|
||||
|
||||
@Component({
|
||||
selector: 'adf-copy-conent-test-component',
|
||||
selector: 'adf-copy-conent-test-component',
|
||||
template: `<span adf-clipboard="placeholder">{{ mockText }}</span>`
|
||||
})
|
||||
class TestCopyClipboardComponent {
|
||||
|
||||
mockText = 'text to copy';
|
||||
placeholder = 'copy text';
|
||||
|
||||
@@ -92,27 +80,22 @@ describe('CopyClipboardDirective', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
declarations: [
|
||||
TestCopyClipboardComponent
|
||||
]
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [TestCopyClipboardComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(TestCopyClipboardComponent);
|
||||
element = fixture.debugElement.nativeElement;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should show tooltip when hover element', (() => {
|
||||
it('should show tooltip when hover element', () => {
|
||||
const spanHTMLElement = element.querySelector<HTMLInputElement>('span');
|
||||
spanHTMLElement.dispatchEvent(new Event('mouseenter'));
|
||||
fixture.detectChanges();
|
||||
expect(fixture.debugElement.nativeElement.querySelector('.adf-copy-tooltip')).not.toBeNull();
|
||||
}));
|
||||
});
|
||||
|
||||
it('should not show tooltip when element it is not hovered', (() => {
|
||||
it('should not show tooltip when element it is not hovered', () => {
|
||||
const spanHTMLElement = element.querySelector<HTMLInputElement>('span');
|
||||
spanHTMLElement.dispatchEvent(new Event('mouseenter'));
|
||||
fixture.detectChanges();
|
||||
@@ -121,7 +104,7 @@ describe('CopyClipboardDirective', () => {
|
||||
spanHTMLElement.dispatchEvent(new Event('mouseleave'));
|
||||
fixture.detectChanges();
|
||||
expect(fixture.debugElement.nativeElement.querySelector('.adf-copy-tooltip')).toBeNull();
|
||||
}));
|
||||
});
|
||||
|
||||
it('should copy the content of element when click it', fakeAsync(() => {
|
||||
const spanHTMLElement = element.querySelector<HTMLInputElement>('span');
|
||||
@@ -137,7 +120,7 @@ describe('CopyClipboardDirective', () => {
|
||||
const spanHTMLElement = element.querySelector<HTMLInputElement>('span');
|
||||
fixture.detectChanges();
|
||||
spyOn(navigator.clipboard, 'writeText');
|
||||
spanHTMLElement.dispatchEvent(new KeyboardEvent('keydown', {code: 'Enter', key: 'Enter'}));
|
||||
spanHTMLElement.dispatchEvent(new KeyboardEvent('keydown', { code: 'Enter', key: 'Enter' }));
|
||||
tick();
|
||||
fixture.detectChanges();
|
||||
expect(navigator.clipboard.writeText).toHaveBeenCalledWith('text to copy');
|
||||
|
@@ -20,7 +20,6 @@ import { TestBed } from '@angular/core/testing';
|
||||
import { ClipboardService } from './clipboard.service';
|
||||
import { MatSnackBarModule } from '@angular/material/snack-bar';
|
||||
import { CoreTestingModule } from '../testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('ClipboardService', () => {
|
||||
let clipboardService: ClipboardService;
|
||||
@@ -29,11 +28,7 @@ describe('ClipboardService', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule,
|
||||
MatSnackBarModule
|
||||
]
|
||||
imports: [CoreTestingModule, MatSnackBarModule]
|
||||
});
|
||||
clipboardService = TestBed.inject(ClipboardService);
|
||||
notificationService = TestBed.inject(NotificationService);
|
||||
@@ -61,8 +56,7 @@ describe('ClipboardService', () => {
|
||||
clipboardService.copyToClipboard(inputElement);
|
||||
|
||||
expect(inputElement.select).toHaveBeenCalledWith();
|
||||
expect(inputElement.setSelectionRange)
|
||||
.toHaveBeenCalledWith(0, inputElement.value.length);
|
||||
expect(inputElement.setSelectionRange).toHaveBeenCalledWith(0, inputElement.value.length);
|
||||
expect(navigator.clipboard.writeText).toHaveBeenCalledWith('some text');
|
||||
});
|
||||
|
||||
|
@@ -17,16 +17,11 @@
|
||||
|
||||
import { Injectable, Inject } from '@angular/core';
|
||||
import { DOCUMENT } from '@angular/common';
|
||||
import { LogService } from '../common/services/log.service';
|
||||
import { NotificationService } from '../notifications/services/notification.service';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ClipboardService {
|
||||
|
||||
constructor(
|
||||
@Inject(DOCUMENT) private document: any,
|
||||
private logService: LogService,
|
||||
private notificationService: NotificationService) { }
|
||||
constructor(@Inject(DOCUMENT) private document: any, private notificationService: NotificationService) {}
|
||||
|
||||
/**
|
||||
* Checks if the target element can have its text copied.
|
||||
@@ -58,9 +53,7 @@ export class ClipboardService {
|
||||
this.document.execCommand('copy');
|
||||
}
|
||||
this.notify(message);
|
||||
} catch (error) {
|
||||
this.logService.error(error);
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,16 +69,14 @@ export class ClipboardService {
|
||||
navigator.clipboard.writeText(content);
|
||||
} else {
|
||||
document.addEventListener('copy', (e: ClipboardEvent) => {
|
||||
e.clipboardData.setData('text/plain', (content));
|
||||
e.clipboardData.setData('text/plain', content);
|
||||
e.preventDefault();
|
||||
document.removeEventListener('copy', null);
|
||||
});
|
||||
document.execCommand('copy');
|
||||
}
|
||||
this.notify(message);
|
||||
} catch (error) {
|
||||
this.logService.error(error);
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
|
||||
private notify(message) {
|
||||
@@ -93,5 +84,4 @@ export class ClipboardService {
|
||||
this.notificationService.openSnackMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -20,28 +20,18 @@ import { CommentModel } from '../../models/comment.model';
|
||||
import { CommentListComponent } from './comment-list.component';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import {
|
||||
commentUserNoPictureDefined,
|
||||
commentUserPictureDefined,
|
||||
mockCommentOne,
|
||||
testUser
|
||||
} from './mocks/comment-list.mock';
|
||||
import { commentUserNoPictureDefined, commentUserPictureDefined, mockCommentOne, testUser } from './mocks/comment-list.mock';
|
||||
import { CommentListServiceMock } from './mocks/comment-list.service.mock';
|
||||
import { ADF_COMMENTS_SERVICE } from '../interfaces/comments.token';
|
||||
|
||||
describe('CommentListComponent', () => {
|
||||
|
||||
let commentList: CommentListComponent;
|
||||
let fixture: ComponentFixture<CommentListComponent>;
|
||||
let element: HTMLElement;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
imports: [CoreTestingModule],
|
||||
providers: [
|
||||
{
|
||||
provide: ADF_COMMENTS_SERVICE,
|
||||
@@ -123,7 +113,7 @@ describe('CommentListComponent', () => {
|
||||
|
||||
it('comment date time should start with Yesterday when comment date is yesterday', async () => {
|
||||
const commentOld = new CommentModel(mockCommentOne);
|
||||
commentOld.created = new Date((Date.now() - 24 * 3600 * 1000));
|
||||
commentOld.created = new Date(Date.now() - 24 * 3600 * 1000);
|
||||
commentList.comments = [commentOld];
|
||||
|
||||
fixture.detectChanges();
|
||||
@@ -135,7 +125,7 @@ describe('CommentListComponent', () => {
|
||||
|
||||
it('comment date time should not start with Today/Yesterday when comment date is before yesterday', async () => {
|
||||
const commentOld = new CommentModel(mockCommentOne);
|
||||
commentOld.created = new Date((Date.now() - 24 * 3600 * 1000 * 2));
|
||||
commentOld.created = new Date(Date.now() - 24 * 3600 * 1000 * 2);
|
||||
commentList.comments = [commentOld];
|
||||
|
||||
fixture.detectChanges();
|
||||
|
@@ -19,7 +19,6 @@ import { SimpleChange } from '@angular/core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { CommentsComponent } from './comments.component';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { CommentsServiceMock, commentsResponseMock } from './mocks/comments.service.mock';
|
||||
import { of, throwError } from 'rxjs';
|
||||
import { ADF_COMMENTS_SERVICE } from './interfaces/comments.token';
|
||||
@@ -34,10 +33,7 @@ describe('CommentsComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
imports: [CoreTestingModule],
|
||||
providers: [
|
||||
{
|
||||
provide: ADF_COMMENTS_SERVICE,
|
||||
@@ -60,7 +56,7 @@ describe('CommentsComponent', () => {
|
||||
|
||||
it('should load comments when id specified', () => {
|
||||
const change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({id: change});
|
||||
component.ngOnChanges({ id: change });
|
||||
|
||||
expect(getCommentSpy).toHaveBeenCalled();
|
||||
});
|
||||
@@ -70,7 +66,7 @@ describe('CommentsComponent', () => {
|
||||
getCommentSpy.and.returnValue(throwError({}));
|
||||
|
||||
const change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({id: change});
|
||||
component.ngOnChanges({ id: change });
|
||||
|
||||
expect(emitSpy).toHaveBeenCalled();
|
||||
});
|
||||
@@ -82,7 +78,7 @@ describe('CommentsComponent', () => {
|
||||
|
||||
it('should display comments when the entity has comments', async () => {
|
||||
const change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({id: change});
|
||||
component.ngOnChanges({ id: change });
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
@@ -93,7 +89,7 @@ describe('CommentsComponent', () => {
|
||||
|
||||
it('should display comments count when the entity has comments', async () => {
|
||||
const change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({id: change});
|
||||
component.ngOnChanges({ id: change });
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
@@ -114,7 +110,7 @@ describe('CommentsComponent', () => {
|
||||
|
||||
it('should display comments input by default', async () => {
|
||||
const change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({id: change});
|
||||
component.ngOnChanges({ id: change });
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
@@ -141,7 +137,7 @@ describe('CommentsComponent', () => {
|
||||
});
|
||||
|
||||
it('should fetch new comments when id changed', () => {
|
||||
component.ngOnChanges({id: change});
|
||||
component.ngOnChanges({ id: change });
|
||||
expect(getCommentSpy).toHaveBeenCalledWith('456');
|
||||
});
|
||||
|
||||
@@ -151,13 +147,12 @@ describe('CommentsComponent', () => {
|
||||
});
|
||||
|
||||
it('should not fetch new comments when id changed to null', () => {
|
||||
component.ngOnChanges({id: nullChange});
|
||||
component.ngOnChanges({ id: nullChange });
|
||||
expect(getCommentSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Add comment', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
component.id = '123';
|
||||
fixture.detectChanges();
|
||||
@@ -229,7 +224,7 @@ describe('CommentsComponent', () => {
|
||||
});
|
||||
|
||||
it('should clear comment when escape key is pressed', async () => {
|
||||
const event = new KeyboardEvent('keydown', {key: 'Escape'});
|
||||
const event = new KeyboardEvent('keydown', { key: 'Escape' });
|
||||
let element = fixture.nativeElement.querySelector('#comment-input');
|
||||
element.dispatchEvent(event);
|
||||
|
||||
@@ -271,5 +266,5 @@ describe('CommentsComponent', () => {
|
||||
component.addComment();
|
||||
expect(addCommentSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -18,19 +18,13 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { UserPreferencesService } from './user-preferences.service';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { CoreModule } from '../../core.module';
|
||||
|
||||
describe('DirectionalityConfigService', () => {
|
||||
let userPreferencesService: UserPreferencesService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
userPreferencesService = TestBed.inject(UserPreferencesService);
|
||||
});
|
||||
|
@@ -22,11 +22,13 @@ import { AppConfigService, AppConfigValues } from '../../app-config/app-config.s
|
||||
import { logLevels, LogLevelsEnum } from '../models/log-levels.model';
|
||||
import { Subject } from 'rxjs';
|
||||
|
||||
/**
|
||||
* @deprecated This service is deprecated and will be removed in future versions.
|
||||
*/
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class LogService {
|
||||
|
||||
get currentLogLevel() {
|
||||
const configLevel: string = this.appConfig.get<string>(AppConfigValues.LOG_LEVEL);
|
||||
|
||||
@@ -51,7 +53,6 @@ export class LogService {
|
||||
*/
|
||||
error(message?: any, ...optionalParams: any[]) {
|
||||
if (this.currentLogLevel >= LogLevelsEnum.ERROR) {
|
||||
|
||||
this.messageBus(message, 'ERROR');
|
||||
|
||||
console.error(message, ...optionalParams);
|
||||
@@ -66,7 +67,6 @@ export class LogService {
|
||||
*/
|
||||
debug(message?: any, ...optionalParams: any[]) {
|
||||
if (this.currentLogLevel >= LogLevelsEnum.DEBUG) {
|
||||
|
||||
this.messageBus(message, 'DEBUG');
|
||||
|
||||
console.debug(message, ...optionalParams);
|
||||
@@ -81,7 +81,6 @@ export class LogService {
|
||||
*/
|
||||
info(message?: any, ...optionalParams: any[]) {
|
||||
if (this.currentLogLevel >= LogLevelsEnum.INFO) {
|
||||
|
||||
this.messageBus(message, 'INFO');
|
||||
|
||||
console.info(message, ...optionalParams);
|
||||
@@ -96,7 +95,6 @@ export class LogService {
|
||||
*/
|
||||
log(message?: any, ...optionalParams: any[]) {
|
||||
if (this.currentLogLevel >= LogLevelsEnum.TRACE) {
|
||||
|
||||
this.messageBus(message, 'LOG');
|
||||
|
||||
console.log(message, ...optionalParams);
|
||||
@@ -111,7 +109,6 @@ export class LogService {
|
||||
*/
|
||||
trace(message?: any, ...optionalParams: any[]) {
|
||||
if (this.currentLogLevel >= LogLevelsEnum.TRACE) {
|
||||
|
||||
this.messageBus(message, 'TRACE');
|
||||
|
||||
console.trace(message, ...optionalParams);
|
||||
@@ -126,7 +123,6 @@ export class LogService {
|
||||
*/
|
||||
warn(message?: any, ...optionalParams: any[]) {
|
||||
if (this.currentLogLevel >= LogLevelsEnum.WARN) {
|
||||
|
||||
this.messageBus(message, 'WARN');
|
||||
|
||||
console.warn(message, ...optionalParams);
|
||||
@@ -142,7 +138,6 @@ export class LogService {
|
||||
*/
|
||||
assert(test?: boolean, message?: string, ...optionalParams: any[]) {
|
||||
if (this.currentLogLevel !== LogLevelsEnum.SILENT) {
|
||||
|
||||
this.messageBus(message, 'ASSERT');
|
||||
|
||||
console.assert(test, message, ...optionalParams);
|
||||
|
@@ -20,10 +20,8 @@ import { AppConfigService } from '../../app-config/app-config.service';
|
||||
import { StorageService } from '../../common/services/storage.service';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { AppConfigServiceMock } from '../mock/app-config.service.mock';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('StorageService', () => {
|
||||
|
||||
let storage: StorageService;
|
||||
let appConfig: AppConfigServiceMock;
|
||||
const key = 'test_key';
|
||||
@@ -32,9 +30,7 @@ describe('StorageService', () => {
|
||||
describe('StorageService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
appConfig = TestBed.inject(AppConfigService);
|
||||
appConfig.config = {
|
||||
@@ -78,10 +74,7 @@ describe('StorageService', () => {
|
||||
describe('StorageService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
appConfig = TestBed.inject(AppConfigService);
|
||||
|
||||
|
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { TranslateService, TranslateModule } from '@ngx-translate/core';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { AppConfigService } from '../../app-config/app-config.service';
|
||||
import { StorageService } from '../../common/services/storage.service';
|
||||
import { UserPreferencesService, UserPreferenceValues } from '../../common/services/user-preferences.service';
|
||||
@@ -26,7 +26,6 @@ import { AlfrescoApiService } from '../../services/alfresco-api.service';
|
||||
import { AlfrescoApiServiceMock } from '../../mock';
|
||||
|
||||
describe('UserPreferencesService', () => {
|
||||
|
||||
const supportedPaginationSize = [5, 10, 15, 20];
|
||||
let preferences: UserPreferencesService;
|
||||
let storage: StorageService;
|
||||
@@ -36,10 +35,7 @@ describe('UserPreferencesService', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
appConfig = TestBed.inject(AppConfigService);
|
||||
appConfig.config = {
|
||||
|
@@ -20,7 +20,6 @@ import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { ContextMenuOverlayService } from './context-menu-overlay.service';
|
||||
import { Injector } from '@angular/core';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('ContextMenuOverlayService', () => {
|
||||
let contextMenuOverlayService: ContextMenuOverlayService;
|
||||
@@ -36,11 +35,8 @@ describe('ContextMenuOverlayService', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
providers: [ Overlay ]
|
||||
imports: [CoreTestingModule],
|
||||
providers: [Overlay]
|
||||
});
|
||||
overlay = TestBed.inject(Overlay);
|
||||
injector = TestBed.inject(Injector);
|
||||
@@ -48,10 +44,7 @@ describe('ContextMenuOverlayService', () => {
|
||||
|
||||
describe('Overlay', () => {
|
||||
beforeEach(() => {
|
||||
contextMenuOverlayService = new ContextMenuOverlayService(
|
||||
injector,
|
||||
overlay
|
||||
);
|
||||
contextMenuOverlayService = new ContextMenuOverlayService(injector, overlay);
|
||||
});
|
||||
|
||||
it('should create a custom overlay', () => {
|
||||
|
@@ -19,16 +19,13 @@ import { Component } from '@angular/core';
|
||||
import { TestBed, ComponentFixture } from '@angular/core/testing';
|
||||
import { ContextMenuModule } from './context-menu.module';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { HarnessLoader } from '@angular/cdk/testing';
|
||||
import { MatIconHarness } from '@angular/material/icon/testing';
|
||||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-test-component',
|
||||
template: `
|
||||
<div id="target" [adf-context-menu]="actions" [adf-context-menu-enabled]="true"></div>
|
||||
`
|
||||
template: ` <div id="target" [adf-context-menu]="actions" [adf-context-menu-enabled]="true"></div> `
|
||||
})
|
||||
class TestComponent {
|
||||
actions;
|
||||
@@ -83,14 +80,8 @@ describe('ContextMenuDirective', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule,
|
||||
ContextMenuModule
|
||||
],
|
||||
declarations: [
|
||||
TestComponent
|
||||
]
|
||||
imports: [CoreTestingModule, ContextMenuModule],
|
||||
declarations: [TestComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(TestComponent);
|
||||
fixture.componentInstance.actions = actions;
|
||||
@@ -118,7 +109,9 @@ describe('ContextMenuDirective', () => {
|
||||
|
||||
it('should reset DOM element reference on Escape event', () => {
|
||||
const event = new KeyboardEvent('keydown', {
|
||||
bubbles : true, cancelable : true, key : 'Escape'
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
key: 'Escape'
|
||||
});
|
||||
|
||||
document.querySelector('.cdk-overlay-backdrop')?.dispatchEvent(event);
|
||||
@@ -169,9 +162,16 @@ describe('ContextMenuDirective', () => {
|
||||
});
|
||||
|
||||
it('should not render item icon if not set', async () => {
|
||||
expect((await loader.getAllHarnesses(MatIconHarness.with({
|
||||
ancestor: 'adf-context-menu', name: 'Action 1'
|
||||
}))).length).toBe(0);
|
||||
expect(
|
||||
(
|
||||
await loader.getAllHarnesses(
|
||||
MatIconHarness.with({
|
||||
ancestor: 'adf-context-menu',
|
||||
name: 'Action 1'
|
||||
})
|
||||
)
|
||||
).length
|
||||
).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -21,7 +21,6 @@ import { DataColumn } from '../../data/data-column.model';
|
||||
import { Observable, Subject } from 'rxjs';
|
||||
import { MatMenuTrigger } from '@angular/material/menu';
|
||||
import { CoreTestingModule } from '../../../testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||
import { HarnessLoader } from '@angular/cdk/testing';
|
||||
@@ -41,10 +40,7 @@ describe('ColumnsSelectorComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [ColumnsSelectorComponent]
|
||||
}).compileComponents();
|
||||
|
||||
@@ -52,32 +48,38 @@ describe('ColumnsSelectorComponent', () => {
|
||||
loader = TestbedHarnessEnvironment.loader(fixture);
|
||||
|
||||
component = fixture.componentInstance;
|
||||
inputColumns = [{
|
||||
id: 'id0',
|
||||
key: 'key0',
|
||||
title: 'title0',
|
||||
type: 'text'
|
||||
}, {
|
||||
id: 'id1',
|
||||
key: 'key1',
|
||||
title: 'title1',
|
||||
type: 'text'
|
||||
}, {
|
||||
id: 'id2',
|
||||
key: 'key2',
|
||||
title: 'title2',
|
||||
type: 'text'
|
||||
}, {
|
||||
id: 'id3',
|
||||
key: 'NoTitle',
|
||||
type: 'text'
|
||||
}, {
|
||||
id: 'id4',
|
||||
key: 'IsHidden',
|
||||
type: 'text',
|
||||
title: 'title4',
|
||||
isHidden: true
|
||||
}];
|
||||
inputColumns = [
|
||||
{
|
||||
id: 'id0',
|
||||
key: 'key0',
|
||||
title: 'title0',
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
id: 'id1',
|
||||
key: 'key1',
|
||||
title: 'title1',
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
id: 'id2',
|
||||
key: 'key2',
|
||||
title: 'title2',
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
id: 'id3',
|
||||
key: 'NoTitle',
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
id: 'id4',
|
||||
key: 'IsHidden',
|
||||
type: 'text',
|
||||
title: 'title4',
|
||||
isHidden: true
|
||||
}
|
||||
];
|
||||
|
||||
mainMenuTrigger = {
|
||||
menuOpened: menuOpenedTrigger.asObservable(),
|
||||
@@ -114,13 +116,13 @@ describe('ColumnsSelectorComponent', () => {
|
||||
|
||||
const checkboxes = await loader.getAllHarnesses(MatCheckboxHarness);
|
||||
|
||||
const inputColumnsWithTitle = inputColumns.filter(column => !!column.title);
|
||||
const inputColumnsWithTitle = inputColumns.filter((column) => !!column.title);
|
||||
expect(checkboxes.length).toBe(inputColumnsWithTitle.length);
|
||||
|
||||
for await (const checkbox of checkboxes) {
|
||||
const checkboxLabel = await checkbox.getLabelText();
|
||||
|
||||
const inputColumn = inputColumnsWithTitle.find(inputColumnWithTitle => inputColumnWithTitle.title === checkboxLabel);
|
||||
const inputColumn = inputColumnsWithTitle.find((inputColumnWithTitle) => inputColumnWithTitle.title === checkboxLabel);
|
||||
expect(inputColumn).toBeTruthy('Should have all columns with title');
|
||||
}
|
||||
});
|
||||
@@ -149,14 +151,13 @@ describe('ColumnsSelectorComponent', () => {
|
||||
const firstColumnCheckbox = await loader.getHarness(MatCheckboxHarness);
|
||||
const checkBoxName = await firstColumnCheckbox.getLabelText();
|
||||
|
||||
const toggledColumnItem = component.columnItems.find(item => item.title === checkBoxName);
|
||||
const toggledColumnItem = component.columnItems.find((item) => item.title === checkBoxName);
|
||||
expect(toggledColumnItem.isHidden).toBeFalsy();
|
||||
|
||||
await firstColumnCheckbox.toggle();
|
||||
expect(toggledColumnItem.isHidden).toBe(true);
|
||||
});
|
||||
|
||||
|
||||
describe('checkboxes', () => {
|
||||
it('should have set proper default state', async () => {
|
||||
menuOpenedTrigger.next();
|
||||
|
@@ -27,7 +27,6 @@ import { DataTableComponent, ShowHeaderMode } from './datatable.component';
|
||||
import { CoreTestingModule } from '../../../testing/core.testing.module';
|
||||
import { DataColumnListComponent } from '../../data-column/data-column-list.component';
|
||||
import { DataColumnComponent } from '../../data-column/data-column.component';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { domSanitizerMock } from '../../../mock/dom-sanitizer-mock';
|
||||
import { matIconRegistryMock } from '../../../mock/mat-icon-registry-mock';
|
||||
import { CdkDrag, CdkDragDrop, CdkDropList } from '@angular/cdk/drag-drop';
|
||||
@@ -140,7 +139,7 @@ describe('DataTable', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), CoreTestingModule],
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [CustomColumnHeaderComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(DataTableComponent);
|
||||
@@ -1280,7 +1279,7 @@ describe('Accesibility', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), CoreTestingModule],
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [CustomColumnTemplateComponent],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
});
|
||||
@@ -1483,7 +1482,7 @@ describe('Drag&Drop column header', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), CoreTestingModule],
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [CustomColumnTemplateComponent],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
});
|
||||
@@ -1584,7 +1583,7 @@ describe('Show/hide columns', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), CoreTestingModule],
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [CustomColumnTemplateComponent],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
});
|
||||
@@ -1691,7 +1690,7 @@ describe('Column Resizing', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), CoreTestingModule],
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [CustomColumnTemplateComponent],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
});
|
||||
|
@@ -18,17 +18,13 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { EmptyListComponent } from './empty-list.component';
|
||||
import { CoreTestingModule } from '../../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('EmptyListComponentComponent', () => {
|
||||
let fixture: ComponentFixture<EmptyListComponent>;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(EmptyListComponent);
|
||||
});
|
||||
|
@@ -20,7 +20,6 @@ import { ObjectDataTableAdapter } from '../../data/object-datatable-adapter';
|
||||
import { ObjectDataColumn } from '../../data/object-datacolumn.model';
|
||||
import { CoreTestingModule } from '../../../testing/core.testing.module';
|
||||
import { JsonCellComponent } from './json-cell.component';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||
import { HarnessLoader } from '@angular/cdk/testing';
|
||||
import { MatButtonHarness } from '@angular/material/button/testing';
|
||||
@@ -35,7 +34,7 @@ describe('JsonCellComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), CoreTestingModule]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(JsonCellComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
@@ -17,16 +17,12 @@
|
||||
|
||||
import { DataColumnComponent } from './data-column.component';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
describe('DataColumnListComponent', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -19,20 +19,15 @@ import { TestBed, ComponentFixture } from '@angular/core/testing';
|
||||
import { DataTableComponent } from '../components/datatable/datatable.component';
|
||||
import { HeaderFilterTemplateDirective } from './header-filter-template.directive';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('HeaderFilterTemplateDirective', () => {
|
||||
|
||||
let fixture: ComponentFixture<DataTableComponent>;
|
||||
let dataTable: DataTableComponent;
|
||||
let directive: HeaderFilterTemplateDirective;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(DataTableComponent);
|
||||
dataTable = fixture.componentInstance;
|
||||
|
@@ -19,20 +19,15 @@ import { TestBed, ComponentFixture } from '@angular/core/testing';
|
||||
import { DataTableComponent } from '../components/datatable/datatable.component';
|
||||
import { LoadingContentTemplateDirective } from './loading-template.directive';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('LoadingContentTemplateDirective', () => {
|
||||
|
||||
let fixture: ComponentFixture<DataTableComponent>;
|
||||
let dataTable: DataTableComponent;
|
||||
let directive: LoadingContentTemplateDirective;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(DataTableComponent);
|
||||
dataTable = fixture.componentInstance;
|
||||
|
@@ -19,20 +19,15 @@ import { TestBed, ComponentFixture } from '@angular/core/testing';
|
||||
import { DataTableComponent } from '../components/datatable/datatable.component';
|
||||
import { NoContentTemplateDirective } from './no-content-template.directive';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('NoContentTemplateDirective', () => {
|
||||
|
||||
let fixture: ComponentFixture<DataTableComponent>;
|
||||
let dataTable: DataTableComponent;
|
||||
let directive: NoContentTemplateDirective;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(DataTableComponent);
|
||||
dataTable = fixture.componentInstance;
|
||||
|
@@ -19,20 +19,15 @@ import { TestBed, ComponentFixture } from '@angular/core/testing';
|
||||
import { DataTableComponent } from '../components/datatable/datatable.component';
|
||||
import { NoPermissionTemplateDirective } from './no-permission-template.directive';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('NoPermissionTemplateDirective', () => {
|
||||
|
||||
let fixture: ComponentFixture<DataTableComponent>;
|
||||
let dataTable: DataTableComponent;
|
||||
let directive: NoPermissionTemplateDirective;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(DataTableComponent);
|
||||
dataTable = fixture.componentInstance;
|
||||
|
@@ -21,7 +21,6 @@ import { By } from '@angular/platform-browser';
|
||||
import { HighlightTransformService } from '../common/services/highlight-transform.service';
|
||||
import { HighlightDirective } from './highlight.directive';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
/* spellchecker: disable */
|
||||
const template: string = `
|
||||
@@ -41,19 +40,13 @@ class TestComponent {
|
||||
}
|
||||
|
||||
describe('HighlightDirective', () => {
|
||||
|
||||
let fixture: ComponentFixture<TestComponent>;
|
||||
let component: TestComponent;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
declarations: [
|
||||
TestComponent
|
||||
]
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [TestComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(TestComponent);
|
||||
component = fixture.componentInstance;
|
||||
@@ -77,8 +70,12 @@ describe('HighlightDirective', () => {
|
||||
const containerElement2 = fixture.debugElement.query(By.css('#innerDiv14'));
|
||||
expect(containerElement1).not.toBeNull();
|
||||
expect(containerElement2).not.toBeNull();
|
||||
expect(containerElement1.nativeElement.innerHTML).toBe('Lorem ipsum <span class="highlight-for-free-willy">salana-eyong-aysis</span> dolor sit amet');
|
||||
expect(containerElement2.nativeElement.innerHTML).toBe('sed do eiusmod <span class="highlight-for-free-willy">salana-eyong-aysis</span> tempor incididunt');
|
||||
expect(containerElement1.nativeElement.innerHTML).toBe(
|
||||
'Lorem ipsum <span class="highlight-for-free-willy">salana-eyong-aysis</span> dolor sit amet'
|
||||
);
|
||||
expect(containerElement2.nativeElement.innerHTML).toBe(
|
||||
'sed do eiusmod <span class="highlight-for-free-willy">salana-eyong-aysis</span> tempor incididunt'
|
||||
);
|
||||
});
|
||||
|
||||
it('should NOT replace the searched text in an element without the proper selector class', () => {
|
||||
|
@@ -23,12 +23,9 @@ import { AuthenticationService } from '../auth/services/authentication.service';
|
||||
import { AppConfigService } from '../app-config/app-config.service';
|
||||
import { LogoutDirective } from './logout.directive';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('LogoutDirective', () => {
|
||||
|
||||
describe('No input', () => {
|
||||
|
||||
@Component({
|
||||
selector: 'adf-test-component',
|
||||
template: '<button adf-logout></button>'
|
||||
@@ -45,13 +42,8 @@ describe('LogoutDirective', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
declarations: [
|
||||
TestComponent
|
||||
]
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [TestComponent]
|
||||
});
|
||||
router = TestBed.inject(Router);
|
||||
authService = TestBed.inject(AuthenticationService);
|
||||
@@ -107,10 +99,9 @@ describe('LogoutDirective', () => {
|
||||
expect(authService.logout).toHaveBeenCalled();
|
||||
expect(router.navigate).toHaveBeenCalledWith(['/login']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('redirectUri', () => {
|
||||
|
||||
@Component({
|
||||
selector: 'adf-test-component',
|
||||
template: '<button adf-logout redirectUri="/myCustomUri"></button>'
|
||||
@@ -126,13 +117,8 @@ describe('LogoutDirective', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
declarations: [
|
||||
TestComponent
|
||||
]
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [TestComponent]
|
||||
});
|
||||
router = TestBed.inject(Router);
|
||||
authService = TestBed.inject(AuthenticationService);
|
||||
@@ -150,10 +136,9 @@ describe('LogoutDirective', () => {
|
||||
expect(authService.logout).toHaveBeenCalled();
|
||||
expect(router.navigate).toHaveBeenCalledWith(['/myCustomUri']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('enableRedirect', () => {
|
||||
|
||||
@Component({
|
||||
selector: 'adf-test-component',
|
||||
template: '<button adf-logout [enableRedirect]="false"></button>'
|
||||
@@ -169,13 +154,8 @@ describe('LogoutDirective', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
declarations: [
|
||||
TestComponent
|
||||
]
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [TestComponent]
|
||||
});
|
||||
router = TestBed.inject(Router);
|
||||
authService = TestBed.inject(AuthenticationService);
|
||||
@@ -192,6 +172,5 @@ describe('LogoutDirective', () => {
|
||||
expect(authService.logout).toHaveBeenCalled();
|
||||
expect(router.navigate).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
@@ -16,24 +16,28 @@
|
||||
*/
|
||||
|
||||
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { Chip, CoreTestingModule, DynamicChipListComponent } from '@alfresco/adf-core';
|
||||
import { SimpleChange } from '@angular/core';
|
||||
|
||||
describe('DynamicChipListComponent', () => {
|
||||
let chips: Chip[] = [{
|
||||
name: 'test1',
|
||||
id: '0ee933fa-57fc-4587-8a77-b787e814f1d2'
|
||||
}, {
|
||||
name: 'test2',
|
||||
id: 'fcb92659-1f10-41b4-9b17-851b72a3b597'
|
||||
}, {
|
||||
name: 'test3',
|
||||
id: 'fb4213c0-729d-466c-9a6c-ee2e937273bf'
|
||||
}, {
|
||||
name: 'test4',
|
||||
id: 'as4213c0-729d-466c-9a6c-ee2e937273as'
|
||||
}];
|
||||
let chips: Chip[] = [
|
||||
{
|
||||
name: 'test1',
|
||||
id: '0ee933fa-57fc-4587-8a77-b787e814f1d2'
|
||||
},
|
||||
{
|
||||
name: 'test2',
|
||||
id: 'fcb92659-1f10-41b4-9b17-851b72a3b597'
|
||||
},
|
||||
{
|
||||
name: 'test3',
|
||||
id: 'fb4213c0-729d-466c-9a6c-ee2e937273bf'
|
||||
},
|
||||
{
|
||||
name: 'test4',
|
||||
id: 'as4213c0-729d-466c-9a6c-ee2e937273as'
|
||||
}
|
||||
];
|
||||
let component: DynamicChipListComponent;
|
||||
let fixture: ComponentFixture<DynamicChipListComponent>;
|
||||
let element: HTMLElement;
|
||||
@@ -59,10 +63,7 @@ describe('DynamicChipListComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
const resizeObserverSpy = spyOn(window, 'ResizeObserver').and.callThrough();
|
||||
fixture = TestBed.createComponent(DynamicChipListComponent);
|
||||
@@ -210,10 +211,12 @@ describe('DynamicChipListComponent', () => {
|
||||
}));
|
||||
|
||||
it('should not render view more button when chip takes more than one line and there are no more chips', fakeAsync(() => {
|
||||
renderChips([{
|
||||
name: 'VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag',
|
||||
id: '0ee933fa-57fc-4587-8a77-b787e814f1d2'
|
||||
}]);
|
||||
renderChips([
|
||||
{
|
||||
name: 'VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag',
|
||||
id: '0ee933fa-57fc-4587-8a77-b787e814f1d2'
|
||||
}
|
||||
]);
|
||||
component.ngOnChanges({
|
||||
chips: new SimpleChange(undefined, component.chips, true)
|
||||
});
|
||||
@@ -225,13 +228,16 @@ describe('DynamicChipListComponent', () => {
|
||||
}));
|
||||
|
||||
it('should render view more button when chip takes more than one line and there are more chips', fakeAsync(() => {
|
||||
renderChips([{
|
||||
name: 'VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag',
|
||||
id: '0ee933fa-57fc-4587-8a77-b787e814f1d2'
|
||||
}, {
|
||||
name: 'Some other tag',
|
||||
id: '0ee933fa-57fc-4587-8a77-b787e814f1d3'
|
||||
}]);
|
||||
renderChips([
|
||||
{
|
||||
name: 'VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag VeryLongTag',
|
||||
id: '0ee933fa-57fc-4587-8a77-b787e814f1d2'
|
||||
},
|
||||
{
|
||||
name: 'Some other tag',
|
||||
id: '0ee933fa-57fc-4587-8a77-b787e814f1d3'
|
||||
}
|
||||
]);
|
||||
component.ngOnChanges({
|
||||
chips: new SimpleChange(undefined, component.chips, true)
|
||||
});
|
||||
|
@@ -22,10 +22,8 @@ import { TextWidgetComponent, CheckboxWidgetComponent } from '../widgets';
|
||||
import { FormFieldComponent } from './form-field.component';
|
||||
import { FormBaseModule } from '../../form-base.module';
|
||||
import { CoreTestingModule } from '../../../testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('FormFieldComponent', () => {
|
||||
|
||||
let fixture: ComponentFixture<FormFieldComponent>;
|
||||
let component: FormFieldComponent;
|
||||
let form: FormModel;
|
||||
@@ -34,11 +32,7 @@ describe('FormFieldComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule,
|
||||
FormBaseModule
|
||||
]
|
||||
imports: [CoreTestingModule, FormBaseModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(FormFieldComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
@@ -43,7 +43,6 @@ import {
|
||||
} from './mock/form-renderer.component.mock';
|
||||
import { FormService } from '../services/form.service';
|
||||
import { CoreTestingModule } from '../../testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { FormRenderingService } from '../services/form-rendering.service';
|
||||
import { TextWidgetComponent } from './widgets';
|
||||
import { FormRulesManager } from '../models/form-rules.model';
|
||||
@@ -88,7 +87,7 @@ describe('Form Renderer Component', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), CoreTestingModule, FormBaseModule]
|
||||
imports: [CoreTestingModule, FormBaseModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(FormRendererComponent);
|
||||
formRendererComponent = fixture.componentInstance;
|
||||
@@ -430,9 +429,7 @@ describe('Form Renderer Component', () => {
|
||||
const twoSpanTextWidgetContainerId = '#field-1ff21afc-7df4-4607-8363-1dc8576e1c8e-container';
|
||||
const oneSpanTextWidgetContainerId = '#field-f4285ad-g123-1a73-521d-7nm4a7231aul0-container';
|
||||
|
||||
const formSizedElement = fixture.nativeElement.querySelector(
|
||||
`${oneSpanTextWidgetContainerId} section.adf-grid-list-column-view`
|
||||
);
|
||||
const formSizedElement = fixture.nativeElement.querySelector(`${oneSpanTextWidgetContainerId} section.adf-grid-list-column-view`);
|
||||
expectElementToBeVisible(formSizedElement);
|
||||
const sectionGridElement: HTMLElement[] = fixture.nativeElement.querySelectorAll(
|
||||
`${oneSpanTextWidgetContainerId} section .adf-grid-list-single-column`
|
||||
|
@@ -17,7 +17,6 @@
|
||||
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { UntypedFormControl } from '@angular/forms';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { CoreTestingModule } from '../../../testing/core.testing.module';
|
||||
import { InplaceFormInputComponent } from './inplace-form-input.component';
|
||||
|
||||
@@ -28,10 +27,7 @@ describe('InplaceFormInputComponent', () => {
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [InplaceFormInputComponent]
|
||||
}).compileComponents();
|
||||
});
|
||||
@@ -48,9 +44,7 @@ describe('InplaceFormInputComponent', () => {
|
||||
formControl.setValue('New Value');
|
||||
fixture.detectChanges();
|
||||
|
||||
const input = fixture.nativeElement.querySelector(
|
||||
'[data-automation-id="adf-inplace-input"]'
|
||||
);
|
||||
const input = fixture.nativeElement.querySelector('[data-automation-id="adf-inplace-input"]');
|
||||
|
||||
expect(input.value).toBe('New Value');
|
||||
});
|
||||
@@ -63,9 +57,7 @@ describe('InplaceFormInputComponent', () => {
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
const error = fixture.nativeElement.querySelector(
|
||||
'[data-automation-id="adf-inplace-input-error"]'
|
||||
);
|
||||
const error = fixture.nativeElement.querySelector('[data-automation-id="adf-inplace-input-error"]');
|
||||
|
||||
expect(error).toBeTruthy();
|
||||
});
|
||||
@@ -75,9 +67,7 @@ describe('InplaceFormInputComponent', () => {
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
const error = fixture.nativeElement.querySelector(
|
||||
'[data-automation-id="adf-inplace-input-label"]'
|
||||
);
|
||||
const error = fixture.nativeElement.querySelector('[data-automation-id="adf-inplace-input-label"]');
|
||||
|
||||
expect(error).toBeTruthy();
|
||||
});
|
||||
|
@@ -21,7 +21,6 @@ import { AmountWidgetComponent, ADF_AMOUNT_SETTINGS } from './amount.widget';
|
||||
import { FormBaseModule } from '../../../form-base.module';
|
||||
import { FormFieldTypes } from '../core/form-field-types';
|
||||
import { CoreTestingModule } from '../../../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { FormModel } from '../core/form.model';
|
||||
import { HarnessLoader } from '@angular/cdk/testing';
|
||||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||
@@ -37,7 +36,7 @@ describe('AmountWidgetComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), CoreTestingModule, FormBaseModule]
|
||||
imports: [CoreTestingModule, FormBaseModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(AmountWidgetComponent);
|
||||
widget = fixture.componentInstance;
|
||||
@@ -145,7 +144,7 @@ describe('AmountWidgetComponent - rendering', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), CoreTestingModule, FormBaseModule]
|
||||
imports: [CoreTestingModule, FormBaseModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(AmountWidgetComponent);
|
||||
widget = fixture.componentInstance;
|
||||
@@ -340,7 +339,7 @@ describe('AmountWidgetComponent settings', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), CoreTestingModule, FormBaseModule],
|
||||
imports: [CoreTestingModule, FormBaseModule],
|
||||
providers: [
|
||||
{
|
||||
provide: ADF_AMOUNT_SETTINGS,
|
||||
|
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
|
||||
import { FormModel } from '../core/form.model';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { FormFieldModel } from '../core/form-field.model';
|
||||
import { FormService } from '../../../services/form.service';
|
||||
import { CoreTestingModule } from '../../../../testing/core.testing.module';
|
||||
@@ -46,13 +45,10 @@ describe('BaseViewerWidgetComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
CoreTestingModule,
|
||||
TranslateModule.forRoot()
|
||||
],
|
||||
declarations: [ BaseViewerWidgetComponent ],
|
||||
providers: [ { provide: FormService, useValue: formServiceStub } ]
|
||||
});
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [BaseViewerWidgetComponent],
|
||||
providers: [{ provide: FormService, useValue: formServiceStub }]
|
||||
});
|
||||
|
||||
formServiceStub = TestBed.inject(FormService);
|
||||
fixture = TestBed.createComponent(BaseViewerWidgetComponent);
|
||||
@@ -82,7 +78,14 @@ describe('BaseViewerWidgetComponent', () => {
|
||||
* @param fixture test fixture
|
||||
* @param done callback
|
||||
*/
|
||||
function assertFileId(value: any, expectedFileId: string, fakeForm: FormModel, widget: BaseViewerWidgetComponent, fixture: ComponentFixture<BaseViewerWidgetComponent>, done: DoneFn) {
|
||||
function assertFileId(
|
||||
value: any,
|
||||
expectedFileId: string,
|
||||
fakeForm: FormModel,
|
||||
widget: BaseViewerWidgetComponent,
|
||||
fixture: ComponentFixture<BaseViewerWidgetComponent>,
|
||||
done: DoneFn
|
||||
) {
|
||||
const fakeField = new FormFieldModel(fakeForm, { id: 'fakeField', value });
|
||||
widget.field = fakeField;
|
||||
|
||||
@@ -93,4 +96,3 @@ function assertFileId(value: any, expectedFileId: string, fakeForm: FormModel, w
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -21,7 +21,7 @@ import { FormFieldModel } from '../core/form-field.model';
|
||||
import { FormModel } from '../core/form.model';
|
||||
import { CheckboxWidgetComponent } from './checkbox.widget';
|
||||
import { FormBaseModule } from '../../../form-base.module';
|
||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||
import { TranslateLoader } from '@ngx-translate/core';
|
||||
import { TranslateLoaderService } from '../../../../translation/translate-loader.service';
|
||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
import { CoreTestingModule } from '../../../../testing';
|
||||
@@ -39,7 +39,7 @@ describe('CheckboxWidgetComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), CoreTestingModule, FormBaseModule, MatCheckboxModule, MatTooltipModule],
|
||||
imports: [CoreTestingModule, FormBaseModule, MatCheckboxModule, MatTooltipModule],
|
||||
providers: [{ provide: TranslateLoader, useClass: TranslateLoaderService }]
|
||||
});
|
||||
fixture = TestBed.createComponent(CheckboxWidgetComponent);
|
||||
|
@@ -20,7 +20,6 @@ import { FormFieldModel } from '../core/form-field.model';
|
||||
import { FormModel } from '../core/form.model';
|
||||
import { DateTimeWidgetComponent } from './date-time.widget';
|
||||
import { CoreTestingModule } from '../../../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import { FormFieldTypes } from '../core/form-field-types';
|
||||
import { DateFieldValidator, DateTimeFieldValidator } from '../core';
|
||||
@@ -38,7 +37,7 @@ describe('DateTimeWidgetComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), CoreTestingModule, MatTooltipModule]
|
||||
imports: [CoreTestingModule, MatTooltipModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(DateTimeWidgetComponent);
|
||||
|
||||
|
@@ -21,7 +21,6 @@ import { FormFieldModel } from '../core/form-field.model';
|
||||
import { FormModel } from '../core/form.model';
|
||||
import { DateWidgetComponent } from './date.widget';
|
||||
import { CoreTestingModule } from '../../../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { FormFieldTypes } from '../core/form-field-types';
|
||||
import { DateFieldValidator, MaxDateFieldValidator, MinDateFieldValidator } from '../core/form-field-validator';
|
||||
|
||||
@@ -34,10 +33,7 @@ describe('DateWidgetComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
|
||||
form = new FormModel();
|
||||
@@ -168,9 +164,8 @@ describe('DateWidgetComponent', () => {
|
||||
});
|
||||
|
||||
describe('when is required', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
widget.field = new FormFieldModel( new FormModel({ taskId: '<id>' }), {
|
||||
widget.field = new FormFieldModel(new FormModel({ taskId: '<id>' }), {
|
||||
type: FormFieldTypes.DATE,
|
||||
required: true
|
||||
});
|
||||
@@ -190,7 +185,6 @@ describe('DateWidgetComponent', () => {
|
||||
});
|
||||
|
||||
describe('template check', () => {
|
||||
|
||||
afterEach(() => {
|
||||
fixture.destroy();
|
||||
TestBed.resetTestingModule();
|
||||
@@ -217,7 +211,7 @@ describe('DateWidgetComponent', () => {
|
||||
widget.field = new FormFieldModel(form, {
|
||||
id: 'date-field-id',
|
||||
name: 'date-name',
|
||||
value: '30-12-9999',
|
||||
value: '30-12-9999',
|
||||
type: 'date',
|
||||
dateDisplayFormat: 'MM-DD-YYYY'
|
||||
});
|
||||
|
@@ -25,7 +25,6 @@ import { FormFieldModel, FormFieldTypes, FormModel } from '../core';
|
||||
import { MatInputHarness } from '@angular/material/input/testing';
|
||||
import { MatTooltipHarness } from '@angular/material/tooltip/testing';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { CoreTestingModule } from '../../../../testing';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
|
||||
@@ -37,12 +36,7 @@ describe('DecimalComponent', () => {
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule,
|
||||
MatInputModule,
|
||||
FormsModule
|
||||
],
|
||||
imports: [CoreTestingModule, MatInputModule, FormsModule],
|
||||
declarations: [DecimalWidgetComponent],
|
||||
providers: [FormService]
|
||||
}).compileComponents();
|
||||
|
@@ -21,22 +21,16 @@ import { FormFieldModel } from '../core/form-field.model';
|
||||
import { FormModel } from '../core/form.model';
|
||||
import { HyperlinkWidgetComponent } from './hyperlink.widget';
|
||||
import { CoreTestingModule } from '../../../../testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
|
||||
describe('HyperlinkWidgetComponent', () => {
|
||||
|
||||
let widget: HyperlinkWidgetComponent;
|
||||
let fixture: ComponentFixture<HyperlinkWidgetComponent>;
|
||||
let element: HTMLElement;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule,
|
||||
MatTooltipModule
|
||||
]
|
||||
imports: [CoreTestingModule, MatTooltipModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(HyperlinkWidgetComponent);
|
||||
widget = fixture.componentInstance;
|
||||
@@ -134,8 +128,8 @@ describe('HyperlinkWidgetComponent', () => {
|
||||
const url = 'www.alfresco.com';
|
||||
|
||||
widget.field = new FormFieldModel(new FormModel(), {
|
||||
value: url,
|
||||
hyperlinkUrl: 'www.alfresco-test.com'
|
||||
value: url,
|
||||
hyperlinkUrl: 'www.alfresco-test.com'
|
||||
});
|
||||
widget.ngOnInit();
|
||||
|
||||
@@ -146,7 +140,7 @@ describe('HyperlinkWidgetComponent', () => {
|
||||
const url = 'www.alfresco.com';
|
||||
|
||||
widget.field = new FormFieldModel(new FormModel(), {
|
||||
displayText: url
|
||||
displayText: url
|
||||
});
|
||||
widget.ngOnInit();
|
||||
|
||||
|
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { MultilineTextWidgetComponentComponent } from './multiline-text.widget';
|
||||
import { CoreTestingModule } from '../../../../testing/core.testing.module';
|
||||
import { FormFieldModel } from '../core/form-field.model';
|
||||
@@ -35,7 +34,7 @@ describe('MultilineTextWidgetComponentComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), CoreTestingModule]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(MultilineTextWidgetComponentComponent);
|
||||
widget = fixture.componentInstance;
|
||||
|
@@ -19,7 +19,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { CoreTestingModule } from '../../../../testing';
|
||||
import { FormFieldModel, FormFieldTypes, FormModel } from '../core';
|
||||
import { NumberWidgetComponent } from './number.widget';
|
||||
@@ -36,7 +35,7 @@ describe('NumberWidgetComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), CoreTestingModule, MatInputModule, FormsModule, MatIconModule]
|
||||
imports: [CoreTestingModule, MatInputModule, FormsModule, MatIconModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(NumberWidgetComponent);
|
||||
widget = fixture.componentInstance;
|
||||
|
@@ -24,7 +24,6 @@ import { FormsModule } from '@angular/forms';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { CoreTestingModule } from '../../../../testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { HarnessLoader } from '@angular/cdk/testing';
|
||||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||
import { MatInputHarness } from '@angular/material/input/testing';
|
||||
@@ -42,7 +41,7 @@ describe('TextWidgetComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), CoreTestingModule, MatInputModule, FormsModule, MatIconModule]
|
||||
imports: [CoreTestingModule, MatInputModule, FormsModule, MatIconModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(TextWidgetComponent);
|
||||
widget = fixture.componentInstance;
|
||||
|
@@ -20,22 +20,17 @@ import { FormFieldModel } from './core/form-field.model';
|
||||
import { FormModel } from './core/form.model';
|
||||
import { WidgetComponent } from './widget.component';
|
||||
import { CoreTestingModule } from '../../../testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { filter } from 'rxjs/operators';
|
||||
import { FormRulesEvent } from '../../events/form-rules.event';
|
||||
|
||||
describe('WidgetComponent', () => {
|
||||
|
||||
let widget: WidgetComponent;
|
||||
let fixture: ComponentFixture<WidgetComponent>;
|
||||
let element: HTMLElement;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(WidgetComponent);
|
||||
|
||||
@@ -46,7 +41,6 @@ describe('WidgetComponent', () => {
|
||||
});
|
||||
|
||||
describe('Events', () => {
|
||||
|
||||
it('should click event be redirect on the form event service', fakeAsync(() => {
|
||||
widget.formService.formEvents.subscribe((event) => {
|
||||
expect(event).toBeTruthy();
|
||||
@@ -56,7 +50,7 @@ describe('WidgetComponent', () => {
|
||||
}));
|
||||
|
||||
it('should click event be redirect on the form rules event service', fakeAsync(() => {
|
||||
widget.formService.formRulesEvent.pipe(filter(event => event.type === 'click')).subscribe((event) => {
|
||||
widget.formService.formRulesEvent.pipe(filter((event) => event.type === 'click')).subscribe((event) => {
|
||||
expect(event).toBeTruthy();
|
||||
});
|
||||
|
||||
@@ -77,7 +71,7 @@ describe('WidgetComponent', () => {
|
||||
|
||||
let lastValue: FormFieldModel;
|
||||
|
||||
widget.fieldChanged.subscribe((field) => lastValue = field);
|
||||
widget.fieldChanged.subscribe((field) => (lastValue = field));
|
||||
widget.ngAfterViewInit();
|
||||
|
||||
expect(lastValue).not.toBe(null);
|
||||
@@ -90,7 +84,7 @@ describe('WidgetComponent', () => {
|
||||
const fakeField = new FormFieldModel(fakeForm, { id: 'fakeField', value: 'fakeValue' });
|
||||
|
||||
let lastValue: FormFieldModel;
|
||||
widget.fieldChanged.subscribe((field) => lastValue = field);
|
||||
widget.fieldChanged.subscribe((field) => (lastValue = field));
|
||||
widget.onFieldChanged(fakeField);
|
||||
|
||||
expect(lastValue).not.toBe(null);
|
||||
@@ -103,7 +97,7 @@ describe('WidgetComponent', () => {
|
||||
const fakeField = new FormFieldModel(fakeForm, { id: 'fakeField', value: 'fakeValue' });
|
||||
|
||||
let lastValue: FormRulesEvent;
|
||||
widget.formService.formRulesEvent.subscribe((event) => lastValue = event);
|
||||
widget.formService.formRulesEvent.subscribe((event) => (lastValue = event));
|
||||
|
||||
widget.onFieldChanged(fakeField);
|
||||
expect(lastValue.type).toEqual('fieldValueChanged');
|
||||
|
@@ -55,7 +55,10 @@ export class WidgetComponent implements AfterViewInit {
|
||||
* Emitted when a field value changes.
|
||||
*/
|
||||
@Output()
|
||||
fieldChanged: EventEmitter<FormFieldModel> = new EventEmitter<FormFieldModel>();
|
||||
fieldChanged = new EventEmitter<FormFieldModel>();
|
||||
|
||||
@Output()
|
||||
widgetError = new EventEmitter<any>();
|
||||
|
||||
touched: boolean = false;
|
||||
|
||||
|
@@ -17,7 +17,6 @@
|
||||
|
||||
import { FormBaseModule } from '../form-base.module';
|
||||
import { CoreTestingModule } from '../../testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { ByPassFormRuleManager, FormRulesManager, formRulesManagerFactory, FORM_RULES_MANAGER } from './form-rules.model';
|
||||
import { Injector } from '@angular/core';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
@@ -34,11 +33,9 @@ class CustomRuleManager extends FormRulesManager<any> {
|
||||
protected handleRuleEvent(): void {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
describe('Form Rules', () => {
|
||||
|
||||
let injector: Injector;
|
||||
const customRuleManager = new CustomRuleManager(null);
|
||||
let formService: FormService;
|
||||
@@ -46,11 +43,7 @@ describe('Form Rules', () => {
|
||||
describe('Injection token provided', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule,
|
||||
FormBaseModule
|
||||
],
|
||||
imports: [CoreTestingModule, FormBaseModule],
|
||||
providers: [
|
||||
{
|
||||
provide: FORM_RULES_MANAGER,
|
||||
@@ -115,11 +108,7 @@ describe('Form Rules', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule,
|
||||
FormBaseModule
|
||||
]
|
||||
imports: [CoreTestingModule, FormBaseModule]
|
||||
});
|
||||
injector = TestBed.inject(Injector);
|
||||
rulesManager = formRulesManagerFactory<any>(injector);
|
||||
|
@@ -19,28 +19,22 @@ import { TestBed } from '@angular/core/testing';
|
||||
import { formModelTabs } from '../../mock';
|
||||
import { FormService } from './form.service';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('Form service', () => {
|
||||
let service: FormService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
service = TestBed.inject(FormService);
|
||||
});
|
||||
|
||||
describe('parseForm', () => {
|
||||
|
||||
it('should parse a Form Definition with tabs', () => {
|
||||
expect(formModelTabs.formRepresentation.formDefinition).toBeDefined();
|
||||
const formParsed = service.parseForm(formModelTabs);
|
||||
expect(formParsed).toBeDefined();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
@@ -16,24 +16,19 @@
|
||||
*/
|
||||
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import {
|
||||
ContainerModel,
|
||||
FormFieldModel,
|
||||
FormFieldTypes,
|
||||
FormModel,
|
||||
TabModel,
|
||||
FormOutcomeModel
|
||||
} from '../components/widgets/core';
|
||||
import { ContainerModel, FormFieldModel, FormFieldTypes, FormModel, TabModel, FormOutcomeModel } from '../components/widgets/core';
|
||||
import { WidgetVisibilityModel, WidgetTypeEnum } from '../models/widget-visibility.model';
|
||||
import { WidgetVisibilityService } from './widget-visibility.service';
|
||||
import {
|
||||
fakeFormJson,
|
||||
formTest, formValues, complexVisibilityJsonVisible,
|
||||
nextConditionForm, complexVisibilityJsonNotVisible,
|
||||
formTest,
|
||||
formValues,
|
||||
complexVisibilityJsonVisible,
|
||||
nextConditionForm,
|
||||
complexVisibilityJsonNotVisible,
|
||||
headerVisibilityCond
|
||||
} from '../../mock/form/widget-visibility-cloud.service.mock';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
declare let jasmine: any;
|
||||
|
||||
@@ -45,10 +40,7 @@ describe('WidgetVisibilityCloudService', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
service = TestBed.inject(WidgetVisibilityService);
|
||||
jasmine.Ajax.install();
|
||||
@@ -59,7 +51,6 @@ describe('WidgetVisibilityCloudService', () => {
|
||||
});
|
||||
|
||||
describe('should be able to evaluate next condition operations', () => {
|
||||
|
||||
it('using == and return true', () => {
|
||||
booleanResult = service.evaluateCondition('test', 'test', '==');
|
||||
expect(booleanResult).toBeTruthy();
|
||||
@@ -167,7 +158,8 @@ describe('WidgetVisibilityCloudService', () => {
|
||||
name: 'FORM_VARIABLE_TEST',
|
||||
type: 'string',
|
||||
value: 'form_value_test'
|
||||
}]
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -484,7 +476,6 @@ describe('WidgetVisibilityCloudService', () => {
|
||||
});
|
||||
|
||||
it('should use the process variables when they are passed to check the visibility', () => {
|
||||
|
||||
visibilityObjTest.leftType = WidgetTypeEnum.field;
|
||||
visibilityObjTest.leftValue = 'FIELD_FORM_EMPTY';
|
||||
visibilityObjTest.operator = '==';
|
||||
@@ -560,13 +551,15 @@ describe('WidgetVisibilityCloudService', () => {
|
||||
visibilityObjTest.leftType = 'FIELD_TEST';
|
||||
visibilityObjTest.operator = '==';
|
||||
visibilityObjTest.rightType = 'LEFT_FORM_FIELD_ID';
|
||||
const contModel = new ContainerModel(new FormFieldModel(fakeFormWithField, {
|
||||
id: 'fake-container-id',
|
||||
type: FormFieldTypes.GROUP,
|
||||
name: 'fake-container-name',
|
||||
isVisible: true,
|
||||
visibilityCondition: visibilityObjTest
|
||||
}));
|
||||
const contModel = new ContainerModel(
|
||||
new FormFieldModel(fakeFormWithField, {
|
||||
id: 'fake-container-id',
|
||||
type: FormFieldTypes.GROUP,
|
||||
name: 'fake-container-name',
|
||||
isVisible: true,
|
||||
visibilityCondition: visibilityObjTest
|
||||
})
|
||||
);
|
||||
|
||||
fakeFormWithField.fieldsCache.push(contModel.field);
|
||||
service.refreshVisibility(fakeFormWithField);
|
||||
@@ -579,13 +572,15 @@ describe('WidgetVisibilityCloudService', () => {
|
||||
visibilityObjTest.operator = '!=';
|
||||
visibilityObjTest.rightType = WidgetTypeEnum.field;
|
||||
visibilityObjTest.rightValue = 'RIGHT_FORM_FIELD_ID';
|
||||
const contModel = new ContainerModel(new FormFieldModel(fakeFormWithField, {
|
||||
id: 'fake-container-id',
|
||||
type: FormFieldTypes.GROUP,
|
||||
name: 'fake-container-name',
|
||||
isVisible: true,
|
||||
visibilityCondition: visibilityObjTest
|
||||
}));
|
||||
const contModel = new ContainerModel(
|
||||
new FormFieldModel(fakeFormWithField, {
|
||||
id: 'fake-container-id',
|
||||
type: FormFieldTypes.GROUP,
|
||||
name: 'fake-container-name',
|
||||
isVisible: true,
|
||||
visibilityCondition: visibilityObjTest
|
||||
})
|
||||
);
|
||||
service.refreshEntityVisibility(contModel.field);
|
||||
expect(contModel.isVisible).toBeFalsy();
|
||||
});
|
||||
@@ -633,7 +628,8 @@ describe('WidgetVisibilityCloudService', () => {
|
||||
name: 'No'
|
||||
}
|
||||
]
|
||||
}, {
|
||||
},
|
||||
{
|
||||
id: 'textBoxTest',
|
||||
name: 'textbox test',
|
||||
type: 'people',
|
||||
@@ -661,7 +657,6 @@ describe('WidgetVisibilityCloudService', () => {
|
||||
});
|
||||
|
||||
describe('Visibility based on form variables', () => {
|
||||
|
||||
const fakeFormWithVariables = new FormModel(fakeFormJson);
|
||||
const complexVisibilityModel = new FormModel(complexVisibilityJsonVisible);
|
||||
const complexVisibilityJsonNotVisibleModel = new FormModel(complexVisibilityJsonNotVisible);
|
||||
@@ -682,15 +677,19 @@ describe('WidgetVisibilityCloudService', () => {
|
||||
});
|
||||
|
||||
it('should be able to analyze a complex visibility JSON truthy', () => {
|
||||
const isVisible = service.isFieldVisible(complexVisibilityModel,
|
||||
complexVisibilityJsonVisible.formDefinition.fields[2].fields[2][0].visibilityCondition);
|
||||
const isVisible = service.isFieldVisible(
|
||||
complexVisibilityModel,
|
||||
complexVisibilityJsonVisible.formDefinition.fields[2].fields[2][0].visibilityCondition
|
||||
);
|
||||
|
||||
expect(isVisible).toBe(true);
|
||||
});
|
||||
|
||||
it('should be able to analyze a complex visibility JSON false', () => {
|
||||
const isVisible = service.isFieldVisible(complexVisibilityJsonNotVisibleModel,
|
||||
complexVisibilityJsonNotVisible.formDefinition.fields[2].fields[2][0].visibilityCondition);
|
||||
const isVisible = service.isFieldVisible(
|
||||
complexVisibilityJsonNotVisibleModel,
|
||||
complexVisibilityJsonNotVisible.formDefinition.fields[2].fields[2][0].visibilityCondition
|
||||
);
|
||||
|
||||
expect(isVisible).toBe(false);
|
||||
});
|
||||
|
@@ -16,25 +16,21 @@
|
||||
*/
|
||||
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import {
|
||||
ContainerModel,
|
||||
FormFieldModel,
|
||||
FormFieldTypes,
|
||||
FormModel,
|
||||
TabModel
|
||||
} from '../components/widgets/core';
|
||||
import { ContainerModel, FormFieldModel, FormFieldTypes, FormModel, TabModel } from '../components/widgets/core';
|
||||
import { WidgetVisibilityModel } from '../models/widget-visibility.model';
|
||||
import { WidgetVisibilityService } from './widget-visibility.service';
|
||||
import {
|
||||
fakeFormJson, formTest,
|
||||
formValues, complexVisibilityJsonVisible,
|
||||
complexVisibilityJsonNotVisible, tabVisibilityJsonMock,
|
||||
fakeFormJson,
|
||||
formTest,
|
||||
formValues,
|
||||
complexVisibilityJsonVisible,
|
||||
complexVisibilityJsonNotVisible,
|
||||
tabVisibilityJsonMock,
|
||||
tabInvalidFormVisibility,
|
||||
fakeFormChainedVisibilityJson,
|
||||
fakeFormCheckBoxVisibilityJson
|
||||
} from '../../mock/form/widget-visibility.service.mock';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('WidgetVisibilityService', () => {
|
||||
let service: WidgetVisibilityService;
|
||||
@@ -42,7 +38,7 @@ describe('WidgetVisibilityService', () => {
|
||||
|
||||
const stubFormWithFields = new FormModel(fakeFormJson);
|
||||
|
||||
const evaluateConditions = (conditionsArgs: [leftValue: any, rightValue: any][], operator: string ): (boolean | undefined)[] => {
|
||||
const evaluateConditions = (conditionsArgs: [leftValue: any, rightValue: any][], operator: string): (boolean | undefined)[] => {
|
||||
const resultsArray: (boolean | undefined)[] = [];
|
||||
|
||||
conditionsArgs.forEach(([leftValue, rightValue]) => {
|
||||
@@ -53,27 +49,26 @@ describe('WidgetVisibilityService', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
service = TestBed.inject(WidgetVisibilityService);
|
||||
});
|
||||
|
||||
describe('should be able to evaluate next condition operations', () => {
|
||||
|
||||
it('using == and return true', () => {
|
||||
const resultsArray = evaluateConditions([
|
||||
[true, true],
|
||||
[false, false],
|
||||
['true', true],
|
||||
[true, 'true'],
|
||||
['true', 'true'],
|
||||
['test', 'test'],
|
||||
['4', 4],
|
||||
[0, 0]
|
||||
], '==');
|
||||
const resultsArray = evaluateConditions(
|
||||
[
|
||||
[true, true],
|
||||
[false, false],
|
||||
['true', true],
|
||||
[true, 'true'],
|
||||
['true', 'true'],
|
||||
['test', 'test'],
|
||||
['4', 4],
|
||||
[0, 0]
|
||||
],
|
||||
'=='
|
||||
);
|
||||
|
||||
resultsArray.forEach((result) => {
|
||||
expect(result).toBe(true);
|
||||
@@ -81,16 +76,19 @@ describe('WidgetVisibilityService', () => {
|
||||
});
|
||||
|
||||
it('using == and return false', () => {
|
||||
const resultsArray = evaluateConditions([
|
||||
[true, false],
|
||||
[false, true],
|
||||
['false', true],
|
||||
[false, 'true'],
|
||||
['false', 'true'],
|
||||
['test', 'testt'],
|
||||
['2', 3],
|
||||
[0, 1]
|
||||
], '==');
|
||||
const resultsArray = evaluateConditions(
|
||||
[
|
||||
[true, false],
|
||||
[false, true],
|
||||
['false', true],
|
||||
[false, 'true'],
|
||||
['false', 'true'],
|
||||
['test', 'testt'],
|
||||
['2', 3],
|
||||
[0, 1]
|
||||
],
|
||||
'=='
|
||||
);
|
||||
|
||||
resultsArray.forEach((result) => {
|
||||
expect(result).toBe(false);
|
||||
@@ -98,16 +96,19 @@ describe('WidgetVisibilityService', () => {
|
||||
});
|
||||
|
||||
it('using != and return true', () => {
|
||||
const resultsArray = evaluateConditions([
|
||||
['test', 'te'],
|
||||
['4', 123],
|
||||
[0, 1],
|
||||
[true, false],
|
||||
[false, true],
|
||||
['false', true],
|
||||
[false, 'true'],
|
||||
['false', 'true']
|
||||
], '!=');
|
||||
const resultsArray = evaluateConditions(
|
||||
[
|
||||
['test', 'te'],
|
||||
['4', 123],
|
||||
[0, 1],
|
||||
[true, false],
|
||||
[false, true],
|
||||
['false', true],
|
||||
[false, 'true'],
|
||||
['false', 'true']
|
||||
],
|
||||
'!='
|
||||
);
|
||||
|
||||
resultsArray.forEach((result) => {
|
||||
expect(result).toBe(true);
|
||||
@@ -115,16 +116,19 @@ describe('WidgetVisibilityService', () => {
|
||||
});
|
||||
|
||||
it('using != and return false', () => {
|
||||
const resultsArray = evaluateConditions([
|
||||
['testtest', 'testtest'],
|
||||
['7', 7],
|
||||
[0, 0],
|
||||
[true, true],
|
||||
[false, false],
|
||||
['true', true],
|
||||
[true, 'true'],
|
||||
['true', 'true']
|
||||
], '!=');
|
||||
const resultsArray = evaluateConditions(
|
||||
[
|
||||
['testtest', 'testtest'],
|
||||
['7', 7],
|
||||
[0, 0],
|
||||
[true, true],
|
||||
[false, false],
|
||||
['true', true],
|
||||
[true, 'true'],
|
||||
['true', 'true']
|
||||
],
|
||||
'!='
|
||||
);
|
||||
|
||||
resultsArray.forEach((result) => {
|
||||
expect(result).toBe(false);
|
||||
@@ -132,11 +136,14 @@ describe('WidgetVisibilityService', () => {
|
||||
});
|
||||
|
||||
it('using < and return false', () => {
|
||||
const resultsArray = evaluateConditions([
|
||||
[2, 1],
|
||||
[1, 0],
|
||||
[0, -1]
|
||||
], '<');
|
||||
const resultsArray = evaluateConditions(
|
||||
[
|
||||
[2, 1],
|
||||
[1, 0],
|
||||
[0, -1]
|
||||
],
|
||||
'<'
|
||||
);
|
||||
|
||||
resultsArray.forEach((result) => {
|
||||
expect(result).toBe(false);
|
||||
@@ -144,12 +151,15 @@ describe('WidgetVisibilityService', () => {
|
||||
});
|
||||
|
||||
it('using <= and return true', () => {
|
||||
const resultsArray = evaluateConditions([
|
||||
[3, 4],
|
||||
[0, 1],
|
||||
[0, 0],
|
||||
[1, 1]
|
||||
], '<=');
|
||||
const resultsArray = evaluateConditions(
|
||||
[
|
||||
[3, 4],
|
||||
[0, 1],
|
||||
[0, 0],
|
||||
[1, 1]
|
||||
],
|
||||
'<='
|
||||
);
|
||||
|
||||
resultsArray.forEach((result) => {
|
||||
expect(result).toBe(true);
|
||||
@@ -157,12 +167,15 @@ describe('WidgetVisibilityService', () => {
|
||||
});
|
||||
|
||||
it('using > and return false', () => {
|
||||
const resultsArray = evaluateConditions([
|
||||
[0, 1],
|
||||
[0, 141],
|
||||
[-144, 0],
|
||||
[32, 44]
|
||||
], '>');
|
||||
const resultsArray = evaluateConditions(
|
||||
[
|
||||
[0, 1],
|
||||
[0, 141],
|
||||
[-144, 0],
|
||||
[32, 44]
|
||||
],
|
||||
'>'
|
||||
);
|
||||
|
||||
resultsArray.forEach((result) => {
|
||||
expect(result).toBe(false);
|
||||
@@ -170,13 +183,16 @@ describe('WidgetVisibilityService', () => {
|
||||
});
|
||||
|
||||
it('using >= and return true', () => {
|
||||
const resultsArray = evaluateConditions([
|
||||
[12, 2],
|
||||
[2, 2],
|
||||
[1, 0],
|
||||
[0, 0],
|
||||
[0, -10]
|
||||
], '>=');
|
||||
const resultsArray = evaluateConditions(
|
||||
[
|
||||
[12, 2],
|
||||
[2, 2],
|
||||
[1, 0],
|
||||
[0, 0],
|
||||
[0, -10]
|
||||
],
|
||||
'>='
|
||||
);
|
||||
|
||||
resultsArray.forEach((result) => {
|
||||
expect(result).toBe(true);
|
||||
@@ -249,7 +265,8 @@ describe('WidgetVisibilityService', () => {
|
||||
name: 'FORM_VARIABLE_TEST',
|
||||
type: 'string',
|
||||
value: 'form_value_test'
|
||||
}]
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -415,7 +432,6 @@ describe('WidgetVisibilityService', () => {
|
||||
expect(isVisible).toBeTruthy();
|
||||
});
|
||||
|
||||
|
||||
it('should return true when left field value is equal to true and rigth value is equal to "true"', () => {
|
||||
spyOn(service, 'getFieldValue').and.returnValue(true);
|
||||
spyOn(service, 'isFormFieldValid').and.returnValue(true);
|
||||
@@ -670,13 +686,15 @@ describe('WidgetVisibilityService', () => {
|
||||
visibilityObjTest.leftFormFieldId = 'FIELD_TEST';
|
||||
visibilityObjTest.operator = '==';
|
||||
visibilityObjTest.rightFormFieldId = 'LEFT_FORM_FIELD_ID';
|
||||
const contModel = new ContainerModel(new FormFieldModel(fakeFormWithField, {
|
||||
id: 'fake-container-id',
|
||||
type: FormFieldTypes.GROUP,
|
||||
name: 'fake-container-name',
|
||||
isVisible: true,
|
||||
visibilityCondition: visibilityObjTest
|
||||
}));
|
||||
const contModel = new ContainerModel(
|
||||
new FormFieldModel(fakeFormWithField, {
|
||||
id: 'fake-container-id',
|
||||
type: FormFieldTypes.GROUP,
|
||||
name: 'fake-container-name',
|
||||
isVisible: true,
|
||||
visibilityCondition: visibilityObjTest
|
||||
})
|
||||
);
|
||||
|
||||
fakeFormWithField.fieldsCache.push(contModel.field);
|
||||
service.refreshVisibility(fakeFormWithField);
|
||||
@@ -687,13 +705,15 @@ describe('WidgetVisibilityService', () => {
|
||||
visibilityObjTest.leftFormFieldId = 'FIELD_TEST';
|
||||
visibilityObjTest.operator = '!=';
|
||||
visibilityObjTest.rightFormFieldId = 'RIGHT_FORM_FIELD_ID';
|
||||
const contModel = new ContainerModel(new FormFieldModel(fakeFormWithField, {
|
||||
id: 'fake-container-id',
|
||||
type: FormFieldTypes.GROUP,
|
||||
name: 'fake-container-name',
|
||||
isVisible: true,
|
||||
visibilityCondition: visibilityObjTest
|
||||
}));
|
||||
const contModel = new ContainerModel(
|
||||
new FormFieldModel(fakeFormWithField, {
|
||||
id: 'fake-container-id',
|
||||
type: FormFieldTypes.GROUP,
|
||||
name: 'fake-container-name',
|
||||
isVisible: true,
|
||||
visibilityCondition: visibilityObjTest
|
||||
})
|
||||
);
|
||||
service.refreshEntityVisibility(contModel.field);
|
||||
expect(contModel.isVisible).toBeFalsy();
|
||||
});
|
||||
@@ -752,7 +772,8 @@ describe('WidgetVisibilityService', () => {
|
||||
name: 'No'
|
||||
}
|
||||
]
|
||||
}, {
|
||||
},
|
||||
{
|
||||
id: 'textBoxTest',
|
||||
name: 'textbox test',
|
||||
type: 'people',
|
||||
@@ -780,7 +801,6 @@ describe('WidgetVisibilityService', () => {
|
||||
});
|
||||
|
||||
describe('Visibility based on form variables', () => {
|
||||
|
||||
let fakeFormWithVariables = new FormModel(fakeFormJson);
|
||||
const fakeTabVisibilityModel = new FormModel(tabVisibilityJsonMock);
|
||||
const complexVisibilityModel = new FormModel(complexVisibilityJsonVisible);
|
||||
@@ -804,14 +824,19 @@ describe('WidgetVisibilityService', () => {
|
||||
});
|
||||
|
||||
it('should be able to analyze a complex visibility JSON truthy', () => {
|
||||
const isVisible = service.isFieldVisible(complexVisibilityModel,
|
||||
complexVisibilityJsonVisible.formDefinition.fields[2].fields[2][0].visibilityCondition);
|
||||
const isVisible = service.isFieldVisible(
|
||||
complexVisibilityModel,
|
||||
complexVisibilityJsonVisible.formDefinition.fields[2].fields[2][0].visibilityCondition
|
||||
);
|
||||
|
||||
expect(isVisible).toBe(true);
|
||||
});
|
||||
|
||||
it('should be able to analyze a complex visibility JSON false', () => {
|
||||
const formField = new FormFieldModel(complexVisibilityJsonNotVisibleModel, complexVisibilityJsonNotVisible.formDefinition.fields[2].fields[2][0]);
|
||||
const formField = new FormFieldModel(
|
||||
complexVisibilityJsonNotVisibleModel,
|
||||
complexVisibilityJsonNotVisible.formDefinition.fields[2].fields[2][0]
|
||||
);
|
||||
const isVisible = service.isFieldVisible(complexVisibilityJsonNotVisibleModel, new WidgetVisibilityModel(formField.visibilityCondition));
|
||||
expect(isVisible).toBe(false);
|
||||
});
|
||||
@@ -899,7 +924,6 @@ describe('WidgetVisibilityService', () => {
|
||||
});
|
||||
|
||||
describe('Visibility calculation in complex forms', () => {
|
||||
|
||||
const fakeFormWithVariables = new FormModel(fakeFormChainedVisibilityJson);
|
||||
|
||||
it('Should be able to validate correctly the visibility for the text field for complex expressions', () => {
|
||||
@@ -927,7 +951,6 @@ describe('WidgetVisibilityService', () => {
|
||||
});
|
||||
|
||||
describe('Visibility calculation in checkbox forms', () => {
|
||||
|
||||
const fakeFormWithValues = new FormModel(fakeFormCheckBoxVisibilityJson);
|
||||
|
||||
it('Should be able to validate correctly the visibility for the checkbox expression', () => {
|
||||
|
@@ -17,7 +17,6 @@
|
||||
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { IdentityUserInfoComponent } from './identity-user-info.component';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { MatMenuModule } from '@angular/material/menu';
|
||||
import { By } from '@angular/platform-browser';
|
||||
@@ -28,9 +27,21 @@ describe('IdentityUserInfoComponent', () => {
|
||||
let fixture: ComponentFixture<IdentityUserInfoComponent>;
|
||||
let element: HTMLElement;
|
||||
|
||||
const identityUserMock = { firstName: 'fake-identity-first-name', lastName: 'fake-identity-last-name', email: 'fakeIdentity@email.com' } as unknown as IdentityUserModel;
|
||||
const identityUserWithOutFirstNameMock = { firstName: null, lastName: 'fake-identity-last-name', email: 'fakeIdentity@email.com' } as unknown as IdentityUserModel;
|
||||
const identityUserWithOutLastNameMock = { firstName: 'fake-identity-first-name', lastName: null, email: 'fakeIdentity@email.com' } as unknown as IdentityUserModel;
|
||||
const identityUserMock = {
|
||||
firstName: 'fake-identity-first-name',
|
||||
lastName: 'fake-identity-last-name',
|
||||
email: 'fakeIdentity@email.com'
|
||||
} as unknown as IdentityUserModel;
|
||||
const identityUserWithOutFirstNameMock = {
|
||||
firstName: null,
|
||||
lastName: 'fake-identity-last-name',
|
||||
email: 'fakeIdentity@email.com'
|
||||
} as unknown as IdentityUserModel;
|
||||
const identityUserWithOutLastNameMock = {
|
||||
firstName: 'fake-identity-first-name',
|
||||
lastName: null,
|
||||
email: 'fakeIdentity@email.com'
|
||||
} as unknown as IdentityUserModel;
|
||||
|
||||
const whenFixtureReady = async () => {
|
||||
fixture.detectChanges();
|
||||
@@ -40,11 +51,7 @@ describe('IdentityUserInfoComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule,
|
||||
MatMenuModule
|
||||
]
|
||||
imports: [CoreTestingModule, MatMenuModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(IdentityUserInfoComponent);
|
||||
component = fixture.componentInstance;
|
||||
@@ -70,7 +77,6 @@ describe('IdentityUserInfoComponent', () => {
|
||||
});
|
||||
|
||||
describe('when identity user is logged in', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
component.identityUser = identityUserMock;
|
||||
component.isLoggedIn = true;
|
||||
|
@@ -21,7 +21,7 @@ import { MatTabChangeEvent } from '@angular/material/tabs';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { InfoDrawerComponent } from './info-drawer.component';
|
||||
import { of } from 'rxjs';
|
||||
import { TranslateService, TranslateModule } from '@ngx-translate/core';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { ESCAPE } from '@angular/cdk/keycodes';
|
||||
import { HarnessLoader } from '@angular/cdk/testing';
|
||||
@@ -36,10 +36,7 @@ describe('InfoDrawerComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
translateService = TestBed.inject(TranslateService);
|
||||
spyOn(translateService, 'get').and.callFake((key) => of(key));
|
||||
@@ -56,7 +53,7 @@ describe('InfoDrawerComponent', () => {
|
||||
|
||||
it('should emit when tab is changed', () => {
|
||||
const tabEmitSpy = spyOn(component.currentTab, 'emit');
|
||||
const event = {index: 1, tab: {textLabel: 'DETAILS'}} as MatTabChangeEvent;
|
||||
const event = { index: 1, tab: { textLabel: 'DETAILS' } } as MatTabChangeEvent;
|
||||
component.onTabChange(event);
|
||||
expect(tabEmitSpy).toHaveBeenCalledWith(1);
|
||||
});
|
||||
@@ -91,12 +88,9 @@ describe('InfoDrawerComponent', () => {
|
||||
@Component({
|
||||
template: `
|
||||
<adf-info-drawer [selectedIndex]="tabIndex" [icon]="icon" title="Fake Title Custom">
|
||||
<adf-info-drawer-tab label="Tab1">
|
||||
</adf-info-drawer-tab>
|
||||
<adf-info-drawer-tab label="Tab2">
|
||||
</adf-info-drawer-tab>
|
||||
<adf-info-drawer-tab label="Tab3" icon="tab-icon">
|
||||
</adf-info-drawer-tab>
|
||||
<adf-info-drawer-tab label="Tab1"></adf-info-drawer-tab>
|
||||
<adf-info-drawer-tab label="Tab2"></adf-info-drawer-tab>
|
||||
<adf-info-drawer-tab label="Tab3" icon="tab-icon"></adf-info-drawer-tab>
|
||||
</adf-info-drawer>
|
||||
`
|
||||
})
|
||||
@@ -111,18 +105,12 @@ describe('Custom InfoDrawer', () => {
|
||||
let translateService: TranslateService;
|
||||
let loader: HarnessLoader;
|
||||
|
||||
const getNodeIcon = () =>
|
||||
fixture.debugElement.queryAll(By.css('[info-drawer-node-icon]'));
|
||||
const getNodeIcon = () => fixture.debugElement.queryAll(By.css('[info-drawer-node-icon]'));
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
declarations: [
|
||||
CustomInfoDrawerComponent
|
||||
]
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [CustomInfoDrawerComponent]
|
||||
});
|
||||
translateService = TestBed.inject(TranslateService);
|
||||
spyOn(translateService, 'get').and.callFake((key) => of(key));
|
||||
@@ -174,7 +162,7 @@ describe('Custom InfoDrawer', () => {
|
||||
it('should render a icon with title', () => {
|
||||
component.icon = '/assets/images/ft_ic_miscellaneous.svg';
|
||||
fixture.detectChanges();
|
||||
const icon = getNodeIcon();
|
||||
const icon = getNodeIcon();
|
||||
const srcAttribute = icon[0].nativeElement.getAttribute('src');
|
||||
expect(icon.length).toBe(1);
|
||||
expect(srcAttribute).toContain('/assets/images/ft_ic_miscellaneous.svg');
|
||||
@@ -182,10 +170,7 @@ describe('Custom InfoDrawer', () => {
|
||||
});
|
||||
|
||||
@Component({
|
||||
template: `
|
||||
<adf-info-drawer [showHeader]="showHeader" [icon]="icon" title="Fake Visibility Info Drawer Title">
|
||||
</adf-info-drawer>
|
||||
`
|
||||
template: ` <adf-info-drawer [showHeader]="showHeader" [icon]="icon" title="Fake Visibility Info Drawer Title"> </adf-info-drawer> `
|
||||
})
|
||||
class VisibilityInfoDrawerComponent extends InfoDrawerComponent {
|
||||
showHeader: boolean;
|
||||
@@ -195,18 +180,12 @@ class VisibilityInfoDrawerComponent extends InfoDrawerComponent {
|
||||
describe('Header visibility InfoDrawer', () => {
|
||||
let fixture: ComponentFixture<VisibilityInfoDrawerComponent>;
|
||||
let component: VisibilityInfoDrawerComponent;
|
||||
const getNodeIcon = () =>
|
||||
fixture.debugElement.queryAll(By.css('[info-drawer-node-icon]'));
|
||||
const getNodeIcon = () => fixture.debugElement.queryAll(By.css('[info-drawer-node-icon]'));
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
declarations: [
|
||||
VisibilityInfoDrawerComponent
|
||||
]
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [VisibilityInfoDrawerComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(VisibilityInfoDrawerComponent);
|
||||
fixture.detectChanges();
|
||||
|
@@ -20,11 +20,9 @@ import { AppConfigService } from '../app-config/app-config.service';
|
||||
import { LanguageMenuComponent } from './language-menu.component';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { UserPreferencesService } from '../common/services/user-preferences.service';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { LanguageService } from './service/language.service';
|
||||
|
||||
describe('LanguageMenuComponent', () => {
|
||||
|
||||
let fixture: ComponentFixture<LanguageMenuComponent>;
|
||||
let component: LanguageMenuComponent;
|
||||
let appConfig: AppConfigService;
|
||||
@@ -49,10 +47,7 @@ describe('LanguageMenuComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
|
||||
fixture = TestBed.createComponent(LanguageMenuComponent);
|
||||
@@ -71,7 +66,7 @@ describe('LanguageMenuComponent', () => {
|
||||
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
component.languages$.subscribe(langs => {
|
||||
component.languages$.subscribe((langs) => {
|
||||
expect(langs).toEqual(languages);
|
||||
done();
|
||||
});
|
||||
|
@@ -22,7 +22,6 @@ import { By } from '@angular/platform-browser';
|
||||
import { SidenavLayoutModule } from '../../layout.module';
|
||||
import { Component } from '@angular/core';
|
||||
import { MaterialModule } from '../../../material.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { HarnessLoader } from '@angular/cdk/testing';
|
||||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||
import { MatToolbarHarness } from '@angular/material/toolbar/testing';
|
||||
@@ -35,10 +34,7 @@ describe('HeaderLayoutComponent', () => {
|
||||
describe('Input parameters', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(HeaderLayoutComponent);
|
||||
loader = TestbedHarnessEnvironment.loader(fixture);
|
||||
@@ -257,8 +253,7 @@ describe('HeaderLayoutComponent', () => {
|
||||
describe('Template transclusion', () => {
|
||||
@Component({
|
||||
selector: 'adf-test-layout-header',
|
||||
template: `
|
||||
<adf-layout-header title="test" color="primary">
|
||||
template: ` <adf-layout-header title="test" color="primary">
|
||||
<p>Test text</p>
|
||||
<p></p>
|
||||
</adf-layout-header>`
|
||||
@@ -267,7 +262,7 @@ describe('HeaderLayoutComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), CoreTestingModule, SidenavLayoutModule, MaterialModule],
|
||||
imports: [CoreTestingModule, SidenavLayoutModule, MaterialModule],
|
||||
declarations: [HeaderLayoutTesterComponent]
|
||||
});
|
||||
});
|
||||
|
@@ -21,7 +21,6 @@ import { MaterialModule } from '../../../material.module';
|
||||
import { SidebarActionMenuComponent } from './sidebar-action-menu.component';
|
||||
import { CoreTestingModule } from '../../../testing/core.testing.module';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('SidebarActionMenuComponent', () => {
|
||||
let element: HTMLElement;
|
||||
@@ -30,10 +29,7 @@ describe('SidebarActionMenuComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(SidebarActionMenuComponent);
|
||||
element = fixture.nativeElement;
|
||||
@@ -86,14 +82,8 @@ describe('Custom SidebarActionMenuComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [
|
||||
SidebarActionMenuComponent,
|
||||
CustomSidebarActionMenuComponent
|
||||
],
|
||||
imports: [
|
||||
MaterialModule,
|
||||
NoopAnimationsModule
|
||||
]
|
||||
declarations: [SidebarActionMenuComponent, CustomSidebarActionMenuComponent],
|
||||
imports: [MaterialModule, NoopAnimationsModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(CustomSidebarActionMenuComponent);
|
||||
fixture.detectChanges();
|
||||
|
@@ -17,7 +17,6 @@
|
||||
|
||||
import { BasicAlfrescoAuthService, CoreTestingModule, LoginDialogPanelComponent } from '@alfresco/adf-core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { of } from 'rxjs';
|
||||
import { OidcAuthenticationService } from '../../../auth/services/oidc-authentication.service';
|
||||
|
||||
@@ -31,13 +30,8 @@ describe('LoginDialogPanelComponent', () => {
|
||||
|
||||
beforeEach(async () => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
providers: [
|
||||
{ provide: OidcAuthenticationService, useValue: {} }
|
||||
]
|
||||
imports: [CoreTestingModule],
|
||||
providers: [{ provide: OidcAuthenticationService, useValue: {} }]
|
||||
});
|
||||
fixture = TestBed.createComponent(LoginDialogPanelComponent);
|
||||
basicAlfrescoAuthService = TestBed.inject(BasicAlfrescoAuthService);
|
||||
|
@@ -22,7 +22,6 @@ import {
|
||||
CoreTestingModule,
|
||||
LoginErrorEvent,
|
||||
LoginSuccessEvent,
|
||||
LogService,
|
||||
UserPreferencesService
|
||||
} from '@alfresco/adf-core';
|
||||
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
|
||||
@@ -61,14 +60,12 @@ describe('LoginComponent', () => {
|
||||
|
||||
beforeEach(fakeAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
CoreTestingModule
|
||||
],
|
||||
imports: [CoreTestingModule],
|
||||
providers: [
|
||||
{
|
||||
provide: OidcAuthenticationService, useValue: {
|
||||
ssoLogin: () => {
|
||||
},
|
||||
provide: OidcAuthenticationService,
|
||||
useValue: {
|
||||
ssoLogin: () => {},
|
||||
isPublicUrl: () => false,
|
||||
hasValidIdToken: () => false,
|
||||
isLoggedIn: () => false
|
||||
@@ -89,9 +86,6 @@ describe('LoginComponent', () => {
|
||||
userPreferences = TestBed.inject(UserPreferencesService);
|
||||
appConfigService = TestBed.inject(AppConfigService);
|
||||
|
||||
const logService = TestBed.inject(LogService);
|
||||
spyOn(logService, 'error');
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
@@ -117,17 +111,11 @@ describe('LoginComponent', () => {
|
||||
};
|
||||
|
||||
it('should be autocomplete off', () => {
|
||||
expect(
|
||||
element
|
||||
.querySelector('#adf-login-form')
|
||||
.getAttribute('autocomplete')
|
||||
).toBe('off');
|
||||
expect(element.querySelector('#adf-login-form').getAttribute('autocomplete')).toBe('off');
|
||||
});
|
||||
|
||||
it('should redirect to route on successful login', () => {
|
||||
spyOn(basicAlfrescoAuthService, 'login').and.returnValue(
|
||||
of({ type: 'type', ticket: 'ticket' })
|
||||
);
|
||||
spyOn(basicAlfrescoAuthService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' }));
|
||||
const redirect = '/home';
|
||||
component.successRoute = redirect;
|
||||
spyOn(router, 'navigate');
|
||||
@@ -200,7 +188,6 @@ describe('LoginComponent', () => {
|
||||
});
|
||||
|
||||
describe('Login button', () => {
|
||||
|
||||
const getLoginButton = () => element.querySelector('#login-button');
|
||||
const getLoginButtonText = () => element.querySelector('#login-button span.adf-login-button-label').innerText;
|
||||
|
||||
@@ -290,12 +277,11 @@ describe('LoginComponent', () => {
|
||||
});
|
||||
|
||||
describe('Remember me', () => {
|
||||
|
||||
it('should be checked by default', () => {
|
||||
expect(element.querySelector('#adf-login-remember input[type="checkbox"]').checked).toBe(true);
|
||||
});
|
||||
|
||||
it('should set the component\'s rememberMe property properly', () => {
|
||||
it('should set the component rememberMe property properly', () => {
|
||||
element.querySelector('#adf-login-remember').dispatchEvent(new Event('change'));
|
||||
fixture.detectChanges();
|
||||
|
||||
@@ -335,10 +321,11 @@ describe('LoginComponent', () => {
|
||||
});
|
||||
|
||||
describe('Copyright text', () => {
|
||||
|
||||
it('should render the default copyright text', () => {
|
||||
expect(element.querySelector('[data-automation-id="login-copyright"]')).toBeDefined();
|
||||
expect(element.querySelector('[data-automation-id="login-copyright"]').innerText).toEqual('\u00A9 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.');
|
||||
expect(element.querySelector('[data-automation-id="login-copyright"]').innerText).toEqual(
|
||||
'\u00A9 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.'
|
||||
);
|
||||
});
|
||||
|
||||
it('should render the customised copyright text', () => {
|
||||
@@ -376,7 +363,6 @@ describe('LoginComponent', () => {
|
||||
});
|
||||
|
||||
describe('Error', () => {
|
||||
|
||||
it('should render validation min-length error when the username is just 1 character with a custom validation Validators.minLength(3)', () => {
|
||||
component.fieldsValidation = {
|
||||
username: ['', Validators.compose([Validators.required, Validators.minLength(3)])],
|
||||
@@ -529,12 +515,14 @@ describe('LoginComponent', () => {
|
||||
});
|
||||
|
||||
it('should return CORS error when server CORS error occurs', (done) => {
|
||||
spyOn(basicAlfrescoAuthService, 'login').and.returnValue(throwError({
|
||||
error: {
|
||||
crossDomain: true,
|
||||
message: 'ERROR: the network is offline, Origin is not allowed by Access-Control-Allow-Origin'
|
||||
}
|
||||
}));
|
||||
spyOn(basicAlfrescoAuthService, 'login').and.returnValue(
|
||||
throwError({
|
||||
error: {
|
||||
crossDomain: true,
|
||||
message: 'ERROR: the network is offline, Origin is not allowed by Access-Control-Allow-Origin'
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
component.error.subscribe(() => {
|
||||
fixture.detectChanges();
|
||||
@@ -550,8 +538,7 @@ describe('LoginComponent', () => {
|
||||
});
|
||||
|
||||
it('should return CSRF error when server CSRF error occurs', fakeAsync(() => {
|
||||
spyOn(basicAlfrescoAuthService, 'login')
|
||||
.and.returnValue(throwError({ message: 'ERROR: Invalid CSRF-token', status: 403 }));
|
||||
spyOn(basicAlfrescoAuthService, 'login').and.returnValue(throwError({ message: 'ERROR: Invalid CSRF-token', status: 403 }));
|
||||
|
||||
component.error.subscribe(() => {
|
||||
fixture.detectChanges();
|
||||
@@ -565,14 +552,12 @@ describe('LoginComponent', () => {
|
||||
}));
|
||||
|
||||
it('should return ECM read-only error when error occurs', fakeAsync(() => {
|
||||
spyOn(basicAlfrescoAuthService, 'login')
|
||||
.and.returnValue(
|
||||
throwError(
|
||||
{
|
||||
message: 'ERROR: 00170728 Access Denied. The system is currently in read-only mode',
|
||||
status: 403
|
||||
}
|
||||
));
|
||||
spyOn(basicAlfrescoAuthService, 'login').and.returnValue(
|
||||
throwError({
|
||||
message: 'ERROR: 00170728 Access Denied. The system is currently in read-only mode',
|
||||
status: 403
|
||||
})
|
||||
);
|
||||
|
||||
component.error.subscribe(() => {
|
||||
fixture.detectChanges();
|
||||
@@ -635,9 +620,7 @@ describe('LoginComponent', () => {
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.isError).toBe(false);
|
||||
expect(event).toEqual(
|
||||
new LoginSuccessEvent({ type: 'type', ticket: 'ticket' }, 'fake-username', null)
|
||||
);
|
||||
expect(event).toEqual(new LoginSuccessEvent({ type: 'type', ticket: 'ticket' }, 'fake-username', null));
|
||||
});
|
||||
|
||||
loginWithCredentials('fake-username', 'fake-password');
|
||||
@@ -652,9 +635,7 @@ describe('LoginComponent', () => {
|
||||
expect(component.isError).toBe(true);
|
||||
expect(getLoginErrorElement()).toBeDefined();
|
||||
expect(getLoginErrorMessage()).toEqual('LOGIN.MESSAGES.LOGIN-ERROR-CREDENTIALS');
|
||||
expect(error).toEqual(
|
||||
new LoginErrorEvent('Fake server error')
|
||||
);
|
||||
expect(error).toEqual(new LoginErrorEvent('Fake server error'));
|
||||
});
|
||||
|
||||
loginWithCredentials('fake-username', 'fake-wrong-password');
|
||||
@@ -695,9 +676,7 @@ describe('LoginComponent', () => {
|
||||
}));
|
||||
|
||||
describe('SSO ', () => {
|
||||
|
||||
describe('implicitFlow ', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
appConfigService.config.oauth2 = { implicitFlow: true, silentLogin: false };
|
||||
appConfigService.load();
|
||||
@@ -727,7 +706,6 @@ describe('LoginComponent', () => {
|
||||
expect(component.ssoLogin).toBe(false);
|
||||
expect(component.redirectToSSOLogin).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
}));
|
||||
|
||||
it('should render the implicitFlow button in case silentLogin is disabled', fakeAsync(() => {
|
||||
@@ -739,7 +717,6 @@ describe('LoginComponent', () => {
|
||||
fixture.whenStable().then(() => {
|
||||
expect(component.ssoLogin).toBe(true);
|
||||
});
|
||||
|
||||
}));
|
||||
|
||||
it('should not show the login base auth button', fakeAsync(() => {
|
||||
|
@@ -17,7 +17,6 @@
|
||||
|
||||
import { CoreTestingModule, LoginComponent, LoginFooterDirective } from '@alfresco/adf-core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { OidcAuthenticationService } from '../../auth/services/oidc-authentication.service';
|
||||
|
||||
describe('LoginFooterDirective', () => {
|
||||
@@ -27,13 +26,11 @@ describe('LoginFooterDirective', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
imports: [CoreTestingModule],
|
||||
providers: [
|
||||
{
|
||||
provide: OidcAuthenticationService, useValue: {}
|
||||
provide: OidcAuthenticationService,
|
||||
useValue: {}
|
||||
}
|
||||
]
|
||||
});
|
||||
|
@@ -17,7 +17,6 @@
|
||||
|
||||
import { CoreTestingModule, LoginComponent, LoginHeaderDirective } from '@alfresco/adf-core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { OidcAuthenticationService } from '../../auth/services/oidc-authentication.service';
|
||||
|
||||
describe('LoginHeaderDirective', () => {
|
||||
@@ -27,13 +26,8 @@ describe('LoginHeaderDirective', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
providers: [
|
||||
{ provide: OidcAuthenticationService, useValue: {} }
|
||||
]
|
||||
imports: [CoreTestingModule],
|
||||
providers: [{ provide: OidcAuthenticationService, useValue: {} }]
|
||||
});
|
||||
fixture = TestBed.createComponent(LoginComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
@@ -21,11 +21,9 @@ import { NotificationHistoryComponent } from './notification-history.component';
|
||||
import { OverlayContainer } from '@angular/cdk/overlay';
|
||||
import { NotificationService } from '../services/notification.service';
|
||||
import { StorageService } from '../../common/services/storage.service';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { NotificationModel, NOTIFICATION_TYPE } from '../models/notification.model';
|
||||
|
||||
describe('Notification History Component', () => {
|
||||
|
||||
let fixture: ComponentFixture<NotificationHistoryComponent>;
|
||||
let component: NotificationHistoryComponent;
|
||||
let element: HTMLElement;
|
||||
@@ -42,10 +40,7 @@ describe('Notification History Component', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(NotificationHistoryComponent);
|
||||
component = fixture.componentInstance;
|
||||
@@ -66,7 +61,6 @@ describe('Notification History Component', () => {
|
||||
});
|
||||
|
||||
describe('ui ', () => {
|
||||
|
||||
it('should empty message be present when there are no notifications in the history', (done) => {
|
||||
openNotification();
|
||||
fixture.detectChanges();
|
||||
@@ -109,15 +103,12 @@ describe('Notification History Component', () => {
|
||||
it('should show message when pushed directly to Notification History', (done) => {
|
||||
const callBackSpy = jasmine.createSpy('callBack');
|
||||
fixture.detectChanges();
|
||||
notificationService.pushToNotificationHistory(
|
||||
{
|
||||
clickCallBack: callBackSpy,
|
||||
messages: ['My new message'],
|
||||
datetime: new Date(),
|
||||
type: NOTIFICATION_TYPE.RECURSIVE
|
||||
|
||||
} as NotificationModel
|
||||
);
|
||||
notificationService.pushToNotificationHistory({
|
||||
clickCallBack: callBackSpy,
|
||||
messages: ['My new message'],
|
||||
datetime: new Date(),
|
||||
type: NOTIFICATION_TYPE.RECURSIVE
|
||||
} as NotificationModel);
|
||||
openNotification();
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
@@ -148,12 +139,16 @@ describe('Notification History Component', () => {
|
||||
});
|
||||
|
||||
it('should read notifications from local storage', (done) => {
|
||||
storage.setItem(NotificationHistoryComponent.NOTIFICATION_STORAGE, JSON.stringify([{
|
||||
messages: ['My new message'],
|
||||
datetime: new Date(),
|
||||
type: NOTIFICATION_TYPE.RECURSIVE
|
||||
|
||||
} as NotificationModel]));
|
||||
storage.setItem(
|
||||
NotificationHistoryComponent.NOTIFICATION_STORAGE,
|
||||
JSON.stringify([
|
||||
{
|
||||
messages: ['My new message'],
|
||||
datetime: new Date(),
|
||||
type: NOTIFICATION_TYPE.RECURSIVE
|
||||
} as NotificationModel
|
||||
])
|
||||
);
|
||||
fixture.detectChanges();
|
||||
openNotification();
|
||||
fixture.whenStable().then(() => {
|
||||
|
@@ -21,7 +21,6 @@ import { MatSnackBarConfig, MatSnackBarModule } from '@angular/material/snack-ba
|
||||
import { NotificationService } from './notification.service';
|
||||
import { TranslationService } from '../../translation/translation.service';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { HarnessLoader } from '@angular/cdk/testing';
|
||||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||
import { MatIconHarness } from '@angular/material/icon/testing';
|
||||
@@ -92,7 +91,7 @@ describe('NotificationService', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), CoreTestingModule, MatSnackBarModule],
|
||||
imports: [CoreTestingModule, MatSnackBarModule],
|
||||
declarations: [ProvidesNotificationServiceComponent]
|
||||
});
|
||||
translationService = TestBed.inject(TranslationService);
|
||||
|
@@ -24,13 +24,11 @@ import { BehaviorSubject } from 'rxjs';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { Component, ChangeDetectorRef } from '@angular/core';
|
||||
import { RequestPaginationModel } from '../models/request-pagination.model';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
@Component({
|
||||
template: ``
|
||||
})
|
||||
class TestPaginatedComponent implements PaginatedComponent {
|
||||
|
||||
private _pagination: BehaviorSubject<PaginationModel>;
|
||||
|
||||
get pagination(): BehaviorSubject<PaginationModel> {
|
||||
@@ -52,7 +50,6 @@ class TestPaginatedComponent implements PaginatedComponent {
|
||||
}
|
||||
|
||||
describe('InfinitePaginationComponent', () => {
|
||||
|
||||
let fixture: ComponentFixture<InfinitePaginationComponent>;
|
||||
let component: InfinitePaginationComponent;
|
||||
let pagination: PaginationModel;
|
||||
@@ -60,13 +57,8 @@ describe('InfinitePaginationComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
declarations: [
|
||||
TestPaginatedComponent
|
||||
]
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [TestPaginatedComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(InfinitePaginationComponent);
|
||||
component = fixture.componentInstance;
|
||||
@@ -84,7 +76,6 @@ describe('InfinitePaginationComponent', () => {
|
||||
});
|
||||
|
||||
describe('View', () => {
|
||||
|
||||
it('should show the loading spinner if loading', () => {
|
||||
pagination.hasMoreItems = true;
|
||||
component.isLoading = true;
|
||||
@@ -116,7 +107,7 @@ describe('InfinitePaginationComponent', () => {
|
||||
});
|
||||
|
||||
it('should NOT show the load more button if there are no more elements to load', (done) => {
|
||||
pagination = {maxItems: 444, skipCount: 25, totalItems: 30, hasMoreItems: false};
|
||||
pagination = { maxItems: 444, skipCount: 25, totalItems: 30, hasMoreItems: false };
|
||||
|
||||
component.target.pagination.next(pagination);
|
||||
|
||||
@@ -132,7 +123,7 @@ describe('InfinitePaginationComponent', () => {
|
||||
});
|
||||
|
||||
it('should show the load more button if there are more elements to load', (done) => {
|
||||
pagination = {maxItems: 444, skipCount: 25, totalItems: 55, hasMoreItems: true};
|
||||
pagination = { maxItems: 444, skipCount: 25, totalItems: 55, hasMoreItems: true };
|
||||
|
||||
component.target.pagination.next(pagination);
|
||||
|
||||
@@ -157,7 +148,7 @@ describe('InfinitePaginationComponent', () => {
|
||||
});
|
||||
|
||||
it('should trigger the loadMore event with skipcount 0 to reload all the elements', (done) => {
|
||||
pagination = {maxItems: 444, skipCount: 25, totalItems: 55, hasMoreItems: true};
|
||||
pagination = { maxItems: 444, skipCount: 25, totalItems: 55, hasMoreItems: true };
|
||||
|
||||
component.target.pagination.next(pagination);
|
||||
|
||||
@@ -175,7 +166,7 @@ describe('InfinitePaginationComponent', () => {
|
||||
});
|
||||
|
||||
it('should trigger the loadMore event with merge true to reload all the elements', (done) => {
|
||||
pagination = {maxItems: 444, skipCount: 25, totalItems: 55, hasMoreItems: true};
|
||||
pagination = { maxItems: 444, skipCount: 25, totalItems: 55, hasMoreItems: true };
|
||||
|
||||
component.target.pagination.next(pagination);
|
||||
|
||||
@@ -194,16 +185,15 @@ describe('InfinitePaginationComponent', () => {
|
||||
});
|
||||
|
||||
describe('Target', () => {
|
||||
|
||||
let spyTarget;
|
||||
|
||||
beforeEach(() => {
|
||||
pagination = {maxItems: 444, skipCount: 0, totalItems: 888, hasMoreItems: true};
|
||||
pagination = { maxItems: 444, skipCount: 0, totalItems: 888, hasMoreItems: true };
|
||||
|
||||
spyTarget = spyOn(component.target, 'updatePagination').and.callThrough();
|
||||
});
|
||||
|
||||
it('should subscribe to target\'s pagination observable to update pagination and pagesize correctly', () => {
|
||||
it('should subscribe to target pagination observable to update pagination and pagesize correctly', () => {
|
||||
component.target.updatePagination(pagination);
|
||||
fixture.detectChanges();
|
||||
|
||||
@@ -211,7 +201,7 @@ describe('InfinitePaginationComponent', () => {
|
||||
expect(component.pageSize).toBe(25);
|
||||
});
|
||||
|
||||
it('should call the target\'s updatePagination on invoking the onLoadMore', () => {
|
||||
it('should call the target updatePagination on invoking the onLoadMore', () => {
|
||||
component.target.updatePagination(pagination);
|
||||
|
||||
fixture.detectChanges();
|
||||
@@ -226,7 +216,7 @@ describe('InfinitePaginationComponent', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should call the target\'s updatePagination on invoking the onLoadMore with a specific pageSize', () => {
|
||||
it('should call the target updatePagination on invoking the onLoadMore with a specific pageSize', () => {
|
||||
component.pageSize = 7;
|
||||
component.target.updatePagination(pagination);
|
||||
fixture.detectChanges();
|
||||
@@ -241,12 +231,12 @@ describe('InfinitePaginationComponent', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should unsubscribe from the target\'s pagination on onDestroy', () => {
|
||||
it('should unsubscribe from the target pagination on onDestroy', () => {
|
||||
fixture.detectChanges();
|
||||
fixture.destroy();
|
||||
|
||||
const emitNewPaginationEvent = () => {
|
||||
const newPagination = {maxItems: 1, skipCount: 0, totalItems: 2, hasMoreItems: true};
|
||||
const newPagination = { maxItems: 1, skipCount: 0, totalItems: 2, hasMoreItems: true };
|
||||
component.target.pagination.next(newPagination);
|
||||
};
|
||||
|
||||
|
@@ -21,7 +21,6 @@ import { PaginationComponent } from './pagination.component';
|
||||
import { PaginatedComponent } from './paginated-component.interface';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { PaginationModel } from '../models/pagination.model';
|
||||
import { setupTestBed } from '@alfresco/adf-core';
|
||||
|
||||
@@ -33,22 +32,18 @@ class FakePaginationInput implements PaginationModel {
|
||||
maxItems = 25;
|
||||
|
||||
constructor(pagesCount: number, currentPage: number, lastPageItems: number) {
|
||||
this.totalItems = ((pagesCount - 1) * this.maxItems) + lastPageItems;
|
||||
this.totalItems = (pagesCount - 1) * this.maxItems + lastPageItems;
|
||||
this.skipCount = (currentPage - 1) * this.maxItems;
|
||||
}
|
||||
}
|
||||
|
||||
describe('PaginationComponent', () => {
|
||||
|
||||
let fixture: ComponentFixture<PaginationComponent>;
|
||||
let component: PaginationComponent;
|
||||
|
||||
setupTestBed({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
schemas: [ NO_ERRORS_SCHEMA ]
|
||||
imports: [CoreTestingModule],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -87,7 +82,7 @@ describe('PaginationComponent', () => {
|
||||
});
|
||||
|
||||
it('has range', () => {
|
||||
expect(component.range).toEqual([ 1, 10 ]);
|
||||
expect(component.range).toEqual([1, 10]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -101,12 +96,11 @@ describe('PaginationComponent', () => {
|
||||
});
|
||||
|
||||
it('has range', () => {
|
||||
expect(component.range).toEqual([ 1, 25 ]);
|
||||
expect(component.range).toEqual([1, 25]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Middle page', () => {
|
||||
|
||||
// This test describes 6 pages being on the third page
|
||||
// and last page has 5 items
|
||||
|
||||
@@ -137,7 +131,7 @@ describe('PaginationComponent', () => {
|
||||
});
|
||||
|
||||
it('has range', () => {
|
||||
expect(component.range).toEqual([ 51, 75 ]);
|
||||
expect(component.range).toEqual([51, 75]);
|
||||
});
|
||||
|
||||
it('goes next', () => {
|
||||
@@ -186,7 +180,6 @@ describe('PaginationComponent', () => {
|
||||
});
|
||||
|
||||
describe('First page', () => {
|
||||
|
||||
// This test describes 10 pages being on the first page
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -207,12 +200,11 @@ describe('PaginationComponent', () => {
|
||||
});
|
||||
|
||||
it('has range', () => {
|
||||
expect(component.range).toEqual([ 1, 25 ]);
|
||||
expect(component.range).toEqual([1, 25]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Last page', () => {
|
||||
|
||||
// This test describes 10 pages being on the last page
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -233,7 +225,7 @@ describe('PaginationComponent', () => {
|
||||
});
|
||||
|
||||
it('has range', () => {
|
||||
expect(component.range).toEqual([ 226, 230 ]);
|
||||
expect(component.range).toEqual([226, 230]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -249,13 +241,12 @@ describe('PaginationComponent', () => {
|
||||
expect(component.isFirstPage).toBe(true, 'isFirstPage');
|
||||
expect(component.isLastPage).toBe(true, 'isLastPage');
|
||||
|
||||
expect(component.range).toEqual([ 0, 0 ], 'range');
|
||||
expect(component.pages).toEqual([ 1 ], 'pages');
|
||||
expect(component.range).toEqual([0, 0], 'range');
|
||||
expect(component.pages).toEqual([1], 'pages');
|
||||
});
|
||||
});
|
||||
|
||||
describe('with paginated component', () => {
|
||||
|
||||
it('should take pagination from the external component', () => {
|
||||
const pagination: PaginationModel = {};
|
||||
|
||||
@@ -347,7 +338,6 @@ describe('PaginationComponent', () => {
|
||||
|
||||
expect(fixture.debugElement.nativeElement.querySelector('.adf-pagination__block')).toBeNull();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('without total items', () => {
|
||||
@@ -366,7 +356,7 @@ describe('PaginationComponent', () => {
|
||||
});
|
||||
|
||||
it('has range', () => {
|
||||
expect(component.range).toEqual([ 26, 50 ]);
|
||||
expect(component.range).toEqual([26, 50]);
|
||||
});
|
||||
it('cannot calculate number of pages', () => {
|
||||
expect(component.pages).toEqual([1]);
|
||||
@@ -384,8 +374,10 @@ describe('PaginationComponent', () => {
|
||||
it('should only some pages be available if over 100', () => {
|
||||
component.pagination = new FakePaginationInput(101, 30, 5);
|
||||
|
||||
const expectedPages = [1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
|
||||
31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 101];
|
||||
const expectedPages = [
|
||||
1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
|
||||
43, 44, 45, 46, 47, 48, 49, 50, 101
|
||||
];
|
||||
|
||||
expect(component.limitedPages).toEqual(expectedPages);
|
||||
expect(component.limitedPages).not.toEqual(component.pages);
|
||||
|
@@ -17,7 +17,6 @@
|
||||
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { DateTimePipe } from './date-time.pipe';
|
||||
import { addMinutes, isValid } from 'date-fns';
|
||||
|
||||
@@ -26,7 +25,7 @@ describe('DateTimePipe', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), CoreTestingModule],
|
||||
imports: [CoreTestingModule],
|
||||
providers: [DateTimePipe]
|
||||
});
|
||||
|
||||
|
@@ -21,19 +21,14 @@ import { UserPreferencesService } from '../common/services/user-preferences.serv
|
||||
import { of } from 'rxjs';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { DecimalNumberPipe } from './decimal-number.pipe';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('DecimalNumberPipe', () => {
|
||||
|
||||
let pipe: DecimalNumberPipe;
|
||||
let userPreferences: UserPreferencesService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
userPreferences = TestBed.inject(UserPreferencesService);
|
||||
spyOn(userPreferences, 'select').and.returnValue(of(''));
|
||||
|
@@ -23,20 +23,15 @@ import { of } from 'rxjs';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { registerLocaleData } from '@angular/common';
|
||||
import localeFr from '@angular/common/locales/fr';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
registerLocaleData(localeFr);
|
||||
|
||||
describe('LocalizedDatePipe', () => {
|
||||
|
||||
let pipe: LocalizedDatePipe;
|
||||
let userPreferences: UserPreferencesService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
userPreferences = TestBed.inject(UserPreferencesService);
|
||||
spyOn(userPreferences, 'select').and.returnValue(of(''));
|
||||
|
@@ -21,19 +21,14 @@ import { AppConfigService } from '../app-config/app-config.service';
|
||||
import { UserPreferencesService } from '../common/services/user-preferences.service';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { of } from 'rxjs';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('TimeAgoPipe', () => {
|
||||
|
||||
let pipe: TimeAgoPipe;
|
||||
let userPreferences: UserPreferencesService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
userPreferences = TestBed.inject(UserPreferencesService);
|
||||
spyOn(userPreferences, 'select').and.returnValue(of(''));
|
||||
@@ -56,10 +51,9 @@ describe('TimeAgoPipe', () => {
|
||||
});
|
||||
|
||||
describe('When a locale is given', () => {
|
||||
|
||||
it('should return a localised message', () => {
|
||||
const date = new Date();
|
||||
const transformedDate = pipe.transform(date, 'de');
|
||||
const transformedDate = pipe.transform(date, 'de');
|
||||
/* cspell:disable-next-line */
|
||||
expect(transformedDate).toBe('vor weniger als 1 Minute');
|
||||
});
|
||||
|
@@ -21,11 +21,9 @@ import { SearchTextInputComponent } from './search-text-input.component';
|
||||
import { DebugElement } from '@angular/core';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { Subject } from 'rxjs';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { UserPreferencesService } from '../common/services/user-preferences.service';
|
||||
|
||||
describe('SearchTextInputComponent', () => {
|
||||
|
||||
let fixture: ComponentFixture<SearchTextInputComponent>;
|
||||
let component: SearchTextInputComponent;
|
||||
let debugElement: DebugElement;
|
||||
@@ -34,10 +32,7 @@ describe('SearchTextInputComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(SearchTextInputComponent);
|
||||
component = fixture.componentInstance;
|
||||
@@ -52,7 +47,6 @@ describe('SearchTextInputComponent', () => {
|
||||
});
|
||||
|
||||
describe('component rendering', () => {
|
||||
|
||||
it('should display a search input field when specified', async () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
@@ -67,7 +61,6 @@ describe('SearchTextInputComponent', () => {
|
||||
});
|
||||
|
||||
describe('expandable option false', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
component.expandable = false;
|
||||
});
|
||||
@@ -86,7 +79,6 @@ describe('SearchTextInputComponent', () => {
|
||||
});
|
||||
|
||||
describe('search button', () => {
|
||||
|
||||
it('should NOT display a autocomplete list control when configured not to', fakeAsync(() => {
|
||||
fixture.detectChanges();
|
||||
|
||||
@@ -345,7 +337,6 @@ describe('SearchTextInputComponent', () => {
|
||||
expect(component.subscriptAnimationState.value).toEqual('inactive');
|
||||
expect(component.searchTerm).toEqual('');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('Collapse on blur', () => {
|
||||
@@ -355,7 +346,7 @@ describe('SearchTextInputComponent', () => {
|
||||
tick(200);
|
||||
}));
|
||||
|
||||
it('should collapse search on blur when the collapseOnBlur is set to true', fakeAsync (() => {
|
||||
it('should collapse search on blur when the collapseOnBlur is set to true', fakeAsync(() => {
|
||||
const searchVisibilityChangeSpy = spyOn(component.searchVisibility, 'emit');
|
||||
const resetEmitSpy = spyOn(component.reset, 'emit');
|
||||
component.collapseOnBlur = true;
|
||||
|
@@ -20,8 +20,8 @@ import { MatIcon, MatIconModule } from '@angular/material/icon';
|
||||
import { MAT_SNACK_BAR_DATA, MatSnackBarModule, MatSnackBarRef } from '@angular/material/snack-bar';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { SnackbarContentComponent } from './snackbar-content.component';
|
||||
import { CoreTestingModule } from '@alfresco/adf-core';
|
||||
|
||||
describe('SnackbarContentComponent', () => {
|
||||
let component: SnackbarContentComponent;
|
||||
@@ -30,24 +30,20 @@ describe('SnackbarContentComponent', () => {
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [SnackbarContentComponent],
|
||||
imports: [
|
||||
MatIconModule,
|
||||
MatSnackBarModule,
|
||||
MatButtonModule,
|
||||
TranslateModule.forRoot()
|
||||
],
|
||||
providers: [{
|
||||
provide: MatSnackBarRef,
|
||||
useValue: {
|
||||
dismissWithAction() {
|
||||
imports: [CoreTestingModule, MatIconModule, MatSnackBarModule, MatButtonModule],
|
||||
providers: [
|
||||
{
|
||||
provide: MatSnackBarRef,
|
||||
useValue: {
|
||||
dismissWithAction() {}
|
||||
}
|
||||
},
|
||||
{
|
||||
provide: MAT_SNACK_BAR_DATA,
|
||||
useValue: {}
|
||||
}
|
||||
}, {
|
||||
provide: MAT_SNACK_BAR_DATA,
|
||||
useValue: {}
|
||||
}]
|
||||
})
|
||||
.compileComponents();
|
||||
]
|
||||
}).compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(SnackbarContentComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
@@ -18,17 +18,14 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { TranslateService, TranslateModule } from '@ngx-translate/core';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { of } from 'rxjs';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-test-component',
|
||||
template: `
|
||||
<adf-empty-content
|
||||
icon="delete"
|
||||
[title]="'CUSTOM_TITLE'"
|
||||
[subtitle]="'CUSTOM_SUBTITLE'">
|
||||
<adf-empty-content icon="delete" [title]="'CUSTOM_TITLE'" [subtitle]="'CUSTOM_SUBTITLE'">
|
||||
<div class="adf-empty-content__text">SUBTITLE-1</div>
|
||||
<div class="adf-empty-content__text">SUBTITLE-2</div>
|
||||
<div class="adf-empty-content__text">SUBTITLE-3</div>
|
||||
@@ -38,19 +35,13 @@ import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
class TestComponent {}
|
||||
|
||||
describe('EmptyContentComponent', () => {
|
||||
|
||||
let fixture: ComponentFixture<TestComponent>;
|
||||
let translateService: TranslateService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
declarations: [
|
||||
TestComponent
|
||||
]
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [TestComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(TestComponent);
|
||||
translateService = TestBed.inject(TranslateService);
|
||||
|
@@ -21,10 +21,8 @@ import { ErrorContentComponent } from './error-content.component';
|
||||
import { TranslationService } from '../../translation/translation.service';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { of } from 'rxjs';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('ErrorContentComponent', () => {
|
||||
|
||||
let fixture: ComponentFixture<ErrorContentComponent>;
|
||||
let errorContentComponent: ErrorContentComponent;
|
||||
let element: HTMLElement;
|
||||
@@ -32,13 +30,8 @@ describe('ErrorContentComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
providers: [
|
||||
{ provide: ActivatedRoute, useValue: { params: of() } }
|
||||
]
|
||||
imports: [CoreTestingModule],
|
||||
providers: [{ provide: ActivatedRoute, useValue: { params: of() } }]
|
||||
});
|
||||
fixture = TestBed.createComponent(ErrorContentComponent);
|
||||
element = fixture.nativeElement;
|
||||
|
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { ToolbarComponent } from './toolbar.component';
|
||||
import { ToolbarModule } from './toolbar.module';
|
||||
@@ -26,11 +25,7 @@ describe('ToolbarComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule,
|
||||
ToolbarModule
|
||||
]
|
||||
imports: [CoreTestingModule, ToolbarModule]
|
||||
});
|
||||
|
||||
fixture = TestBed.createComponent(ToolbarComponent);
|
||||
|
@@ -19,7 +19,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { MatDialogRef } from '@angular/material/dialog';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { DownloadPromptDialogComponent } from './download-prompt-dialog.component';
|
||||
import { CoreTestingModule } from '../../../testing/core.testing.module';
|
||||
import { DownloadPromptActions } from '../../models/download-prompt.actions';
|
||||
@@ -37,13 +36,8 @@ describe('DownloadPromptDialogComponent', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [DownloadPromptDialogComponent],
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
providers: [
|
||||
{ provide: MatDialogRef, useValue: mockDialog }
|
||||
]
|
||||
imports: [CoreTestingModule],
|
||||
providers: [{ provide: MatDialogRef, useValue: mockDialog }]
|
||||
});
|
||||
matDialogRef = TestBed.inject(MatDialogRef);
|
||||
|
||||
|
@@ -21,11 +21,9 @@ import { UrlService } from '../../common/services/url.service';
|
||||
import { ImgViewerComponent } from './img-viewer.component';
|
||||
import { CoreTestingModule } from '../../testing';
|
||||
import { AppConfigService } from '../../app-config/app-config.service';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { By } from '@angular/platform-browser';
|
||||
|
||||
describe('Test Img viewer component ', () => {
|
||||
|
||||
let component: ImgViewerComponent;
|
||||
let urlService: UrlService;
|
||||
let fixture: ComponentFixture<ImgViewerComponent>;
|
||||
@@ -38,15 +36,11 @@ describe('Test Img viewer component ', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
});
|
||||
|
||||
describe('Zoom customization', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
urlService = TestBed.inject(UrlService);
|
||||
fixture = TestBed.createComponent(ImgViewerComponent);
|
||||
@@ -58,16 +52,13 @@ describe('Test Img viewer component ', () => {
|
||||
});
|
||||
|
||||
describe('default value', () => {
|
||||
|
||||
it('should use default zoom if is not present a custom zoom in the app.config', () => {
|
||||
fixture.detectChanges();
|
||||
expect(component.scale).toBe(1.0);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('custom value', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
const appConfig: AppConfigService = TestBed.inject(AppConfigService);
|
||||
appConfig.config['adf-viewer-render.image-viewer-scaling'] = 70;
|
||||
@@ -78,7 +69,7 @@ describe('Test Img viewer component ', () => {
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
expect(component.scale).toBe(0.70);
|
||||
expect(component.scale).toBe(0.7);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -86,14 +77,14 @@ describe('Test Img viewer component ', () => {
|
||||
});
|
||||
|
||||
describe('Url', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
urlService = TestBed.inject(UrlService);
|
||||
fixture = TestBed.createComponent(ImgViewerComponent);
|
||||
|
||||
element = fixture.nativeElement;
|
||||
component = fixture.componentInstance;
|
||||
component.urlFile = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==';
|
||||
component.urlFile =
|
||||
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==';
|
||||
fixture.detectChanges();
|
||||
fixture.componentInstance.ngAfterViewInit();
|
||||
component.ngAfterViewInit();
|
||||
@@ -115,7 +106,6 @@ describe('Test Img viewer component ', () => {
|
||||
});
|
||||
|
||||
describe('Blob', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
urlService = TestBed.inject(UrlService);
|
||||
fixture = TestBed.createComponent(ImgViewerComponent);
|
||||
@@ -169,7 +159,6 @@ describe('Test Img viewer component ', () => {
|
||||
});
|
||||
|
||||
describe('toolbar actions', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ImgViewerComponent);
|
||||
element = fixture.nativeElement;
|
||||
@@ -193,7 +182,7 @@ describe('Test Img viewer component ', () => {
|
||||
component.zoomIn();
|
||||
expect(component.scale).toBe(1.4);
|
||||
expect(component.cropper.zoom).toHaveBeenCalledWith(0.2);
|
||||
}));
|
||||
}));
|
||||
|
||||
it('should update scales on zoom out', fakeAsync(() => {
|
||||
spyOn(component, 'zoomOut').and.callThrough();
|
||||
@@ -381,5 +370,4 @@ describe('Test Img viewer component ', () => {
|
||||
expect(component.reset).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -19,7 +19,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
||||
import { PdfPasswordDialogComponent } from './pdf-viewer-password-dialog';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
declare const pdfjsLib: any;
|
||||
|
||||
@@ -30,10 +29,7 @@ describe('PdfPasswordDialogComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
imports: [CoreTestingModule],
|
||||
providers: [
|
||||
{
|
||||
provide: MAT_DIALOG_DATA,
|
||||
|
@@ -19,10 +19,8 @@ import { DomSanitizer } from '@angular/platform-browser';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { PdfThumbComponent } from './pdf-viewer-thumb.component';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('PdfThumbComponent', () => {
|
||||
|
||||
let fixture: ComponentFixture<PdfThumbComponent>;
|
||||
let component: PdfThumbComponent;
|
||||
const domSanitizer = {
|
||||
@@ -32,10 +30,12 @@ describe('PdfThumbComponent', () => {
|
||||
const height = 119;
|
||||
const page = {
|
||||
id: 'pageId',
|
||||
getPage: jasmine.createSpy('getPage').and.returnValue(Promise.resolve({
|
||||
getViewport: () => ({ height: width, width: height }),
|
||||
render: jasmine.createSpy('render').and.returnValue({ promise: Promise.resolve() })
|
||||
})),
|
||||
getPage: jasmine.createSpy('getPage').and.returnValue(
|
||||
Promise.resolve({
|
||||
getViewport: () => ({ height: width, width: height }),
|
||||
render: jasmine.createSpy('render').and.returnValue({ promise: Promise.resolve() })
|
||||
})
|
||||
),
|
||||
|
||||
getWidth: jasmine.createSpy('getWidth').and.returnValue(width),
|
||||
getHeight: jasmine.createSpy('getHeight').and.returnValue(height)
|
||||
@@ -43,13 +43,8 @@ describe('PdfThumbComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
providers: [
|
||||
{ provide: DomSanitizer, useValue: domSanitizer }
|
||||
]
|
||||
imports: [CoreTestingModule],
|
||||
providers: [{ provide: DomSanitizer, useValue: domSanitizer }]
|
||||
});
|
||||
fixture = TestBed.createComponent(PdfThumbComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
@@ -19,13 +19,11 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { PdfThumbListComponent } from './pdf-viewer-thumbnails.component';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { DOWN_ARROW, UP_ARROW, ESCAPE } from '@angular/cdk/keycodes';
|
||||
|
||||
declare const pdfjsViewer: any;
|
||||
|
||||
describe('PdfThumbListComponent', () => {
|
||||
|
||||
let fixture: ComponentFixture<PdfThumbListComponent>;
|
||||
let component: PdfThumbListComponent;
|
||||
|
||||
@@ -45,26 +43,36 @@ describe('PdfThumbListComponent', () => {
|
||||
return this._currentPageNumber;
|
||||
},
|
||||
pdfDocument: {
|
||||
getPage: () => Promise.resolve({
|
||||
getViewport: () => ({ height: 421, width: 335 }),
|
||||
render: jasmine.createSpy('render').and.returnValue({ promise: Promise.resolve() })
|
||||
})
|
||||
getPage: () =>
|
||||
Promise.resolve({
|
||||
getViewport: () => ({ height: 421, width: 335 }),
|
||||
render: jasmine.createSpy('render').and.returnValue({ promise: Promise.resolve() })
|
||||
})
|
||||
},
|
||||
_pages: [
|
||||
page(1), page(2), page(3), page(4),
|
||||
page(5), page(6), page(7), page(8),
|
||||
page(9), page(10), page(11), page(12),
|
||||
page(13), page(14), page(15), page(16)
|
||||
page(1),
|
||||
page(2),
|
||||
page(3),
|
||||
page(4),
|
||||
page(5),
|
||||
page(6),
|
||||
page(7),
|
||||
page(8),
|
||||
page(9),
|
||||
page(10),
|
||||
page(11),
|
||||
page(12),
|
||||
page(13),
|
||||
page(14),
|
||||
page(15),
|
||||
page(16)
|
||||
],
|
||||
eventBus: new pdfjsViewer.EventBus()
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(PdfThumbListComponent);
|
||||
component = fixture.componentInstance;
|
||||
@@ -173,7 +181,7 @@ describe('PdfThumbListComponent', () => {
|
||||
|
||||
describe('Keyboard events', () => {
|
||||
it('should select next page in the list on DOWN_ARROW event', () => {
|
||||
const event = new KeyboardEvent('keydown', {keyCode: DOWN_ARROW} as KeyboardEventInit);
|
||||
const event = new KeyboardEvent('keydown', { keyCode: DOWN_ARROW } as KeyboardEventInit);
|
||||
fixture.detectChanges();
|
||||
component.goTo(1);
|
||||
expect(document.activeElement.id).toBe('1');
|
||||
@@ -183,7 +191,7 @@ describe('PdfThumbListComponent', () => {
|
||||
});
|
||||
|
||||
it('should select previous page in the list on UP_ARROW event', () => {
|
||||
const event = new KeyboardEvent('keydown', {keyCode: UP_ARROW} as KeyboardEventInit);
|
||||
const event = new KeyboardEvent('keydown', { keyCode: UP_ARROW } as KeyboardEventInit);
|
||||
fixture.detectChanges();
|
||||
component.goTo(2);
|
||||
expect(document.activeElement.id).toBe('2');
|
||||
@@ -193,7 +201,7 @@ describe('PdfThumbListComponent', () => {
|
||||
});
|
||||
|
||||
it('should not select previous page if it is the first page', () => {
|
||||
const event = new KeyboardEvent('keydown', {keyCode: UP_ARROW} as KeyboardEventInit);
|
||||
const event = new KeyboardEvent('keydown', { keyCode: UP_ARROW } as KeyboardEventInit);
|
||||
fixture.detectChanges();
|
||||
component.goTo(1);
|
||||
expect(document.activeElement.id).toBe('1');
|
||||
@@ -203,7 +211,7 @@ describe('PdfThumbListComponent', () => {
|
||||
});
|
||||
|
||||
it('should not select next item if it is the last page', () => {
|
||||
const event = new KeyboardEvent('keydown', {keyCode: DOWN_ARROW} as KeyboardEventInit);
|
||||
const event = new KeyboardEvent('keydown', { keyCode: DOWN_ARROW } as KeyboardEventInit);
|
||||
fixture.detectChanges();
|
||||
component.scrollInto(16);
|
||||
fixture.detectChanges();
|
||||
@@ -216,7 +224,7 @@ describe('PdfThumbListComponent', () => {
|
||||
});
|
||||
|
||||
it('should emit on ESCAPE event', () => {
|
||||
const event = new KeyboardEvent('keydown', {keyCode: ESCAPE} as KeyboardEventInit);
|
||||
const event = new KeyboardEvent('keydown', { keyCode: ESCAPE } as KeyboardEventInit);
|
||||
spyOn(component.close, 'emit');
|
||||
fixture.detectChanges();
|
||||
|
||||
|
@@ -26,7 +26,6 @@ import { of } from 'rxjs';
|
||||
import { take } from 'rxjs/operators';
|
||||
import { AppConfigService } from '../../app-config/app-config.service';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { PdfThumbListComponent } from '@alfresco/adf-core';
|
||||
import { By } from '@angular/platform-browser';
|
||||
|
||||
@@ -36,19 +35,12 @@ declare const pdfjsLib: any;
|
||||
selector: 'adf-test-dialog-component',
|
||||
template: ''
|
||||
})
|
||||
class TestDialogComponent {
|
||||
}
|
||||
class TestDialogComponent {}
|
||||
|
||||
@Component({
|
||||
template: `
|
||||
<adf-pdf-viewer [allowThumbnails]="true"
|
||||
[showToolbar]="true"
|
||||
[urlFile]="urlFile">
|
||||
</adf-pdf-viewer>
|
||||
`
|
||||
template: ` <adf-pdf-viewer [allowThumbnails]="true" [showToolbar]="true" [urlFile]="urlFile"> </adf-pdf-viewer> `
|
||||
})
|
||||
class UrlTestComponent {
|
||||
|
||||
@ViewChild(PdfViewerComponent, { static: true })
|
||||
pdfViewerComponent: PdfViewerComponent;
|
||||
|
||||
@@ -60,15 +52,9 @@ class UrlTestComponent {
|
||||
}
|
||||
|
||||
@Component({
|
||||
template: `
|
||||
<adf-pdf-viewer [allowThumbnails]="true"
|
||||
[showToolbar]="true"
|
||||
[urlFile]="urlFile">
|
||||
</adf-pdf-viewer>
|
||||
`
|
||||
template: ` <adf-pdf-viewer [allowThumbnails]="true" [showToolbar]="true" [urlFile]="urlFile"> </adf-pdf-viewer> `
|
||||
})
|
||||
class UrlTestPasswordComponent {
|
||||
|
||||
@ViewChild(PdfViewerComponent, { static: true })
|
||||
pdfViewerComponent: PdfViewerComponent;
|
||||
|
||||
@@ -80,15 +66,9 @@ class UrlTestPasswordComponent {
|
||||
}
|
||||
|
||||
@Component({
|
||||
template: `
|
||||
<adf-pdf-viewer [allowThumbnails]="true"
|
||||
[showToolbar]="true"
|
||||
[blobFile]="blobFile">
|
||||
</adf-pdf-viewer>
|
||||
`
|
||||
template: ` <adf-pdf-viewer [allowThumbnails]="true" [showToolbar]="true" [blobFile]="blobFile"> </adf-pdf-viewer> `
|
||||
})
|
||||
class BlobTestComponent {
|
||||
|
||||
@ViewChild(PdfViewerComponent, { static: true })
|
||||
pdfViewerComponent: PdfViewerComponent;
|
||||
|
||||
@@ -101,25 +81,24 @@ class BlobTestComponent {
|
||||
createFakeBlob(): Blob {
|
||||
const pdfData = atob(
|
||||
'JVBERi0xLjcKCjEgMCBvYmogICUgZW50cnkgcG9pbnQKPDwKICAvVHlwZSAvQ2F0YWxvZwog' +
|
||||
'IC9QYWdlcyAyIDAgUgo+PgplbmRvYmoKCjIgMCBvYmoKPDwKICAvVHlwZSAvUGFnZXMKICAv' +
|
||||
'TWVkaWFCb3ggWyAwIDAgMjAwIDIwMCBdCiAgL0NvdW50IDEKICAvS2lkcyBbIDMgMCBSIF0K' +
|
||||
'Pj4KZW5kb2JqCgozIDAgb2JqCjw8CiAgL1R5cGUgL1BhZ2UKICAvUGFyZW50IDIgMCBSCiAg' +
|
||||
'L1Jlc291cmNlcyA8PAogICAgL0ZvbnQgPDwKICAgICAgL0YxIDQgMCBSIAogICAgPj4KICA+' +
|
||||
'PgogIC9Db250ZW50cyA1IDAgUgo+PgplbmRvYmoKCjQgMCBvYmoKPDwKICAvVHlwZSAvRm9u' +
|
||||
'dAogIC9TdWJ0eXBlIC9UeXBlMQogIC9CYXNlRm9udCAvVGltZXMtUm9tYW4KPj4KZW5kb2Jq' +
|
||||
'Cgo1IDAgb2JqICAlIHBhZ2UgY29udGVudAo8PAogIC9MZW5ndGggNDQKPj4Kc3RyZWFtCkJU' +
|
||||
'CjcwIDUwIFRECi9GMSAxMiBUZgooSGVsbG8sIHdvcmxkISkgVGoKRVQKZW5kc3RyZWFtCmVu' +
|
||||
'ZG9iagoKeHJlZgowIDYKMDAwMDAwMDAwMCA2NTUzNSBmIAowMDAwMDAwMDEwIDAwMDAwIG4g' +
|
||||
'CjAwMDAwMDAwNzkgMDAwMDAgbiAKMDAwMDAwMDE3MyAwMDAwMCBuIAowMDAwMDAwMzAxIDAw' +
|
||||
'MDAwIG4gCjAwMDAwMDAzODAgMDAwMDAgbiAKdHJhaWxlcgo8PAogIC9TaXplIDYKICAvUm9v' +
|
||||
'dCAxIDAgUgo+PgpzdGFydHhyZWYKNDkyCiUlRU9G');
|
||||
'IC9QYWdlcyAyIDAgUgo+PgplbmRvYmoKCjIgMCBvYmoKPDwKICAvVHlwZSAvUGFnZXMKICAv' +
|
||||
'TWVkaWFCb3ggWyAwIDAgMjAwIDIwMCBdCiAgL0NvdW50IDEKICAvS2lkcyBbIDMgMCBSIF0K' +
|
||||
'Pj4KZW5kb2JqCgozIDAgb2JqCjw8CiAgL1R5cGUgL1BhZ2UKICAvUGFyZW50IDIgMCBSCiAg' +
|
||||
'L1Jlc291cmNlcyA8PAogICAgL0ZvbnQgPDwKICAgICAgL0YxIDQgMCBSIAogICAgPj4KICA+' +
|
||||
'PgogIC9Db250ZW50cyA1IDAgUgo+PgplbmRvYmoKCjQgMCBvYmoKPDwKICAvVHlwZSAvRm9u' +
|
||||
'dAogIC9TdWJ0eXBlIC9UeXBlMQogIC9CYXNlRm9udCAvVGltZXMtUm9tYW4KPj4KZW5kb2Jq' +
|
||||
'Cgo1IDAgb2JqICAlIHBhZ2UgY29udGVudAo8PAogIC9MZW5ndGggNDQKPj4Kc3RyZWFtCkJU' +
|
||||
'CjcwIDUwIFRECi9GMSAxMiBUZgooSGVsbG8sIHdvcmxkISkgVGoKRVQKZW5kc3RyZWFtCmVu' +
|
||||
'ZG9iagoKeHJlZgowIDYKMDAwMDAwMDAwMCA2NTUzNSBmIAowMDAwMDAwMDEwIDAwMDAwIG4g' +
|
||||
'CjAwMDAwMDAwNzkgMDAwMDAgbiAKMDAwMDAwMDE3MyAwMDAwMCBuIAowMDAwMDAwMzAxIDAw' +
|
||||
'MDAwIG4gCjAwMDAwMDAzODAgMDAwMDAgbiAKdHJhaWxlcgo8PAogIC9TaXplIDYKICAvUm9v' +
|
||||
'dCAxIDAgUgo+PgpzdGFydHhyZWYKNDkyCiUlRU9G'
|
||||
);
|
||||
return new Blob([pdfData], { type: 'application/pdf' });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
describe('Test PdfViewer component', () => {
|
||||
|
||||
let component: PdfViewerComponent;
|
||||
let fixture: ComponentFixture<PdfViewerComponent>;
|
||||
let element: HTMLElement;
|
||||
@@ -128,21 +107,13 @@ describe('Test PdfViewer component', () => {
|
||||
|
||||
beforeEach((done) => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
declarations: [
|
||||
TestDialogComponent,
|
||||
UrlTestComponent,
|
||||
UrlTestPasswordComponent,
|
||||
BlobTestComponent
|
||||
],
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [TestDialogComponent, UrlTestComponent, UrlTestPasswordComponent, BlobTestComponent],
|
||||
providers: [
|
||||
{
|
||||
provide: MatDialog, useValue: {
|
||||
open: () => {
|
||||
}
|
||||
provide: MatDialog,
|
||||
useValue: {
|
||||
open: () => {}
|
||||
}
|
||||
},
|
||||
RenderingQueueServices
|
||||
@@ -164,7 +135,6 @@ describe('Test PdfViewer component', () => {
|
||||
});
|
||||
|
||||
describe('User interaction', () => {
|
||||
|
||||
let fixtureUrlTestComponent: ComponentFixture<UrlTestComponent>;
|
||||
let componentUrlTestComponent: UrlTestComponent;
|
||||
let elementUrlTestComponent: HTMLElement;
|
||||
@@ -176,11 +146,9 @@ describe('Test PdfViewer component', () => {
|
||||
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
componentUrlTestComponent.pdfViewerComponent.rendered
|
||||
.pipe(take(1))
|
||||
.subscribe(() => {
|
||||
done();
|
||||
});
|
||||
componentUrlTestComponent.pdfViewerComponent.rendered.pipe(take(1)).subscribe(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -271,10 +239,8 @@ describe('Test PdfViewer component', () => {
|
||||
}, 55000);
|
||||
|
||||
describe('Zoom', () => {
|
||||
|
||||
it('should zoom in increment the scale value', fakeAsync(() => {
|
||||
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {
|
||||
});
|
||||
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {});
|
||||
|
||||
const zoomInButton: any = elementUrlTestComponent.querySelector('#viewer-zoom-in-button');
|
||||
|
||||
@@ -288,8 +254,7 @@ describe('Test PdfViewer component', () => {
|
||||
}), 55000);
|
||||
|
||||
it('should zoom out decrement the scale value', fakeAsync(() => {
|
||||
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {
|
||||
});
|
||||
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {});
|
||||
const zoomOutButton: any = elementUrlTestComponent.querySelector('#viewer-zoom-out-button');
|
||||
|
||||
tick(250);
|
||||
@@ -302,8 +267,7 @@ describe('Test PdfViewer component', () => {
|
||||
}), 55000);
|
||||
|
||||
it('should it-in button toggle page-fit and auto scale mode', fakeAsync(() => {
|
||||
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {
|
||||
});
|
||||
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {});
|
||||
|
||||
const itPage: any = elementUrlTestComponent.querySelector('#viewer-scale-page-button');
|
||||
|
||||
@@ -320,7 +284,6 @@ describe('Test PdfViewer component', () => {
|
||||
});
|
||||
|
||||
describe('Resize interaction', () => {
|
||||
|
||||
it('should resize event trigger setScaleUpdatePages', (done) => {
|
||||
spyOn(componentUrlTestComponent.pdfViewerComponent, 'onResize');
|
||||
EventMock.resizeMobileView();
|
||||
@@ -329,12 +292,10 @@ describe('Test PdfViewer component', () => {
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.onResize).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
|
||||
}, 55000);
|
||||
});
|
||||
|
||||
describe('Thumbnails', () => {
|
||||
|
||||
it('should have own context', (done) => {
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
@@ -366,7 +327,6 @@ describe('Test PdfViewer component', () => {
|
||||
});
|
||||
|
||||
describe('Viewer events', () => {
|
||||
|
||||
it('should react on the emit of pageChange event', (done) => {
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
@@ -441,9 +401,7 @@ describe('Test PdfViewer component', () => {
|
||||
});
|
||||
|
||||
describe('Zoom customization', () => {
|
||||
|
||||
describe('custom value', () => {
|
||||
|
||||
let fixtureUrlTestComponent: ComponentFixture<UrlTestComponent>;
|
||||
let componentUrlTestComponent: UrlTestComponent;
|
||||
let elementUrlTestComponent: HTMLElement;
|
||||
@@ -458,11 +416,9 @@ describe('Test PdfViewer component', () => {
|
||||
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
componentUrlTestComponent.pdfViewerComponent.rendered
|
||||
.pipe(take(1))
|
||||
.subscribe(() => {
|
||||
done();
|
||||
});
|
||||
componentUrlTestComponent.pdfViewerComponent.rendered.pipe(take(1)).subscribe(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -470,8 +426,7 @@ describe('Test PdfViewer component', () => {
|
||||
});
|
||||
|
||||
it('should use the custom zoom if it is present in the app.config', (done) => {
|
||||
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {
|
||||
});
|
||||
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {});
|
||||
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
@@ -482,7 +437,6 @@ describe('Test PdfViewer component', () => {
|
||||
});
|
||||
|
||||
describe('less than the minimum allowed value', () => {
|
||||
|
||||
let fixtureUrlTestComponent: ComponentFixture<UrlTestComponent>;
|
||||
let componentUrlTestComponent: UrlTestComponent;
|
||||
let elementUrlTestComponent: HTMLElement;
|
||||
@@ -497,11 +451,9 @@ describe('Test PdfViewer component', () => {
|
||||
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
componentUrlTestComponent.pdfViewerComponent.rendered
|
||||
.pipe(take(1))
|
||||
.subscribe(() => {
|
||||
done();
|
||||
});
|
||||
componentUrlTestComponent.pdfViewerComponent.rendered.pipe(take(1)).subscribe(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -509,8 +461,7 @@ describe('Test PdfViewer component', () => {
|
||||
});
|
||||
|
||||
it('should use the minimum scale zoom if the value given in app.config is less than the minimum allowed scale', (done) => {
|
||||
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {
|
||||
});
|
||||
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {});
|
||||
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
@@ -519,12 +470,10 @@ describe('Test PdfViewer component', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
// TODO: https://alfresco.atlassian.net/browse/ACS-6061
|
||||
// eslint-disable-next-line
|
||||
xdescribe('greater than the maximum allowed value', () => {
|
||||
|
||||
let fixtureUrlTestComponent: ComponentFixture<UrlTestComponent>;
|
||||
let componentUrlTestComponent: UrlTestComponent;
|
||||
let elementUrlTestComponent: HTMLElement;
|
||||
@@ -539,11 +488,9 @@ describe('Test PdfViewer component', () => {
|
||||
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
componentUrlTestComponent.pdfViewerComponent.rendered
|
||||
.pipe(take(1))
|
||||
.subscribe(() => {
|
||||
done();
|
||||
});
|
||||
componentUrlTestComponent.pdfViewerComponent.rendered.pipe(take(1)).subscribe(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -551,8 +498,7 @@ describe('Test PdfViewer component', () => {
|
||||
});
|
||||
|
||||
it('should use the maximum scale zoom if the value given in app.config is greater than the maximum allowed scale', (done) => {
|
||||
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {
|
||||
});
|
||||
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {});
|
||||
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
@@ -582,7 +528,6 @@ describe('Test PdfViewer component', () => {
|
||||
});
|
||||
|
||||
describe('View with url file', () => {
|
||||
|
||||
let fixtureUrlTestComponent: ComponentFixture<UrlTestComponent>;
|
||||
let elementUrlTestComponent: HTMLElement;
|
||||
|
||||
@@ -613,7 +558,6 @@ describe('Test PdfViewer component', () => {
|
||||
}, 55000);
|
||||
|
||||
it('should Input Page elements be present', (done) => {
|
||||
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
/* cspell:disable-next-line */
|
||||
@@ -639,7 +583,6 @@ describe('Test PdfViewer component', () => {
|
||||
});
|
||||
|
||||
describe('View with blob file', () => {
|
||||
|
||||
let fixtureBlobTestComponent: ComponentFixture<BlobTestComponent>;
|
||||
let elementBlobTestComponent: HTMLElement;
|
||||
|
||||
@@ -706,12 +649,11 @@ describe('Test PdfViewer component', () => {
|
||||
});
|
||||
|
||||
describe('Password protection dialog', () => {
|
||||
|
||||
let fixtureUrlTestPasswordComponent: ComponentFixture<UrlTestPasswordComponent>;
|
||||
let componentUrlTestPasswordComponent: UrlTestPasswordComponent;
|
||||
|
||||
describe('Open password dialog', () => {
|
||||
beforeEach( async () => {
|
||||
beforeEach(async () => {
|
||||
fixtureUrlTestPasswordComponent = TestBed.createComponent(UrlTestPasswordComponent);
|
||||
componentUrlTestPasswordComponent = fixtureUrlTestPasswordComponent.componentInstance;
|
||||
|
||||
@@ -780,9 +722,12 @@ describe('Test PdfViewer component', () => {
|
||||
fixtureUrlTestPasswordComponent = TestBed.createComponent(UrlTestPasswordComponent);
|
||||
componentUrlTestPasswordComponent = fixtureUrlTestPasswordComponent.componentInstance;
|
||||
|
||||
spyOn(dialog, 'open').and.callFake(() => ({
|
||||
afterClosed: () => of('')
|
||||
} as any));
|
||||
spyOn(dialog, 'open').and.callFake(
|
||||
() =>
|
||||
({
|
||||
afterClosed: () => of('')
|
||||
} as any)
|
||||
);
|
||||
|
||||
spyOn(componentUrlTestPasswordComponent.pdfViewerComponent.close, 'emit');
|
||||
|
||||
|
@@ -19,20 +19,15 @@ import { SimpleChange } from '@angular/core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { TxtViewerComponent } from './txt-viewer.component';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('Text View component', () => {
|
||||
|
||||
let component: TxtViewerComponent;
|
||||
let fixture: ComponentFixture<TxtViewerComponent>;
|
||||
let element: HTMLElement;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
fixture = TestBed.createComponent(TxtViewerComponent);
|
||||
|
||||
@@ -41,7 +36,6 @@ describe('Text View component', () => {
|
||||
});
|
||||
|
||||
describe('View', () => {
|
||||
|
||||
it('Should text container be present with urlFile', (done) => {
|
||||
fixture.detectChanges();
|
||||
const urlFile = './fake-test-file.txt';
|
||||
@@ -57,7 +51,7 @@ describe('Text View component', () => {
|
||||
});
|
||||
|
||||
it('Should text container be present with Blob file', (done) => {
|
||||
const blobFile = new Blob(['text example'], {type: 'text/txt'});
|
||||
const blobFile = new Blob(['text example'], { type: 'text/txt' });
|
||||
|
||||
const change = new SimpleChange(null, blobFile, true);
|
||||
|
||||
@@ -69,5 +63,5 @@ describe('Text View component', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -22,9 +22,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { RenderingQueueServices } from '../services/rendering-queue.services';
|
||||
import { ViewerRenderComponent } from './viewer-render.component';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { AppExtensionService, ViewerExtensionRef } from '@alfresco/adf-extensions';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
@@ -61,12 +59,9 @@ class DoubleViewerComponent {
|
||||
|
||||
urlFileViewer1: string;
|
||||
urlFileViewer2: string;
|
||||
|
||||
}
|
||||
|
||||
|
||||
describe('ViewerComponent', () => {
|
||||
|
||||
let component: ViewerRenderComponent;
|
||||
let fixture: ComponentFixture<ViewerRenderComponent>;
|
||||
let element: HTMLElement;
|
||||
@@ -75,21 +70,9 @@ describe('ViewerComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
NoopAnimationsModule,
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule,
|
||||
MatButtonModule,
|
||||
MatIconModule
|
||||
],
|
||||
declarations: [
|
||||
DoubleViewerComponent
|
||||
],
|
||||
providers: [
|
||||
RenderingQueueServices,
|
||||
{provide: Location, useClass: SpyLocation},
|
||||
MatDialog
|
||||
]
|
||||
imports: [CoreTestingModule, MatButtonModule, MatIconModule],
|
||||
declarations: [DoubleViewerComponent],
|
||||
providers: [RenderingQueueServices, { provide: Location, useClass: SpyLocation }, MatDialog]
|
||||
});
|
||||
fixture = TestBed.createComponent(ViewerRenderComponent);
|
||||
element = fixture.nativeElement;
|
||||
@@ -103,7 +86,6 @@ describe('ViewerComponent', () => {
|
||||
});
|
||||
|
||||
describe('Double viewer Test', () => {
|
||||
|
||||
it('should not reload the content of all the viewer after type change', async () => {
|
||||
const fixtureDouble = TestBed.createComponent(DoubleViewerComponent);
|
||||
|
||||
@@ -405,7 +387,6 @@ describe('ViewerComponent', () => {
|
||||
});
|
||||
|
||||
describe('Base component', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
component.urlFile = 'fake-test-file.pdf';
|
||||
component.mimeType = 'application/pdf';
|
||||
@@ -426,17 +407,14 @@ describe('ViewerComponent', () => {
|
||||
});
|
||||
|
||||
describe('Attribute', () => {
|
||||
|
||||
it('should urlFile present not thrown any error ', () => {
|
||||
expect(() => {
|
||||
component.ngOnChanges();
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('error handling', () => {
|
||||
|
||||
it('should switch to the unknown template if the type specific viewers throw an error', (done) => {
|
||||
component.urlFile = 'fake-url-file.icns';
|
||||
component.mimeType = 'image/png';
|
||||
@@ -454,9 +432,7 @@ describe('ViewerComponent', () => {
|
||||
});
|
||||
|
||||
describe('Events', () => {
|
||||
|
||||
it('should if the extension change extension Change event be fired ', (done) => {
|
||||
|
||||
component.extensionChange.subscribe((fileExtension) => {
|
||||
expect(fileExtension).toEqual('png');
|
||||
done();
|
||||
@@ -469,7 +445,6 @@ describe('ViewerComponent', () => {
|
||||
});
|
||||
|
||||
describe('display name property override by urlFile', () => {
|
||||
|
||||
it('should fileName override the default name if is present and urlFile is set', () => {
|
||||
component.urlFile = 'fake-test-file.pdf';
|
||||
component.fileName = 'test name';
|
||||
@@ -490,16 +465,14 @@ describe('ViewerComponent', () => {
|
||||
});
|
||||
|
||||
describe('display name property override by blobFile', () => {
|
||||
|
||||
it('should fileName override the name if is present and blobFile is set', () => {
|
||||
component.fileName = 'blob file display name';
|
||||
component.blobFile = new Blob(['This is my blob content'], {type: 'text/plain'});
|
||||
component.blobFile = new Blob(['This is my blob content'], { type: 'text/plain' });
|
||||
fixture.detectChanges();
|
||||
component.ngOnChanges();
|
||||
|
||||
expect(component.internalFileName).toEqual('blob file display name');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -16,10 +16,7 @@
|
||||
*/
|
||||
|
||||
import { ComponentFixture, discardPeriodicTasks, fakeAsync, flush, TestBed, tick } from '@angular/core/testing';
|
||||
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import {
|
||||
@@ -45,11 +42,9 @@ import { By } from '@angular/platform-browser';
|
||||
selector: 'adf-dialog-dummy',
|
||||
template: ``
|
||||
})
|
||||
class DummyDialogComponent {
|
||||
}
|
||||
class DummyDialogComponent {}
|
||||
|
||||
describe('ViewerComponent', () => {
|
||||
|
||||
let component: ViewerComponent<any>;
|
||||
let fixture: ComponentFixture<ViewerComponent<any>>;
|
||||
let element: HTMLElement;
|
||||
@@ -59,13 +54,7 @@ describe('ViewerComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
NoopAnimationsModule,
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule,
|
||||
MatButtonModule,
|
||||
MatIconModule
|
||||
],
|
||||
imports: [CoreTestingModule, MatButtonModule, MatIconModule],
|
||||
declarations: [
|
||||
ViewerWithCustomToolbarComponent,
|
||||
ViewerWithCustomSidebarComponent,
|
||||
@@ -73,10 +62,7 @@ describe('ViewerComponent', () => {
|
||||
ViewerWithCustomMoreActionsComponent,
|
||||
ViewerWithCustomToolbarActionsComponent
|
||||
],
|
||||
providers: [
|
||||
MatDialog,
|
||||
{ provide: DownloadPromptDialogComponent, useClass: DummyDialogComponent}
|
||||
]
|
||||
providers: [MatDialog, { provide: DownloadPromptDialogComponent, useClass: DummyDialogComponent }]
|
||||
});
|
||||
|
||||
fixture = TestBed.createComponent(ViewerComponent);
|
||||
@@ -91,7 +77,7 @@ describe('ViewerComponent', () => {
|
||||
appConfigService.config = {
|
||||
...appConfigService.config,
|
||||
viewer: {
|
||||
enableDownloadPrompt: false,
|
||||
enableDownloadPrompt: false,
|
||||
enableDownloadPromptReminder: false,
|
||||
downloadPromptDelay: 3,
|
||||
downloadPromptReminderDelay: 2
|
||||
@@ -103,17 +89,14 @@ describe('ViewerComponent', () => {
|
||||
fixture.destroy();
|
||||
});
|
||||
|
||||
|
||||
describe('Mime Type Test', () => {
|
||||
|
||||
it('should mimeType change when blobFile changes', () => {
|
||||
const mockSimpleChanges: any = { blobFile: {currentValue: { type: 'image/png'}}};
|
||||
const mockSimpleChanges: any = { blobFile: { currentValue: { type: 'image/png' } } };
|
||||
|
||||
component.ngOnChanges(mockSimpleChanges);
|
||||
|
||||
expect(component.mimeType).toBe('image/png');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('originalMimeType', () => {
|
||||
@@ -149,11 +132,10 @@ describe('ViewerComponent', () => {
|
||||
});
|
||||
|
||||
describe('File Name Test', () => {
|
||||
|
||||
it('should fileName be set by urlFile input if the fileName is not provided as Input', () => {
|
||||
component.fileName = '';
|
||||
spyOn(viewUtilService, 'getFilenameFromUrl').and.returnValue('fakeFileName.jpeg');
|
||||
const mockSimpleChanges: any = { urlFile: {currentValue: 'https://fakefile.url/fakeFileName.jpeg'}};
|
||||
const mockSimpleChanges: any = { urlFile: { currentValue: 'https://fakefile.url/fakeFileName.jpeg' } };
|
||||
|
||||
component.ngOnChanges(mockSimpleChanges);
|
||||
fixture.detectChanges();
|
||||
@@ -164,18 +146,17 @@ describe('ViewerComponent', () => {
|
||||
it('should set fileName providing fileName input', () => {
|
||||
component.fileName = 'testFileName.jpg';
|
||||
spyOn(viewUtilService, 'getFilenameFromUrl').and.returnValue('fakeFileName.jpeg');
|
||||
const mockSimpleChanges: any = { urlFile: {currentValue: 'https://fakefile.url/fakeFileName.jpeg'}};
|
||||
const mockSimpleChanges: any = { urlFile: { currentValue: 'https://fakefile.url/fakeFileName.jpeg' } };
|
||||
|
||||
component.ngOnChanges(mockSimpleChanges);
|
||||
fixture.detectChanges();fixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(element.querySelector('#adf-viewer-display-name').textContent).toEqual('testFileName.jpg');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('Viewer Example Component Rendering', () => {
|
||||
|
||||
it('should use custom toolbar', (done) => {
|
||||
const customFixture = TestBed.createComponent(ViewerWithCustomToolbarComponent);
|
||||
const customElement: HTMLElement = customFixture.nativeElement;
|
||||
@@ -232,12 +213,10 @@ describe('ViewerComponent', () => {
|
||||
expect(customElement.querySelector('.adf-viewer-container-more-actions')).toBeDefined();
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('Toolbar', () => {
|
||||
|
||||
it('should show only next file button', async () => {
|
||||
component.allowNavigate = true;
|
||||
component.canNavigateBefore = false;
|
||||
@@ -360,11 +339,9 @@ describe('ViewerComponent', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('Base component', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
component.mimeType = 'application/pdf';
|
||||
|
||||
@@ -372,7 +349,6 @@ describe('ViewerComponent', () => {
|
||||
});
|
||||
|
||||
describe('SideBar Test', () => {
|
||||
|
||||
it('should NOT display sidebar if is not allowed', (done) => {
|
||||
component.showRightSidebar = true;
|
||||
component.allowRightSidebar = false;
|
||||
@@ -407,7 +383,6 @@ describe('ViewerComponent', () => {
|
||||
expect(sidebar).toBeNull();
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('should display sidebar on the left side', (done) => {
|
||||
@@ -444,9 +419,7 @@ describe('ViewerComponent', () => {
|
||||
});
|
||||
|
||||
describe('View', () => {
|
||||
|
||||
describe('Overlay mode true', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
component.overlayMode = true;
|
||||
component.fileName = 'fake-test-file.pdf';
|
||||
@@ -458,7 +431,7 @@ describe('ViewerComponent', () => {
|
||||
});
|
||||
|
||||
it('should file name be present if is overlay mode ', async () => {
|
||||
const mockSimpleChanges: any = { blobFile: {currentValue: { type: 'image/png'}}};
|
||||
const mockSimpleChanges: any = { blobFile: { currentValue: { type: 'image/png' } } };
|
||||
component.ngOnChanges(mockSimpleChanges);
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
@@ -513,7 +486,6 @@ describe('ViewerComponent', () => {
|
||||
});
|
||||
|
||||
describe('Overlay mode false', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
component.overlayMode = false;
|
||||
fixture.detectChanges();
|
||||
@@ -533,7 +505,6 @@ describe('ViewerComponent', () => {
|
||||
});
|
||||
|
||||
describe('Attribute', () => {
|
||||
|
||||
it('should showViewer default value be true', () => {
|
||||
expect(component.showViewer).toBe(true);
|
||||
});
|
||||
@@ -547,7 +518,6 @@ describe('ViewerComponent', () => {
|
||||
});
|
||||
|
||||
describe('Close Button', () => {
|
||||
|
||||
const getRightCloseButton = () => element.querySelector<HTMLButtonElement>('[data-automation-id="adf-toolbar-right-back"]');
|
||||
const getLeftCloseButton = () => element.querySelector<HTMLButtonElement>('[data-automation-id="adf-toolbar-left-back"]');
|
||||
|
||||
@@ -562,7 +532,7 @@ describe('ViewerComponent', () => {
|
||||
|
||||
it('should show close button on right side when closeButtonPosition is right and allowGoBack is true', () => {
|
||||
component.allowGoBack = true;
|
||||
component.closeButtonPosition = CloseButtonPosition.Right;
|
||||
component.closeButtonPosition = CloseButtonPosition.Right;
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(getRightCloseButton()).not.toBeNull();
|
||||
@@ -579,7 +549,6 @@ describe('ViewerComponent', () => {
|
||||
});
|
||||
|
||||
describe('Viewer component - Full Screen Mode - Mocking fixture element', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ViewerComponent);
|
||||
element = fixture.nativeElement;
|
||||
@@ -634,31 +603,30 @@ describe('ViewerComponent', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Download Prompt Dialog',() => {
|
||||
|
||||
describe('Download Prompt Dialog', () => {
|
||||
let dialogOpenSpy: jasmine.Spy;
|
||||
|
||||
beforeEach(() => {
|
||||
appConfigService.config = {
|
||||
...appConfigService.config,
|
||||
viewer: {
|
||||
enableDownloadPrompt: true,
|
||||
enableDownloadPrompt: true,
|
||||
enableDownloadPromptReminder: true,
|
||||
downloadPromptDelay: 3,
|
||||
downloadPromptReminderDelay: 2
|
||||
}
|
||||
};
|
||||
dialogOpenSpy = spyOn(dialog, 'open').and.returnValue({afterClosed: () => of(null)} as any);
|
||||
dialogOpenSpy = spyOn(dialog, 'open').and.returnValue({ afterClosed: () => of(null) } as any);
|
||||
component.urlFile = undefined;
|
||||
component.clearDownloadPromptTimeouts();
|
||||
});
|
||||
|
||||
it('should configure initial timeout to display non responsive dialog when initialising component', (() => {
|
||||
it('should configure initial timeout to display non responsive dialog when initialising component', () => {
|
||||
fixture.detectChanges();
|
||||
expect(component.downloadPromptTimer).toBeDefined();
|
||||
}));
|
||||
});
|
||||
|
||||
it('should configure reminder timeout to display non responsive dialog after initial dialog', fakeAsync( () => {
|
||||
it('should configure reminder timeout to display non responsive dialog after initial dialog', fakeAsync(() => {
|
||||
dialogOpenSpy.and.returnValue({ afterClosed: () => of(DownloadPromptActions.WAIT) } as any);
|
||||
fixture.detectChanges();
|
||||
tick(3000);
|
||||
@@ -668,14 +636,14 @@ describe('ViewerComponent', () => {
|
||||
discardPeriodicTasks();
|
||||
}));
|
||||
|
||||
it('should show initial non responsive dialog after initial timeout', fakeAsync( () => {
|
||||
it('should show initial non responsive dialog after initial timeout', fakeAsync(() => {
|
||||
fixture.detectChanges();
|
||||
tick(3000);
|
||||
fixture.detectChanges();
|
||||
expect(dialogOpenSpy).toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should show reminder non responsive dialog after initial dialog', fakeAsync( () => {
|
||||
it('should show reminder non responsive dialog after initial dialog', fakeAsync(() => {
|
||||
dialogOpenSpy.and.returnValue({ afterClosed: () => of(DownloadPromptActions.WAIT) } as any);
|
||||
fixture.detectChanges();
|
||||
tick(3000);
|
||||
@@ -689,7 +657,7 @@ describe('ViewerComponent', () => {
|
||||
discardPeriodicTasks();
|
||||
}));
|
||||
|
||||
it('should emit downloadFileEvent when DownloadPromptDialog return DownloadPromptActions.DOWNLOAD on close', fakeAsync( () => {
|
||||
it('should emit downloadFileEvent when DownloadPromptDialog return DownloadPromptActions.DOWNLOAD on close', fakeAsync(() => {
|
||||
dialogOpenSpy.and.returnValue({ afterClosed: () => of(DownloadPromptActions.DOWNLOAD) } as any);
|
||||
spyOn(component.downloadFile, 'emit');
|
||||
fixture.detectChanges();
|
||||
|
@@ -22,7 +22,6 @@ import { TestBed } from '@angular/core/testing';
|
||||
import { ViewerRenderComponent } from '../components/viewer-render.component';
|
||||
import { ViewerExtensionDirective } from './viewer-extension.directive';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('ExtensionViewerDirective', () => {
|
||||
let extensionViewerDirective: ViewerExtensionDirective;
|
||||
@@ -36,10 +35,7 @@ describe('ExtensionViewerDirective', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
],
|
||||
imports: [CoreTestingModule],
|
||||
providers: [
|
||||
{ provide: Location, useClass: SpyLocation },
|
||||
ViewerExtensionDirective,
|
||||
@@ -50,7 +46,7 @@ describe('ExtensionViewerDirective', () => {
|
||||
});
|
||||
extensionViewerDirective = TestBed.inject(ViewerExtensionDirective);
|
||||
viewerRenderer = TestBed.inject(ViewerRenderComponent);
|
||||
extensionViewerDirective.templateModel = {template: '', isVisible: false};
|
||||
extensionViewerDirective.templateModel = { template: '', isVisible: false };
|
||||
});
|
||||
|
||||
it('is defined', () => {
|
||||
|
Reference in New Issue
Block a user