use material snackBar (#474)

This commit is contained in:
Cilibiu Bogdan
2018-06-29 15:00:02 +01:00
committed by Denys Vuika
parent d89473046c
commit 9f2d7e3edf
4 changed files with 71 additions and 106 deletions
@@ -27,7 +27,7 @@ import { Component, DebugElement } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { Observable } from 'rxjs/Rx'; import { Observable } from 'rxjs/Rx';
import { NotificationService } from '@alfresco/adf-core'; import { MatSnackBar } from '@angular/material';
import { NodeActionsService } from '../services/node-actions.service'; import { NodeActionsService } from '../services/node-actions.service';
import { NodeCopyDirective } from './node-copy.directive'; import { NodeCopyDirective } from './node-copy.directive';
import { AppTestingModule } from '../../testing/app-testing.module'; import { AppTestingModule } from '../../testing/app-testing.module';
@@ -44,7 +44,7 @@ describe('NodeCopyDirective', () => {
let fixture: ComponentFixture<TestComponent>; let fixture: ComponentFixture<TestComponent>;
let component: TestComponent; let component: TestComponent;
let element: DebugElement; let element: DebugElement;
let notificationService: NotificationService; let snackBar: MatSnackBar;
let service: NodeActionsService; let service: NodeActionsService;
let contentApi: ContentApiService; let contentApi: ContentApiService;
@@ -62,13 +62,13 @@ describe('NodeCopyDirective', () => {
fixture = TestBed.createComponent(TestComponent); fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance; component = fixture.componentInstance;
element = fixture.debugElement.query(By.directive(NodeCopyDirective)); element = fixture.debugElement.query(By.directive(NodeCopyDirective));
notificationService = TestBed.get(NotificationService); snackBar = TestBed.get(MatSnackBar);
service = TestBed.get(NodeActionsService); service = TestBed.get(NodeActionsService);
}); });
describe('Copy node action', () => { describe('Copy node action', () => {
beforeEach(() => { beforeEach(() => {
spyOn(notificationService, 'openSnackMessageAction').and.callThrough(); spyOn(snackBar, 'open').and.callThrough();
}); });
it('notifies successful copy of a node', () => { it('notifies successful copy of a node', () => {
@@ -82,9 +82,7 @@ describe('NodeCopyDirective', () => {
service.contentCopied.next(<any>createdItems); service.contentCopied.next(<any>createdItems);
expect(service.copyNodes).toHaveBeenCalled(); expect(service.copyNodes).toHaveBeenCalled();
expect(notificationService.openSnackMessageAction).toHaveBeenCalledWith( expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.INFO.NODE_COPY.SINGULAR');
'APP.MESSAGES.INFO.NODE_COPY.SINGULAR', 'APP.ACTIONS.UNDO', 10000
);
}); });
it('notifies successful copy of multiple nodes', () => { it('notifies successful copy of multiple nodes', () => {
@@ -102,9 +100,7 @@ describe('NodeCopyDirective', () => {
service.contentCopied.next(<any>createdItems); service.contentCopied.next(<any>createdItems);
expect(service.copyNodes).toHaveBeenCalled(); expect(service.copyNodes).toHaveBeenCalled();
expect(notificationService.openSnackMessageAction).toHaveBeenCalledWith( expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.INFO.NODE_COPY.PLURAL');
'APP.MESSAGES.INFO.NODE_COPY.PLURAL', 'APP.ACTIONS.UNDO', 10000
);
}); });
it('notifies partially copy of one node out of a multiple selection of nodes', () => { it('notifies partially copy of one node out of a multiple selection of nodes', () => {
@@ -121,9 +117,7 @@ describe('NodeCopyDirective', () => {
service.contentCopied.next(<any>createdItems); service.contentCopied.next(<any>createdItems);
expect(service.copyNodes).toHaveBeenCalled(); expect(service.copyNodes).toHaveBeenCalled();
expect(notificationService.openSnackMessageAction).toHaveBeenCalledWith( expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.INFO.NODE_COPY.PARTIAL_SINGULAR');
'APP.MESSAGES.INFO.NODE_COPY.PARTIAL_SINGULAR', 'APP.ACTIONS.UNDO', 10000
);
}); });
it('notifies partially copy of more nodes out of a multiple selection of nodes', () => { it('notifies partially copy of more nodes out of a multiple selection of nodes', () => {
@@ -142,9 +136,7 @@ describe('NodeCopyDirective', () => {
service.contentCopied.next(<any>createdItems); service.contentCopied.next(<any>createdItems);
expect(service.copyNodes).toHaveBeenCalled(); expect(service.copyNodes).toHaveBeenCalled();
expect(notificationService.openSnackMessageAction).toHaveBeenCalledWith( expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.INFO.NODE_COPY.PARTIAL_PLURAL');
'APP.MESSAGES.INFO.NODE_COPY.PARTIAL_PLURAL', 'APP.ACTIONS.UNDO', 10000
);
}); });
it('notifies of failed copy of multiple nodes', () => { it('notifies of failed copy of multiple nodes', () => {
@@ -161,9 +153,7 @@ describe('NodeCopyDirective', () => {
service.contentCopied.next(<any>createdItems); service.contentCopied.next(<any>createdItems);
expect(service.copyNodes).toHaveBeenCalled(); expect(service.copyNodes).toHaveBeenCalled();
expect(notificationService.openSnackMessageAction).toHaveBeenCalledWith( expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.INFO.NODE_COPY.FAIL_PLURAL');
'APP.MESSAGES.INFO.NODE_COPY.FAIL_PLURAL', '', 3000
);
}); });
it('notifies of failed copy of one node', () => { it('notifies of failed copy of one node', () => {
@@ -178,9 +168,7 @@ describe('NodeCopyDirective', () => {
service.contentCopied.next(<any>createdItems); service.contentCopied.next(<any>createdItems);
expect(service.copyNodes).toHaveBeenCalled(); expect(service.copyNodes).toHaveBeenCalled();
expect(notificationService.openSnackMessageAction).toHaveBeenCalledWith( expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.INFO.NODE_COPY.FAIL_SINGULAR');
'APP.MESSAGES.INFO.NODE_COPY.FAIL_SINGULAR', '', 3000
);
}); });
it('notifies error if success message was not emitted', () => { it('notifies error if success message was not emitted', () => {
@@ -193,7 +181,7 @@ describe('NodeCopyDirective', () => {
service.contentCopied.next(); service.contentCopied.next();
expect(service.copyNodes).toHaveBeenCalled(); expect(service.copyNodes).toHaveBeenCalled();
expect(notificationService.openSnackMessageAction).toHaveBeenCalledWith('APP.MESSAGES.ERRORS.GENERIC', '', 3000); expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.ERRORS.GENERIC');
}); });
it('notifies permission error on copy of node', () => { it('notifies permission error on copy of node', () => {
@@ -205,9 +193,7 @@ describe('NodeCopyDirective', () => {
element.triggerEventHandler('click', null); element.triggerEventHandler('click', null);
expect(service.copyNodes).toHaveBeenCalled(); expect(service.copyNodes).toHaveBeenCalled();
expect(notificationService.openSnackMessageAction).toHaveBeenCalledWith( expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.ERRORS.PERMISSION');
'APP.MESSAGES.ERRORS.PERMISSION', '', 3000
);
}); });
it('notifies generic error message on all errors, but 403', () => { it('notifies generic error message on all errors, but 403', () => {
@@ -219,9 +205,7 @@ describe('NodeCopyDirective', () => {
element.triggerEventHandler('click', null); element.triggerEventHandler('click', null);
expect(service.copyNodes).toHaveBeenCalled(); expect(service.copyNodes).toHaveBeenCalled();
expect(notificationService.openSnackMessageAction).toHaveBeenCalledWith( expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.ERRORS.GENERIC');
'APP.MESSAGES.ERRORS.GENERIC', '', 3000
);
}); });
}); });
@@ -229,7 +213,7 @@ describe('NodeCopyDirective', () => {
beforeEach(() => { beforeEach(() => {
spyOn(service, 'copyNodes').and.returnValue(Observable.of('OPERATION.SUCCES.CONTENT.COPY')); spyOn(service, 'copyNodes').and.returnValue(Observable.of('OPERATION.SUCCES.CONTENT.COPY'));
spyOn(notificationService, 'openSnackMessageAction').and.returnValue({ spyOn(snackBar, 'open').and.returnValue({
onAction: () => Observable.of({}) onAction: () => Observable.of({})
}); });
}); });
@@ -245,9 +229,7 @@ describe('NodeCopyDirective', () => {
service.contentCopied.next(<any>createdItems); service.contentCopied.next(<any>createdItems);
expect(service.copyNodes).toHaveBeenCalled(); expect(service.copyNodes).toHaveBeenCalled();
expect(notificationService.openSnackMessageAction).toHaveBeenCalledWith( expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.INFO.NODE_COPY.SINGULAR');
'APP.MESSAGES.INFO.NODE_COPY.SINGULAR', 'APP.ACTIONS.UNDO', 10000
);
expect(contentApi.deleteNode).toHaveBeenCalledWith(createdItems[0].entry.id, { permanent: true }); expect(contentApi.deleteNode).toHaveBeenCalledWith(createdItems[0].entry.id, { permanent: true });
}); });
@@ -269,9 +251,7 @@ describe('NodeCopyDirective', () => {
service.contentCopied.next(<any>createdItems); service.contentCopied.next(<any>createdItems);
expect(service.copyNodes).toHaveBeenCalled(); expect(service.copyNodes).toHaveBeenCalled();
expect(notificationService.openSnackMessageAction).toHaveBeenCalledWith( expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.INFO.NODE_COPY.PLURAL');
'APP.MESSAGES.INFO.NODE_COPY.PLURAL', 'APP.ACTIONS.UNDO', 10000
);
expect(spyOnDeleteNode).toHaveBeenCalled(); expect(spyOnDeleteNode).toHaveBeenCalled();
expect(spyOnDeleteNode.calls.allArgs()) expect(spyOnDeleteNode.calls.allArgs())
@@ -290,9 +270,7 @@ describe('NodeCopyDirective', () => {
expect(service.copyNodes).toHaveBeenCalled(); expect(service.copyNodes).toHaveBeenCalled();
expect(contentApi.deleteNode).toHaveBeenCalled(); expect(contentApi.deleteNode).toHaveBeenCalled();
expect(notificationService.openSnackMessageAction['calls'].allArgs()) expect(snackBar.open['calls'].argsFor(0)[0]).toEqual('APP.MESSAGES.INFO.NODE_COPY.SINGULAR');
.toEqual([['APP.MESSAGES.INFO.NODE_COPY.SINGULAR', 'APP.ACTIONS.UNDO', 10000],
['APP.MESSAGES.ERRORS.GENERIC', '', 3000]]);
}); });
it('notifies when some error of type Error occurs on Undo action', () => { it('notifies when some error of type Error occurs on Undo action', () => {
@@ -307,9 +285,7 @@ describe('NodeCopyDirective', () => {
expect(service.copyNodes).toHaveBeenCalled(); expect(service.copyNodes).toHaveBeenCalled();
expect(contentApi.deleteNode).toHaveBeenCalled(); expect(contentApi.deleteNode).toHaveBeenCalled();
expect(notificationService.openSnackMessageAction['calls'].allArgs()) expect(snackBar.open['calls'].argsFor(0)[0]).toEqual('APP.MESSAGES.INFO.NODE_COPY.SINGULAR');
.toEqual([['APP.MESSAGES.INFO.NODE_COPY.SINGULAR', 'APP.ACTIONS.UNDO', 10000],
['APP.MESSAGES.ERRORS.GENERIC', '', 3000]]);
}); });
it('notifies permission error when it occurs on Undo action', () => { it('notifies permission error when it occurs on Undo action', () => {
@@ -324,9 +300,7 @@ describe('NodeCopyDirective', () => {
expect(service.copyNodes).toHaveBeenCalled(); expect(service.copyNodes).toHaveBeenCalled();
expect(contentApi.deleteNode).toHaveBeenCalled(); expect(contentApi.deleteNode).toHaveBeenCalled();
expect(notificationService.openSnackMessageAction['calls'].allArgs()) expect(snackBar.open['calls'].argsFor(0)[0]).toEqual('APP.MESSAGES.INFO.NODE_COPY.SINGULAR');
.toEqual([['APP.MESSAGES.INFO.NODE_COPY.SINGULAR', 'APP.ACTIONS.UNDO', 10000],
['APP.MESSAGES.ERRORS.PERMISSION', '', 3000]]);
}); });
}); });
@@ -25,8 +25,9 @@
import { Directive, HostListener, Input } from '@angular/core'; import { Directive, HostListener, Input } from '@angular/core';
import { Observable } from 'rxjs/Rx'; import { Observable } from 'rxjs/Rx';
import { MatSnackBar } from '@angular/material';
import { TranslationService, NotificationService } from '@alfresco/adf-core'; import { TranslationService } from '@alfresco/adf-core';
import { MinimalNodeEntity } from 'alfresco-js-api'; import { MinimalNodeEntity } from 'alfresco-js-api';
import { NodeActionsService } from '../services/node-actions.service'; import { NodeActionsService } from '../services/node-actions.service';
import { ContentManagementService } from '../services/content-management.service'; import { ContentManagementService } from '../services/content-management.service';
@@ -49,7 +50,7 @@ export class NodeCopyDirective {
constructor( constructor(
private content: ContentManagementService, private content: ContentManagementService,
private contentApi: ContentApiService, private contentApi: ContentApiService,
private notification: NotificationService, private snackBar: MatSnackBar,
private nodeActionsService: NodeActionsService, private nodeActionsService: NodeActionsService,
private translation: TranslationService private translation: TranslationService
) {} ) {}
@@ -107,10 +108,14 @@ export class NodeCopyDirective {
} }
const undo = (numberOfCopiedItems > 0) ? this.translation.instant('APP.ACTIONS.UNDO') : ''; const undo = (numberOfCopiedItems > 0) ? this.translation.instant('APP.ACTIONS.UNDO') : '';
const withUndo = (numberOfCopiedItems > 0) ? '_WITH_UNDO' : '';
const message = this.translation.instant(i18nMessageString, { success: numberOfCopiedItems, failed: failedItems }); const message = this.translation.instant(i18nMessageString, { success: numberOfCopiedItems, failed: failedItems });
this.notification.openSnackMessageAction(message, undo, NodeActionsService[`SNACK_MESSAGE_DURATION${withUndo}`])
this.snackBar
.open(message, undo, {
panelClass: 'info-snackbar',
duration: 3000
})
.onAction() .onAction()
.subscribe(() => this.deleteCopy(newItems)); .subscribe(() => this.deleteCopy(newItems));
} }
@@ -139,7 +144,11 @@ export class NodeCopyDirective {
} }
const message = this.translation.instant(i18nMessageString); const message = this.translation.instant(i18nMessageString);
this.notification.openSnackMessageAction(message, '', NodeActionsService.SNACK_MESSAGE_DURATION);
this.snackBar.open(message, '', {
panelClass: 'error-snackbar',
duration: 3000
});
} }
); );
} }
@@ -27,7 +27,8 @@ import { Component, DebugElement } from '@angular/core';
import { ComponentFixture, TestBed, fakeAsync } from '@angular/core/testing'; import { ComponentFixture, TestBed, fakeAsync } from '@angular/core/testing';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { Observable } from 'rxjs/Rx'; import { Observable } from 'rxjs/Rx';
import { NotificationService, TranslationService } from '@alfresco/adf-core'; import { MatSnackBar } from '@angular/material';
import { TranslationService } from '@alfresco/adf-core';
import { NodeActionsService } from '../services/node-actions.service'; import { NodeActionsService } from '../services/node-actions.service';
import { NodeMoveDirective } from './node-move.directive'; import { NodeMoveDirective } from './node-move.directive';
import { EffectsModule, Actions, ofType } from '@ngrx/effects'; import { EffectsModule, Actions, ofType } from '@ngrx/effects';
@@ -48,11 +49,11 @@ describe('NodeMoveDirective', () => {
let fixture: ComponentFixture<TestComponent>; let fixture: ComponentFixture<TestComponent>;
let component: TestComponent; let component: TestComponent;
let element: DebugElement; let element: DebugElement;
let notificationService: NotificationService;
let service: NodeActionsService; let service: NodeActionsService;
let actions$: Actions; let actions$: Actions;
let translationService: TranslationService; let translationService: TranslationService;
let contentApi: ContentApiService; let contentApi: ContentApiService;
let snackBar: MatSnackBar;
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
@@ -73,8 +74,8 @@ describe('NodeMoveDirective', () => {
fixture = TestBed.createComponent(TestComponent); fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance; component = fixture.componentInstance;
element = fixture.debugElement.query(By.directive(NodeMoveDirective)); element = fixture.debugElement.query(By.directive(NodeMoveDirective));
notificationService = TestBed.get(NotificationService);
service = TestBed.get(NodeActionsService); service = TestBed.get(NodeActionsService);
snackBar = TestBed.get(MatSnackBar);
}); });
beforeEach(() => { beforeEach(() => {
@@ -93,7 +94,7 @@ describe('NodeMoveDirective', () => {
describe('Move node action', () => { describe('Move node action', () => {
beforeEach(() => { beforeEach(() => {
spyOn(notificationService, 'openSnackMessageAction').and.callThrough(); spyOn(snackBar, 'open').and.callThrough();
}); });
it('notifies successful move of a node', () => { it('notifies successful move of a node', () => {
@@ -114,9 +115,7 @@ describe('NodeMoveDirective', () => {
service.contentMoved.next(moveResponse); service.contentMoved.next(moveResponse);
expect(service.moveNodes).toHaveBeenCalled(); expect(service.moveNodes).toHaveBeenCalled();
expect(notificationService.openSnackMessageAction).toHaveBeenCalledWith( expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.INFO.NODE_MOVE.SINGULAR');
'APP.MESSAGES.INFO.NODE_MOVE.SINGULAR', 'APP.ACTIONS.UNDO', 10000
);
}); });
it('notifies successful move of multiple nodes', () => { it('notifies successful move of multiple nodes', () => {
@@ -139,9 +138,7 @@ describe('NodeMoveDirective', () => {
service.contentMoved.next(moveResponse); service.contentMoved.next(moveResponse);
expect(service.moveNodes).toHaveBeenCalled(); expect(service.moveNodes).toHaveBeenCalled();
expect(notificationService.openSnackMessageAction).toHaveBeenCalledWith( expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.INFO.NODE_MOVE.PLURAL');
'APP.MESSAGES.INFO.NODE_MOVE.PLURAL', 'APP.ACTIONS.UNDO', 10000
);
}); });
it('notifies partial move of a node', () => { it('notifies partial move of a node', () => {
@@ -162,9 +159,7 @@ describe('NodeMoveDirective', () => {
service.contentMoved.next(moveResponse); service.contentMoved.next(moveResponse);
expect(service.moveNodes).toHaveBeenCalled(); expect(service.moveNodes).toHaveBeenCalled();
expect(notificationService.openSnackMessageAction).toHaveBeenCalledWith( expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.INFO.NODE_MOVE.PARTIAL.SINGULAR');
'APP.MESSAGES.INFO.NODE_MOVE.PARTIAL.SINGULAR', 'APP.ACTIONS.UNDO', 10000
);
}); });
it('notifies partial move of multiple nodes', () => { it('notifies partial move of multiple nodes', () => {
@@ -187,9 +182,7 @@ describe('NodeMoveDirective', () => {
service.contentMoved.next(moveResponse); service.contentMoved.next(moveResponse);
expect(service.moveNodes).toHaveBeenCalled(); expect(service.moveNodes).toHaveBeenCalled();
expect(notificationService.openSnackMessageAction).toHaveBeenCalledWith( expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.INFO.NODE_MOVE.PARTIAL.PLURAL');
'APP.MESSAGES.INFO.NODE_MOVE.PARTIAL.PLURAL', 'APP.ACTIONS.UNDO', 10000
);
}); });
it('notifies successful move and the number of nodes that could not be moved', () => { it('notifies successful move and the number of nodes that could not be moved', () => {
@@ -211,9 +204,8 @@ describe('NodeMoveDirective', () => {
service.contentMoved.next(moveResponse); service.contentMoved.next(moveResponse);
expect(service.moveNodes).toHaveBeenCalled(); expect(service.moveNodes).toHaveBeenCalled();
expect(notificationService.openSnackMessageAction).toHaveBeenCalledWith( expect(snackBar.open['calls'].argsFor(0)[0])
'APP.MESSAGES.INFO.NODE_MOVE.SINGULAR APP.MESSAGES.INFO.NODE_MOVE.PARTIAL.FAIL', 'APP.ACTIONS.UNDO', 10000 .toBe('APP.MESSAGES.INFO.NODE_MOVE.SINGULAR APP.MESSAGES.INFO.NODE_MOVE.PARTIAL.FAIL');
);
}); });
it('notifies successful move and the number of partially moved ones', () => { it('notifies successful move and the number of partially moved ones', () => {
@@ -235,9 +227,8 @@ describe('NodeMoveDirective', () => {
service.contentMoved.next(moveResponse); service.contentMoved.next(moveResponse);
expect(service.moveNodes).toHaveBeenCalled(); expect(service.moveNodes).toHaveBeenCalled();
expect(notificationService.openSnackMessageAction).toHaveBeenCalledWith( expect(snackBar.open['calls'].argsFor(0)[0])
'APP.MESSAGES.INFO.NODE_MOVE.SINGULAR APP.MESSAGES.INFO.NODE_MOVE.PARTIAL.SINGULAR', 'APP.ACTIONS.UNDO', 10000 .toBe('APP.MESSAGES.INFO.NODE_MOVE.SINGULAR APP.MESSAGES.INFO.NODE_MOVE.PARTIAL.SINGULAR');
);
}); });
it('notifies error if success message was not emitted', () => { it('notifies error if success message was not emitted', () => {
@@ -257,7 +248,7 @@ describe('NodeMoveDirective', () => {
service.contentMoved.next(moveResponse); service.contentMoved.next(moveResponse);
expect(service.moveNodes).toHaveBeenCalled(); expect(service.moveNodes).toHaveBeenCalled();
expect(notificationService.openSnackMessageAction).toHaveBeenCalledWith('APP.MESSAGES.ERRORS.GENERIC', '', 3000); expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.ERRORS.GENERIC');
}); });
it('notifies permission error on move of node', () => { it('notifies permission error on move of node', () => {
@@ -269,9 +260,7 @@ describe('NodeMoveDirective', () => {
element.triggerEventHandler('click', null); element.triggerEventHandler('click', null);
expect(service.moveNodes).toHaveBeenCalled(); expect(service.moveNodes).toHaveBeenCalled();
expect(notificationService.openSnackMessageAction).toHaveBeenCalledWith( expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.ERRORS.PERMISSION');
'APP.MESSAGES.ERRORS.PERMISSION', '', 3000
);
}); });
it('notifies generic error message on all errors, but 403', () => { it('notifies generic error message on all errors, but 403', () => {
@@ -283,9 +272,7 @@ describe('NodeMoveDirective', () => {
element.triggerEventHandler('click', null); element.triggerEventHandler('click', null);
expect(service.moveNodes).toHaveBeenCalled(); expect(service.moveNodes).toHaveBeenCalled();
expect(notificationService.openSnackMessageAction).toHaveBeenCalledWith( expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.ERRORS.GENERIC');
'APP.MESSAGES.ERRORS.GENERIC', '', 3000
);
}); });
it('notifies conflict error message on 409', () => { it('notifies conflict error message on 409', () => {
@@ -297,9 +284,7 @@ describe('NodeMoveDirective', () => {
element.triggerEventHandler('click', null); element.triggerEventHandler('click', null);
expect(service.moveNodes).toHaveBeenCalled(); expect(service.moveNodes).toHaveBeenCalled();
expect(notificationService.openSnackMessageAction).toHaveBeenCalledWith( expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.ERRORS.NODE_MOVE');
'APP.MESSAGES.ERRORS.NODE_MOVE', '', 3000
);
}); });
it('notifies error if move response has only failed items', () => { it('notifies error if move response has only failed items', () => {
@@ -320,9 +305,7 @@ describe('NodeMoveDirective', () => {
service.contentMoved.next(moveResponse); service.contentMoved.next(moveResponse);
expect(service.moveNodes).toHaveBeenCalled(); expect(service.moveNodes).toHaveBeenCalled();
expect(notificationService.openSnackMessageAction).toHaveBeenCalledWith( expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.ERRORS.GENERIC');
'APP.MESSAGES.ERRORS.GENERIC', '', 3000
);
}); });
}); });
@@ -330,11 +313,11 @@ describe('NodeMoveDirective', () => {
beforeEach(() => { beforeEach(() => {
spyOn(service, 'moveNodes').and.returnValue(Observable.of('OPERATION.SUCCES.CONTENT.MOVE')); spyOn(service, 'moveNodes').and.returnValue(Observable.of('OPERATION.SUCCES.CONTENT.MOVE'));
spyOn(notificationService, 'openSnackMessageAction').and.returnValue({ spyOn(snackBar, 'open').and.returnValue({
onAction: () => Observable.of({}) onAction: () => Observable.of({})
}); });
spyOn(notificationService, 'openSnackMessage').and.callThrough(); // spyOn(snackBar, 'open').and.callThrough();
}); });
it('should move node back to initial parent, after succeeded move', () => { it('should move node back to initial parent, after succeeded move', () => {
@@ -355,8 +338,7 @@ describe('NodeMoveDirective', () => {
expect(service.moveNodeAction) expect(service.moveNodeAction)
.toHaveBeenCalledWith(movedItems.succeeded[0].itemMoved.entry, movedItems.succeeded[0].initialParentId); .toHaveBeenCalledWith(movedItems.succeeded[0].itemMoved.entry, movedItems.succeeded[0].initialParentId);
expect(notificationService.openSnackMessageAction) expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.INFO.NODE_MOVE.SINGULAR');
.toHaveBeenCalledWith('APP.MESSAGES.INFO.NODE_MOVE.SINGULAR', 'APP.ACTIONS.UNDO', 10000);
}); });
it('should move node back to initial parent, after succeeded move of a single file', () => { it('should move node back to initial parent, after succeeded move of a single file', () => {
@@ -377,8 +359,7 @@ describe('NodeMoveDirective', () => {
service.contentMoved.next(<any>movedItems); service.contentMoved.next(<any>movedItems);
expect(service.moveNodeAction).toHaveBeenCalledWith(node.entry, initialParent); expect(service.moveNodeAction).toHaveBeenCalledWith(node.entry, initialParent);
expect(notificationService.openSnackMessageAction) expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.INFO.NODE_MOVE.SINGULAR');
.toHaveBeenCalledWith('APP.MESSAGES.INFO.NODE_MOVE.SINGULAR', 'APP.ACTIONS.UNDO', 10000);
}); });
it('should restore deleted folder back to initial parent, after succeeded moving all its files', () => { it('should restore deleted folder back to initial parent, after succeeded moving all its files', () => {
@@ -403,8 +384,7 @@ describe('NodeMoveDirective', () => {
service.contentMoved.next(<any>movedItems); service.contentMoved.next(<any>movedItems);
expect(contentApi.restoreNode).toHaveBeenCalled(); expect(contentApi.restoreNode).toHaveBeenCalled();
expect(notificationService.openSnackMessageAction) expect(snackBar.open['calls'].argsFor(0)[0]).toBe('APP.MESSAGES.INFO.NODE_MOVE.SINGULAR');
.toHaveBeenCalledWith('APP.MESSAGES.INFO.NODE_MOVE.SINGULAR', 'APP.ACTIONS.UNDO', 10000);
}); });
it('should notify when error occurs on Undo Move action', fakeAsync(done => { it('should notify when error occurs on Undo Move action', fakeAsync(done => {
@@ -25,8 +25,9 @@
import { Directive, HostListener, Input } from '@angular/core'; import { Directive, HostListener, Input } from '@angular/core';
import { TranslationService, NotificationService } from '@alfresco/adf-core'; import { TranslationService } from '@alfresco/adf-core';
import { MinimalNodeEntity } from 'alfresco-js-api'; import { MinimalNodeEntity } from 'alfresco-js-api';
import { MatSnackBar } from '@angular/material';
import { ContentManagementService } from '../services/content-management.service'; import { ContentManagementService } from '../services/content-management.service';
import { NodeActionsService } from '../services/node-actions.service'; import { NodeActionsService } from '../services/node-actions.service';
@@ -54,9 +55,9 @@ export class NodeMoveDirective {
private store: Store<AppStore>, private store: Store<AppStore>,
private contentApi: ContentApiService, private contentApi: ContentApiService,
private content: ContentManagementService, private content: ContentManagementService,
private notification: NotificationService,
private nodeActionsService: NodeActionsService, private nodeActionsService: NodeActionsService,
private translation: TranslationService private translation: TranslationService,
private snackBar: MatSnackBar
) {} ) {}
moveSelected() { moveSelected() {
@@ -125,7 +126,6 @@ export class NodeMoveDirective {
} }
const undo = (succeeded + partiallySucceeded > 0) ? this.translation.instant('APP.ACTIONS.UNDO') : ''; const undo = (succeeded + partiallySucceeded > 0) ? this.translation.instant('APP.ACTIONS.UNDO') : '';
const withUndo = errorMessage ? '' : '_WITH_UNDO';
failedMessage = errorMessage ? errorMessage : failedMessage; failedMessage = errorMessage ? errorMessage : failedMessage;
const beforePartialSuccessMessage = (successMessage && partialSuccessMessage) ? ' ' : ''; const beforePartialSuccessMessage = (successMessage && partialSuccessMessage) ? ' ' : '';
@@ -139,13 +139,15 @@ export class NodeMoveDirective {
); );
// TODO: review in terms of i18n // TODO: review in terms of i18n
this.notification.openSnackMessageAction( this.snackBar
.open(
messages[successMessage] messages[successMessage]
+ beforePartialSuccessMessage + messages[partialSuccessMessage] + beforePartialSuccessMessage + messages[partialSuccessMessage]
+ beforeFailedMessage + messages[failedMessage], + beforeFailedMessage + messages[failedMessage]
undo, , undo, {
NodeActionsService[`SNACK_MESSAGE_DURATION${withUndo}`] panelClass: 'info-snackbar',
) duration: 3000
})
.onAction() .onAction()
.subscribe(() => this.revertMoving(moveResponse, initialParentId)); .subscribe(() => this.revertMoving(moveResponse, initialParentId));
} }