Commit 105f1282 authored by Paul Slaughter's avatar Paul Slaughter

Fix resolve button not showing for threads

**What happened?**
In [this MR][1], we wanted to hide the resolve button if
the user can't resolve some notes. Unfortunately, this
didn't take into account unresolvable notes like system
notes.

[1]: https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/32859
parent 50a8955d
...@@ -36,10 +36,11 @@ export default { ...@@ -36,10 +36,11 @@ export default {
}, },
}, },
computed: { computed: {
resolvableNotes() {
return this.discussion.notes.filter(x => x.resolvable);
},
userCanResolveDiscussion() { userCanResolveDiscussion() {
return this.discussion.notes.every( return this.resolvableNotes.every(note => note.current_user && note.current_user.can_resolve);
note => note.current_user && note.current_user.can_resolve,
);
}, },
}, },
}; };
......
...@@ -7,6 +7,18 @@ import ResolveDiscussionButton from '~/notes/components/discussion_resolve_butto ...@@ -7,6 +7,18 @@ import ResolveDiscussionButton from '~/notes/components/discussion_resolve_butto
import ResolveWithIssueButton from '~/notes/components/discussion_resolve_with_issue_button.vue'; import ResolveWithIssueButton from '~/notes/components/discussion_resolve_with_issue_button.vue';
import JumpToNextDiscussionButton from '~/notes/components/discussion_jump_to_next_button.vue'; import JumpToNextDiscussionButton from '~/notes/components/discussion_jump_to_next_button.vue';
// NOTE: clone mock_data so that it is not accidentally mutated
const createDiscussionMock = (props = {}) =>
Object.assign(JSON.parse(JSON.stringify(discussionMock)), props);
const createNoteMock = (props = {}) =>
Object.assign(JSON.parse(JSON.stringify(discussionMock.notes[0])), props);
const createResolvableNote = () =>
createNoteMock({ resolvable: true, current_user: { can_resolve: true } });
const createUnresolvableNote = () =>
createNoteMock({ resolvable: false, current_user: { can_resolve: false } });
const createUnallowedNote = () =>
createNoteMock({ resolvable: true, current_user: { can_resolve: false } });
describe('DiscussionActions', () => { describe('DiscussionActions', () => {
let wrapper; let wrapper;
const createComponentFactory = (shallow = true) => props => { const createComponentFactory = (shallow = true) => props => {
...@@ -66,13 +78,23 @@ describe('DiscussionActions', () => { ...@@ -66,13 +78,23 @@ describe('DiscussionActions', () => {
expect(wrapper.find(JumpToNextDiscussionButton).exists()).toBe(false); expect(wrapper.find(JumpToNextDiscussionButton).exists()).toBe(false);
}); });
it('does not renders discussion button for non-member', () => { describe.each`
const discussion = JSON.parse(JSON.stringify(discussionMock)); desc | notes | shouldRender
discussion.notes[1].current_user.can_resolve = false; ${'with no notes'} | ${[]} | ${true}
createComponent({ discussion }); ${'with resolvable notes'} | ${[createResolvableNote(), createResolvableNote()]} | ${true}
${'with unresolvable notes'} | ${[createResolvableNote(), createUnresolvableNote()]} | ${true}
${'with unallowed note'} | ${[createResolvableNote(), createUnallowedNote()]} | ${false}
`('$desc', ({ notes, shouldRender }) => {
beforeEach(() => {
createComponent({
discussion: createDiscussionMock({ notes }),
});
});
expect(wrapper.find(ResolveDiscussionButton).exists()).toBe(false); it(shouldRender ? 'renders resolve buttons' : 'does not render resolve buttons', () => {
expect(wrapper.find(ResolveWithIssueButton).exists()).toBe(false); expect(wrapper.find(ResolveDiscussionButton).exists()).toBe(shouldRender);
expect(wrapper.find(ResolveWithIssueButton).exists()).toBe(shouldRender);
});
}); });
}); });
......
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