Commit ba40c7f1 authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'mr-widget-discussion-state-fix' into 'master'

Fixed MR widget unresolved discussions state

See merge request gitlab-org/gitlab-ce!21705
parents 4945b8bf a77a26ea
...@@ -10,6 +10,7 @@ import service from '../services/notes_service'; ...@@ -10,6 +10,7 @@ import service from '../services/notes_service';
import loadAwardsHandler from '../../awards_handler'; import loadAwardsHandler from '../../awards_handler';
import sidebarTimeTrackingEventHub from '../../sidebar/event_hub'; import sidebarTimeTrackingEventHub from '../../sidebar/event_hub';
import { isInViewport, scrollToElement } from '../../lib/utils/common_utils'; import { isInViewport, scrollToElement } from '../../lib/utils/common_utils';
import mrWidgetEventHub from '../../vue_merge_request_widget/event_hub';
let eTagPoll; let eTagPoll;
...@@ -61,9 +62,11 @@ export const refetchDiscussionById = ({ commit, state }, { path, discussionId }) ...@@ -61,9 +62,11 @@ export const refetchDiscussionById = ({ commit, state }, { path, discussionId })
.catch(() => {}); .catch(() => {});
}); });
export const deleteNote = ({ commit }, note) => export const deleteNote = ({ commit, dispatch }, note) =>
service.deleteNote(note.path).then(() => { service.deleteNote(note.path).then(() => {
commit(types.DELETE_NOTE, note); commit(types.DELETE_NOTE, note);
dispatch('updateMergeRequestWidget');
}); });
export const updateNote = ({ commit }, { endpoint, note }) => export const updateNote = ({ commit }, { endpoint, note }) =>
...@@ -84,20 +87,22 @@ export const replyToDiscussion = ({ commit }, { endpoint, data }) => ...@@ -84,20 +87,22 @@ export const replyToDiscussion = ({ commit }, { endpoint, data }) =>
return res; return res;
}); });
export const createNewNote = ({ commit }, { endpoint, data }) => export const createNewNote = ({ commit, dispatch }, { endpoint, data }) =>
service service
.createNewNote(endpoint, data) .createNewNote(endpoint, data)
.then(res => res.json()) .then(res => res.json())
.then(res => { .then(res => {
if (!res.errors) { if (!res.errors) {
commit(types.ADD_NEW_NOTE, res); commit(types.ADD_NEW_NOTE, res);
dispatch('updateMergeRequestWidget');
} }
return res; return res;
}); });
export const removePlaceholderNotes = ({ commit }) => commit(types.REMOVE_PLACEHOLDER_NOTES); export const removePlaceholderNotes = ({ commit }) => commit(types.REMOVE_PLACEHOLDER_NOTES);
export const toggleResolveNote = ({ commit }, { endpoint, isResolved, discussion }) => export const toggleResolveNote = ({ commit, dispatch }, { endpoint, isResolved, discussion }) =>
service service
.toggleResolveNote(endpoint, isResolved) .toggleResolveNote(endpoint, isResolved)
.then(res => res.json()) .then(res => res.json())
...@@ -105,6 +110,8 @@ export const toggleResolveNote = ({ commit }, { endpoint, isResolved, discussion ...@@ -105,6 +110,8 @@ export const toggleResolveNote = ({ commit }, { endpoint, isResolved, discussion
const mutationType = discussion ? types.UPDATE_DISCUSSION : types.UPDATE_NOTE; const mutationType = discussion ? types.UPDATE_DISCUSSION : types.UPDATE_NOTE;
commit(mutationType, res); commit(mutationType, res);
dispatch('updateMergeRequestWidget');
}); });
export const closeIssue = ({ commit, dispatch, state }) => { export const closeIssue = ({ commit, dispatch, state }) => {
...@@ -333,5 +340,9 @@ export const fetchDiscussionDiffLines = ({ commit }, discussion) => ...@@ -333,5 +340,9 @@ export const fetchDiscussionDiffLines = ({ commit }, discussion) =>
}); });
}); });
export const updateMergeRequestWidget = () => {
mrWidgetEventHub.$emit('mr.discussion.updated');
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests // prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {}; export default () => {};
import { import { Vue, mrWidgetOptions } from './dependencies';
Vue,
mrWidgetOptions,
} from './dependencies';
import Translate from '../vue_shared/translate'; import Translate from '../vue_shared/translate';
Vue.use(Translate); Vue.use(Translate);
......
...@@ -107,10 +107,14 @@ export default { ...@@ -107,10 +107,14 @@ export default {
created() { created() {
this.initPolling(); this.initPolling();
this.bindEventHubListeners(); this.bindEventHubListeners();
eventHub.$on('mr.discussion.updated', this.checkStatus);
}, },
mounted() { mounted() {
this.handleMounted(); this.handleMounted();
}, },
beforeDestroy() {
eventHub.$off('mr.discussion.updated', this.checkStatus);
},
methods: { methods: {
createService(store) { createService(store) {
const endpoints = { const endpoints = {
......
---
title: Fixed merge request widget discussion state not updating after resolving discussions
merge_request: 21705
author:
type: fixed
...@@ -3,6 +3,7 @@ import _ from 'underscore'; ...@@ -3,6 +3,7 @@ import _ from 'underscore';
import { headersInterceptor } from 'spec/helpers/vue_resource_helper'; import { headersInterceptor } from 'spec/helpers/vue_resource_helper';
import * as actions from '~/notes/stores/actions'; import * as actions from '~/notes/stores/actions';
import createStore from '~/notes/stores'; import createStore from '~/notes/stores';
import mrWidgetEventHub from '~/vue_merge_request_widget/event_hub';
import testAction from '../../helpers/vuex_action_helper'; import testAction from '../../helpers/vuex_action_helper';
import { resetStore } from '../helpers'; import { resetStore } from '../helpers';
import { import {
...@@ -317,4 +318,195 @@ describe('Actions Notes Store', () => { ...@@ -317,4 +318,195 @@ 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', () => {
spyOn(mrWidgetEventHub, '$emit');
actions.updateMergeRequestWidget();
expect(mrWidgetEventHub.$emit).toHaveBeenCalledWith('mr.discussion.updated');
});
});
}); });
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