Commit be178977 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'ph/301148/fixDraftsNotShowingOnDiscussion' into 'master'

Fix drafts not showing after reload

See merge request gitlab-org/gitlab!62197
parents 9c54f152 511051ee
...@@ -41,11 +41,18 @@ export const deleteDraft = ({ commit, getters }, draft) => ...@@ -41,11 +41,18 @@ export const deleteDraft = ({ commit, getters }, draft) =>
}) })
.catch(() => flash(__('An error occurred while deleting the comment'))); .catch(() => flash(__('An error occurred while deleting the comment')));
export const fetchDrafts = ({ commit, getters }) => export const fetchDrafts = ({ commit, getters, state, dispatch }) =>
service service
.fetchDrafts(getters.getNotesData.draftsPath) .fetchDrafts(getters.getNotesData.draftsPath)
.then((res) => res.data) .then((res) => res.data)
.then((data) => commit(types.SET_BATCH_COMMENTS_DRAFTS, data)) .then((data) => commit(types.SET_BATCH_COMMENTS_DRAFTS, data))
.then(() => {
state.drafts.forEach((draft) => {
if (!draft.line_code) {
dispatch('convertToDiscussion', draft.discussion_id, { root: true });
}
});
})
.catch(() => flash(__('An error occurred while fetching pending comments'))); .catch(() => flash(__('An error occurred while fetching pending comments')));
export const publishSingleDraft = ({ commit, dispatch, getters }, draftId) => { export const publishSingleDraft = ({ commit, dispatch, getters }, draftId) => {
......
...@@ -139,9 +139,14 @@ describe('Batch comments store actions', () => { ...@@ -139,9 +139,14 @@ describe('Batch comments store actions', () => {
it('commits SET_BATCH_COMMENTS_DRAFTS with returned data', (done) => { it('commits SET_BATCH_COMMENTS_DRAFTS with returned data', (done) => {
const commit = jest.fn(); const commit = jest.fn();
const dispatch = jest.fn();
const context = { const context = {
getters, getters,
commit, commit,
dispatch,
state: {
drafts: [{ line_code: '123' }, { line_code: null, discussion_id: '1' }],
},
}; };
res = { id: 1 }; res = { id: 1 };
mock.onAny().reply(200, res); mock.onAny().reply(200, res);
...@@ -150,6 +155,7 @@ describe('Batch comments store actions', () => { ...@@ -150,6 +155,7 @@ describe('Batch comments store actions', () => {
.fetchDrafts(context) .fetchDrafts(context)
.then(() => { .then(() => {
expect(commit).toHaveBeenCalledWith('SET_BATCH_COMMENTS_DRAFTS', { id: 1 }); expect(commit).toHaveBeenCalledWith('SET_BATCH_COMMENTS_DRAFTS', { id: 1 });
expect(dispatch).toHaveBeenCalledWith('convertToDiscussion', '1', { root: true });
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment