2017-08-11 11:39:16 -04:00
|
|
|
import Vue from 'vue';
|
2020-11-16 13:09:15 -05:00
|
|
|
import { mount, createLocalVue, createWrapper } from '@vue/test-utils';
|
2019-12-09 07:07:58 -05:00
|
|
|
import { TEST_HOST } from 'spec/test_constants';
|
2020-08-17 17:09:56 -04:00
|
|
|
import AxiosMockAdapter from 'axios-mock-adapter';
|
2018-06-21 08:22:40 -04:00
|
|
|
import createStore from '~/notes/stores';
|
2017-12-04 11:19:07 -05:00
|
|
|
import noteActions from '~/notes/components/note_actions.vue';
|
2017-08-11 11:39:16 -04:00
|
|
|
import { userDataMock } from '../mock_data';
|
2020-06-16 17:08:20 -04:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2017-08-11 11:39:16 -04:00
|
|
|
|
2019-01-25 04:59:22 -05:00
|
|
|
describe('noteActions', () => {
|
|
|
|
let wrapper;
|
2018-06-21 08:22:40 -04:00
|
|
|
let store;
|
2019-02-06 05:31:46 -05:00
|
|
|
let props;
|
2020-06-16 17:08:20 -04:00
|
|
|
let actions;
|
|
|
|
let axiosMock;
|
2019-02-06 05:31:46 -05:00
|
|
|
|
2020-11-16 13:09:15 -05:00
|
|
|
const mountNoteActions = (propsData, computed) => {
|
2019-02-06 05:31:46 -05:00
|
|
|
const localVue = createLocalVue();
|
2020-11-16 13:09:15 -05:00
|
|
|
return mount(localVue.extend(noteActions), {
|
2019-02-06 05:31:46 -05:00
|
|
|
store,
|
|
|
|
propsData,
|
|
|
|
localVue,
|
2020-06-16 17:08:20 -04:00
|
|
|
computed,
|
2019-02-06 05:31:46 -05:00
|
|
|
});
|
|
|
|
};
|
2017-08-11 11:39:16 -04:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2018-06-21 08:22:40 -04:00
|
|
|
store = createStore();
|
2020-06-16 17:08:20 -04:00
|
|
|
|
2019-02-06 05:31:46 -05:00
|
|
|
props = {
|
|
|
|
accessLevel: 'Maintainer',
|
2020-06-16 17:08:20 -04:00
|
|
|
authorId: 1,
|
|
|
|
author: userDataMock,
|
2019-02-06 05:31:46 -05:00
|
|
|
canDelete: true,
|
|
|
|
canEdit: true,
|
|
|
|
canAwardEmoji: true,
|
|
|
|
canReportAsAbuse: true,
|
2020-09-16 11:09:32 -04:00
|
|
|
isAuthor: true,
|
|
|
|
isContributor: false,
|
|
|
|
noteableType: 'MergeRequest',
|
2019-02-06 05:31:46 -05:00
|
|
|
noteId: '539',
|
2020-01-20 19:08:46 -05:00
|
|
|
noteUrl: `${TEST_HOST}/group/project/-/merge_requests/1#note_1`,
|
2020-09-16 11:09:32 -04:00
|
|
|
projectName: 'project',
|
2019-02-06 05:31:46 -05:00
|
|
|
reportAbusePath: `${TEST_HOST}/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-ce%2Fissues%2F7%23note_539&user_id=26`,
|
|
|
|
showReply: false,
|
|
|
|
};
|
2020-06-16 17:08:20 -04:00
|
|
|
|
|
|
|
actions = {
|
|
|
|
updateAssignees: jest.fn(),
|
|
|
|
};
|
|
|
|
|
|
|
|
axiosMock = new AxiosMockAdapter(axios);
|
2017-08-11 11:39:16 -04:00
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2017-08-11 11:39:16 -04:00
|
|
|
afterEach(() => {
|
2019-01-25 04:59:22 -05:00
|
|
|
wrapper.destroy();
|
2020-06-16 17:08:20 -04:00
|
|
|
axiosMock.restore();
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('user is logged in', () => {
|
2017-08-11 11:39:16 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
store.dispatch('setUserData', userDataMock);
|
|
|
|
|
2020-11-16 13:09:15 -05:00
|
|
|
wrapper = mountNoteActions(props);
|
2017-08-11 11:39:16 -04:00
|
|
|
});
|
|
|
|
|
2020-09-16 11:09:32 -04:00
|
|
|
it('should render noteable author badge', () => {
|
2020-12-23 07:10:26 -05:00
|
|
|
expect(wrapper.findAll('.note-role').at(0).text().trim()).toEqual('Author');
|
2020-09-16 11:09:32 -04:00
|
|
|
});
|
|
|
|
|
2017-08-11 11:39:16 -04:00
|
|
|
it('should render access level badge', () => {
|
2020-12-23 07:10:26 -05:00
|
|
|
expect(wrapper.findAll('.note-role').at(1).text().trim()).toEqual(props.accessLevel);
|
2017-08-11 11:39:16 -04:00
|
|
|
});
|
|
|
|
|
2020-09-16 11:09:32 -04:00
|
|
|
it('should render contributor badge', () => {
|
|
|
|
wrapper.setProps({
|
|
|
|
accessLevel: null,
|
|
|
|
isContributor: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
2020-12-23 07:10:26 -05:00
|
|
|
expect(wrapper.findAll('.note-role').at(1).text().trim()).toBe('Contributor');
|
2020-09-16 11:09:32 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-08-11 11:39:16 -04:00
|
|
|
it('should render emoji link', () => {
|
2019-01-25 04:59:22 -05:00
|
|
|
expect(wrapper.find('.js-add-award').exists()).toBe(true);
|
2019-05-31 08:45:37 -04:00
|
|
|
expect(wrapper.find('.js-add-award').attributes('data-position')).toBe('right');
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('actions dropdown', () => {
|
|
|
|
it('should be possible to edit the comment', () => {
|
2019-01-25 04:59:22 -05:00
|
|
|
expect(wrapper.find('.js-note-edit').exists()).toBe(true);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
|
2019-06-06 06:05:42 -04:00
|
|
|
it('should be possible to report abuse to admin', () => {
|
2019-01-25 04:59:22 -05:00
|
|
|
expect(wrapper.find(`a[href="${props.reportAbusePath}"]`).exists()).toBe(true);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
|
2018-09-07 09:39:20 -04:00
|
|
|
it('should be possible to copy link to a note', () => {
|
2019-01-25 04:59:22 -05:00
|
|
|
expect(wrapper.find('.js-btn-copy-note-link').exists()).toBe(true);
|
2018-09-07 09:39:20 -04:00
|
|
|
});
|
|
|
|
|
2020-12-23 19:10:25 -05:00
|
|
|
it('should not show copy link action when `noteUrl` prop is empty', (done) => {
|
2019-01-25 04:59:22 -05:00
|
|
|
wrapper.setProps({
|
|
|
|
...props,
|
2020-06-16 17:08:20 -04:00
|
|
|
author: {
|
|
|
|
avatar_url: 'mock_path',
|
|
|
|
id: 26,
|
|
|
|
name: 'Example Maintainer',
|
|
|
|
path: '/ExampleMaintainer',
|
|
|
|
state: 'active',
|
|
|
|
username: 'ExampleMaintainer',
|
|
|
|
},
|
2019-01-25 04:59:22 -05:00
|
|
|
noteUrl: '',
|
|
|
|
});
|
|
|
|
|
2018-09-07 09:39:20 -04:00
|
|
|
Vue.nextTick()
|
|
|
|
.then(() => {
|
2019-01-25 04:59:22 -05:00
|
|
|
expect(wrapper.find('.js-btn-copy-note-link').exists()).toBe(false);
|
2018-09-07 09:39:20 -04:00
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
2017-08-04 11:51:35 -04:00
|
|
|
it('should be possible to delete comment', () => {
|
2019-01-25 04:59:22 -05:00
|
|
|
expect(wrapper.find('.js-note-delete').exists()).toBe(true);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
2019-01-09 18:46:43 -05:00
|
|
|
|
2020-12-23 19:10:25 -05:00
|
|
|
it('closes tooltip when dropdown opens', (done) => {
|
2019-01-09 18:46:43 -05:00
|
|
|
wrapper.find('.more-actions-toggle').trigger('click');
|
|
|
|
|
|
|
|
const rootWrapper = createWrapper(wrapper.vm.$root);
|
|
|
|
Vue.nextTick()
|
|
|
|
.then(() => {
|
|
|
|
const emitted = Object.keys(rootWrapper.emitted());
|
|
|
|
|
|
|
|
expect(emitted).toEqual(['bv::hide::tooltip']);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
2020-06-16 17:08:20 -04:00
|
|
|
|
2020-06-30 05:08:37 -04:00
|
|
|
it('should not be possible to assign or unassign the comment author in a merge request', () => {
|
2020-06-16 17:08:20 -04:00
|
|
|
const assignUserButton = wrapper.find('[data-testid="assign-user"]');
|
2020-06-30 05:08:37 -04:00
|
|
|
expect(assignUserButton.exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-06-16 17:08:20 -04:00
|
|
|
|
2020-06-30 05:08:37 -04:00
|
|
|
describe('when a user has access to edit an issue', () => {
|
|
|
|
const testButtonClickTriggersAction = () => {
|
|
|
|
axiosMock.onPut(`${TEST_HOST}/api/v4/projects/group/project/issues/1`).reply(() => {
|
|
|
|
expect(actions.updateAssignees).toHaveBeenCalled();
|
2020-06-16 17:08:20 -04:00
|
|
|
});
|
|
|
|
|
2020-06-30 05:08:37 -04:00
|
|
|
const assignUserButton = wrapper.find('[data-testid="assign-user"]');
|
|
|
|
expect(assignUserButton.exists()).toBe(true);
|
|
|
|
assignUserButton.trigger('click');
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-11-16 13:09:15 -05:00
|
|
|
wrapper = mountNoteActions(props, {
|
2020-06-30 05:08:37 -04:00
|
|
|
targetType: () => 'issue',
|
2020-06-16 17:08:20 -04:00
|
|
|
});
|
2020-06-30 05:08:37 -04:00
|
|
|
store.state.noteableData = {
|
|
|
|
current_user: {
|
|
|
|
can_update: true,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
store.state.userData = userDataMock;
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
2020-06-30 05:08:37 -04:00
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
axiosMock.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be possible to assign the comment author', testButtonClickTriggersAction);
|
|
|
|
it('should be possible to unassign the comment author', testButtonClickTriggersAction);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when a user does not have access to edit an issue', () => {
|
|
|
|
const testButtonDoesNotRender = () => {
|
|
|
|
const assignUserButton = wrapper.find('[data-testid="assign-user"]');
|
|
|
|
expect(assignUserButton.exists()).toBe(false);
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-11-16 13:09:15 -05:00
|
|
|
wrapper = mountNoteActions(props, {
|
2020-06-30 05:08:37 -04:00
|
|
|
targetType: () => 'issue',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not be possible to assign the comment author', testButtonDoesNotRender);
|
|
|
|
it('should not be possible to unassign the comment author', testButtonDoesNotRender);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('user is not logged in', () => {
|
2017-08-11 11:39:16 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
store.dispatch('setUserData', {});
|
2020-11-16 13:09:15 -05:00
|
|
|
wrapper = mountNoteActions({
|
2019-02-06 05:31:46 -05:00
|
|
|
...props,
|
2017-08-11 11:39:16 -04:00
|
|
|
canDelete: false,
|
|
|
|
canEdit: false,
|
2018-04-06 14:19:37 -04:00
|
|
|
canAwardEmoji: false,
|
2017-08-11 11:39:16 -04:00
|
|
|
canReportAsAbuse: false,
|
2019-01-25 04:59:22 -05:00
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
|
2017-08-11 11:39:16 -04:00
|
|
|
it('should not render emoji link', () => {
|
2019-01-25 04:59:22 -05:00
|
|
|
expect(wrapper.find('.js-add-award').exists()).toBe(false);
|
2017-08-11 11:39:16 -04:00
|
|
|
});
|
2017-08-04 11:51:35 -04:00
|
|
|
|
2017-08-11 11:39:16 -04:00
|
|
|
it('should not render actions dropdown', () => {
|
2019-01-25 04:59:22 -05:00
|
|
|
expect(wrapper.find('.more-actions').exists()).toBe(false);
|
2017-08-04 11:51:35 -04:00
|
|
|
});
|
|
|
|
});
|
2019-02-06 05:31:46 -05:00
|
|
|
|
2019-04-02 22:00:18 -04:00
|
|
|
describe('for showReply = true', () => {
|
2019-02-06 05:31:46 -05:00
|
|
|
beforeEach(() => {
|
2020-11-16 13:09:15 -05:00
|
|
|
wrapper = mountNoteActions({
|
2019-04-02 22:00:18 -04:00
|
|
|
...props,
|
|
|
|
showReply: true,
|
2019-02-06 05:31:46 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-02 22:00:18 -04:00
|
|
|
it('shows a reply button', () => {
|
|
|
|
const replyButton = wrapper.find({ ref: 'replyButton' });
|
2019-02-06 05:31:46 -05:00
|
|
|
|
2019-04-02 22:00:18 -04:00
|
|
|
expect(replyButton.exists()).toBe(true);
|
2019-02-06 05:31:46 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-02 22:00:18 -04:00
|
|
|
describe('for showReply = false', () => {
|
2019-02-06 05:31:46 -05:00
|
|
|
beforeEach(() => {
|
2020-11-16 13:09:15 -05:00
|
|
|
wrapper = mountNoteActions({
|
2019-04-02 22:00:18 -04:00
|
|
|
...props,
|
|
|
|
showReply: false,
|
2019-02-06 05:31:46 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-02 22:00:18 -04:00
|
|
|
it('does not show a reply button', () => {
|
|
|
|
const replyButton = wrapper.find({ ref: 'replyButton' });
|
2019-02-06 05:31:46 -05:00
|
|
|
|
2019-04-02 22:00:18 -04:00
|
|
|
expect(replyButton.exists()).toBe(false);
|
2019-02-06 05:31:46 -05:00
|
|
|
});
|
|
|
|
});
|
2020-06-01 02:08:21 -04:00
|
|
|
|
|
|
|
describe('Draft notes', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
store.dispatch('setUserData', userDataMock);
|
|
|
|
|
2020-11-16 13:09:15 -05:00
|
|
|
wrapper = mountNoteActions({ ...props, canResolve: true, isDraft: true });
|
2020-06-01 02:08:21 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the right resolve button title', () => {
|
|
|
|
const resolveButton = wrapper.find({ ref: 'resolveButton' });
|
|
|
|
|
|
|
|
expect(resolveButton.exists()).toBe(true);
|
|
|
|
expect(resolveButton.attributes('title')).toBe('Thread stays unresolved');
|
|
|
|
});
|
|
|
|
});
|
2017-08-09 15:13:00 -04:00
|
|
|
});
|