mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
fix the private access to the service variables (#8202)
* fix the private access to the service variables * fix issues with unit tests
This commit is contained in:
@@ -26,7 +26,7 @@ import { AspectEntry, AspectPaging, AspectsApi } from '@alfresco/js-api';
|
||||
})
|
||||
export class AspectListService {
|
||||
|
||||
_aspectsApi: AspectsApi;
|
||||
private _aspectsApi: AspectsApi;
|
||||
get aspectsApi(): AspectsApi {
|
||||
this._aspectsApi = this._aspectsApi ?? new AspectsApi(this.alfrescoApiService.getInstance());
|
||||
return this._aspectsApi;
|
||||
|
@@ -56,7 +56,7 @@ export class DialogAspectListService {
|
||||
width,
|
||||
role: 'dialog',
|
||||
disableClose: true
|
||||
}).afterClosed().subscribe(() => DialogAspectListService.focusOnClose(selectorAutoFocusedOnClose));
|
||||
}).afterClosed().subscribe(() => this.focusOnClose(selectorAutoFocusedOnClose));
|
||||
this.overlayContainer.getContainerElement().setAttribute('role', 'main');
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ export class DialogAspectListService {
|
||||
this.overlayContainer.getContainerElement().setAttribute('role', 'region');
|
||||
}
|
||||
|
||||
private static focusOnClose(selectorAutoFocusedOnClose: string): void {
|
||||
private focusOnClose(selectorAutoFocusedOnClose: string): void {
|
||||
if (selectorAutoFocusedOnClose) {
|
||||
document.querySelector<HTMLElement>(selectorAutoFocusedOnClose).focus();
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ import { catchError } from 'rxjs/operators';
|
||||
})
|
||||
export class AuditService {
|
||||
|
||||
_auditApi: AuditApi;
|
||||
private _auditApi: AuditApi;
|
||||
get auditApi(): AuditApi {
|
||||
this._auditApi = this._auditApi ?? new AuditApi(this.apiService.getInstance());
|
||||
return this._auditApi;
|
||||
|
@@ -26,7 +26,7 @@ import { catchError } from 'rxjs/operators';
|
||||
})
|
||||
export class FavoritesApiService {
|
||||
|
||||
_favoritesApi: FavoritesApi;
|
||||
private _favoritesApi: FavoritesApi;
|
||||
get favoritesApi(): FavoritesApi {
|
||||
this._favoritesApi = this._favoritesApi ?? new FavoritesApi(this.apiService.getInstance());
|
||||
return this._favoritesApi;
|
||||
|
@@ -27,7 +27,7 @@ import { ClassesApi } from '@alfresco/js-api';
|
||||
})
|
||||
export class PropertyDescriptorsService {
|
||||
|
||||
private _classesApi;
|
||||
private _classesApi: ClassesApi;
|
||||
get classesApi(): ClassesApi {
|
||||
this._classesApi = this._classesApi ?? new ClassesApi(this.alfrescoApiService.getInstance());
|
||||
return this._classesApi;
|
||||
|
@@ -25,7 +25,7 @@ import { map } from 'rxjs/operators';
|
||||
})
|
||||
export class ContentTypeService {
|
||||
|
||||
_typesApi: TypesApi;
|
||||
private _typesApi: TypesApi;
|
||||
get typesApi(): TypesApi {
|
||||
this._typesApi = this._typesApi ?? new TypesApi(this.alfrescoApiService.getInstance());
|
||||
return this._typesApi;
|
||||
|
@@ -24,7 +24,7 @@ import { AlfrescoApiService } from '@alfresco/adf-core';
|
||||
})
|
||||
export class GroupService {
|
||||
|
||||
_groupsApi: GroupsApi;
|
||||
private _groupsApi: GroupsApi;
|
||||
get groupsApi(): GroupsApi {
|
||||
this._groupsApi = this._groupsApi ?? new GroupsApi(this.alfrescoApiService.getInstance());
|
||||
return this._groupsApi;
|
||||
|
@@ -30,7 +30,7 @@ import { OverlayContainer } from '@angular/cdk/overlay';
|
||||
})
|
||||
export class NewVersionUploaderService {
|
||||
|
||||
_versionsApi: VersionsApi;
|
||||
private _versionsApi: VersionsApi;
|
||||
get versionsApi(): VersionsApi {
|
||||
this._versionsApi = this._versionsApi ?? new VersionsApi(this.apiService.getInstance());
|
||||
return this._versionsApi;
|
||||
|
@@ -42,7 +42,7 @@ import { RoleModel } from '../models/role.model';
|
||||
})
|
||||
export class NodePermissionService {
|
||||
|
||||
_groupsApi: GroupsApi;
|
||||
private _groupsApi: GroupsApi;
|
||||
get groupsApi(): GroupsApi {
|
||||
this._groupsApi = this._groupsApi ?? new GroupsApi(this.apiService.getInstance());
|
||||
return this._groupsApi;
|
||||
|
@@ -42,7 +42,7 @@ import { SearchForm } from '../models/search-form.interface';
|
||||
})
|
||||
export abstract class BaseQueryBuilderService {
|
||||
|
||||
_searchApi: SearchApi;
|
||||
private _searchApi: SearchApi;
|
||||
get searchApi(): SearchApi {
|
||||
this._searchApi = this._searchApi ?? new SearchApi(this.alfrescoApiService.getInstance());
|
||||
return this._searchApi;
|
||||
|
@@ -24,9 +24,6 @@ import { SearchConfigurationInterface } from '@alfresco/adf-core';
|
||||
})
|
||||
export class SearchConfigurationService implements SearchConfigurationInterface {
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a QueryBody object with custom search parameters.
|
||||
*
|
||||
|
@@ -27,7 +27,7 @@ import { RatingServiceInterface } from './rating.service.interface';
|
||||
})
|
||||
export class RatingService implements RatingServiceInterface {
|
||||
|
||||
_ratingsApi: RatingsApi;
|
||||
private _ratingsApi: RatingsApi;
|
||||
get ratingsApi(): RatingsApi {
|
||||
this._ratingsApi = this._ratingsApi ?? new RatingsApi(this.apiService.getInstance());
|
||||
return this._ratingsApi;
|
||||
|
@@ -25,8 +25,6 @@ import {
|
||||
RequestQuery,
|
||||
RequestSortDefinitionInner,
|
||||
ResultSetPaging,
|
||||
SearchApi,
|
||||
SearchRequest,
|
||||
TagBody,
|
||||
TagEntry
|
||||
} from '@alfresco/js-api';
|
||||
@@ -34,6 +32,8 @@ import {
|
||||
describe('TagService', () => {
|
||||
|
||||
let service: TagService;
|
||||
let logService: LogService;
|
||||
let userPreferencesService: UserPreferencesService;
|
||||
|
||||
setupTestBed({
|
||||
imports: [
|
||||
@@ -44,10 +44,13 @@ describe('TagService', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
service = TestBed.inject(TagService);
|
||||
spyOn(service['tagsApi'], 'deleteTagFromNode').and.returnValue(
|
||||
logService = TestBed.inject(LogService);
|
||||
userPreferencesService = TestBed.inject(UserPreferencesService);
|
||||
|
||||
spyOn(service.tagsApi, 'deleteTagFromNode').and.returnValue(
|
||||
Promise.resolve({})
|
||||
);
|
||||
spyOn(service['tagsApi'], 'createTagForNode').and.returnValue(
|
||||
spyOn(service.tagsApi, 'createTagForNode').and.returnValue(
|
||||
Promise.resolve(new TagEntry({}))
|
||||
);
|
||||
});
|
||||
@@ -82,11 +85,11 @@ describe('TagService', () => {
|
||||
describe('createTags', () => {
|
||||
it('should call createTags on tagsApi', () => {
|
||||
spyOn(service.tagsApi, 'createTags').and.returnValue(Promise.resolve([]));
|
||||
const tag1: TagBody = new TagBody();
|
||||
const tag1 = new TagBody();
|
||||
tag1.tag = 'Some tag 1';
|
||||
const tag2: TagBody = new TagBody();
|
||||
const tag2 = new TagBody();
|
||||
tag2.tag = 'Some tag 2';
|
||||
const tags: TagBody[] = [tag1, tag2];
|
||||
const tags = [tag1, tag2];
|
||||
service.createTags(tags);
|
||||
expect(service.tagsApi.createTags).toHaveBeenCalledWith(tags);
|
||||
});
|
||||
@@ -106,9 +109,8 @@ describe('TagService', () => {
|
||||
}));
|
||||
|
||||
it('should call error on logService when error occurs during tags creation', fakeAsync(() => {
|
||||
const logService: LogService = TestBed.inject(LogService);
|
||||
spyOn(logService, 'error');
|
||||
const error: string = 'Some error';
|
||||
const error = 'Some error';
|
||||
spyOn(service.tagsApi, 'createTags').and.returnValue(Promise.reject(error));
|
||||
service.createTags([]);
|
||||
tick();
|
||||
@@ -124,15 +126,16 @@ describe('TagService', () => {
|
||||
});
|
||||
|
||||
it('should call search on searchApi with correct parameters', () => {
|
||||
const searchSpy: jasmine.Spy<(queryBody: SearchRequest) => Promise<ResultSetPaging>> =
|
||||
spyOn(SearchApi.prototype, 'search').and.returnValue(Promise.resolve(result));
|
||||
const name: string = 'test';
|
||||
const sortingByName: RequestSortDefinitionInner = new RequestSortDefinitionInner();
|
||||
const maxItems: number = 25;
|
||||
spyOnProperty(TestBed.inject(UserPreferencesService), 'paginationSize').and.returnValue(maxItems);
|
||||
const searchSpy = spyOn(service.searchApi, 'search').and.returnValue(Promise.resolve(result));
|
||||
const name = 'test';
|
||||
const maxItems = 25;
|
||||
spyOnProperty(userPreferencesService, 'paginationSize').and.returnValue(maxItems);
|
||||
|
||||
const sortingByName = new RequestSortDefinitionInner();
|
||||
sortingByName.field = 'cm:name';
|
||||
sortingByName.ascending = true;
|
||||
sortingByName.type = RequestSortDefinitionInner.TypeEnum.FIELD;
|
||||
|
||||
service.searchTags(name);
|
||||
expect(searchSpy).toHaveBeenCalledWith({
|
||||
query: {
|
||||
@@ -148,7 +151,8 @@ describe('TagService', () => {
|
||||
});
|
||||
|
||||
it('should return observable which emits paging object for tags', (done) => {
|
||||
spyOn(SearchApi.prototype, 'search').and.returnValue(Promise.resolve(result));
|
||||
spyOn(service.searchApi, 'search').and.returnValue(Promise.resolve(result));
|
||||
|
||||
service.searchTags('test').subscribe((tagsResult) => {
|
||||
expect(tagsResult).toBe(result);
|
||||
done();
|
||||
@@ -156,10 +160,9 @@ describe('TagService', () => {
|
||||
});
|
||||
|
||||
it('should call error on logService when error occurs during fetching paging object for tags', fakeAsync(() => {
|
||||
const logService: LogService = TestBed.inject(LogService);
|
||||
spyOn(logService, 'error');
|
||||
const error: string = 'Some error';
|
||||
spyOn(SearchApi.prototype, 'search').and.returnValue(Promise.reject(error));
|
||||
spyOn(service.searchApi, 'search').and.returnValue(Promise.reject(error));
|
||||
service.searchTags('test').subscribe({
|
||||
error: () => {
|
||||
expect(logService.error).toHaveBeenCalledWith(error);
|
||||
@@ -200,9 +203,8 @@ describe('TagService', () => {
|
||||
}));
|
||||
|
||||
it('should call error on logService when error occurs during tag update', fakeAsync(() => {
|
||||
const logService: LogService = TestBed.inject(LogService);
|
||||
spyOn(logService, 'error');
|
||||
const error: string = 'Some error';
|
||||
const error = 'Some error';
|
||||
spyOn(service.tagsApi, 'updateTag').and.returnValue(Promise.reject(error));
|
||||
service.updateTag(tag.entry.id, tagBody);
|
||||
tick();
|
||||
|
@@ -33,16 +33,19 @@ import {
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
// eslint-disable-next-line @angular-eslint/directive-class-suffix
|
||||
export class TagService {
|
||||
|
||||
_tagsApi: TagsApi;
|
||||
private _tagsApi: TagsApi;
|
||||
get tagsApi(): TagsApi {
|
||||
this._tagsApi = this._tagsApi ?? new TagsApi(this.apiService.getInstance());
|
||||
return this._tagsApi;
|
||||
}
|
||||
|
||||
private searchApi: SearchApi = new SearchApi(this.apiService.getInstance());
|
||||
private _searchApi: SearchApi;
|
||||
get searchApi(): SearchApi {
|
||||
this._searchApi = this._searchApi ?? new SearchApi(this.apiService.getInstance());
|
||||
return this._searchApi;
|
||||
}
|
||||
|
||||
/** Emitted when tag information is updated. */
|
||||
@Output()
|
||||
|
Reference in New Issue
Block a user