2020-03-13 15:44:24 +05:30
|
|
|
import { shallowMount, mount } from '@vue/test-utils';
|
2019-07-31 22:56:46 +05:30
|
|
|
import DiscussionActions from '~/notes/components/discussion_actions.vue';
|
|
|
|
import ReplyPlaceholder from '~/notes/components/discussion_reply_placeholder.vue';
|
|
|
|
import ResolveDiscussionButton from '~/notes/components/discussion_resolve_button.vue';
|
|
|
|
import ResolveWithIssueButton from '~/notes/components/discussion_resolve_with_issue_button.vue';
|
2020-01-01 13:55:28 +05:30
|
|
|
import createStore from '~/notes/stores';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { discussionMock } from '../mock_data';
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
// 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 = () =>
|
2021-01-29 00:20:46 +05:30
|
|
|
createNoteMock({ resolvable: true, current_user: { can_resolve_discussion: true } });
|
2019-12-04 20:38:33 +05:30
|
|
|
const createUnresolvableNote = () =>
|
2021-01-29 00:20:46 +05:30
|
|
|
createNoteMock({ resolvable: false, current_user: { can_resolve_discussion: false } });
|
2019-12-04 20:38:33 +05:30
|
|
|
const createUnallowedNote = () =>
|
2021-01-29 00:20:46 +05:30
|
|
|
createNoteMock({ resolvable: true, current_user: { can_resolve_discussion: false } });
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
describe('DiscussionActions', () => {
|
|
|
|
let wrapper;
|
2021-09-04 01:27:46 +05:30
|
|
|
const createComponentFactory = (shallow = true) => (props, options) => {
|
2019-07-31 22:56:46 +05:30
|
|
|
const store = createStore();
|
|
|
|
const mountFn = shallow ? shallowMount : mount;
|
|
|
|
|
|
|
|
wrapper = mountFn(DiscussionActions, {
|
|
|
|
store,
|
|
|
|
propsData: {
|
|
|
|
discussion: discussionMock,
|
|
|
|
isResolving: false,
|
|
|
|
resolveButtonTitle: 'Resolve discussion',
|
|
|
|
resolveWithIssuePath: '/some/issue/path',
|
|
|
|
shouldShowJumpToNextDiscussion: true,
|
|
|
|
...props,
|
|
|
|
},
|
2021-09-04 01:27:46 +05:30
|
|
|
...options,
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('rendering', () => {
|
|
|
|
const createComponent = createComponentFactory();
|
|
|
|
|
|
|
|
it('renders reply placeholder, resolve discussion button, resolve with issue button and jump to next discussion button', () => {
|
|
|
|
createComponent();
|
2023-05-27 22:25:52 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(wrapper.findComponent(ReplyPlaceholder).exists()).toBe(true);
|
|
|
|
expect(wrapper.findComponent(ResolveDiscussionButton).exists()).toBe(true);
|
|
|
|
expect(wrapper.findComponent(ResolveWithIssueButton).exists()).toBe(true);
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('only renders reply placholder if disccusion is not resolvable', () => {
|
|
|
|
const discussion = { ...discussionMock };
|
|
|
|
discussion.resolvable = false;
|
|
|
|
createComponent({ discussion });
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(wrapper.findComponent(ReplyPlaceholder).exists()).toBe(true);
|
|
|
|
expect(wrapper.findComponent(ResolveDiscussionButton).exists()).toBe(false);
|
|
|
|
expect(wrapper.findComponent(ResolveWithIssueButton).exists()).toBe(false);
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render resolve with issue button if resolveWithIssuePath is falsy', () => {
|
|
|
|
createComponent({ resolveWithIssuePath: '' });
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(wrapper.findComponent(ResolveWithIssueButton).exists()).toBe(false);
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
describe.each`
|
|
|
|
desc | notes | shouldRender
|
|
|
|
${'with no notes'} | ${[]} | ${true}
|
|
|
|
${'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 }),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
it(`${shouldRender ? 'renders' : 'does not render'} resolve buttons`, () => {
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(wrapper.findComponent(ResolveDiscussionButton).exists()).toBe(shouldRender);
|
|
|
|
expect(wrapper.findComponent(ResolveWithIssueButton).exists()).toBe(shouldRender);
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
});
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('events handling', () => {
|
|
|
|
const createComponent = createComponentFactory(false);
|
|
|
|
|
|
|
|
it('emits showReplyForm event when clicking on reply placeholder', () => {
|
2021-09-04 01:27:46 +05:30
|
|
|
createComponent({}, { attachTo: document.body });
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
wrapper.findComponent(ReplyPlaceholder).find('textarea').trigger('focus');
|
2023-05-27 22:25:52 +05:30
|
|
|
expect(wrapper.emitted().showReplyForm).toHaveLength(1);
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('emits resolve event when clicking on resolve button', () => {
|
2021-09-04 01:27:46 +05:30
|
|
|
createComponent();
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
wrapper.findComponent(ResolveDiscussionButton).find('button').trigger('click');
|
2023-05-27 22:25:52 +05:30
|
|
|
expect(wrapper.emitted().resolve).toHaveLength(1);
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|