2019-03-02 22:35:43 +05:30
|
|
|
import { shallowMount, createLocalVue } from '@vue/test-utils';
|
2018-11-08 19:23:39 +05:30
|
|
|
import createStore from '~/notes/stores';
|
|
|
|
import noteableDiscussion from '~/notes/components/noteable_discussion.vue';
|
2019-03-02 22:35:43 +05:30
|
|
|
import ReplyPlaceholder from '~/notes/components/discussion_reply_placeholder.vue';
|
2019-05-18 00:54:41 +05:30
|
|
|
import ResolveWithIssueButton from '~/notes/components/discussion_resolve_with_issue_button.vue';
|
|
|
|
import NoteForm from '~/notes/components/note_form.vue';
|
2018-11-08 19:23:39 +05:30
|
|
|
import '~/behaviors/markdown/render_gfm';
|
2018-03-17 18:26:18 +05:30
|
|
|
import { noteableDataMock, discussionMock, notesDataMock } from '../mock_data';
|
2018-12-13 13:39:08 +05:30
|
|
|
import mockDiffFile from '../../diffs/mock_data/diff_file';
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
const discussionWithTwoUnresolvedNotes = 'merge_requests/resolved_diff_discussion.json';
|
|
|
|
|
|
|
|
describe('noteable_discussion component', () => {
|
|
|
|
let store;
|
2019-03-02 22:35:43 +05:30
|
|
|
let wrapper;
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
preloadFixtures(discussionWithTwoUnresolvedNotes);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
beforeEach(() => {
|
2018-11-18 11:00:15 +05:30
|
|
|
window.mrTabs = {};
|
2018-11-08 19:23:39 +05:30
|
|
|
store = createStore();
|
2018-03-17 18:26:18 +05:30
|
|
|
store.dispatch('setNoteableData', noteableDataMock);
|
|
|
|
store.dispatch('setNotesData', notesDataMock);
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
const localVue = createLocalVue();
|
|
|
|
wrapper = shallowMount(noteableDiscussion, {
|
2018-03-17 18:26:18 +05:30
|
|
|
store,
|
2018-11-08 19:23:39 +05:30
|
|
|
propsData: { discussion: discussionMock },
|
2019-03-02 22:35:43 +05:30
|
|
|
localVue,
|
|
|
|
sync: false,
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper.destroy();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should render user avatar', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(wrapper.find('.user-avatar-link').exists()).toBe(true);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('should not render discussion header for non diff discussions', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(wrapper.find('.discussion-header').exists()).toBe(false);
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
it('should render discussion header', done => {
|
2018-12-13 13:39:08 +05:30
|
|
|
const discussion = { ...discussionMock };
|
|
|
|
discussion.diff_file = mockDiffFile;
|
|
|
|
discussion.diff_discussion = true;
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper.setProps({ discussion });
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper.vm
|
|
|
|
.$nextTick()
|
|
|
|
.then(() => {
|
|
|
|
expect(wrapper.find('.discussion-header').exists()).toBe(true);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('actions', () => {
|
2018-05-09 12:01:36 +05:30
|
|
|
it('should toggle reply form', done => {
|
2019-03-02 22:35:43 +05:30
|
|
|
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-05-18 00:54:41 +05:30
|
|
|
|
|
|
|
const noteForm = wrapper.find(NoteForm);
|
|
|
|
|
|
|
|
expect(noteForm.exists()).toBe(true);
|
|
|
|
|
|
|
|
const noteFormProps = noteForm.props();
|
|
|
|
|
|
|
|
expect(noteFormProps.discussion).toBe(discussionMock);
|
|
|
|
expect(noteFormProps.isEditing).toBe(false);
|
|
|
|
expect(noteFormProps.line).toBe(null);
|
|
|
|
expect(noteFormProps.saveButtonTitle).toBe('Comment');
|
|
|
|
expect(noteFormProps.autosaveKey).toBe(`Note/Issue/${discussionMock.id}/Reply`);
|
2019-03-02 22:35:43 +05:30
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2018-05-01 15:08:00 +05:30
|
|
|
|
|
|
|
it('does not render jump to discussion button', () => {
|
|
|
|
expect(
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper.find('*[data-original-title="Jump to next unresolved discussion"]').exists(),
|
|
|
|
).toBe(false);
|
2018-05-01 15:08:00 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
describe('methods', () => {
|
|
|
|
describe('jumpToNextDiscussion', () => {
|
2018-11-18 11:00:15 +05:30
|
|
|
it('expands next unresolved discussion', done => {
|
|
|
|
const discussion2 = getJSONFixture(discussionWithTwoUnresolvedNotes)[0];
|
|
|
|
discussion2.resolved = false;
|
2019-02-15 15:39:39 +05:30
|
|
|
discussion2.active = true;
|
2018-11-18 11:00:15 +05:30
|
|
|
discussion2.id = 'next'; // prepare this for being identified as next one (to be jumped to)
|
2019-03-02 22:35:43 +05:30
|
|
|
store.dispatch('setInitialNotes', [discussionMock, discussion2]);
|
2018-11-18 11:00:15 +05:30
|
|
|
window.mrTabs.currentAction = 'show';
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper.vm
|
|
|
|
.$nextTick()
|
2018-11-18 11:00:15 +05:30
|
|
|
.then(() => {
|
2019-03-02 22:35:43 +05:30
|
|
|
spyOn(wrapper.vm, 'expandDiscussion').and.stub();
|
2018-11-18 11:00:15 +05:30
|
|
|
|
|
|
|
const nextDiscussionId = discussion2.id;
|
|
|
|
|
|
|
|
setFixtures(`
|
|
|
|
<div class="discussion" data-discussion-id="${nextDiscussionId}"></div>
|
|
|
|
`);
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper.vm.jumpToNextDiscussion();
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(wrapper.vm.expandDiscussion).toHaveBeenCalledWith({
|
|
|
|
discussionId: nextDiscussionId,
|
|
|
|
});
|
2018-11-18 11:00:15 +05:30
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-12-05 23:21:45 +05:30
|
|
|
|
|
|
|
describe('componentData', () => {
|
|
|
|
it('should return first note object for placeholder note', () => {
|
|
|
|
const data = {
|
|
|
|
isPlaceholderNote: true,
|
2018-12-13 13:39:08 +05:30
|
|
|
notes: [{ body: 'hello world!' }],
|
2018-12-05 23:21:45 +05:30
|
|
|
};
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
const note = wrapper.vm.componentData(data);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
expect(note).toEqual(data.notes[0]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return given note for nonplaceholder notes', () => {
|
|
|
|
const data = {
|
2018-12-13 13:39:08 +05:30
|
|
|
notes: [{ id: 12 }],
|
2018-12-05 23:21:45 +05:30
|
|
|
};
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
const note = wrapper.vm.componentData(data);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
expect(note).toEqual(data);
|
|
|
|
});
|
|
|
|
});
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
describe('action text', () => {
|
|
|
|
const commitId = 'razupaltuff';
|
|
|
|
const truncatedCommitId = commitId.substr(0, 8);
|
|
|
|
let commitElement;
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
beforeEach(done => {
|
2019-02-15 15:39:39 +05:30
|
|
|
store.state.diffs = {
|
|
|
|
projectPath: 'something',
|
|
|
|
};
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper.setProps({
|
|
|
|
discussion: {
|
|
|
|
...discussionMock,
|
|
|
|
for_commit: true,
|
|
|
|
commit_id: commitId,
|
|
|
|
diff_discussion: true,
|
|
|
|
diff_file: {
|
|
|
|
...mockDiffFile,
|
2019-02-15 15:39:39 +05:30
|
|
|
},
|
|
|
|
},
|
2019-03-02 22:35:43 +05:30
|
|
|
renderDiffFile: true,
|
|
|
|
});
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper.vm
|
|
|
|
.$nextTick()
|
|
|
|
.then(() => {
|
|
|
|
commitElement = wrapper.find('.commit-sha');
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
2019-02-15 15:39:39 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('for commit discussions', () => {
|
|
|
|
it('should display a monospace started a discussion on commit', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(wrapper.text()).toContain(`started a discussion on commit ${truncatedCommitId}`);
|
|
|
|
expect(commitElement.exists()).toBe(true);
|
|
|
|
expect(commitElement.text()).toContain(truncatedCommitId);
|
2019-02-15 15:39:39 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('for diff discussion with a commit id', () => {
|
|
|
|
it('should display started discussion on commit header', done => {
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper.vm.discussion.for_commit = false;
|
|
|
|
|
|
|
|
wrapper.vm.$nextTick(() => {
|
|
|
|
expect(wrapper.text()).toContain(`started a discussion on commit ${truncatedCommitId}`);
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
expect(commitElement).not.toBe(null);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should display outdated change on commit header', done => {
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper.vm.discussion.for_commit = false;
|
|
|
|
wrapper.vm.discussion.active = false;
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper.vm.$nextTick(() => {
|
|
|
|
expect(wrapper.text()).toContain(
|
2019-02-15 15:39:39 +05:30
|
|
|
`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-03-02 22:35:43 +05:30
|
|
|
Object.assign(wrapper.vm.discussion, {
|
2019-02-15 15:39:39 +05:30
|
|
|
for_commit: false,
|
|
|
|
commit_id: null,
|
|
|
|
});
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper.vm.$nextTick(() => {
|
|
|
|
expect(wrapper.text()).toContain('started a discussion on the diff');
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show discussion on older version text', done => {
|
2019-03-02 22:35:43 +05:30
|
|
|
Object.assign(wrapper.vm.discussion, {
|
2019-02-15 15:39:39 +05:30
|
|
|
for_commit: false,
|
|
|
|
commit_id: null,
|
|
|
|
active: false,
|
|
|
|
});
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper.vm.$nextTick(() => {
|
|
|
|
expect(wrapper.text()).toContain('started a discussion on an old version of the diff');
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-05-18 00:54:41 +05:30
|
|
|
|
|
|
|
describe('for resolved discussion', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
const discussion = getJSONFixture(discussionWithTwoUnresolvedNotes)[0];
|
|
|
|
wrapper.setProps({ discussion });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not display a button to resolve with issue', () => {
|
|
|
|
const button = wrapper.find(ResolveWithIssueButton);
|
|
|
|
|
|
|
|
expect(button.exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('for unresolved discussion', () => {
|
|
|
|
beforeEach(done => {
|
|
|
|
const discussion = {
|
|
|
|
...getJSONFixture(discussionWithTwoUnresolvedNotes)[0],
|
|
|
|
expanded: true,
|
|
|
|
};
|
|
|
|
discussion.notes = discussion.notes.map(note => ({
|
|
|
|
...note,
|
|
|
|
resolved: false,
|
|
|
|
}));
|
|
|
|
|
|
|
|
wrapper.setProps({ discussion });
|
|
|
|
wrapper.vm
|
|
|
|
.$nextTick()
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays a button to resolve with issue', () => {
|
|
|
|
const button = wrapper.find(ResolveWithIssueButton);
|
|
|
|
|
|
|
|
expect(button.exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|