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 {
isReplying: false,
isResolving: false,
resolveAsThread: true,
isRepliesCollapsed: (!this.discussion.diff_discussion && this.discussion.resolved) || false,
isRepliesToggledByUser: false,
};
},
computed: {
......@@ -189,6 +189,15 @@ export default {
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: {
isReplying() {
......@@ -233,7 +242,7 @@ export default {
this.toggleDiscussion({ discussionId: this.discussion.id });
},
toggleReplies() {
this.isRepliesCollapsed = !this.isRepliesCollapsed;
this.isRepliesToggledByUser = !this.isRepliesToggledByUser;
},
showReplyForm() {
this.isReplying = true;
......
......@@ -42,7 +42,7 @@ export default {
</script>
<template>
<li :class="className" class="replies-toggle">
<li :class="className" class="replies-toggle js-toggle-replies">
<template v-if="collapsed">
<icon name="chevron-right" @click.native="toggle" />
<div>
......
......@@ -6,6 +6,7 @@ import { noteableDataMock, discussionMock, notesDataMock } from '../mock_data';
import mockDiffFile from '../../diffs/mock_data/diff_file';
const discussionWithTwoUnresolvedNotes = 'merge_requests/resolved_diff_discussion.json';
const diffDiscussionFixture = 'merge_requests/diff_discussion.json';
describe('noteable_discussion component', () => {
const Component = Vue.extend(noteableDiscussion);
......@@ -115,6 +116,49 @@ describe('noteable_discussion component', () => {
.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', () => {
......
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