[ACS-6196] await-thenable rule for ESLint, fix issues (#9027)

* fix issues for core lib

* fix content services lib

* fix and cleanup process services

* [ci:force] process services cloud

* [ci:force] align coverage with all libs

* [ci:force] fix the insights
This commit is contained in:
Denys Vuika
2023-10-26 14:33:48 +01:00
committed by GitHub
parent 7ebdce7875
commit ba96ed14b2
45 changed files with 638 additions and 1224 deletions

View File

@@ -72,26 +72,27 @@ describe('NodeAspectService', () => {
expect(nodeApiService.updateNode).toHaveBeenCalledWith('fake-node-id', expectedParameters);
});
it('should send and update node event once the node has been updated', async () => {
await nodeApiService.nodeUpdated.subscribe((nodeUpdated) => {
expect(nodeUpdated.id).toBe('fake-node-id');
expect(nodeUpdated.aspectNames).toEqual(['a', 'b', 'c']);
});
it('should send and update node event once the node has been updated', () => {
let lastValue: Node;
nodeApiService.nodeUpdated.subscribe((nodeUpdated) => lastValue = nodeUpdated);
const fakeNode = new Node({ id: 'fake-node-id', aspectNames: ['a', 'b', 'c'] });
spyOn(dialogAspectListService, 'openAspectListDialog').and.returnValue(of(['a', 'b', 'c']));
spyOn(nodeApiService, 'updateNode').and.returnValue(of(fakeNode));
nodeAspectService.updateNodeAspects('fake-node-id');
expect(lastValue.id).toBe('fake-node-id');
expect(lastValue.aspectNames).toEqual(['a', 'b', 'c']);
});
it('should send and update node aspect once the node has been updated', async () => {
await cardViewContentUpdateService.updatedAspect$.subscribe((nodeUpdated) => {
expect(nodeUpdated.id).toBe('fake-node-id');
expect(nodeUpdated.aspectNames).toEqual(['a', 'b', 'c']);
});
it('should send and update node aspect once the node has been updated', () => {
let lastValue: Node;
cardViewContentUpdateService.updatedAspect$.subscribe((nodeUpdated) => lastValue = nodeUpdated);
const fakeNode = new Node({ id: 'fake-node-id', aspectNames: ['a', 'b', 'c'] });
spyOn(dialogAspectListService, 'openAspectListDialog').and.returnValue(of(['a', 'b', 'c']));
spyOn(nodeApiService, 'updateNode').and.returnValue(of(fakeNode));
nodeAspectService.updateNodeAspects('fake-node-id');
expect(lastValue.id).toBe('fake-node-id');
expect(lastValue.aspectNames).toEqual(['a', 'b', 'c']);
});
it('should call emit on refresh from TagService', () => {

View File

@@ -126,7 +126,7 @@ describe('PeopleContentService', () => {
await peopleContentService.getCurrentUserInfo().toPromise();
expect(await peopleContentService.isCurrentUserAdmin()).toBe(true);
expect(peopleContentService.isCurrentUserAdmin()).toBe(true);
expect(getCurrentPersonSpy.calls.count()).toEqual(1);
});

View File

@@ -127,14 +127,14 @@ describe('ContentNodeSelectorPanelComponent', () => {
component.currentFolderId = 'fake-starting-folder';
});
it('should trigger siteChange event on init with parent site Title of start folder', async () => {
await component.siteChange.subscribe((siteTitle: string) => {
expect(siteTitle).toBe('fake-site');
});
it('should trigger siteChange event on init with parent site Title of start folder', () => {
let lastValue: string;
component.siteChange.subscribe((siteTitle: string) => lastValue = siteTitle);
component.ngOnInit();
fixture.detectChanges();
expect(component.startSiteGuid).toBe('fake-site');
expect(lastValue).toBe('fake-site');
});
it('should trigger siteChange event when a site is selected in sites-dropdown', async () => {
@@ -142,12 +142,12 @@ describe('ContentNodeSelectorPanelComponent', () => {
fixture.detectChanges();
await fixture.whenStable();
await component.siteChange.subscribe((siteTitle: string) => {
expect(siteTitle).toBe('fake-new-site');
});
let lastValue: string;
component.siteChange.subscribe((siteTitle: string) => lastValue = siteTitle);
const sitesDropdown = fixture.debugElement.query(By.directive(DropdownSitesComponent));
sitesDropdown.componentInstance.selectedSite({ value: fakeSiteEntry });
expect(lastValue).toBe('fake-new-site');
});
});
@@ -177,14 +177,14 @@ describe('ContentNodeSelectorPanelComponent', () => {
expect(component.documentList.sortingMode).toBe('server');
});
it('should trigger the select event when selection has been made', async () => {
it('should trigger the select event when selection has been made', () => {
const expectedNode = { id: 'fakeid' } as Node;
await component.select.subscribe((nodes) => {
expect(nodes.length).toBe(1);
expect(nodes[0]).toBe(expectedNode);
});
let lastValue: Node[];
component.select.subscribe((nodes) => lastValue = nodes);
component.chosenNode = [expectedNode];
expect(lastValue.length).toBe(1);
expect(lastValue[0]).toBe(expectedNode);
});
it('should be able to filter out the exclude site content', () => {

View File

@@ -56,7 +56,7 @@ describe('FileAutoDownloadComponent', () => {
const waitButton = getButton('#cancelButton');
waitButton.dispatchEvent(new Event('click'));
await fixture.detectChanges();
fixture.detectChanges();
await fixture.whenStable();
expect(matDialogRef.close).toHaveBeenCalled();
@@ -66,7 +66,7 @@ describe('FileAutoDownloadComponent', () => {
const waitButton = getButton('#downloadButton');
waitButton.dispatchEvent(new Event('click'));
await fixture.detectChanges();
fixture.detectChanges();
await fixture.whenStable();
expect(matDialogRef.close).toHaveBeenCalled();

View File

@@ -23,6 +23,7 @@ import { of } from 'rxjs';
import { TestBed } from '@angular/core/testing';
import { ContentTestingModule } from '../../testing/content.testing.module';
import { TranslateModule } from '@ngx-translate/core';
import { PermissionModel } from '../models/permissions.model';
describe('DocumentActionsService', () => {
@@ -94,17 +95,18 @@ describe('DocumentActionsService', () => {
expect(service.getHandler('delete')).toBeDefined();
});
it('should not delete the file node if there are no permissions', async () => {
it('should not delete the file node if there are no permissions', () => {
spyOn(documentListService, 'deleteNode').and.returnValue(of(true));
await service.permissionEvent.subscribe((permission) => {
expect(permission).toBeDefined();
expect(permission.type).toEqual('content');
expect(permission.action).toEqual('delete');
});
let lastValue: PermissionModel;
service.permissionEvent.subscribe((permission) => lastValue = permission);
const file = new FileNode();
service.getHandler('delete')(file);
expect(lastValue).toBeDefined();
expect(lastValue.type).toEqual('content');
expect(lastValue.action).toEqual('delete');
});
it('should call the error on the returned Observable if there are no permissions', async () => {
@@ -132,20 +134,21 @@ describe('DocumentActionsService', () => {
expect(documentListService.deleteNode).toHaveBeenCalledWith(file.entry.id);
});
it('should not delete the file node if there is no delete permission', async () => {
it('should not delete the file node if there is no delete permission', () => {
spyOn(documentListService, 'deleteNode').and.callThrough();
await service.permissionEvent.subscribe((permissionBack) => {
expect(permissionBack).toBeDefined();
expect(permissionBack.type).toEqual('content');
expect(permissionBack.action).toEqual('delete');
});
let lastValue: PermissionModel;
service.permissionEvent.subscribe((permissionBack) => lastValue = permissionBack);
const permission = 'delete';
const file = new FileNode();
const fileWithPermission: any = file;
fileWithPermission.entry.allowableOperations = ['create', 'update'];
service.getHandler('delete')(fileWithPermission, null, permission);
expect(lastValue).toBeDefined();
expect(lastValue.type).toEqual('content');
expect(lastValue.action).toEqual('delete');
});
it('should delete the file node if there is the delete and others permission ', () => {
@@ -202,10 +205,9 @@ describe('DocumentActionsService', () => {
expect(documentListService.deleteNode).not.toHaveBeenCalled();
});
it('should emit success event upon node deletion', async () => {
await service.success.subscribe((message) => {
expect(message).toEqual('CORE.DELETE_NODE.SINGULAR');
});
it('should emit success event upon node deletion', () => {
let lastValue: string;
service.success.subscribe((message) => lastValue = message);
spyOn(documentListService, 'deleteNode').and.returnValue(of(true));
const target = jasmine.createSpyObj('obj', ['reload']);
@@ -214,5 +216,6 @@ describe('DocumentActionsService', () => {
const fileWithPermission: any = file;
fileWithPermission.entry.allowableOperations = [permission];
service.getHandler('delete')(fileWithPermission, target, permission);
expect(lastValue).toEqual('CORE.DELETE_NODE.SINGULAR');
});
});

View File

@@ -31,9 +31,9 @@ import { ContentNodeDialogService } from '../../content-node-selector/content-no
})
export class DocumentActionsService {
permissionEvent: Subject<PermissionModel> = new Subject<PermissionModel>();
error: Subject<Error> = new Subject<Error>();
success: Subject<string> = new Subject<string>();
permissionEvent = new Subject<PermissionModel>();
error = new Subject<Error>();
success = new Subject<string>();
private handlers: { [id: string]: ContentActionHandler } = {};
@@ -113,7 +113,7 @@ export class DocumentActionsService {
return actionObservable;
}
private prepareHandlers(actionObservable): void {
private prepareHandlers(actionObservable: Subject<string>): void {
actionObservable.subscribe(
(fileOperationMessage) => {
this.success.next(fileOperationMessage);

View File

@@ -24,6 +24,7 @@ import { DocumentListService } from './document-list.service';
import { FolderActionsService } from './folder-actions.service';
import { ContentTestingModule } from '../../testing/content.testing.module';
import { TranslateModule } from '@ngx-translate/core';
import { PermissionModel } from '../models/permissions.model';
describe('FolderActionsService', () => {
@@ -87,17 +88,17 @@ describe('FolderActionsService', () => {
expect(service.getHandler('delete')).toBeDefined();
});
it('should not delete the folder node if there are no permissions', async () => {
it('should not delete the folder node if there are no permissions', () => {
spyOn(documentListService, 'deleteNode').and.callThrough();
await service.permissionEvent.subscribe((permission) => {
expect(permission).toBeDefined();
expect(permission.type).toEqual('folder');
expect(permission.action).toEqual('delete');
});
let lastValue: PermissionModel;
service.permissionEvent.subscribe((permission) => lastValue = permission);
const folder = new FolderNode();
service.getHandler('delete')(folder);
expect(lastValue).toBeDefined();
expect(lastValue.type).toEqual('folder');
expect(lastValue.action).toEqual('delete');
});
it('should delete the folder node if there is the delete permission', () => {
@@ -116,22 +117,22 @@ describe('FolderActionsService', () => {
expect(deleteObservable.subscribe).toBeDefined();
});
it('should not delete the folder node if there is no delete permission', async () => {
it('should not delete the folder node if there is no delete permission', () => {
spyOn(documentListService, 'deleteNode').and.callFake(() => new Observable<any>((observer) => {
observer.next();
observer.complete();
}));
await service.permissionEvent.subscribe((permission) => {
expect(permission).toBeDefined();
expect(permission.type).toEqual('folder');
expect(permission.action).toEqual('delete');
});
let lastValue: PermissionModel;
service.permissionEvent.subscribe((permission) => lastValue = permission);
const folder = new FolderNode();
const folderWithPermission: any = folder;
folderWithPermission.entry.allowableOperations = ['create', 'update'];
service.getHandler('delete')(folderWithPermission);
expect(lastValue).toBeDefined();
expect(lastValue.type).toEqual('folder');
expect(lastValue.action).toEqual('delete');
});
it('should call the error on the returned Observable if there is no delete permission', async () => {
@@ -219,15 +220,14 @@ describe('FolderActionsService', () => {
expect(documentListService.deleteNode).toHaveBeenCalled();
});
it('should emit success event upon node deletion', async () => {
it('should emit success event upon node deletion', () => {
spyOn(documentListService, 'deleteNode').and.callFake(() => new Observable<any>((observer) => {
observer.next();
observer.complete();
}));
await service.success.subscribe((nodeId) => {
expect(nodeId).not.toBeNull();
});
let lastValue: string;
service.success.subscribe((nodeId) => lastValue = nodeId);
const permission = 'delete';
const target = jasmine.createSpyObj('obj', ['reload']);
@@ -236,5 +236,6 @@ describe('FolderActionsService', () => {
folderWithPermission.entry.allowableOperations = [permission];
service.getHandler('delete')(folderWithPermission, target, permission);
expect(lastValue).not.toBeNull();
});
});

View File

@@ -30,9 +30,9 @@ import { NodeActionsService } from './node-actions.service';
})
export class FolderActionsService {
permissionEvent: Subject<PermissionModel> = new Subject<PermissionModel>();
error: Subject<Error> = new Subject<Error>();
success: Subject<string> = new Subject<string>();
permissionEvent = new Subject<PermissionModel>();
error = new Subject<Error>();
success = new Subject<string>();
private handlers: { [id: string]: ContentActionHandler } = {};

View File

@@ -86,15 +86,15 @@ describe('AddPermissionComponent', () => {
fixture.componentInstance.selectedItems = fakeAuthorityResults;
spyOn(nodePermissionService, 'updateNodePermissions').and.returnValue(of(new Node({ id: 'fake-node-id'})));
await fixture.componentInstance.success.subscribe((node) => {
expect(node.id).toBe('fake-node-id');
});
let lastValue: Node;
fixture.componentInstance.success.subscribe((node) => lastValue = node);
fixture.detectChanges();
await fixture.whenStable();
const addButton = element.querySelector<HTMLButtonElement>('#adf-add-permission-action-button');
addButton.click();
expect(lastValue.id).toBe('fake-node-id');
});
it('should NOT emit a success event when the user does not have permission to update the node', () => {
@@ -111,13 +111,15 @@ describe('AddPermissionComponent', () => {
fixture.componentInstance.selectedItems = fakeAuthorityResults;
spyOn(nodePermissionService, 'updateNodePermissions').and.returnValue(throwError({ error: 'err'}));
await fixture.componentInstance.error.subscribe((error) => {
expect(error.error).toBe('err');
});
let lastValue: any;
fixture.componentInstance.error.subscribe((error) => lastValue = error);
fixture.detectChanges();
await fixture.whenStable();
const addButton = element.querySelector<HTMLButtonElement>('#adf-add-permission-action-button');
addButton.click();
expect(lastValue.error).toBe('err');
});
});

View File

@@ -39,11 +39,11 @@ export class AddPermissionComponent implements OnInit {
/** Emitted when the node is updated successfully. */
@Output()
success: EventEmitter<Node> = new EventEmitter();
success = new EventEmitter<Node>();
/** Emitted when an error occurs during the update. */
@Output()
error: EventEmitter<any> = new EventEmitter();
error = new EventEmitter<any>();
selectedItems: NodeEntry[] = [];
currentNode: Node;

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { LogService, UserPreferencesService } from '@alfresco/adf-core';
import { UserPreferencesService } from '@alfresco/adf-core';
import { TagService } from './tag.service';
import { fakeAsync, TestBed, tick } from '@angular/core/testing';
import { ContentTestingModule } from '../../testing/content.testing.module';
@@ -25,8 +25,8 @@ import { Pagination, Tag, TagBody, TagEntry, TagPaging, TagPagingList } from '@a
describe('TagService', () => {
let service: TagService;
let logService: LogService;
let userPreferencesService: UserPreferencesService;
let tagEntry: TagEntry;
const mockTagPaging = (): TagPaging => {
const tagPaging = new TagPaging();
@@ -45,17 +45,19 @@ describe('TagService', () => {
imports: [TranslateModule.forRoot(), ContentTestingModule]
});
service = TestBed.inject(TagService);
logService = TestBed.inject(LogService);
userPreferencesService = TestBed.inject(UserPreferencesService);
tagEntry = new TagEntry({ entry: { id: '1', tag: 'test-tag' } });
spyOn(service.tagsApi, 'deleteTagFromNode').and.returnValue(Promise.resolve());
spyOn(service.tagsApi, 'createTagForNode').and.returnValue(Promise.resolve(new TagEntry({})));
spyOn(service.tagsApi, 'createTagForNode').and.returnValue(Promise.resolve(tagEntry));
spyOn(service.tagsApi, 'deleteTag').and.returnValue(Promise.resolve());
});
describe('Content tests', () => {
it('should catch errors on getTagsByNodeId call', async () => {
spyOn(service, 'getTagsByNodeId').and.returnValue(throwError({ error: 'error' }));
await service.getTagsByNodeId('fake-node-id').subscribe(
service.getTagsByNodeId('fake-node-id').subscribe(
() => {
throwError('This call should fail');
},
@@ -66,31 +68,28 @@ describe('TagService', () => {
});
it('should trigger a refresh event on removeTag() call', async () => {
await service.refresh.subscribe(() => {
expect(service.tagsApi.deleteTagFromNode).toHaveBeenCalledWith('fake-node-id', 'fake-tag');
});
service.removeTag('fake-node-id', 'fake-tag');
expect(service.tagsApi.deleteTagFromNode).toHaveBeenCalledWith('fake-node-id', 'fake-tag');
});
it('should trigger a refresh event on addTag() call', async () => {
await service.refresh.subscribe((res) => {
expect(res).toBeDefined();
});
let lastValue: any;
service.refresh.subscribe((res) => lastValue = res);
service.addTag('fake-node-id', 'fake-tag');
await service.addTag('fake-node-id', 'fake-tag').toPromise();
expect(lastValue).toBe(tagEntry);
});
it('should trigger a refresh event on deleteTag() call', async () => {
await service.refresh.subscribe((res) => {
expect(res).toBeDefined();
});
let lastValue = false;
service.refresh.subscribe(() => lastValue = true);
service.deleteTag('fake-tag-id');
await service.deleteTag('fake-tag-id').toPromise();
expect(lastValue).toBeTrue();
});
describe('createTags', () => {
it('should call createTags on tagsApi', (done) => {
it('should call createTags on tagsApi', () => {
spyOn(service.tagsApi, 'createTags').and.returnValue(Promise.resolve([]));
const tag1 = new TagBody();
tag1.tag = 'Some tag 1';
@@ -100,10 +99,9 @@ describe('TagService', () => {
service.createTags(tags);
expect(service.tagsApi.createTags).toHaveBeenCalledWith(tags);
done();
});
it('should emit refresh when tags creation is success', fakeAsync(() => {
it('should emit refresh when tags creation is success', async () => {
const tags: TagEntry[] = [
{
entry: {
@@ -114,19 +112,10 @@ describe('TagService', () => {
];
spyOn(service.refresh, 'emit');
spyOn(service.tagsApi, 'createTags').and.returnValue(Promise.resolve(tags));
service.createTags([]);
tick();
expect(service.refresh.emit).toHaveBeenCalledWith(tags);
}));
it('should call error on logService when error occurs during tags creation', fakeAsync(() => {
spyOn(logService, 'error');
const error = 'Some error';
spyOn(service.tagsApi, 'createTags').and.returnValue(Promise.reject(error));
service.createTags([]);
tick();
expect(logService.error).toHaveBeenCalledWith(error);
}));
await service.createTags([]).toPromise();
expect(service.refresh.emit).toHaveBeenCalledWith(tags);
});
});
describe('getAllTheTags', () => {
@@ -176,18 +165,6 @@ describe('TagService', () => {
});
tick();
}));
it('should call error on logService when error occurs during fetching paging object for tags', fakeAsync(() => {
spyOn(logService, 'error');
const error: string = 'Some error';
spyOn(service.tagsApi, 'listTags').and.returnValue(Promise.reject(error));
service.getAllTheTags().subscribe({
error: () => {
expect(logService.error).toHaveBeenCalledWith(error);
}
});
tick();
}));
});
describe('searchTags', () => {
@@ -247,18 +224,6 @@ describe('TagService', () => {
});
tick();
}));
it('should call error on logService when error occurs during fetching paging object for tags', fakeAsync(() => {
spyOn(logService, 'error');
const error: string = 'Some error';
spyOn(service.tagsApi, 'listTags').and.returnValue(Promise.reject(error));
service.searchTags('test').subscribe({
error: () => {
expect(logService.error).toHaveBeenCalledWith(error);
}
});
tick();
}));
});
describe('updateTag', () => {
@@ -283,22 +248,12 @@ describe('TagService', () => {
expect(service.tagsApi.updateTag).toHaveBeenCalledWith(tag.entry.id, tagBody);
});
it('should emit refresh when tag updated successfully', fakeAsync(() => {
it('should emit refresh when tag updated successfully', async () => {
spyOn(service.refresh, 'emit');
spyOn(service.tagsApi, 'updateTag').and.returnValue(Promise.resolve(updatedTag));
service.updateTag(tag.entry.id, tagBody);
tick();
await service.updateTag(tag.entry.id, tagBody).toPromise();
expect(service.refresh.emit).toHaveBeenCalledWith(updatedTag);
}));
it('should call error on logService when error occurs during tag update', fakeAsync(() => {
spyOn(logService, 'error');
const error = 'Some error';
spyOn(service.tagsApi, 'updateTag').and.returnValue(Promise.reject(error));
service.updateTag(tag.entry.id, tagBody);
tick();
expect(logService.error).toHaveBeenCalledWith(error);
}));
});
});
describe('findTagByName', () => {
@@ -334,19 +289,6 @@ describe('TagService', () => {
done();
});
});
it('should call error on logService when error occurs during fetching tag for name', fakeAsync(() => {
spyOn(logService, 'error');
const error = 'Some error';
spyOn(service.tagsApi, 'listTags').and.returnValue(Promise.reject(error));
service.findTagByName(tagName).subscribe({
error: () => {
expect(logService.error).toHaveBeenCalledWith(error);
}
});
tick();
}));
});
describe('assignTagsToNode', () => {

View File

@@ -15,17 +15,16 @@
* limitations under the License.
*/
import { AlfrescoApiService, LogService, UserPreferencesService } from '@alfresco/adf-core';
import { AlfrescoApiService, UserPreferencesService } from '@alfresco/adf-core';
import { EventEmitter, Injectable, Output } from '@angular/core';
import { from, Observable, throwError } from 'rxjs';
import { catchError, map, tap } from 'rxjs/operators';
import { from, Observable } from 'rxjs';
import { map, tap } from 'rxjs/operators';
import { TagBody, TagEntry, TagPaging, TagsApi } from '@alfresco/js-api';
@Injectable({
providedIn: 'root'
})
export class TagService {
private _tagsApi: TagsApi;
get tagsApi(): TagsApi {
this._tagsApi = this._tagsApi ?? new TagsApi(this.apiService.getInstance());
@@ -36,10 +35,7 @@ export class TagService {
@Output()
refresh = new EventEmitter();
constructor(private apiService: AlfrescoApiService,
private logService: LogService,
private userPreferencesService: UserPreferencesService) {
}
constructor(private apiService: AlfrescoApiService, private userPreferencesService: UserPreferencesService) {}
/**
* Gets a list of tags added to a node.
@@ -48,9 +44,7 @@ export class TagService {
* @returns TagPaging object (defined in JS-API) containing the tags
*/
getTagsByNodeId(nodeId: string): Observable<TagPaging> {
return from(this.tagsApi.listTagsForNode(nodeId)).pipe(
catchError((err) => this.handleError(err))
);
return from(this.tagsApi.listTagsForNode(nodeId));
}
/**
@@ -61,10 +55,12 @@ export class TagService {
* @returns TagPaging object (defined in JS-API) containing the tags
*/
getAllTheTags(opts?: any, includedCounts?: boolean): Observable<TagPaging> {
return from(this.tagsApi.listTags({
include: includedCounts ? ['count'] : undefined,
...opts
})).pipe(catchError((err) => this.handleError(err)));
return from(
this.tagsApi.listTags({
include: includedCounts ? ['count'] : undefined,
...opts
})
);
}
/**
@@ -78,15 +74,7 @@ export class TagService {
const tagBody = new TagBody();
tagBody.tag = tagName;
const observableAdd = from(this.tagsApi.createTagForNode(nodeId, [tagBody]));
observableAdd.subscribe((tagEntry: TagEntry) => {
this.refresh.emit(tagEntry);
}, (err) => {
this.handleError(err);
});
return observableAdd;
return from(this.tagsApi.createTagForNode(nodeId, [tagBody])).pipe(tap((tagEntry) => this.refresh.emit(tagEntry)));
}
/**
@@ -97,15 +85,7 @@ export class TagService {
* @returns Null object when the operation completes
*/
removeTag(nodeId: string, tag: string): Observable<void> {
const observableRemove = from(this.tagsApi.deleteTagFromNode(nodeId, tag));
observableRemove.subscribe(() => {
this.refresh.emit();
}, (err) => {
this.handleError(err);
});
return observableRemove;
return from(this.tagsApi.deleteTagFromNode(nodeId, tag)).pipe(tap(() => this.refresh.emit()));
}
/**
@@ -115,12 +95,7 @@ export class TagService {
* @returns Created tags.
*/
createTags(tags: TagBody[]): Observable<TagEntry[]> {
const observableAdd$: Observable<TagEntry[]> = from(this.tagsApi.createTags(tags));
observableAdd$.subscribe(
(tagsEntries: TagEntry[]) => this.refresh.emit(tagsEntries),
(err) => this.handleError(err)
);
return observableAdd$;
return from(this.tagsApi.createTags(tags)).pipe(tap((tagEntries) => this.refresh.emit(tagEntries)));
}
/**
@@ -131,12 +106,7 @@ export class TagService {
* @returns Updated tag.
*/
updateTag(tagId: string, tagBody: TagBody): Observable<TagEntry> {
const observableUpdate$: Observable<TagEntry> = from(this.tagsApi.updateTag(tagId, tagBody));
observableUpdate$.subscribe(
(tagEntry: TagEntry) => this.refresh.emit(tagEntry),
(err) => this.handleError(err)
);
return observableUpdate$;
return from(this.tagsApi.updateTag(tagId, tagBody)).pipe(tap((tagEntry) => this.refresh.emit(tagEntry)));
}
/**
@@ -150,16 +120,24 @@ export class TagService {
* @param maxItems Specify max number of returned tags. Default is specified by UserPreferencesService.
* @returns Found tags which name contains searched name.
*/
searchTags(name: string, sorting = { orderBy: 'tag', direction: 'asc' },
includedCounts?: boolean, skipCount = 0, maxItems?: number): Observable<TagPaging> {
searchTags(
name: string,
sorting = { orderBy: 'tag', direction: 'asc' },
includedCounts?: boolean,
skipCount = 0,
maxItems?: number
): Observable<TagPaging> {
maxItems = maxItems || this.userPreferencesService.paginationSize;
return this.getAllTheTags({
tag: `*${name}*`,
skipCount,
maxItems,
sorting,
matching: true
}, includedCounts).pipe(catchError((err) => this.handleError(err)));
return this.getAllTheTags(
{
tag: `*${name}*`,
skipCount,
maxItems,
sorting,
matching: true
},
includedCounts
);
}
/**
@@ -169,10 +147,7 @@ export class TagService {
* @returns Found tag which name matches exactly to passed name.
*/
findTagByName(name: string): Observable<TagEntry> {
return this.getAllTheTags({ tag: name }).pipe(
map((result) => result.list.entries[0]),
catchError((error) => this.handleError(error))
);
return this.getAllTheTags({ tag: name }).pipe(map((result) => result.list.entries[0]));
}
/**
@@ -184,9 +159,7 @@ export class TagService {
* @returns Null object when the operation completes
*/
deleteTag(tagId: string): Observable<void> {
return from(this.tagsApi.deleteTag(tagId)).pipe(
tap((data) => this.refresh.emit(data))
);
return from(this.tagsApi.deleteTag(tagId)).pipe(tap(() => this.refresh.emit()));
}
/**
@@ -197,13 +170,6 @@ export class TagService {
* @returns Just linked tags to node or single tag if linked only one tag.
*/
assignTagsToNode(nodeId: string, tags: TagBody[]): Observable<TagPaging | TagEntry> {
return from(this.tagsApi.assignTagsToNode(nodeId, tags)).pipe(
tap((data) => this.refresh.emit(data))
);
}
private handleError(error: any) {
this.logService.error(error);
return throwError(error || 'Server error');
return from(this.tagsApi.assignTagsToNode(nodeId, tags)).pipe(tap((data) => this.refresh.emit(data)));
}
}

View File

@@ -146,7 +146,7 @@ describe('UploadButtonComponent', () => {
expect(uploadService.uploadFilesInTheQueue).not.toHaveBeenCalled();
});
it('should create a folder and emit an File uploaded event', async () => {
it('should create a folder and emit an File uploaded event', () => {
component.rootFolderId = '-my-';
spyOn(nodesApiService, 'getNode').and.returnValue(of(fakeFolderNodeWithPermission.entry));
@@ -154,9 +154,8 @@ describe('UploadButtonComponent', () => {
component.ngOnChanges({ rootFolderId: new SimpleChange(null, component.rootFolderId, true) });
fixture.detectChanges();
await component.success.subscribe((e) => {
expect(e.value).toEqual('File uploaded');
});
let lastValue: any;
component.success.subscribe((res) => lastValue = res);
spyOn(component, 'uploadFiles').and.callFake(() => {
component.success.emit({
@@ -164,6 +163,7 @@ describe('UploadButtonComponent', () => {
});
});
component.onDirectoryAdded(fakeEvent);
expect(lastValue.value).toEqual('File uploaded');
});
it('should by default the title of the button get from the JSON file', () => {
@@ -245,14 +245,14 @@ describe('UploadButtonComponent', () => {
expect(addToQueueSpy.calls.mostRecent()).toBeUndefined();
});
it('should output an error when you try to upload a file too big', async () => {
it('should output an error when you try to upload a file too big', () => {
component.maxFilesSize = 100;
await component.error.subscribe((res) => {
expect(res).toBeDefined();
});
let lastValue: FileUploadErrorEvent;
component.error.subscribe((res) => lastValue = res);
component.uploadFiles(files);
expect(lastValue).toBeDefined();
});
it('should not filter out files if max file size is not set', () => {
@@ -346,19 +346,19 @@ describe('UploadButtonComponent', () => {
expect(uploadService.uploadFilesInTheQueue).not.toHaveBeenCalled();
});
it('should emit an error message when getNode fails', async () => {
it('should emit an error message when getNode fails', () => {
component.rootFolderId = 'nodeId';
spyOn(nodesApiService, 'getNode').and.returnValue(throwError('error'));
await component.error.subscribe((value: FileUploadErrorEvent) => {
expect(value.error).toBe('FILE_UPLOAD.BUTTON.PERMISSION_CHECK_ERROR');
});
let lastValue: FileUploadErrorEvent;
component.error.subscribe((value) => lastValue = value);
component.ngOnChanges({ rootFolderId: new SimpleChange(null, component.rootFolderId, true) });
fixture.detectChanges();
component.onFilesAdded(fakeEvent);
expect(lastValue.error).toBe('FILE_UPLOAD.BUTTON.PERMISSION_CHECK_ERROR');
});
it('should not call uploadFiles for node with other permissions', () => {
@@ -394,13 +394,13 @@ describe('UploadButtonComponent', () => {
fixture.detectChanges();
});
it('should emit error if upload errored', async () => {
it('should emit error if upload errored', () => {
spyOn(uploadService, 'getUploadPromise').and.returnValue(mockUploadErrorPromise);
await component.error.subscribe((error) => {
expect(error).not.toBeNull();
});
let lastValue: FileUploadErrorEvent;
component.error.subscribe((error) => lastValue = error);
component.onFilesAdded(fakeEvent);
expect(lastValue).not.toBeNull();
});
});
});

View File

@@ -22,6 +22,7 @@ import { TranslateModule } from '@ngx-translate/core';
import { mockUploadSuccessPromise, mockUploadErrorPromise } from '../../mock/upload.service.mock';
import { UploadService } from '../../common/services/upload.service';
import { FileModel } from '../../common/models/file.model';
import { FileUploadErrorEvent } from '../../common/events/file.event';
const getFakeShareDataRow = (allowableOperations = ['delete', 'update', 'create']) => ({
obj: {
@@ -180,7 +181,7 @@ describe('UploadDragAreaComponent', () => {
fixture.detectChanges();
const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', {
const fakeCustomEvent = new CustomEvent('CustomEvent', {
detail: { data: getFakeShareDataRow([]), files: [fakeItem] }
});
component.onUploadFiles(fakeCustomEvent);
@@ -255,7 +256,7 @@ describe('UploadDragAreaComponent', () => {
expect(fileList.options.path).toBe('pippo/');
});
const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', {
const fakeCustomEvent = new CustomEvent('CustomEvent', {
detail: {
data: getFakeShareDataRow(),
files: [fakeItem]
@@ -294,7 +295,7 @@ describe('UploadDragAreaComponent', () => {
it('should upload a file when user has create permission on target folder', () => {
const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', {
const fakeCustomEvent = new CustomEvent('CustomEvent', {
detail: {
data: getFakeShareDataRow(),
files: [fakeItem]
@@ -318,7 +319,7 @@ describe('UploadDragAreaComponent', () => {
}
};
const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', {
const fakeCustomEvent = new CustomEvent('CustomEvent', {
detail: {
data: getFakeShareDataRow(),
files: [fakePngItem]
@@ -348,7 +349,7 @@ describe('UploadDragAreaComponent', () => {
}
};
const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', {
const fakeCustomEvent = new CustomEvent('CustomEvent', {
detail: {
data: getFakeShareDataRow(),
files: [fakeSuperItem]
@@ -368,7 +369,7 @@ describe('UploadDragAreaComponent', () => {
it('should trigger updating the file version when we drop a file over another file', async () => {
spyOn(component.updateFileVersion, 'emit');
const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', {
const fakeCustomEvent = new CustomEvent('CustomEvent', {
detail: {
data: getFakeFileShareRow(),
files: [fakeItem]
@@ -388,32 +389,33 @@ describe('UploadDragAreaComponent', () => {
it('should raise an error if upload a file goes wrong', async () => {
spyOn(uploadService, 'getUploadPromise').and.callThrough();
const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', {
const fakeCustomEvent = new CustomEvent('CustomEvent', {
detail: {
data: getFakeShareDataRow(),
files: [fakeItem]
}
});
component.error.subscribe((error) => {
expect(error).not.toBeNull();
});
let lastValue: FileUploadErrorEvent;
component.error.subscribe((error) => lastValue = error);
component.onUploadFiles(fakeCustomEvent);
fixture.detectChanges();
await fixture.whenStable();
expect(lastValue).not.toBeNull();
});
it('should emit success if successful of upload a file', async () => {
it('should emit success if successful of upload a file', () => {
spyOn(uploadService, 'getUploadPromise').and.returnValue(mockUploadSuccessPromise);
fixture.detectChanges();
await component.success.subscribe((success) => {
expect(success).not.toBeNull();
});
let lastValue: any;
component.success.subscribe((success) => lastValue = success);
const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', {
const fakeCustomEvent = new CustomEvent('CustomEvent', {
detail: {
data: getFakeShareDataRow(),
files: [fakeItem]
@@ -421,18 +423,18 @@ describe('UploadDragAreaComponent', () => {
});
component.onUploadFiles(fakeCustomEvent);
expect(lastValue).not.toBeNull();
});
it('should emit error if upload errored', async () => {
it('should emit error if upload errored', () => {
spyOn(uploadService, 'getUploadPromise').and.returnValue(mockUploadErrorPromise);
fixture.detectChanges();
await component.error.subscribe((error) => {
expect(error).not.toBeNull();
});
let lastValue: FileUploadErrorEvent;
component.error.subscribe((error) => lastValue = error);
const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', {
const fakeCustomEvent = new CustomEvent('CustomEvent', {
detail: {
data: getFakeShareDataRow(),
files: [fakeItem]
@@ -440,6 +442,7 @@ describe('UploadDragAreaComponent', () => {
});
component.onUploadFiles(fakeCustomEvent);
expect(lastValue).not.toBeNull();
});
});
});

View File

@@ -48,7 +48,7 @@ describe('VersionManagerComponent', () => {
component.node = node;
nodesApiService = TestBed.inject(NodesApiService);
spyOnListVersionHistory = spyOn(component.versionListComponent['versionsApi'], 'listVersionHistory').and.callFake(() =>
spyOnListVersionHistory = spyOn(component.versionListComponent.versionsApi, 'listVersionHistory').and.callFake(() =>
Promise.resolve(new VersionPaging({ list: { entries: [versionEntry] } }))
);
});
@@ -81,24 +81,25 @@ describe('VersionManagerComponent', () => {
expect(versionCommentEl).toBeNull();
});
it('should emit success event upon successful upload of a new version', async () => {
it('should emit success event upon successful upload of a new version', () => {
fixture.detectChanges();
const emittedData = { value: { entry: node } };
await component.uploadSuccess.subscribe((event) => {
expect(event).toBe(node);
});
let lastValue: Node;
component.uploadSuccess.subscribe((event) => lastValue = event);
component.onUploadSuccess(emittedData);
expect(lastValue).toBe(node);
});
it('should emit nodeUpdated event upon successful upload of a new version', () => {
fixture.detectChanges();
nodesApiService.nodeUpdated.subscribe((res) => {
expect(res).toEqual(node);
});
let lastValue: Node;
nodesApiService.nodeUpdated.subscribe((res) => lastValue = res);
const emittedData = { value: { entry: node } };
component.onUploadSuccess(emittedData);
expect(lastValue).toEqual(node);
});
describe('Animation', () => {