Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/notes/utils_spec.js')
-rw-r--r--spec/frontend/notes/utils_spec.js31
1 files changed, 25 insertions, 6 deletions
diff --git a/spec/frontend/notes/utils_spec.js b/spec/frontend/notes/utils_spec.js
index 0882e0a5759..3607c3c546c 100644
--- a/spec/frontend/notes/utils_spec.js
+++ b/spec/frontend/notes/utils_spec.js
@@ -1,12 +1,12 @@
import { sprintf } from '~/locale';
-import { getErrorMessages } from '~/notes/utils';
+import { createNoteErrorMessages, updateNoteErrorMessage } from '~/notes/utils';
import { HTTP_STATUS_UNPROCESSABLE_ENTITY, HTTP_STATUS_BAD_REQUEST } from '~/lib/utils/http_status';
-import { COMMENT_FORM } from '~/notes/i18n';
+import { COMMENT_FORM, UPDATE_COMMENT_FORM } from '~/notes/i18n';
-describe('getErrorMessages', () => {
+describe('createNoteErrorMessages', () => {
describe('when http status is not HTTP_STATUS_UNPROCESSABLE_ENTITY', () => {
it('returns generic error', () => {
- const errorMessages = getErrorMessages(
+ const errorMessages = createNoteErrorMessages(
{ errors: ['unknown error'] },
HTTP_STATUS_BAD_REQUEST,
);
@@ -17,7 +17,7 @@ describe('getErrorMessages', () => {
describe('when http status is HTTP_STATUS_UNPROCESSABLE_ENTITY', () => {
it('returns all errors', () => {
- const errorMessages = getErrorMessages(
+ const errorMessages = createNoteErrorMessages(
{ errors: 'error 1 and error 2' },
HTTP_STATUS_UNPROCESSABLE_ENTITY,
);
@@ -29,7 +29,7 @@ describe('getErrorMessages', () => {
describe('when response contains commands_only errors', () => {
it('only returns commands_only errors', () => {
- const errorMessages = getErrorMessages(
+ const errorMessages = createNoteErrorMessages(
{
errors: {
commands_only: ['commands_only error 1', 'commands_only error 2'],
@@ -44,3 +44,22 @@ describe('getErrorMessages', () => {
});
});
});
+
+describe('updateNoteErrorMessage', () => {
+ describe('with server error', () => {
+ it('returns error message with server error', () => {
+ const error = 'error 1 and error 2';
+ const errorMessage = updateNoteErrorMessage({ response: { data: { errors: error } } });
+
+ expect(errorMessage).toEqual(sprintf(UPDATE_COMMENT_FORM.error, { reason: error }));
+ });
+ });
+
+ describe('without server error', () => {
+ it('returns generic error message', () => {
+ const errorMessage = updateNoteErrorMessage(null);
+
+ expect(errorMessage).toEqual(UPDATE_COMMENT_FORM.defaultError);
+ });
+ });
+});