From 4c77ace5ebdfb904c901a9bfb028422ca5864529 Mon Sep 17 00:00:00 2001 From: Cilibiu Bogdan Date: Wed, 28 Nov 2018 12:32:12 +0200 Subject: [PATCH] [ACA-1057] Upload - snack-bar error messages (#837) * upload error notification * remove duplicate * test --- src/app/app.component.spec.ts | 69 ++++++++++++++++++++++++++++++++++- src/app/app.component.ts | 12 ++++++ 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index f13febce5..a99d54b51 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -26,7 +26,72 @@ import { AppComponent } from './app.component'; describe('AppComponent', () => { - it('should be defined', () => { - expect(AppComponent).toBeDefined(); + let component; + const storeMock = { + dispatch: jasmine.createSpy('dispatch') + }; + + beforeAll(() => { + component = new AppComponent( + null, + null, + null, + storeMock, + null, + null, + null, + null, + null, + null, + null + ); + }); + + describe('onFileUploadedError', () => { + afterEach(() => { + storeMock.dispatch['calls'].reset(); + }); + + it('should dispatch 403 error message', () => { + component.onFileUploadedError({ error: { status: 403 } }); + expect(storeMock.dispatch['calls'].argsFor(0)[0].payload).toBe( + 'APP.MESSAGES.UPLOAD.ERROR.403' + ); + }); + + it('should dispatch 404 error message', () => { + component.onFileUploadedError({ error: { status: 404 } }); + expect(storeMock.dispatch['calls'].argsFor(0)[0].payload).toBe( + 'APP.MESSAGES.UPLOAD.ERROR.404' + ); + }); + + it('should dispatch 409 error message', () => { + component.onFileUploadedError({ error: { status: 409 } }); + expect(storeMock.dispatch['calls'].argsFor(0)[0].payload).toBe( + 'APP.MESSAGES.UPLOAD.ERROR.CONFLICT' + ); + }); + + it('should dispatch 500 error message', () => { + component.onFileUploadedError({ error: { status: 500 } }); + expect(storeMock.dispatch['calls'].argsFor(0)[0].payload).toBe( + 'APP.MESSAGES.UPLOAD.ERROR.500' + ); + }); + + it('should dispatch 504 error message', () => { + component.onFileUploadedError({ error: { status: 504 } }); + expect(storeMock.dispatch['calls'].argsFor(0)[0].payload).toBe( + 'APP.MESSAGES.UPLOAD.ERROR.504' + ); + }); + + it('should dispatch generic error message', () => { + component.onFileUploadedError({ error: { status: 999 } }); + expect(storeMock.dispatch['calls'].argsFor(0)[0].payload).toBe( + 'APP.MESSAGES.UPLOAD.ERROR.GENERIC' + ); + }); }); }); diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 44d073ec7..85c3cdb47 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -167,6 +167,14 @@ export class AppComponent implements OnInit, OnDestroy { onFileUploadedError(error: FileUploadErrorEvent) { let message = 'APP.MESSAGES.UPLOAD.ERROR.GENERIC'; + if (error.error.status === 403) { + message = 'APP.MESSAGES.UPLOAD.ERROR.403'; + } + + if (error.error.status === 404) { + message = 'APP.MESSAGES.UPLOAD.ERROR.404'; + } + if (error.error.status === 409) { message = 'APP.MESSAGES.UPLOAD.ERROR.CONFLICT'; } @@ -175,6 +183,10 @@ export class AppComponent implements OnInit, OnDestroy { message = 'APP.MESSAGES.UPLOAD.ERROR.500'; } + if (error.error.status === 504) { + message = 'APP.MESSAGES.UPLOAD.ERROR.504'; + } + this.store.dispatch(new SnackbarErrorAction(message)); } }