diff options
author | Phil Hughes <me@iamphill.com> | 2018-09-12 16:46:09 +0100 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2018-09-12 16:46:09 +0100 |
commit | 8287f3477f4aaaa50f900ec06bef6e86f489a16d (patch) | |
tree | 8bfecb843a540fe4a7d0721abab0ae9c3914e5da /spec/javascripts/notes | |
parent | f87809f78de9da04f38134ba5ce0cf9ddebf2f63 (diff) | |
download | gitlab-ce-8287f3477f4aaaa50f900ec06bef6e86f489a16d.tar.gz |
Fixed MR widget unresolved discussions state
After resolving a discussion on a merge request page the merge request
widget state would not get updated meaning users would need to refresh
the page to merge (if that option is enabled in the projects settings)
https://gitlab.com/gitlab-org/gitlab-ce/issues/42882
Diffstat (limited to 'spec/javascripts/notes')
-rw-r--r-- | spec/javascripts/notes/stores/actions_spec.js | 193 |
1 files changed, 193 insertions, 0 deletions
diff --git a/spec/javascripts/notes/stores/actions_spec.js b/spec/javascripts/notes/stores/actions_spec.js index b66e8e1ceb3..350162d5bb6 100644 --- a/spec/javascripts/notes/stores/actions_spec.js +++ b/spec/javascripts/notes/stores/actions_spec.js @@ -317,4 +317,197 @@ describe('Actions Notes Store', () => { ); }); }); + + describe('deleteNote', () => { + const interceptor = (request, next) => { + next( + request.respondWith(JSON.stringify({}), { + status: 200, + }), + ); + }; + + beforeEach(() => { + Vue.http.interceptors.push(interceptor); + }); + + afterEach(() => { + Vue.http.interceptors = _.without(Vue.http.interceptors, interceptor); + }); + + it('commits DELETE_NOTE and dispatches updateMergeRequestWidget', done => { + const note = { path: `${gl.TEST_HOST}`, id: 1 }; + + testAction( + actions.deleteNote, + note, + store.state, + [ + { + type: 'DELETE_NOTE', + payload: note, + }, + ], + [ + { + type: 'updateMergeRequestWidget', + }, + ], + done, + ); + }); + }); + + describe('createNewNote', () => { + describe('success', () => { + const res = { + id: 1, + valid: true, + }; + const interceptor = (request, next) => { + next( + request.respondWith(JSON.stringify(res), { + status: 200, + }), + ); + }; + + beforeEach(() => { + Vue.http.interceptors.push(interceptor); + }); + + afterEach(() => { + Vue.http.interceptors = _.without(Vue.http.interceptors, interceptor); + }); + + it('commits ADD_NEW_NOTE and dispatches updateMergeRequestWidget', done => { + testAction( + actions.createNewNote, + { endpoint: `${gl.TEST_HOST}`, data: {} }, + store.state, + [ + { + type: 'ADD_NEW_NOTE', + payload: res, + }, + ], + [ + { + type: 'updateMergeRequestWidget', + }, + ], + done, + ); + }); + }); + + describe('error', () => { + const res = { + errors: ['error'], + }; + const interceptor = (request, next) => { + next( + request.respondWith(JSON.stringify(res), { + status: 200, + }), + ); + }; + + beforeEach(() => { + Vue.http.interceptors.push(interceptor); + }); + + afterEach(() => { + Vue.http.interceptors = _.without(Vue.http.interceptors, interceptor); + }); + + it('does not commit ADD_NEW_NOTE or dispatch updateMergeRequestWidget', done => { + testAction( + actions.createNewNote, + { endpoint: `${gl.TEST_HOST}`, data: {} }, + store.state, + [], + [], + done, + ); + }); + }); + }); + + describe('toggleResolveNote', () => { + const res = { + resolved: true, + }; + const interceptor = (request, next) => { + next( + request.respondWith(JSON.stringify(res), { + status: 200, + }), + ); + }; + + beforeEach(() => { + Vue.http.interceptors.push(interceptor); + }); + + afterEach(() => { + Vue.http.interceptors = _.without(Vue.http.interceptors, interceptor); + }); + + describe('as note', () => { + it('commits UPDATE_NOTE and dispatches updateMergeRequestWidget', done => { + testAction( + actions.toggleResolveNote, + { endpoint: `${gl.TEST_HOST}`, isResolved: true, discussion: false }, + store.state, + [ + { + type: 'UPDATE_NOTE', + payload: res, + }, + ], + [ + { + type: 'updateMergeRequestWidget', + }, + ], + done, + ); + }); + }); + + describe('as discussion', () => { + it('commits UPDATE_DISCUSSION and dispatches updateMergeRequestWidget', done => { + testAction( + actions.toggleResolveNote, + { endpoint: `${gl.TEST_HOST}`, isResolved: true, discussion: true }, + store.state, + [ + { + type: 'UPDATE_DISCUSSION', + payload: res, + }, + ], + [ + { + type: 'updateMergeRequestWidget', + }, + ], + done, + ); + }); + }); + }); + + describe('updateMergeRequestWidget', () => { + it('calls mrWidget checkStatus', () => { + gl.mrWidget = { + checkStatus: jasmine.createSpy('checkStatus'), + }; + + actions.updateMergeRequestWidget(); + + expect(gl.mrWidget.checkStatus).toHaveBeenCalled(); + }); + }); }); |