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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

215 lines
6.3 KiB
JavaScript
Raw Normal View History

2021-03-08 18:12:59 +05:30
import { mount } from '@vue/test-utils';
2021-03-11 19:13:27 +05:30
import { nextTick } from 'vue';
2021-11-18 22:05:49 +05:30
import discussionWithTwoUnresolvedNotes from 'test_fixtures/merge_requests/resolved_diff_discussion.json';
2020-10-24 23:57:45 +05:30
import { trimText } from 'helpers/text_helper';
2022-08-13 15:12:31 +05:30
import { getDiffFileMock } from 'jest/diffs/mock_data/diff_file';
2021-03-08 18:12:59 +05:30
import DiscussionNotes from '~/notes/components/discussion_notes.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';
2021-03-11 19:13:27 +05:30
import NoteableDiscussion from '~/notes/components/noteable_discussion.vue';
import createStore from '~/notes/stores';
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';
2018-03-17 18:26:18 +05:30
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
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);
2021-03-08 18:12:59 +05:30
wrapper = mount(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
});
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
});
2021-03-08 18:12:59 +05:30
it('should render thread header', async () => {
2018-12-13 13:39:08 +05:30
const discussion = { ...discussionMock };
2022-08-13 15:12:31 +05:30
discussion.diff_file = getDiffFileMock();
2018-12-13 13:39:08 +05:30
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 });
2021-03-08 18:12:59 +05:30
await nextTick();
2018-12-13 13:39:08 +05:30
2021-03-08 18:12:59 +05:30
expect(wrapper.find('.discussion-header').exists()).toBe(true);
2018-03-17 18:26:18 +05:30
});
2021-09-04 01:27:46 +05:30
it('should hide actions when diff refs do not exists', async () => {
const discussion = { ...discussionMock };
2022-08-13 15:12:31 +05:30
discussion.diff_file = { ...getDiffFileMock(), diff_refs: null };
2021-09-04 01:27:46 +05:30
discussion.diff_discussion = true;
discussion.expanded = false;
wrapper.setProps({ discussion });
await nextTick();
expect(wrapper.vm.canShowReplyActions).toBe(false);
});
2018-03-17 18:26:18 +05:30
describe('actions', () => {
2021-03-08 18:12:59 +05:30
it('should toggle reply form', async () => {
await nextTick();
2019-03-02 22:35:43 +05:30
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.isReplying).toEqual(false);
2019-03-02 22:35:43 +05:30
2021-03-08 18:12:59 +05:30
const replyPlaceholder = wrapper.find(ReplyPlaceholder);
2021-04-17 20:07:23 +05:30
replyPlaceholder.vm.$emit('focus');
2021-03-08 18:12:59 +05:30
await nextTick();
2019-07-07 11:18:12 +05:30
2021-03-08 18:12:59 +05:30
expect(wrapper.vm.isReplying).toEqual(true);
2019-07-07 11:18:12 +05:30
2021-03-08 18:12:59 +05:30
const noteForm = wrapper.find(NoteForm);
2019-07-07 11:18:12 +05:30
2021-03-08 18:12:59 +05:30
expect(noteForm.exists()).toBe(true);
2019-07-07 11:18:12 +05:30
2021-03-08 18:12:59 +05:30
const noteFormProps = noteForm.props();
expect(noteFormProps.discussion).toBe(discussionMock);
expect(noteFormProps.line).toBe(null);
expect(noteFormProps.autosaveKey).toBe(`Note/Issue/${discussionMock.id}/Reply`);
2018-03-17 18:26:18 +05:30
});
2018-05-01 15:08:00 +05:30
2022-07-23 23:45:48 +05:30
it.each`
noteType | isNoteInternal | saveButtonTitle
${'public'} | ${false} | ${'Reply'}
${'internal'} | ${true} | ${'Reply internally'}
`(
'reply button on form should have title "$saveButtonTitle" when note is $noteType',
async ({ isNoteInternal, saveButtonTitle }) => {
wrapper.setProps({ discussion: { ...discussionMock, confidential: isNoteInternal } });
await nextTick();
const replyPlaceholder = wrapper.find(ReplyPlaceholder);
replyPlaceholder.vm.$emit('focus');
await nextTick();
expect(wrapper.find(NoteForm).props('saveButtonTitle')).toBe(saveButtonTitle);
},
);
2020-10-24 23:57:45 +05:30
it('should expand discussion', async () => {
2021-03-08 18:12:59 +05:30
const discussion = { ...discussionMock, expanded: false };
2020-10-24 23:57:45 +05:30
wrapper.setProps({ discussion });
2021-03-08 18:12:59 +05:30
store.dispatch = jest.fn();
2020-10-24 23:57:45 +05:30
2021-03-08 18:12:59 +05:30
await nextTick();
2020-10-24 23:57:45 +05:30
2021-03-08 18:12:59 +05:30
wrapper.find(DiscussionNotes).vm.$emit('startReplying');
2020-10-24 23:57:45 +05:30
2021-03-08 18:12:59 +05:30
await nextTick();
2020-10-24 23:57:45 +05:30
2021-03-08 18:12:59 +05:30
expect(store.dispatch).toHaveBeenCalledWith('expandDiscussion', {
discussionId: discussion.id,
});
2020-10-24 23:57:45 +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(() => {
2021-11-18 22:05:49 +05:30
const discussion = discussionWithTwoUnresolvedNotes[0];
2019-07-07 11:18:12 +05:30
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 = {
2021-11-18 22:05:49 +05:30
...discussionWithTwoUnresolvedNotes[0],
2019-07-07 11:18:12 +05:30
expanded: true,
};
2021-04-29 21:17:54 +05:30
discussion.resolved = false;
2019-07-07 11:18:12 +05:30
wrapper.setProps({ discussion });
2019-12-26 22:10:19 +05:30
2021-03-08 18:12:59 +05:30
return 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);
2021-03-08 18:12:59 +05:30
wrapper = mount(NoteableDiscussion, {
2020-03-13 15:44:24 +05:30
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);
2021-03-08 18:12:59 +05:30
wrapper = mount(NoteableDiscussion, {
2020-03-13 15:44:24 +05:30
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');
});
});
});
2018-03-17 18:26:18 +05:30
});