Commit 511051ee authored by Phil Hughes's avatar Phil Hughes

Fix drafts not showing after reload

Fixes draft comments not showing in normal discussions
after the page is reloaded.

Changelog: fixed

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/301148
parent e6301685
......@@ -41,11 +41,18 @@ export const deleteDraft = ({ commit, getters }, draft) =>
})
.catch(() => flash(__('An error occurred while deleting the comment')));
export const fetchDrafts = ({ commit, getters }) =>
export const fetchDrafts = ({ commit, getters, state, dispatch }) =>
service
.fetchDrafts(getters.getNotesData.draftsPath)
.then((res) => res.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')));
export const publishSingleDraft = ({ commit, dispatch, getters }, draftId) => {
......
......@@ -139,9 +139,14 @@ describe('Batch comments store actions', () => {
it('commits SET_BATCH_COMMENTS_DRAFTS with returned data', (done) => {
const commit = jest.fn();
const dispatch = jest.fn();
const context = {
getters,
commit,
dispatch,
state: {
drafts: [{ line_code: '123' }, { line_code: null, discussion_id: '1' }],
},
};
res = { id: 1 };
mock.onAny().reply(200, res);
......@@ -150,6 +155,7 @@ describe('Batch comments store actions', () => {
.fetchDrafts(context)
.then(() => {
expect(commit).toHaveBeenCalledWith('SET_BATCH_COMMENTS_DRAFTS', { id: 1 });
expect(dispatch).toHaveBeenCalledWith('convertToDiscussion', '1', { root: true });
})
.then(done)
.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