Commit e6cf3c7a authored by Fatih Acet's avatar Fatih Acet

Allow commenting to resolved non-diff discussions

parent 8e11f1fa
...@@ -68,7 +68,7 @@ export default { ...@@ -68,7 +68,7 @@ export default {
isReplying: false, isReplying: false,
isResolving: false, isResolving: false,
resolveAsThread: true, resolveAsThread: true,
isRepliesCollapsed: (!this.discussion.diff_discussion && this.discussion.resolved) || false, isRepliesToggledByUser: false,
}; };
}, },
computed: { computed: {
...@@ -189,6 +189,15 @@ export default { ...@@ -189,6 +189,15 @@ export default {
return isExpanded || this.alwaysExpanded || isResolvedNonDiffDiscussion; return isExpanded || this.alwaysExpanded || isResolvedNonDiffDiscussion;
}, },
isRepliesCollapsed() {
const { discussion, isRepliesToggledByUser } = this;
const { resolved, notes } = discussion;
const hasReplies = notes.length > 1;
return (
(!discussion.diff_discussion && resolved && hasReplies && !isRepliesToggledByUser) || false
);
},
}, },
watch: { watch: {
isReplying() { isReplying() {
...@@ -233,7 +242,7 @@ export default { ...@@ -233,7 +242,7 @@ export default {
this.toggleDiscussion({ discussionId: this.discussion.id }); this.toggleDiscussion({ discussionId: this.discussion.id });
}, },
toggleReplies() { toggleReplies() {
this.isRepliesCollapsed = !this.isRepliesCollapsed; this.isRepliesToggledByUser = !this.isRepliesToggledByUser;
}, },
showReplyForm() { showReplyForm() {
this.isReplying = true; this.isReplying = true;
......
...@@ -42,7 +42,7 @@ export default { ...@@ -42,7 +42,7 @@ export default {
</script> </script>
<template> <template>
<li :class="className" class="replies-toggle"> <li :class="className" class="replies-toggle js-toggle-replies">
<template v-if="collapsed"> <template v-if="collapsed">
<icon name="chevron-right" @click.native="toggle" /> <icon name="chevron-right" @click.native="toggle" />
<div> <div>
......
...@@ -6,6 +6,7 @@ import { noteableDataMock, discussionMock, notesDataMock } from '../mock_data'; ...@@ -6,6 +6,7 @@ import { noteableDataMock, discussionMock, notesDataMock } from '../mock_data';
import mockDiffFile from '../../diffs/mock_data/diff_file'; import mockDiffFile from '../../diffs/mock_data/diff_file';
const discussionWithTwoUnresolvedNotes = 'merge_requests/resolved_diff_discussion.json'; const discussionWithTwoUnresolvedNotes = 'merge_requests/resolved_diff_discussion.json';
const diffDiscussionFixture = 'merge_requests/diff_discussion.json';
describe('noteable_discussion component', () => { describe('noteable_discussion component', () => {
const Component = Vue.extend(noteableDiscussion); const Component = Vue.extend(noteableDiscussion);
...@@ -115,6 +116,49 @@ describe('noteable_discussion component', () => { ...@@ -115,6 +116,49 @@ describe('noteable_discussion component', () => {
.catch(done.fail); .catch(done.fail);
}); });
}); });
describe('isRepliesCollapsed', () => {
it('should return false for diff discussions', done => {
const diffDiscussion = getJSONFixture(diffDiscussionFixture)[0];
vm.$store.dispatch('setInitialNotes', [diffDiscussion]);
Vue.nextTick()
.then(() => {
expect(vm.isRepliesCollapsed).toEqual(false);
expect(vm.$el.querySelector('.js-toggle-replies')).not.toBeNull();
expect(vm.$el.querySelector('.discussion-reply-holder')).not.toBeNull();
})
.then(done)
.catch(done.fail);
});
it('should return false if discussion does not have a reply', () => {
const discussion = { ...discussionMock, resolved: true };
discussion.notes = discussion.notes.slice(0, 1);
const noRepliesVm = new Component({
store,
propsData: { discussion },
}).$mount();
expect(noRepliesVm.isRepliesCollapsed).toEqual(false);
expect(noRepliesVm.$el.querySelector('.js-toggle-replies')).toBeNull();
expect(vm.$el.querySelector('.discussion-reply-holder')).not.toBeNull();
noRepliesVm.$destroy();
});
it('should return true for resolved non-diff discussion which has replies', () => {
const discussion = { ...discussionMock, resolved: true };
const resolvedDiscussionVm = new Component({
store,
propsData: { discussion },
}).$mount();
expect(resolvedDiscussionVm.isRepliesCollapsed).toEqual(true);
expect(resolvedDiscussionVm.$el.querySelector('.js-toggle-replies')).not.toBeNull();
expect(vm.$el.querySelector('.discussion-reply-holder')).not.toBeNull();
resolvedDiscussionVm.$destroy();
});
});
}); });
describe('methods', () => { describe('methods', () => {
......
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