update edited folder node (#1136)

This commit is contained in:
Cilibiu Bogdan
2019-06-21 15:34:16 +01:00
committed by Denys Vuika
parent 92eed32c61
commit 9b74063032
2 changed files with 58 additions and 6 deletions
@@ -24,7 +24,7 @@
*/
import { TestBed, fakeAsync, tick, flush } from '@angular/core/testing';
import { of, throwError } from 'rxjs';
import { of, throwError, Subject } from 'rxjs';
import { Actions, ofType, EffectsModule } from '@ngrx/effects';
import {
AppStore,
@@ -49,7 +49,7 @@ import { ContentApiService } from '@alfresco/aca-shared';
import { Store } from '@ngrx/store';
import { ContentManagementService } from './content-management.service';
import { NodeActionsService } from './node-actions.service';
import { TranslationService } from '@alfresco/adf-core';
import { TranslationService, AlfrescoApiService } from '@alfresco/adf-core';
import { MatDialog } from '@angular/material/dialog';
import { MatSnackBar } from '@angular/material/snack-bar';
import {
@@ -66,6 +66,7 @@ describe('ContentManagementService', () => {
let snackBar: MatSnackBar;
let nodeActions: NodeActionsService;
let translationService: TranslationService;
let alfrescoApiService: AlfrescoApiService;
beforeEach(() => {
TestBed.configureTestingModule({
@@ -79,6 +80,7 @@ describe('ContentManagementService', () => {
snackBar = TestBed.get(MatSnackBar);
nodeActions = TestBed.get(NodeActionsService);
translationService = TestBed.get(TranslationService);
alfrescoApiService = TestBed.get(AlfrescoApiService);
dialog = TestBed.get(MatDialog);
});
@@ -675,8 +677,6 @@ describe('ContentManagementService', () => {
spyOn(snackBar, 'open').and.returnValue({
onAction: () => of({})
});
// spyOn(snackBar, 'open').and.callThrough();
});
it('should move node back to initial parent, after succeeded move', () => {
@@ -1588,4 +1588,55 @@ describe('ContentManagementService', () => {
expect(dialogRef).toBe(mockDialogInstance);
});
});
describe('editFolder', () => {
it('should open dialog with FolderDialogComponent instance', () => {
const mockDialogInstance = <any>{
componentInstance: { error: of() },
afterClosed: () => of()
};
const node = <any>{ entry: { id: '1', name: 'name1', isFolder: true } };
spyOn(dialog, 'open').and.returnValue(mockDialogInstance);
contentManagementService.editFolder(node);
expect(dialog.open['calls'].argsFor(0)[0].name).toBe(
'FolderDialogComponent'
);
});
it('should raise error when edit operation fails', fakeAsync(() => {
const mockDialogInstance = <any>{
componentInstance: { error: new Subject<any>() },
afterClosed: () => of()
};
const node = <any>{ entry: { id: '1', name: 'name1', isFolder: true } };
spyOn(dialog, 'open').and.returnValue(mockDialogInstance);
spyOn(store, 'dispatch').and.callThrough();
contentManagementService.editFolder(node);
mockDialogInstance.componentInstance.error.next('edit folder error');
expect(store.dispatch['calls'].argsFor(0)[0]).toEqual(
new SnackbarErrorAction('edit folder error')
);
}));
it('should call nodeUpdated event with edited node data', fakeAsync(() => {
const node = <any>{ entry: { id: '1', name: 'name1' } };
const newNode = <any>{ entry: { id: '1', name: 'name-edited' } };
const mockDialogInstance = <any>{
componentInstance: { error: new Subject<any>() },
afterClosed: () => of(newNode)
};
spyOn(alfrescoApiService.nodeUpdated, 'next');
spyOn(dialog, 'open').and.returnValue(mockDialogInstance);
contentManagementService.editFolder(node);
expect(alfrescoApiService.nodeUpdated.next).toHaveBeenCalledWith(newNode);
}));
});
});
@@ -48,7 +48,7 @@ import {
LibraryDialogComponent,
ShareDialogComponent
} from '@alfresco/adf-content-services';
import { TranslationService } from '@alfresco/adf-core';
import { TranslationService, AlfrescoApiService } from '@alfresco/adf-core';
import {
DeletedNodesPaging,
MinimalNodeEntity,
@@ -94,6 +94,7 @@ export class ContentManagementService {
favoriteLibraryToggle = new Subject<any>();
constructor(
private alfrescoApiService: AlfrescoApiService,
private store: Store<AppStore>,
private contentApi: ContentApiService,
private permission: NodePermissionService,
@@ -263,7 +264,7 @@ export class ContentManagementService {
dialog.afterClosed().subscribe(node => {
if (node) {
this.store.dispatch(new ReloadDocumentListAction());
this.alfrescoApiService.nodeUpdated.next(node);
}
});
}