2017-08-11 15:52:29 +00:00
|
|
|
import Vue from 'vue';
|
2018-06-21 12:22:40 +00:00
|
|
|
import createStore from '~/notes/stores';
|
|
|
|
import noteableDiscussion from '~/notes/components/noteable_discussion.vue';
|
|
|
|
import '~/behaviors/markdown/render_gfm';
|
2017-11-30 22:44:41 +00:00
|
|
|
import { noteableDataMock, discussionMock, notesDataMock } from '../mock_data';
|
2017-08-10 17:36:39 +00:00
|
|
|
|
2018-06-21 12:22:40 +00:00
|
|
|
describe('noteable_discussion component', () => {
|
|
|
|
let store;
|
2017-08-11 15:52:29 +00:00
|
|
|
let vm;
|
2017-08-04 15:51:35 +00:00
|
|
|
|
2017-08-11 15:52:29 +00:00
|
|
|
beforeEach(() => {
|
2018-06-21 12:22:40 +00:00
|
|
|
const Component = Vue.extend(noteableDiscussion);
|
2017-08-04 15:51:35 +00:00
|
|
|
|
2018-06-21 12:22:40 +00:00
|
|
|
store = createStore();
|
2017-11-30 22:44:41 +00:00
|
|
|
store.dispatch('setNoteableData', noteableDataMock);
|
2017-08-11 15:52:29 +00:00
|
|
|
store.dispatch('setNotesData', notesDataMock);
|
2017-08-04 15:51:35 +00:00
|
|
|
|
2017-08-11 15:52:29 +00:00
|
|
|
vm = new Component({
|
|
|
|
store,
|
|
|
|
propsData: {
|
2018-06-21 12:22:40 +00:00
|
|
|
discussion: discussionMock,
|
2017-08-11 15:52:29 +00:00
|
|
|
},
|
|
|
|
}).$mount();
|
2017-08-04 15:51:35 +00:00
|
|
|
});
|
|
|
|
|
2017-08-11 15:52:29 +00:00
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
2017-08-04 15:51:35 +00:00
|
|
|
|
2017-08-11 15:52:29 +00:00
|
|
|
it('should render user avatar', () => {
|
2018-03-28 05:11:06 +00:00
|
|
|
expect(vm.$el.querySelector('.user-avatar-link')).not.toBeNull();
|
2017-08-11 15:52:29 +00:00
|
|
|
});
|
2017-08-04 15:51:35 +00:00
|
|
|
|
2017-08-11 15:52:29 +00:00
|
|
|
it('should render discussion header', () => {
|
2018-03-28 05:11:06 +00:00
|
|
|
expect(vm.$el.querySelector('.discussion-header')).not.toBeNull();
|
2017-12-08 20:24:52 +00:00
|
|
|
expect(vm.$el.querySelector('.notes').children.length).toEqual(discussionMock.notes.length);
|
2017-08-11 15:52:29 +00:00
|
|
|
});
|
2017-08-04 15:51:35 +00:00
|
|
|
|
2017-08-11 15:52:29 +00:00
|
|
|
describe('actions', () => {
|
|
|
|
it('should render reply button', () => {
|
2018-03-28 05:11:06 +00:00
|
|
|
expect(vm.$el.querySelector('.js-vue-discussion-reply').textContent.trim()).toEqual(
|
|
|
|
'Reply...',
|
|
|
|
);
|
2017-08-04 15:51:35 +00:00
|
|
|
});
|
|
|
|
|
2018-03-28 05:11:06 +00:00
|
|
|
it('should toggle reply form', done => {
|
2017-08-11 15:52:29 +00:00
|
|
|
vm.$el.querySelector('.js-vue-discussion-reply').click();
|
|
|
|
Vue.nextTick(() => {
|
2018-03-28 05:11:06 +00:00
|
|
|
expect(vm.$refs.noteForm).not.toBeNull();
|
2017-08-11 15:52:29 +00:00
|
|
|
expect(vm.isReplying).toEqual(true);
|
|
|
|
done();
|
2017-08-04 15:51:35 +00:00
|
|
|
});
|
|
|
|
});
|
2018-03-28 05:11:06 +00: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 15:51:35 +00:00
|
|
|
});
|
2018-06-21 12:22:40 +00: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 => {
|
|
|
|
spyOnProperty(vm, 'unresolvedDiscussions').and.returnValue([{}, {}]);
|
|
|
|
|
|
|
|
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], resolved: true }],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
...discussionMock,
|
|
|
|
id: discussionMock.id + 2,
|
|
|
|
notes: [{ ...discussionMock.notes[0], 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 });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-08-09 19:13:00 +00:00
|
|
|
});
|