debian-mirror-gitlab/spec/javascripts/notes/components/noteable_discussion_spec.js

134 lines
3.9 KiB
JavaScript
Raw Normal View History

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-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', () => {
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(() => {
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);
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
});
2018-12-13 13:39:08 +05:30
it('should not render discussion header for non diff discussions', () => {
expect(vm.$el.querySelector('.discussion-header')).toBeNull();
});
2018-03-17 18:26:18 +05:30
it('should render discussion header', () => {
2018-12-13 13:39:08 +05:30
const discussion = { ...discussionMock };
discussion.diff_file = mockDiffFile;
discussion.diff_discussion = true;
const diffDiscussionVm = new Component({
store,
propsData: { discussion },
}).$mount();
expect(diffDiscussionVm.$el.querySelector('.discussion-header')).not.toBeNull();
2018-03-17 18:26:18 +05:30
});
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();
2018-11-18 11:00:15 +05:30
2018-03-17 18:26:18 +05:30
Vue.nextTick(() => {
expect(vm.isReplying).toEqual(true);
2018-11-18 11:00:15 +05:30
// There is a watcher for `isReplying` which will init autosave in the next tick
Vue.nextTick(() => {
expect(vm.$refs.noteForm).not.toBeNull();
done();
});
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(
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('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;
2018-12-23 12:14:25 +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)
vm.$store.dispatch('setInitialNotes', [discussionMock, discussion2]);
window.mrTabs.currentAction = 'show';
Vue.nextTick()
.then(() => {
spyOn(vm, 'expandDiscussion').and.stub();
const nextDiscussionId = discussion2.id;
setFixtures(`
<div class="discussion" data-discussion-id="${nextDiscussionId}"></div>
`);
2018-11-08 19:23:39 +05:30
2018-11-18 11:00:15 +05:30
vm.jumpToNextDiscussion();
2018-11-08 19:23:39 +05:30
2018-11-18 11:00:15 +05:30
expect(vm.expandDiscussion).toHaveBeenCalledWith({ discussionId: nextDiscussionId });
})
.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
};
const note = 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
};
const note = vm.componentData(data);
2018-12-13 13:39:08 +05:30
2018-12-05 23:21:45 +05:30
expect(note).toEqual(data);
});
});
2018-03-17 18:26:18 +05:30
});