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

171 lines
5 KiB
JavaScript
Raw Normal View History

2019-12-26 22:10:19 +05:30
import { mount, 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-07-07 11:18:12 +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';
2020-01-01 13:55:28 +05:30
const localVue = createLocalVue();
2018-11-08 19:23:39 +05:30
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);
2020-01-01 13:55:28 +05:30
wrapper = mount(localVue.extend(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
});
2019-09-30 21:07:59 +05:30
it('should not render thread header for non diff threads', () => {
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-09-30 21:07:59 +05:30
it('should render thread 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-07-07 11:18:12 +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
2019-09-30 21:07:59 +05:30
it('does not render jump to thread button', () => {
expect(wrapper.find('*[data-original-title="Jump to next unresolved thread"]').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', () => {
2019-09-30 21:07:59 +05:30
it('expands next unresolved thread', done => {
2018-11-18 11:00:15 +05:30
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;
2019-09-30 21:07:59 +05:30
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
2019-09-30 21:07:59 +05:30
describe('for resolved thread', () => {
2019-07-07 11:18:12 +05:30
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);
});
});
2019-09-30 21:07:59 +05:30
describe('for unresolved thread', () => {
2019-07-07 11:18:12 +05:30
beforeEach(done => {
const discussion = {
...getJSONFixture(discussionWithTwoUnresolvedNotes)[0],
expanded: true,
};
discussion.notes = discussion.notes.map(note => ({
...note,
resolved: false,
2019-12-04 20:38:33 +05:30
current_user: {
...note.current_user,
can_resolve: true,
},
2019-07-07 11:18:12 +05:30
}));
wrapper.setProps({ discussion });
2019-12-26 22:10:19 +05:30
2019-07-07 11:18:12 +05:30
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
});