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

188 lines
5.4 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';
2020-03-13 15:44:24 +05:30
import {
noteableDataMock,
discussionMock,
notesDataMock,
loggedOutnoteableData,
userDataMock,
} from '../mock_data';
2020-04-22 19:07:51 +05:30
import mockDiffFile from 'jest/diffs/mock_data/diff_file';
import { trimText } from 'helpers/text_helper';
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;
2020-03-13 15:44:24 +05:30
let originalGon;
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,
});
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
});
2020-04-22 19:07:51 +05:30
it('should render thread header', () => {
2018-12-13 13:39:08 +05:30
const discussion = { ...discussionMock };
discussion.diff_file = mockDiffFile;
discussion.diff_discussion = true;
2020-04-22 19:07:51 +05:30
discussion.expanded = false;
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
2020-04-22 19:07:51 +05:30
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.find('.discussion-header').exists()).toBe(true);
});
2018-03-17 18:26:18 +05:30
});
describe('actions', () => {
2020-04-22 19:07:51 +05:30
it('should toggle reply form', () => {
2019-03-02 22:35:43 +05:30
const replyPlaceholder = wrapper.find(ReplyPlaceholder);
2020-04-22 19:07:51 +05:30
return wrapper.vm
2019-03-02 22:35:43 +05:30
.$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`);
2020-04-22 19:07:51 +05:30
});
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
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', () => {
2020-04-22 19:07:51 +05:30
beforeEach(() => {
2019-07-07 11:18:12 +05:30
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
2020-04-22 19:07:51 +05:30
return wrapper.vm.$nextTick();
2019-07-07 11:18:12 +05:30
});
it('displays a button to resolve with issue', () => {
const button = wrapper.find(ResolveWithIssueButton);
expect(button.exists()).toBe(true);
});
});
2020-03-13 15:44:24 +05:30
describe('signout widget', () => {
beforeEach(() => {
2020-05-24 23:13:21 +05:30
originalGon = { ...window.gon };
2020-03-13 15:44:24 +05:30
window.gon = window.gon || {};
});
afterEach(() => {
wrapper.destroy();
window.gon = originalGon;
});
describe('user is logged in', () => {
beforeEach(() => {
window.gon.current_user_id = userDataMock.id;
store.dispatch('setUserData', userDataMock);
wrapper = mount(localVue.extend(noteableDiscussion), {
store,
propsData: { discussion: discussionMock },
localVue,
});
});
it('should not render signed out widget', () => {
expect(Boolean(wrapper.vm.isLoggedIn)).toBe(true);
expect(trimText(wrapper.text())).not.toContain('Please register or sign in to reply');
});
});
describe('user is not logged in', () => {
beforeEach(() => {
window.gon.current_user_id = null;
store.dispatch('setNoteableData', loggedOutnoteableData);
store.dispatch('setNotesData', notesDataMock);
wrapper = mount(localVue.extend(noteableDiscussion), {
store,
propsData: { discussion: discussionMock },
localVue,
});
});
it('should render signed out widget', () => {
expect(Boolean(wrapper.vm.isLoggedIn)).toBe(false);
expect(trimText(wrapper.text())).toContain('Please register or sign in to reply');
});
});
});
2018-03-17 18:26:18 +05:30
});