Commit d8f70c6b authored by Fatih Acet's avatar Fatih Acet

Fix expanding threads when reference link clicked

parent 5d5b707c
...@@ -122,6 +122,8 @@ export default { ...@@ -122,6 +122,8 @@ export default {
this.toggleAward({ awardName, noteId }); this.toggleAward({ awardName, noteId });
}); });
} }
window.addEventListener('hashchange', this.handleHashChanged);
}, },
updated() { updated() {
this.$nextTick(() => { this.$nextTick(() => {
...@@ -131,6 +133,7 @@ export default { ...@@ -131,6 +133,7 @@ export default {
}, },
beforeDestroy() { beforeDestroy() {
this.stopPolling(); this.stopPolling();
window.removeEventListener('hashchange', this.handleHashChanged);
}, },
methods: { methods: {
...mapActions([ ...mapActions([
...@@ -138,7 +141,6 @@ export default { ...@@ -138,7 +141,6 @@ export default {
'fetchDiscussions', 'fetchDiscussions',
'poll', 'poll',
'toggleAward', 'toggleAward',
'scrollToNoteIfNeeded',
'setNotesData', 'setNotesData',
'setNoteableData', 'setNoteableData',
'setUserData', 'setUserData',
...@@ -151,6 +153,13 @@ export default { ...@@ -151,6 +153,13 @@ export default {
'convertToDiscussion', 'convertToDiscussion',
'stopPolling', 'stopPolling',
]), ]),
handleHashChanged() {
const noteId = this.checkLocationHash();
if (noteId) {
this.setTargetNoteHash(getLocationHash());
}
},
fetchNotes() { fetchNotes() {
if (this.isFetching) return null; if (this.isFetching) return null;
...@@ -194,6 +203,8 @@ export default { ...@@ -194,6 +203,8 @@ export default {
this.expandDiscussion({ discussionId: discussion.id }); this.expandDiscussion({ discussionId: discussion.id });
} }
} }
return noteId;
}, },
startReplying(discussionId) { startReplying(discussionId) {
return this.convertToDiscussion(discussionId) return this.convertToDiscussion(discussionId)
......
---
title: Fix expanding collapsed threads when reference link clicked
merge_request: 20148
author:
type: fixed
...@@ -54,7 +54,9 @@ describe('note_app', () => { ...@@ -54,7 +54,9 @@ describe('note_app', () => {
components: { components: {
NotesApp, NotesApp,
}, },
template: '<div class="js-vue-notes-event"><notes-app v-bind="$attrs" /></div>', template: `<div class="js-vue-notes-event">
<notes-app ref="notesApp" v-bind="$attrs" />
</div>`,
}, },
{ {
attachToDocument: true, attachToDocument: true,
...@@ -313,4 +315,20 @@ describe('note_app', () => { ...@@ -313,4 +315,20 @@ describe('note_app', () => {
}); });
}); });
}); });
describe('mounted', () => {
beforeEach(() => {
axiosMock.onAny().reply(mockData.getIndividualNoteResponse);
wrapper = mountComponent();
return waitForDiscussionsRequest();
});
it('should listen hashchange event', () => {
wrapper.vm.$refs.notesApp.handleHashChanged = jest.fn();
// jest.spyOn(wrapper.vm.$refs.notesApp, 'handleHashChanged');
window.dispatchEvent(new Event('hashchange'), '#foo');
expect(wrapper.vm.$refs.notesApp.handleHashChanged).toHaveBeenCalled();
});
});
}); });
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