2020-12-25 04:10:31 -05:00
|
|
|
import { mount } from '@vue/test-utils';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { nextTick } from 'vue';
|
2021-10-08 08:11:10 -04:00
|
|
|
import discussionWithTwoUnresolvedNotes from 'test_fixtures/merge_requests/resolved_diff_discussion.json';
|
2020-08-17 17:09:56 -04:00
|
|
|
import { trimText } from 'helpers/text_helper';
|
2021-02-14 13:09:20 -05:00
|
|
|
import mockDiffFile from 'jest/diffs/mock_data/diff_file';
|
2020-12-25 04:10:31 -05:00
|
|
|
import DiscussionNotes from '~/notes/components/discussion_notes.vue';
|
2019-02-05 03:56:34 -05:00
|
|
|
import ReplyPlaceholder from '~/notes/components/discussion_reply_placeholder.vue';
|
2019-02-25 11:38:29 -05:00
|
|
|
import ResolveWithIssueButton from '~/notes/components/discussion_resolve_with_issue_button.vue';
|
2019-02-26 13:03:00 -05:00
|
|
|
import NoteForm from '~/notes/components/note_form.vue';
|
2021-02-14 13:09:20 -05:00
|
|
|
import NoteableDiscussion from '~/notes/components/noteable_discussion.vue';
|
|
|
|
import createStore from '~/notes/stores';
|
2018-06-21 08:22:40 -04:00
|
|
|
import '~/behaviors/markdown/render_gfm';
|
2019-12-30 10:09:15 -05:00
|
|
|
import {
|
|
|
|
noteableDataMock,
|
|
|
|
discussionMock,
|
|
|
|
notesDataMock,
|
|
|
|
loggedOutnoteableData,
|
|
|
|
userDataMock,
|
|
|
|
} from '../mock_data';
|
2017-08-10 13:36:39 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
describe('noteable_discussion component', () => {
|
|
|
|
let store;
|
2019-01-29 07:16:30 -05:00
|
|
|
let wrapper;
|
2019-12-30 10:09:15 -05:00
|
|
|
let originalGon;
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2018-07-05 18:10:38 -04:00
|
|
|
beforeEach(() => {
|
2018-07-31 22:21:14 -04:00
|
|
|
window.mrTabs = {};
|
2018-06-21 08:22:40 -04:00
|
|
|
store = createStore();
|
2017-11-30 17:44:41 -05:00
|
|
|
store.dispatch('setNoteableData', noteableDataMock);
|
2017-08-11 11:52:29 -04:00
|
|
|
store.dispatch('setNotesData', notesDataMock);
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2020-12-25 04:10:31 -05:00
|
|
|
wrapper = mount(NoteableDiscussion, {
|
2017-08-11 11:52:29 -04:00
|
|
|
store,
|
2018-07-05 18:10:38 -04:00
|
|
|
propsData: { discussion: discussionMock },
|
2019-01-29 07:16:30 -05:00
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
|
2017-08-11 11:52:29 -04:00
|
|
|
afterEach(() => {
|
2019-01-29 07:16:30 -05:00
|
|
|
wrapper.destroy();
|
2017-08-11 11:52:29 -04:00
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2019-06-14 05:28:16 -04:00
|
|
|
it('should not render thread header for non diff threads', () => {
|
2019-01-29 07:16:30 -05:00
|
|
|
expect(wrapper.find('.discussion-header').exists()).toBe(false);
|
2018-11-08 02:58:45 -05:00
|
|
|
});
|
|
|
|
|
2020-12-25 04:10:31 -05:00
|
|
|
it('should render thread header', async () => {
|
2018-11-08 02:58:45 -05:00
|
|
|
const discussion = { ...discussionMock };
|
|
|
|
discussion.diff_file = mockDiffFile;
|
|
|
|
discussion.diff_discussion = true;
|
2020-04-02 14:08:11 -04:00
|
|
|
discussion.expanded = false;
|
2018-12-11 05:22:00 -05:00
|
|
|
|
2019-01-29 07:16:30 -05:00
|
|
|
wrapper.setProps({ discussion });
|
2020-12-25 04:10:31 -05:00
|
|
|
await nextTick();
|
2018-11-08 02:58:45 -05:00
|
|
|
|
2020-12-25 04:10:31 -05:00
|
|
|
expect(wrapper.find('.discussion-header').exists()).toBe(true);
|
2017-08-11 11:52:29 -04:00
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2021-06-08 05:09:56 -04:00
|
|
|
it('should hide actions when diff refs do not exists', async () => {
|
|
|
|
const discussion = { ...discussionMock };
|
|
|
|
discussion.diff_file = { ...mockDiffFile, diff_refs: null };
|
|
|
|
discussion.diff_discussion = true;
|
|
|
|
discussion.expanded = false;
|
|
|
|
|
|
|
|
wrapper.setProps({ discussion });
|
|
|
|
await nextTick();
|
|
|
|
|
|
|
|
expect(wrapper.vm.canShowReplyActions).toBe(false);
|
|
|
|
});
|
|
|
|
|
2017-08-11 11:52:29 -04:00
|
|
|
describe('actions', () => {
|
2020-12-25 04:10:31 -05:00
|
|
|
it('should toggle reply form', async () => {
|
|
|
|
await nextTick();
|
2019-02-05 03:56:34 -05:00
|
|
|
|
2020-12-25 04:10:31 -05:00
|
|
|
expect(wrapper.vm.isReplying).toEqual(false);
|
2019-02-05 03:56:34 -05:00
|
|
|
|
2020-12-25 04:10:31 -05:00
|
|
|
const replyPlaceholder = wrapper.find(ReplyPlaceholder);
|
2021-02-18 01:09:43 -05:00
|
|
|
replyPlaceholder.vm.$emit('focus');
|
2020-12-25 04:10:31 -05:00
|
|
|
await nextTick();
|
2019-02-26 13:03:00 -05:00
|
|
|
|
2020-12-25 04:10:31 -05:00
|
|
|
expect(wrapper.vm.isReplying).toEqual(true);
|
2019-02-26 13:03:00 -05:00
|
|
|
|
2020-12-25 04:10:31 -05:00
|
|
|
const noteForm = wrapper.find(NoteForm);
|
2019-02-26 13:03:00 -05:00
|
|
|
|
2020-12-25 04:10:31 -05:00
|
|
|
expect(noteForm.exists()).toBe(true);
|
2019-02-26 13:03:00 -05:00
|
|
|
|
2020-12-25 04:10:31 -05:00
|
|
|
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`);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
2018-03-28 01:11:06 -04:00
|
|
|
|
2020-08-18 08:10:16 -04:00
|
|
|
it('should expand discussion', async () => {
|
2020-12-25 04:10:31 -05:00
|
|
|
const discussion = { ...discussionMock, expanded: false };
|
2020-08-18 08:10:16 -04:00
|
|
|
|
|
|
|
wrapper.setProps({ discussion });
|
2020-12-25 04:10:31 -05:00
|
|
|
store.dispatch = jest.fn();
|
2020-08-18 08:10:16 -04:00
|
|
|
|
2020-12-25 04:10:31 -05:00
|
|
|
await nextTick();
|
2020-08-18 08:10:16 -04:00
|
|
|
|
2020-12-25 04:10:31 -05:00
|
|
|
wrapper.find(DiscussionNotes).vm.$emit('startReplying');
|
2020-08-18 08:10:16 -04:00
|
|
|
|
2020-12-25 04:10:31 -05:00
|
|
|
await nextTick();
|
2020-08-18 08:10:16 -04:00
|
|
|
|
2020-12-25 04:10:31 -05:00
|
|
|
expect(store.dispatch).toHaveBeenCalledWith('expandDiscussion', {
|
|
|
|
discussionId: discussion.id,
|
|
|
|
});
|
2020-08-18 08:10:16 -04:00
|
|
|
});
|
|
|
|
|
2019-06-14 05:28:16 -04:00
|
|
|
it('does not render jump to thread button', () => {
|
2019-06-14 08:17:02 -04:00
|
|
|
expect(wrapper.find('*[data-original-title="Jump to next unresolved thread"]').exists()).toBe(
|
|
|
|
false,
|
|
|
|
);
|
2018-03-28 01:11:06 -04:00
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
2018-06-21 08:22:40 -04:00
|
|
|
|
2019-06-14 05:28:16 -04:00
|
|
|
describe('for resolved thread', () => {
|
2019-02-25 11:38:29 -05:00
|
|
|
beforeEach(() => {
|
2021-10-08 08:11:10 -04:00
|
|
|
const discussion = discussionWithTwoUnresolvedNotes[0];
|
2019-02-25 11:38:29 -05:00
|
|
|
wrapper.setProps({ discussion });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not display a button to resolve with issue', () => {
|
|
|
|
const button = wrapper.find(ResolveWithIssueButton);
|
|
|
|
|
|
|
|
expect(button.exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-06-14 05:28:16 -04:00
|
|
|
describe('for unresolved thread', () => {
|
2020-04-02 14:08:11 -04:00
|
|
|
beforeEach(() => {
|
2019-02-25 11:38:29 -05:00
|
|
|
const discussion = {
|
2021-10-08 08:11:10 -04:00
|
|
|
...discussionWithTwoUnresolvedNotes[0],
|
2019-02-25 11:38:29 -05:00
|
|
|
expanded: true,
|
|
|
|
};
|
2021-03-31 17:09:15 -04:00
|
|
|
discussion.resolved = false;
|
2019-02-25 11:38:29 -05:00
|
|
|
|
|
|
|
wrapper.setProps({ discussion });
|
2019-11-12 13:06:57 -05:00
|
|
|
|
2020-12-25 04:10:31 -05:00
|
|
|
return nextTick();
|
2019-02-25 11:38:29 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('displays a button to resolve with issue', () => {
|
|
|
|
const button = wrapper.find(ResolveWithIssueButton);
|
|
|
|
|
|
|
|
expect(button.exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
2019-12-30 10:09:15 -05:00
|
|
|
|
|
|
|
describe('signout widget', () => {
|
|
|
|
beforeEach(() => {
|
2020-05-07 17:09:26 -04:00
|
|
|
originalGon = { ...window.gon };
|
2019-12-30 10:09:15 -05:00
|
|
|
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);
|
|
|
|
|
2020-12-25 04:10:31 -05:00
|
|
|
wrapper = mount(NoteableDiscussion, {
|
2019-12-30 10:09:15 -05:00
|
|
|
store,
|
|
|
|
propsData: { discussion: discussionMock },
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2020-12-25 04:10:31 -05:00
|
|
|
wrapper = mount(NoteableDiscussion, {
|
2019-12-30 10:09:15 -05:00
|
|
|
store,
|
|
|
|
propsData: { discussion: discussionMock },
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-08-09 15:13:00 -04:00
|
|
|
});
|