[ACA-2040] show different email invalid error messages (#862)

This commit is contained in:
Suzana Dirla
2018-12-07 16:31:41 +02:00
committed by Denys Vuika
parent b2244cb1c4
commit 904c08461d
3 changed files with 41 additions and 7 deletions

View File

@@ -179,5 +179,35 @@ describe('LibraryMembershipDirective', () => {
tick();
expect(directive.error.emit).toHaveBeenCalled();
}));
it('should emit specific error message on invalid email address server error', fakeAsync(() => {
const emitErrorSpy = spyOn(directive.error, 'emit');
const selection = { entry: { id: 'no-membership-requested' } };
const change = new SimpleChange(null, selection, true);
directive.ngOnChanges({ selection: change });
tick();
const testData = [
{
fixture: 'Failed to resolve sender mail address',
expected: 'APP.MESSAGES.ERRORS.INVALID_SENDER_EMAIL'
},
{
fixture: 'All recipients for the mail action were invalid',
expected: 'APP.MESSAGES.ERRORS.INVALID_RECEIVER_EMAIL'
}
];
testData.forEach(data => {
addMembershipSpy.and.returnValue(throwError({ message: data.fixture }));
emitErrorSpy.calls.reset();
directive.toggleMembershipRequest();
tick();
expect(emitErrorSpy).toHaveBeenCalledWith({
error: { message: data.fixture },
i18nKey: data.expected
});
});
}));
});
});

View File

@@ -134,12 +134,15 @@ export class LibraryMembershipDirective implements OnChanges {
const senderEmailCheck = 'Failed to resolve sender mail address';
const receiverEmailCheck =
'All recipients for the mail action were invalid';
if (
error.message &&
(error.message.includes(senderEmailCheck) ||
error.message.includes(receiverEmailCheck))
) {
errWithMessage.i18nKey = 'APP.MESSAGES.ERRORS.INVALID_EMAIL';
if (error.message) {
if (error.message.includes(senderEmailCheck)) {
errWithMessage.i18nKey =
'APP.MESSAGES.ERRORS.INVALID_SENDER_EMAIL';
} else if (error.message.includes(receiverEmailCheck)) {
errWithMessage.i18nKey =
'APP.MESSAGES.ERRORS.INVALID_RECEIVER_EMAIL';
}
}
this.error.emit(errWithMessage);

View File

@@ -278,7 +278,8 @@
"JOIN_REQUEST_FAILED": "Cannot join the library",
"JOIN_CANCEL_FAILED": "Cannot cancel the request to join the library",
"LEAVE_LIBRARY_FAILED": "Cannot leave this library",
"INVALID_EMAIL": "Sender or receiver email configured on server not valid, contact IT"
"INVALID_SENDER_EMAIL": "Your email address must be valid before requesting to join.",
"INVALID_RECEIVER_EMAIL": "Recipient(s) email address not valid, contact IT."
},
"UPLOAD": {
"ERROR": {