2022-04-04 11:22:00 +05:30
|
|
|
import { mount, createWrapper } from '@vue/test-utils';
|
2020-10-24 23:57:45 +05:30
|
|
|
import AxiosMockAdapter from 'axios-mock-adapter';
|
2022-04-04 11:22:00 +05:30
|
|
|
import { nextTick } from 'vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { TEST_HOST } from 'spec/test_constants';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
import { BV_HIDE_TOOLTIP } from '~/lib/utils/constants';
|
2018-03-17 18:26:18 +05:30
|
|
|
import noteActions from '~/notes/components/note_actions.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import createStore from '~/notes/stores';
|
2021-04-17 20:07:23 +05:30
|
|
|
import UserAccessRoleBadge from '~/vue_shared/components/user_access_role_badge.vue';
|
2018-03-17 18:26:18 +05:30
|
|
|
import { userDataMock } from '../mock_data';
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
describe('noteActions', () => {
|
|
|
|
let wrapper;
|
2018-11-08 19:23:39 +05:30
|
|
|
let store;
|
2019-03-02 22:35:43 +05:30
|
|
|
let props;
|
2020-06-23 00:09:42 +05:30
|
|
|
let actions;
|
|
|
|
let axiosMock;
|
2019-03-02 22:35:43 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
const findUserAccessRoleBadge = (idx) => wrapper.findAll(UserAccessRoleBadge).at(idx);
|
|
|
|
const findUserAccessRoleBadgeText = (idx) => findUserAccessRoleBadge(idx).text().trim();
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
const mountNoteActions = (propsData, computed) => {
|
2022-04-04 11:22:00 +05:30
|
|
|
return mount(noteActions, {
|
2019-03-02 22:35:43 +05:30
|
|
|
store,
|
|
|
|
propsData,
|
2020-06-23 00:09:42 +05:30
|
|
|
computed,
|
2019-03-02 22:35:43 +05:30
|
|
|
});
|
|
|
|
};
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
2018-11-08 19:23:39 +05:30
|
|
|
store = createStore();
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
props = {
|
|
|
|
accessLevel: 'Maintainer',
|
2020-06-23 00:09:42 +05:30
|
|
|
authorId: 1,
|
|
|
|
author: userDataMock,
|
2019-03-02 22:35:43 +05:30
|
|
|
canDelete: true,
|
|
|
|
canEdit: true,
|
|
|
|
canAwardEmoji: true,
|
|
|
|
canReportAsAbuse: true,
|
2020-11-24 15:15:51 +05:30
|
|
|
isAuthor: true,
|
|
|
|
isContributor: false,
|
|
|
|
noteableType: 'MergeRequest',
|
2019-03-02 22:35:43 +05:30
|
|
|
noteId: '539',
|
2020-03-13 15:44:24 +05:30
|
|
|
noteUrl: `${TEST_HOST}/group/project/-/merge_requests/1#note_1`,
|
2020-11-24 15:15:51 +05:30
|
|
|
projectName: 'project',
|
2019-03-02 22:35:43 +05:30
|
|
|
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,
|
2021-04-17 20:07:23 +05:30
|
|
|
awardPath: `${TEST_HOST}/award_emoji`,
|
2019-03-02 22:35:43 +05:30
|
|
|
};
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
actions = {
|
|
|
|
updateAssignees: jest.fn(),
|
|
|
|
};
|
|
|
|
|
|
|
|
axiosMock = new AxiosMockAdapter(axios);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper.destroy();
|
2020-06-23 00:09:42 +05:30
|
|
|
axiosMock.restore();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('user is logged in', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
store.dispatch('setUserData', userDataMock);
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
wrapper = mountNoteActions(props);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it('should render noteable author badge', () => {
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(findUserAccessRoleBadgeText(0)).toBe('Author');
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it('should render access level badge', () => {
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(findUserAccessRoleBadgeText(1)).toBe(props.accessLevel);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('should render contributor badge', async () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
wrapper.setProps({
|
|
|
|
accessLevel: null,
|
|
|
|
isContributor: true,
|
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(findUserAccessRoleBadgeText(1)).toBe('Contributor');
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it('should render emoji link', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(wrapper.find('.js-add-award').exists()).toBe(true);
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(wrapper.find('.js-add-award').attributes('data-position')).toBe('right');
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('actions dropdown', () => {
|
|
|
|
it('should be possible to edit the comment', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(wrapper.find('.js-note-edit').exists()).toBe(true);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
it('should be possible to report abuse to admin', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(wrapper.find(`a[href="${props.reportAbusePath}"]`).exists()).toBe(true);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
it('should be possible to copy link to a note', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(wrapper.find('.js-btn-copy-note-link').exists()).toBe(true);
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('should not show copy link action when `noteUrl` prop is empty', async () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper.setProps({
|
|
|
|
...props,
|
2020-06-23 00:09:42 +05:30
|
|
|
author: {
|
|
|
|
avatar_url: 'mock_path',
|
|
|
|
id: 26,
|
|
|
|
name: 'Example Maintainer',
|
|
|
|
path: '/ExampleMaintainer',
|
|
|
|
state: 'active',
|
|
|
|
username: 'ExampleMaintainer',
|
|
|
|
},
|
2019-03-02 22:35:43 +05:30
|
|
|
noteUrl: '',
|
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(wrapper.find('.js-btn-copy-note-link').exists()).toBe(false);
|
2018-11-20 20:47:30 +05:30
|
|
|
});
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it('should be possible to delete comment', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(wrapper.find('.js-note-delete').exists()).toBe(true);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('closes tooltip when dropdown opens', async () => {
|
2019-07-07 11:18:12 +05:30
|
|
|
wrapper.find('.more-actions-toggle').trigger('click');
|
|
|
|
|
|
|
|
const rootWrapper = createWrapper(wrapper.vm.$root);
|
2022-04-04 11:22:00 +05:30
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
const emitted = Object.keys(rootWrapper.emitted());
|
|
|
|
|
|
|
|
expect(emitted).toEqual([BV_HIDE_TOOLTIP]);
|
2019-07-07 11:18:12 +05:30
|
|
|
});
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
it('should not be possible to assign or unassign the comment author in a merge request', () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
const assignUserButton = wrapper.find('[data-testid="assign-user"]');
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(assignUserButton.exists()).toBe(false);
|
|
|
|
});
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
it('should render the correct (unescaped) name in the Resolved By tooltip', () => {
|
|
|
|
const complexUnescapedName = 'This is a Ǝ\'𝞓\'E "cat"?';
|
|
|
|
wrapper = mountNoteActions({
|
|
|
|
...props,
|
|
|
|
canResolve: true,
|
|
|
|
isResolving: false,
|
|
|
|
isResolved: true,
|
|
|
|
resolvedBy: {
|
|
|
|
name: complexUnescapedName,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const { resolveButton } = wrapper.vm.$refs;
|
|
|
|
expect(resolveButton.$el.getAttribute('title')).toBe(`Resolved by ${complexUnescapedName}`);
|
|
|
|
});
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
|
|
|
});
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
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-23 00:09:42 +05:30
|
|
|
});
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
const assignUserButton = wrapper.find('[data-testid="assign-user"]');
|
|
|
|
expect(assignUserButton.exists()).toBe(true);
|
|
|
|
assignUserButton.trigger('click');
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2021-01-29 00:20:46 +05:30
|
|
|
wrapper = mountNoteActions(props, {
|
2020-07-28 23:09:34 +05:30
|
|
|
targetType: () => 'issue',
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
2020-07-28 23:09:34 +05:30
|
|
|
store.state.noteableData = {
|
|
|
|
current_user: {
|
|
|
|
can_update: true,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
store.state.userData = userDataMock;
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
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(() => {
|
2021-01-29 00:20:46 +05:30
|
|
|
wrapper = mountNoteActions(props, {
|
2020-07-28 23:09:34 +05:30
|
|
|
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);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('user is not logged in', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
store.dispatch('setUserData', {});
|
2021-01-29 00:20:46 +05:30
|
|
|
wrapper = mountNoteActions({
|
2019-03-02 22:35:43 +05:30
|
|
|
...props,
|
2018-03-17 18:26:18 +05:30
|
|
|
canDelete: false,
|
|
|
|
canEdit: false,
|
2018-05-09 12:01:36 +05:30
|
|
|
canAwardEmoji: false,
|
2018-03-17 18:26:18 +05:30
|
|
|
canReportAsAbuse: false,
|
2019-03-02 22:35:43 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render emoji link', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(wrapper.find('.js-add-award').exists()).toBe(false);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render actions dropdown', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(wrapper.find('.more-actions').exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
describe('for showReply = true', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
beforeEach(() => {
|
2021-01-29 00:20:46 +05:30
|
|
|
wrapper = mountNoteActions({
|
2019-07-07 11:18:12 +05:30
|
|
|
...props,
|
|
|
|
showReply: true,
|
2019-03-02 22:35:43 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
it('shows a reply button', () => {
|
|
|
|
const replyButton = wrapper.find({ ref: 'replyButton' });
|
2019-03-02 22:35:43 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(replyButton.exists()).toBe(true);
|
2019-03-02 22:35:43 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
describe('for showReply = false', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
beforeEach(() => {
|
2021-01-29 00:20:46 +05:30
|
|
|
wrapper = mountNoteActions({
|
2019-07-07 11:18:12 +05:30
|
|
|
...props,
|
|
|
|
showReply: false,
|
2019-03-02 22:35:43 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
it('does not show a reply button', () => {
|
|
|
|
const replyButton = wrapper.find({ ref: 'replyButton' });
|
2019-03-02 22:35:43 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(replyButton.exists()).toBe(false);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
describe('Draft notes', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
store.dispatch('setUserData', userDataMock);
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
wrapper = mountNoteActions({ ...props, canResolve: true, isDraft: true });
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|