[ACA-1057] Upload - snack-bar error messages (#837)

* upload error notification

* remove duplicate

* test
This commit is contained in:
Cilibiu Bogdan
2018-11-28 12:32:12 +02:00
committed by Denys Vuika
parent 9b717c2743
commit 4c77ace5eb
2 changed files with 79 additions and 2 deletions

View File

@@ -26,7 +26,72 @@
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
describe('AppComponent', () => { describe('AppComponent', () => {
it('should be defined', () => { let component;
expect(AppComponent).toBeDefined(); const storeMock = <any>{
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'
);
});
}); });
}); });

View File

@@ -167,6 +167,14 @@ export class AppComponent implements OnInit, OnDestroy {
onFileUploadedError(error: FileUploadErrorEvent) { onFileUploadedError(error: FileUploadErrorEvent) {
let message = 'APP.MESSAGES.UPLOAD.ERROR.GENERIC'; 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) { if (error.error.status === 409) {
message = 'APP.MESSAGES.UPLOAD.ERROR.CONFLICT'; message = 'APP.MESSAGES.UPLOAD.ERROR.CONFLICT';
} }
@@ -175,6 +183,10 @@ export class AppComponent implements OnInit, OnDestroy {
message = 'APP.MESSAGES.UPLOAD.ERROR.500'; message = 'APP.MESSAGES.UPLOAD.ERROR.500';
} }
if (error.error.status === 504) {
message = 'APP.MESSAGES.UPLOAD.ERROR.504';
}
this.store.dispatch(new SnackbarErrorAction(message)); this.store.dispatch(new SnackbarErrorAction(message));
} }
} }