From 86823c8bacbfe6116168aa30f505009b02160e49 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Fri, 2 Aug 2024 13:51:37 -0400 Subject: [PATCH] replace more cases --- .../content-management.service.spec.ts | 62 +++++-------------- .../services/content-management.service.ts | 22 +++---- 2 files changed, 23 insertions(+), 61 deletions(-) diff --git a/projects/aca-content/src/lib/services/content-management.service.spec.ts b/projects/aca-content/src/lib/services/content-management.service.spec.ts index 7635707c7b..dcfa4487c3 100644 --- a/projects/aca-content/src/lib/services/content-management.service.spec.ts +++ b/projects/aca-content/src/lib/services/content-management.service.spec.ts @@ -81,6 +81,7 @@ describe('ContentManagementService', () => { let newVersionUploaderService: NewVersionUploaderService; let showErrorSpy: jasmine.Spy; let showInfoSpy: jasmine.Spy; + let showWarningSpy: jasmine.Spy; beforeEach(() => { TestBed.configureTestingModule({ @@ -94,6 +95,7 @@ describe('ContentManagementService', () => { notificationService = TestBed.inject(NotificationService); showErrorSpy = spyOn(notificationService, 'showError'); showInfoSpy = spyOn(notificationService, 'showInfo'); + showWarningSpy = spyOn(notificationService, 'showWarning'); nodeActions = TestBed.inject(NodeActionsService); translationService = TestBed.inject(TranslationService); nodesApiService = TestBed.inject(NodesApiService); @@ -927,14 +929,7 @@ describe('ContentManagementService', () => { }); describe('notification', () => { - it('raises warning on multiple fail and one success', (done) => { - actions$ - .pipe( - ofType(SnackbarActionTypes.Warning), - map((action) => expect(action).toBeDefined()) - ) - .subscribe(() => done()); - + it('raises warning on multiple fail and one success', () => { spyOn(contentApi, 'purgeDeletedNode').and.callFake((id) => { if (id === '1') { return of({}); @@ -958,16 +953,10 @@ describe('ContentManagementService', () => { ]; store.dispatch(new PurgeDeletedNodesAction(selection)); + expect(showWarningSpy).toHaveBeenCalled(); }); - it('raises warning on multiple success and multiple fail', (done) => { - actions$ - .pipe( - ofType(SnackbarActionTypes.Warning), - map((action) => expect(action).toBeDefined()) - ) - .subscribe(() => done()); - + it('raises warning on multiple success and multiple fail', () => { spyOn(contentApi, 'purgeDeletedNode').and.callFake((id) => { if (id === '1') { return of({}); @@ -996,46 +985,28 @@ describe('ContentManagementService', () => { ]; store.dispatch(new PurgeDeletedNodesAction(selection)); + expect(showWarningSpy).toHaveBeenCalled(); }); - it('raises info on one selected node success', (done) => { - actions$ - .pipe( - ofType(SnackbarActionTypes.Info), - map((action) => expect(action).toBeDefined()) - ) - .subscribe(() => done()); - + it('raises info on one selected node success', () => { spyOn(contentApi, 'purgeDeletedNode').and.returnValue(of({})); const selection: any[] = [{ entry: { id: '1', name: 'name1' } }]; store.dispatch(new PurgeDeletedNodesAction(selection)); + expect(showInfoSpy).toHaveBeenCalled(); }); - it('raises error on one selected node fail', (done) => { - actions$ - .pipe( - ofType(SnackbarActionTypes.Error), - map((action) => expect(action).toBeDefined()) - ) - .subscribe(() => done()); - + it('raises error on one selected node fail', () => { spyOn(contentApi, 'purgeDeletedNode').and.returnValue(throwError({})); const selection: any[] = [{ entry: { id: '1', name: 'name1' } }]; store.dispatch(new PurgeDeletedNodesAction(selection)); + expect(showErrorSpy).toHaveBeenCalled(); }); - it('raises info on all nodes success', (done) => { - actions$ - .pipe( - ofType(SnackbarActionTypes.Info), - map((action) => expect(action).toBeDefined()) - ) - .subscribe(() => done()); - + it('raises info on all nodes success', () => { spyOn(contentApi, 'purgeDeletedNode').and.callFake((id) => { if (id === '1') { return of({}); @@ -1051,16 +1022,10 @@ describe('ContentManagementService', () => { const selection: any[] = [{ entry: { id: '1', name: 'name1' } }, { entry: { id: '2', name: 'name2' } }]; store.dispatch(new PurgeDeletedNodesAction(selection)); + expect(showInfoSpy).toHaveBeenCalled(); }); - it('raises error on all nodes fail', (done) => { - actions$ - .pipe( - ofType(SnackbarActionTypes.Error), - map((action) => expect(action).toBeDefined()) - ) - .subscribe(() => done()); - + it('raises error on all nodes fail', () => { spyOn(contentApi, 'purgeDeletedNode').and.callFake((id) => { if (id === '1') { return throwError({}); @@ -1076,6 +1041,7 @@ describe('ContentManagementService', () => { const selection: any[] = [{ entry: { id: '1', name: 'name1' } }, { entry: { id: '2', name: 'name2' } }]; store.dispatch(new PurgeDeletedNodesAction(selection)); + expect(showErrorSpy).toHaveBeenCalled(); }); }); }); diff --git a/projects/aca-content/src/lib/services/content-management.service.ts b/projects/aca-content/src/lib/services/content-management.service.ts index c0ba72f45a..8121f0a9eb 100644 --- a/projects/aca-content/src/lib/services/content-management.service.ts +++ b/projects/aca-content/src/lib/services/content-management.service.ts @@ -763,10 +763,8 @@ export class ContentManagementService { if (status.success.length) { this.store.dispatch(new ReloadDocumentListAction()); } - const message = this.getPurgeMessage(status); - if (message) { - this.store.dispatch(message); - } + + this.sendPurgeMessage(status); }); } @@ -828,38 +826,36 @@ export class ContentManagementService { }, status); } - private getPurgeMessage(status: DeleteStatus): SnackbarAction { + private sendPurgeMessage(status: DeleteStatus): void { if (status.oneSucceeded && status.someFailed && !status.oneFailed) { - return new SnackbarWarningAction('APP.MESSAGES.INFO.TRASH.NODES_PURGE.PARTIAL_SINGULAR', { + this.notificationService.showWarning('APP.MESSAGES.INFO.TRASH.NODES_PURGE.PARTIAL_SINGULAR', null, { name: status.success[0].name, failed: status.fail.length }); } if (status.someSucceeded && !status.oneSucceeded && status.someFailed) { - return new SnackbarWarningAction('APP.MESSAGES.INFO.TRASH.NODES_PURGE.PARTIAL_PLURAL', { + this.notificationService.showWarning('APP.MESSAGES.INFO.TRASH.NODES_PURGE.PARTIAL_PLURAL', null, { number: status.success.length, failed: status.fail.length }); } if (status.oneSucceeded) { - return new SnackbarInfoAction('APP.MESSAGES.INFO.TRASH.NODES_PURGE.SINGULAR', { name: status.success[0].name }); + this.notificationService.showInfo('APP.MESSAGES.INFO.TRASH.NODES_PURGE.SINGULAR', null, { name: status.success[0].name }); } if (status.oneFailed) { - return new SnackbarErrorAction('APP.MESSAGES.ERRORS.TRASH.NODES_PURGE.SINGULAR', { name: status.fail[0].name }); + this.notificationService.showError('APP.MESSAGES.ERRORS.TRASH.NODES_PURGE.SINGULAR', null, { name: status.fail[0].name }); } if (status.allSucceeded) { - return new SnackbarInfoAction('APP.MESSAGES.INFO.TRASH.NODES_PURGE.PLURAL', { number: status.success.length }); + this.notificationService.showInfo('APP.MESSAGES.INFO.TRASH.NODES_PURGE.PLURAL', null, { number: status.success.length }); } if (status.allFailed) { - return new SnackbarErrorAction('APP.MESSAGES.ERRORS.TRASH.NODES_PURGE.PLURAL', { number: status.fail.length }); + this.notificationService.showError('APP.MESSAGES.ERRORS.TRASH.NODES_PURGE.PLURAL', null, { number: status.fail.length }); } - - return null; } private showRestoreNotification(status: DeleteStatus): void {