diff options
author | Fatih Acet <acetfatih@gmail.com> | 2019-05-08 07:36:34 +0000 |
---|---|---|
committer | Fatih Acet <acetfatih@gmail.com> | 2019-05-08 07:36:34 +0000 |
commit | 18dd29c0c3c3367b3188a8bac687dea609736e9a (patch) | |
tree | 468dd4c90c1640d1b7c7e16feba1c2b31e61279f /spec | |
parent | 4f447e0f4b87d77f1de408cd69a66323465437f8 (diff) | |
parent | 4f1d2bf5a29f28a9f961379d4a3f426454b868b0 (diff) | |
download | gitlab-ce-18dd29c0c3c3367b3188a8bac687dea609736e9a.tar.gz |
Merge branch 'winh-notes-error-handling' into 'master'
Handle errors in successful notes reply
Closes #61377
See merge request gitlab-org/gitlab-ce!28082
Diffstat (limited to 'spec')
-rw-r--r-- | spec/frontend/notes/stores/utils_spec.js | 17 | ||||
-rw-r--r-- | spec/javascripts/notes/stores/actions_spec.js | 45 |
2 files changed, 62 insertions, 0 deletions
diff --git a/spec/frontend/notes/stores/utils_spec.js b/spec/frontend/notes/stores/utils_spec.js new file mode 100644 index 00000000000..b31b7491334 --- /dev/null +++ b/spec/frontend/notes/stores/utils_spec.js @@ -0,0 +1,17 @@ +import { hasQuickActions } from '~/notes/stores/utils'; + +describe('hasQuickActions', () => { + it.each` + input | expected + ${'some comment'} | ${false} + ${'/quickaction'} | ${true} + ${'some comment with\n/quickaction'} | ${true} + `('returns $expected for $input', ({ input, expected }) => { + expect(hasQuickActions(input)).toBe(expected); + }); + + it('is stateless', () => { + expect(hasQuickActions('some comment')).toBe(hasQuickActions('some comment')); + expect(hasQuickActions('/quickaction')).toBe(hasQuickActions('/quickaction')); + }); +}); diff --git a/spec/javascripts/notes/stores/actions_spec.js b/spec/javascripts/notes/stores/actions_spec.js index 39901276b8c..7a9f32ddcff 100644 --- a/spec/javascripts/notes/stores/actions_spec.js +++ b/spec/javascripts/notes/stores/actions_spec.js @@ -794,6 +794,51 @@ describe('Actions Notes Store', () => { }); }); + describe('saveNote', () => { + const payload = { endpoint: TEST_HOST, data: { 'note[note]': 'some text' } }; + + describe('if response contains errors', () => { + const res = { errors: { something: ['went wrong'] } }; + + it('throws an error', done => { + actions + .saveNote( + { + commit() {}, + dispatch: () => Promise.resolve(res), + }, + payload, + ) + .then(() => done.fail('Expected error to be thrown!')) + .catch(error => { + expect(error.message).toBe('Failed to save comment!'); + }) + .then(done) + .catch(done.fail); + }); + }); + + describe('if response contains no errors', () => { + const res = { valid: true }; + + it('returns the response', done => { + actions + .saveNote( + { + commit() {}, + dispatch: () => Promise.resolve(res), + }, + payload, + ) + .then(data => { + expect(data).toBe(res); + }) + .then(done) + .catch(done.fail); + }); + }); + }); + describe('submitSuggestion', () => { const discussionId = 'discussion-id'; const noteId = 'note-id'; |