2018-03-17 18:26:18 +05:30
|
|
|
import Vue from 'vue';
|
2018-11-08 19:23:39 +05:30
|
|
|
import createStore from '~/notes/stores';
|
|
|
|
import noteableDiscussion from '~/notes/components/noteable_discussion.vue';
|
|
|
|
import '~/behaviors/markdown/render_gfm';
|
2018-03-17 18:26:18 +05:30
|
|
|
import { noteableDataMock, discussionMock, notesDataMock } from '../mock_data';
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
const discussionWithTwoUnresolvedNotes = 'merge_requests/resolved_diff_discussion.json';
|
|
|
|
|
|
|
|
describe('noteable_discussion component', () => {
|
|
|
|
const Component = Vue.extend(noteableDiscussion);
|
|
|
|
let store;
|
2018-03-17 18:26:18 +05:30
|
|
|
let vm;
|
|
|
|
|
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(() => {
|
|
|
|
store = createStore();
|
2018-03-17 18:26:18 +05:30
|
|
|
store.dispatch('setNoteableData', noteableDataMock);
|
|
|
|
store.dispatch('setNotesData', notesDataMock);
|
|
|
|
|
|
|
|
vm = new Component({
|
|
|
|
store,
|
2018-11-08 19:23:39 +05:30
|
|
|
propsData: { discussion: discussionMock },
|
2018-03-17 18:26:18 +05:30
|
|
|
}).$mount();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render user avatar', () => {
|
2018-05-01 15:08:00 +05:30
|
|
|
expect(vm.$el.querySelector('.user-avatar-link')).not.toBeNull();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should render discussion header', () => {
|
2018-05-01 15:08:00 +05:30
|
|
|
expect(vm.$el.querySelector('.discussion-header')).not.toBeNull();
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.$el.querySelector('.notes').children.length).toEqual(discussionMock.notes.length);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('actions', () => {
|
|
|
|
it('should render reply button', () => {
|
2018-05-01 15:08:00 +05:30
|
|
|
expect(vm.$el.querySelector('.js-vue-discussion-reply').textContent.trim()).toEqual(
|
|
|
|
'Reply...',
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
it('should toggle reply form', done => {
|
2018-03-17 18:26:18 +05:30
|
|
|
vm.$el.querySelector('.js-vue-discussion-reply').click();
|
|
|
|
Vue.nextTick(() => {
|
2018-05-01 15:08:00 +05:30
|
|
|
expect(vm.$refs.noteForm).not.toBeNull();
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(vm.isReplying).toEqual(true);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-05-01 15:08:00 +05:30
|
|
|
|
|
|
|
it('does not render jump to discussion button', () => {
|
|
|
|
expect(
|
|
|
|
vm.$el.querySelector('*[data-original-title="Jump to next unresolved discussion"]'),
|
|
|
|
).toBeNull();
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
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 => {
|
|
|
|
const discussion = getJSONFixture(discussionWithTwoUnresolvedNotes)[0];
|
|
|
|
discussion.notes[0].resolved = false;
|
|
|
|
vm.$store.dispatch('setInitialNotes', [discussion, discussion]);
|
|
|
|
|
|
|
|
Vue.nextTick()
|
|
|
|
.then(() => {
|
|
|
|
expect(vm.hasMultipleUnresolvedDiscussions).toBe(true);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('methods', () => {
|
|
|
|
describe('jumpToNextDiscussion', () => {
|
|
|
|
it('expands next unresolved discussion', () => {
|
|
|
|
spyOn(vm, 'expandDiscussion').and.stub();
|
|
|
|
const discussions = [
|
|
|
|
discussionMock,
|
|
|
|
{
|
|
|
|
...discussionMock,
|
|
|
|
id: discussionMock.id + 1,
|
|
|
|
notes: [{ ...discussionMock.notes[0], resolvable: true, resolved: true }],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
...discussionMock,
|
|
|
|
id: discussionMock.id + 2,
|
|
|
|
notes: [{ ...discussionMock.notes[0], resolvable: true, resolved: false }],
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const nextDiscussionId = discussionMock.id + 2;
|
|
|
|
store.replaceState({
|
|
|
|
...store.state,
|
|
|
|
discussions,
|
|
|
|
});
|
|
|
|
setFixtures(`
|
|
|
|
<div data-discussion-id="${nextDiscussionId}"></div>
|
|
|
|
`);
|
|
|
|
|
|
|
|
vm.jumpToNextDiscussion();
|
|
|
|
|
|
|
|
expect(vm.expandDiscussion).toHaveBeenCalledWith({ discussionId: nextDiscussionId });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|