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