2019-01-29 07:16:30 -05:00
|
|
|
import { shallowMount, createLocalVue } from '@vue/test-utils';
|
2018-06-21 08:22:40 -04:00
|
|
|
import createStore from '~/notes/stores';
|
|
|
|
import noteableDiscussion from '~/notes/components/noteable_discussion.vue';
|
2019-02-05 03:56:34 -05:00
|
|
|
import ReplyPlaceholder from '~/notes/components/discussion_reply_placeholder.vue';
|
2018-06-21 08:22:40 -04:00
|
|
|
import '~/behaviors/markdown/render_gfm';
|
2017-11-30 17:44:41 -05:00
|
|
|
import { noteableDataMock, discussionMock, notesDataMock } from '../mock_data';
|
2018-11-08 02:58:45 -05:00
|
|
|
import mockDiffFile from '../../diffs/mock_data/diff_file';
|
2017-08-10 13:36:39 -04:00
|
|
|
|
2018-07-05 18:10:38 -04:00
|
|
|
const discussionWithTwoUnresolvedNotes = 'merge_requests/resolved_diff_discussion.json';
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
describe('noteable_discussion component', () => {
|
|
|
|
let store;
|
2019-01-29 07:16:30 -05:00
|
|
|
let wrapper;
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2018-07-05 18:10:38 -04:00
|
|
|
preloadFixtures(discussionWithTwoUnresolvedNotes);
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2018-07-05 18:10:38 -04:00
|
|
|
beforeEach(() => {
|
2018-07-31 22:21:14 -04:00
|
|
|
window.mrTabs = {};
|
2018-06-21 08:22:40 -04:00
|
|
|
store = createStore();
|
2017-11-30 17:44:41 -05:00
|
|
|
store.dispatch('setNoteableData', noteableDataMock);
|
2017-08-11 11:52:29 -04:00
|
|
|
store.dispatch('setNotesData', notesDataMock);
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2019-01-29 07:16:30 -05:00
|
|
|
const localVue = createLocalVue();
|
|
|
|
wrapper = shallowMount(noteableDiscussion, {
|
2017-08-11 11:52:29 -04:00
|
|
|
store,
|
2018-07-05 18:10:38 -04:00
|
|
|
propsData: { discussion: discussionMock },
|
2019-01-29 07:16:30 -05:00
|
|
|
localVue,
|
|
|
|
sync: false,
|
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
|
2017-08-11 11:52:29 -04:00
|
|
|
afterEach(() => {
|
2019-01-29 07:16:30 -05:00
|
|
|
wrapper.destroy();
|
2017-08-11 11:52:29 -04:00
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2017-08-11 11:52:29 -04:00
|
|
|
it('should render user avatar', () => {
|
2019-01-29 07:16:30 -05:00
|
|
|
expect(wrapper.find('.user-avatar-link').exists()).toBe(true);
|
2017-08-11 11:52:29 -04:00
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2018-11-08 02:58:45 -05:00
|
|
|
it('should not render discussion header for non diff discussions', () => {
|
2019-01-29 07:16:30 -05:00
|
|
|
expect(wrapper.find('.discussion-header').exists()).toBe(false);
|
2018-11-08 02:58:45 -05:00
|
|
|
});
|
|
|
|
|
2019-01-29 07:16:30 -05:00
|
|
|
it('should render discussion header', done => {
|
2018-11-08 02:58:45 -05:00
|
|
|
const discussion = { ...discussionMock };
|
|
|
|
discussion.diff_file = mockDiffFile;
|
|
|
|
discussion.diff_discussion = true;
|
2018-12-11 05:22:00 -05:00
|
|
|
|
2019-01-29 07:16:30 -05:00
|
|
|
wrapper.setProps({ discussion });
|
2018-11-08 02:58:45 -05:00
|
|
|
|
2019-01-29 07:16:30 -05:00
|
|
|
wrapper.vm
|
|
|
|
.$nextTick()
|
|
|
|
.then(() => {
|
|
|
|
expect(wrapper.find('.discussion-header').exists()).toBe(true);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-08-11 11:52:29 -04:00
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2017-08-11 11:52:29 -04:00
|
|
|
describe('actions', () => {
|
2018-03-28 01:11:06 -04:00
|
|
|
it('should toggle reply form', done => {
|
2019-02-05 03:56:34 -05:00
|
|
|
const replyPlaceholder = wrapper.find(ReplyPlaceholder);
|
|
|
|
|
|
|
|
wrapper.vm
|
|
|
|
.$nextTick()
|
|
|
|
.then(() => {
|
|
|
|
expect(wrapper.vm.isReplying).toEqual(false);
|
|
|
|
|
|
|
|
replyPlaceholder.vm.$emit('onClick');
|
|
|
|
})
|
|
|
|
.then(() => wrapper.vm.$nextTick())
|
|
|
|
.then(() => {
|
|
|
|
expect(wrapper.vm.isReplying).toEqual(true);
|
2019-01-29 07:16:30 -05:00
|
|
|
expect(wrapper.vm.$refs.noteForm).not.toBeNull();
|
2019-02-05 03:56:34 -05:00
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
2018-03-28 01:11:06 -04:00
|
|
|
|
|
|
|
it('does not render jump to discussion button', () => {
|
|
|
|
expect(
|
2019-01-29 07:16:30 -05:00
|
|
|
wrapper.find('*[data-original-title="Jump to next unresolved discussion"]').exists(),
|
|
|
|
).toBe(false);
|
2018-03-28 01:11:06 -04:00
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
2018-06-21 08:22:40 -04:00
|
|
|
|
|
|
|
describe('methods', () => {
|
|
|
|
describe('jumpToNextDiscussion', () => {
|
2018-07-31 22:21:14 -04:00
|
|
|
it('expands next unresolved discussion', done => {
|
|
|
|
const discussion2 = getJSONFixture(discussionWithTwoUnresolvedNotes)[0];
|
|
|
|
discussion2.resolved = false;
|
2018-12-08 02:19:03 -05:00
|
|
|
discussion2.active = true;
|
2018-07-31 22:21:14 -04:00
|
|
|
discussion2.id = 'next'; // prepare this for being identified as next one (to be jumped to)
|
2019-01-29 07:16:30 -05:00
|
|
|
store.dispatch('setInitialNotes', [discussionMock, discussion2]);
|
2018-07-31 22:21:14 -04:00
|
|
|
window.mrTabs.currentAction = 'show';
|
|
|
|
|
2019-01-29 07:16:30 -05:00
|
|
|
wrapper.vm
|
|
|
|
.$nextTick()
|
2018-07-31 22:21:14 -04:00
|
|
|
.then(() => {
|
2019-01-29 07:16:30 -05:00
|
|
|
spyOn(wrapper.vm, 'expandDiscussion').and.stub();
|
2018-07-31 22:21:14 -04:00
|
|
|
|
|
|
|
const nextDiscussionId = discussion2.id;
|
2018-06-21 08:22:40 -04:00
|
|
|
|
2018-07-31 22:21:14 -04:00
|
|
|
setFixtures(`
|
|
|
|
<div class="discussion" data-discussion-id="${nextDiscussionId}"></div>
|
|
|
|
`);
|
2018-07-20 11:24:46 -04:00
|
|
|
|
2019-01-29 07:16:30 -05:00
|
|
|
wrapper.vm.jumpToNextDiscussion();
|
2018-07-31 22:21:14 -04:00
|
|
|
|
2019-01-29 07:16:30 -05:00
|
|
|
expect(wrapper.vm.expandDiscussion).toHaveBeenCalledWith({
|
|
|
|
discussionId: nextDiscussionId,
|
|
|
|
});
|
2018-07-31 22:21:14 -04:00
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2018-06-21 08:22:40 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-10-03 06:17:26 -04:00
|
|
|
|
|
|
|
describe('componentData', () => {
|
|
|
|
it('should return first note object for placeholder note', () => {
|
|
|
|
const data = {
|
|
|
|
isPlaceholderNote: true,
|
2018-10-17 03:13:26 -04:00
|
|
|
notes: [{ body: 'hello world!' }],
|
2018-10-03 06:17:26 -04:00
|
|
|
};
|
|
|
|
|
2019-01-29 07:16:30 -05:00
|
|
|
const note = wrapper.vm.componentData(data);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2018-10-03 06:17:26 -04:00
|
|
|
expect(note).toEqual(data.notes[0]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return given note for nonplaceholder notes', () => {
|
|
|
|
const data = {
|
2018-10-17 03:13:26 -04:00
|
|
|
notes: [{ id: 12 }],
|
2018-10-03 06:17:26 -04:00
|
|
|
};
|
|
|
|
|
2019-01-29 07:16:30 -05:00
|
|
|
const note = wrapper.vm.componentData(data);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2018-10-03 06:17:26 -04:00
|
|
|
expect(note).toEqual(data);
|
|
|
|
});
|
|
|
|
});
|
2018-12-11 05:22:00 -05:00
|
|
|
|
2018-12-20 18:19:44 -05:00
|
|
|
describe('action text', () => {
|
2018-12-11 05:22:00 -05:00
|
|
|
const commitId = 'razupaltuff';
|
2018-12-20 18:19:44 -05:00
|
|
|
const truncatedCommitId = commitId.substr(0, 8);
|
|
|
|
let commitElement;
|
2018-12-11 05:22:00 -05:00
|
|
|
|
2019-01-29 07:16:30 -05:00
|
|
|
beforeEach(done => {
|
2018-12-11 05:22:00 -05:00
|
|
|
store.state.diffs = {
|
|
|
|
projectPath: 'something',
|
|
|
|
};
|
|
|
|
|
2019-01-29 07:16:30 -05:00
|
|
|
wrapper.setProps({
|
|
|
|
discussion: {
|
|
|
|
...discussionMock,
|
|
|
|
for_commit: true,
|
|
|
|
commit_id: commitId,
|
|
|
|
diff_discussion: true,
|
|
|
|
diff_file: {
|
|
|
|
...mockDiffFile,
|
2018-12-11 05:22:00 -05:00
|
|
|
},
|
|
|
|
},
|
2019-01-29 07:16:30 -05:00
|
|
|
renderDiffFile: true,
|
|
|
|
});
|
2018-12-20 18:19:44 -05:00
|
|
|
|
2019-01-29 07:16:30 -05:00
|
|
|
wrapper.vm
|
|
|
|
.$nextTick()
|
|
|
|
.then(() => {
|
|
|
|
commitElement = wrapper.find('.commit-sha');
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2018-12-20 18:19:44 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('for commit discussions', () => {
|
|
|
|
it('should display a monospace started a discussion on commit', () => {
|
2019-01-29 07:16:30 -05:00
|
|
|
expect(wrapper.text()).toContain(`started a discussion on commit ${truncatedCommitId}`);
|
|
|
|
expect(commitElement.exists()).toBe(true);
|
|
|
|
expect(commitElement.text()).toContain(truncatedCommitId);
|
2018-12-20 18:19:44 -05:00
|
|
|
});
|
2018-12-11 05:22:00 -05:00
|
|
|
});
|
|
|
|
|
2018-12-20 18:19:44 -05:00
|
|
|
describe('for diff discussion with a commit id', () => {
|
|
|
|
it('should display started discussion on commit header', done => {
|
2019-01-29 07:16:30 -05:00
|
|
|
wrapper.vm.discussion.for_commit = false;
|
|
|
|
|
|
|
|
wrapper.vm.$nextTick(() => {
|
|
|
|
expect(wrapper.text()).toContain(`started a discussion on commit ${truncatedCommitId}`);
|
2018-12-11 05:22:00 -05:00
|
|
|
|
2018-12-20 18:19:44 -05:00
|
|
|
expect(commitElement).not.toBe(null);
|
2018-12-11 05:22:00 -05:00
|
|
|
|
2018-12-20 18:19:44 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-12-11 05:22:00 -05:00
|
|
|
|
2018-12-20 18:19:44 -05:00
|
|
|
it('should display outdated change on commit header', done => {
|
2019-01-29 07:16:30 -05:00
|
|
|
wrapper.vm.discussion.for_commit = false;
|
|
|
|
wrapper.vm.discussion.active = false;
|
2018-12-20 18:19:44 -05:00
|
|
|
|
2019-01-29 07:16:30 -05:00
|
|
|
wrapper.vm.$nextTick(() => {
|
|
|
|
expect(wrapper.text()).toContain(
|
2018-12-20 18:19:44 -05:00
|
|
|
`started a discussion on an outdated change in commit ${truncatedCommitId}`,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(commitElement).not.toBe(null);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('for diff discussions without a commit id', () => {
|
|
|
|
it('should show started a discussion on the diff text', done => {
|
2019-01-29 07:16:30 -05:00
|
|
|
Object.assign(wrapper.vm.discussion, {
|
2018-12-20 18:19:44 -05:00
|
|
|
for_commit: false,
|
|
|
|
commit_id: null,
|
|
|
|
});
|
|
|
|
|
2019-01-29 07:16:30 -05:00
|
|
|
wrapper.vm.$nextTick(() => {
|
|
|
|
expect(wrapper.text()).toContain('started a discussion on the diff');
|
2018-12-20 18:19:44 -05:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show discussion on older version text', done => {
|
2019-01-29 07:16:30 -05:00
|
|
|
Object.assign(wrapper.vm.discussion, {
|
2018-12-20 18:19:44 -05:00
|
|
|
for_commit: false,
|
|
|
|
commit_id: null,
|
|
|
|
active: false,
|
|
|
|
});
|
|
|
|
|
2019-01-29 07:16:30 -05:00
|
|
|
wrapper.vm.$nextTick(() => {
|
|
|
|
expect(wrapper.text()).toContain('started a discussion on an old version of the diff');
|
2018-12-20 18:19:44 -05:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-12-11 05:22:00 -05:00
|
|
|
});
|
|
|
|
});
|
2017-08-09 15:13:00 -04:00
|
|
|
});
|