2017-08-11 11:52:29 -04:00
|
|
|
import Vue from 'vue';
|
2018-06-21 08:22:40 -04:00
|
|
|
import createStore from '~/notes/stores';
|
|
|
|
import noteableDiscussion from '~/notes/components/noteable_discussion.vue';
|
|
|
|
import '~/behaviors/markdown/render_gfm';
|
2017-11-30 17:44:41 -05:00
|
|
|
import { noteableDataMock, discussionMock, notesDataMock } from '../mock_data';
|
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', () => {
|
2018-07-05 18:10:38 -04:00
|
|
|
const Component = Vue.extend(noteableDiscussion);
|
2018-06-21 08:22:40 -04:00
|
|
|
let store;
|
2017-08-11 11:52:29 -04:00
|
|
|
let vm;
|
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
|
|
|
|
2017-08-11 11:52:29 -04:00
|
|
|
vm = new Component({
|
|
|
|
store,
|
2018-07-05 18:10:38 -04:00
|
|
|
propsData: { discussion: discussionMock },
|
2017-08-11 11:52:29 -04:00
|
|
|
}).$mount();
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
|
2017-08-11 11:52:29 -04:00
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2017-08-11 11:52:29 -04:00
|
|
|
it('should render user avatar', () => {
|
2018-03-28 01:11:06 -04:00
|
|
|
expect(vm.$el.querySelector('.user-avatar-link')).not.toBeNull();
|
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 discussion header', () => {
|
2018-03-28 01:11:06 -04:00
|
|
|
expect(vm.$el.querySelector('.discussion-header')).not.toBeNull();
|
2017-12-08 15:24:52 -05:00
|
|
|
expect(vm.$el.querySelector('.notes').children.length).toEqual(discussionMock.notes.length);
|
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', () => {
|
|
|
|
it('should render reply button', () => {
|
2018-03-28 01:11:06 -04:00
|
|
|
expect(vm.$el.querySelector('.js-vue-discussion-reply').textContent.trim()).toEqual(
|
|
|
|
'Reply...',
|
|
|
|
);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
|
2018-03-28 01:11:06 -04:00
|
|
|
it('should toggle reply form', done => {
|
2017-08-11 11:52:29 -04:00
|
|
|
vm.$el.querySelector('.js-vue-discussion-reply').click();
|
2018-07-31 15:24:16 -04:00
|
|
|
|
2017-08-11 11:52:29 -04:00
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(vm.isReplying).toEqual(true);
|
2018-07-31 15:24:16 -04:00
|
|
|
|
|
|
|
// There is a watcher for `isReplying` which will init autosave in the next tick
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
expect(vm.$refs.noteForm).not.toBeNull();
|
|
|
|
done();
|
|
|
|
});
|
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(
|
|
|
|
vm.$el.querySelector('*[data-original-title="Jump to next unresolved discussion"]'),
|
|
|
|
).toBeNull();
|
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
2018-06-21 08:22:40 -04:00
|
|
|
|
|
|
|
describe('computed', () => {
|
|
|
|
describe('hasMultipleUnresolvedDiscussions', () => {
|
|
|
|
it('is false if there are no unresolved discussions', done => {
|
|
|
|
spyOnProperty(vm, 'unresolvedDiscussions').and.returnValue([]);
|
|
|
|
|
|
|
|
Vue.nextTick()
|
|
|
|
.then(() => {
|
|
|
|
expect(vm.hasMultipleUnresolvedDiscussions).toBe(false);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is false if there is one unresolved discussion', done => {
|
|
|
|
spyOnProperty(vm, 'unresolvedDiscussions').and.returnValue([discussionMock]);
|
|
|
|
|
|
|
|
Vue.nextTick()
|
|
|
|
.then(() => {
|
|
|
|
expect(vm.hasMultipleUnresolvedDiscussions).toBe(false);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is true if there are two unresolved discussions', done => {
|
2018-07-05 18:10:38 -04:00
|
|
|
const discussion = getJSONFixture(discussionWithTwoUnresolvedNotes)[0];
|
|
|
|
discussion.notes[0].resolved = false;
|
|
|
|
vm.$store.dispatch('setInitialNotes', [discussion, discussion]);
|
2018-06-21 08:22:40 -04:00
|
|
|
|
|
|
|
Vue.nextTick()
|
|
|
|
.then(() => {
|
|
|
|
expect(vm.hasMultipleUnresolvedDiscussions).toBe(true);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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;
|
|
|
|
discussion2.id = 'next'; // prepare this for being identified as next one (to be jumped to)
|
|
|
|
vm.$store.dispatch('setInitialNotes', [discussionMock, discussion2]);
|
|
|
|
window.mrTabs.currentAction = 'show';
|
|
|
|
|
|
|
|
Vue.nextTick()
|
|
|
|
.then(() => {
|
|
|
|
spyOn(vm, 'expandDiscussion').and.stub();
|
|
|
|
|
|
|
|
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
|
|
|
|
2018-07-31 22:21:14 -04:00
|
|
|
vm.jumpToNextDiscussion();
|
|
|
|
|
|
|
|
expect(vm.expandDiscussion).toHaveBeenCalledWith({ discussionId: nextDiscussionId });
|
|
|
|
})
|
|
|
|
.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
|
|
|
};
|
|
|
|
|
|
|
|
const note = 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
|
|
|
};
|
|
|
|
|
|
|
|
const note = vm.componentData(data);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2018-10-03 06:17:26 -04:00
|
|
|
expect(note).toEqual(data);
|
|
|
|
});
|
|
|
|
});
|
2017-08-09 15:13:00 -04:00
|
|
|
});
|