2022-01-21 13:12:45 -05:00
|
|
|
import { mount, createWrapper } from '@vue/test-utils';
|
2020-08-17 17:09:56 -04:00
|
|
|
import AxiosMockAdapter from 'axios-mock-adapter';
|
2022-01-24 10:11:33 -05:00
|
|
|
import { nextTick } from 'vue';
|
2021-02-01 10:08:56 -05:00
|
|
|
import { TEST_HOST } from 'spec/test_constants';
|
2020-06-16 17:08:20 -04:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2021-02-02 19:09:41 -05:00
|
|
|
import { BV_HIDE_TOOLTIP } from '~/lib/utils/constants';
|
2021-02-14 13:09:20 -05:00
|
|
|
import noteActions from '~/notes/components/note_actions.vue';
|
|
|
|
import createStore from '~/notes/stores';
|
2021-03-10 04:09:29 -05:00
|
|
|
import UserAccessRoleBadge from '~/vue_shared/components/user_access_role_badge.vue';
|
2021-02-04 04:09:30 -05:00
|
|
|
import { userDataMock } from '../mock_data';
|
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
|
|
|
|
2022-08-17 05:11:44 -04:00
|
|
|
const findUserAccessRoleBadge = (idx) => wrapper.findAllComponents(UserAccessRoleBadge).at(idx);
|
2021-03-10 04:09:29 -05:00
|
|
|
const findUserAccessRoleBadgeText = (idx) => findUserAccessRoleBadge(idx).text().trim();
|
|
|
|
|
2020-11-16 13:09:15 -05:00
|
|
|
const mountNoteActions = (propsData, computed) => {
|
2022-01-21 13:12:45 -05:00
|
|
|
return mount(noteActions, {
|
2019-02-06 05:31:46 -05:00
|
|
|
store,
|
|
|
|
propsData,
|
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,
|
2021-03-11 07:09:28 -05:00
|
|
|
awardPath: `${TEST_HOST}/award_emoji`,
|
2019-02-06 05:31:46 -05:00
|
|
|
};
|
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', () => {
|
2021-03-10 04:09:29 -05:00
|
|
|
expect(findUserAccessRoleBadgeText(0)).toBe('Author');
|
2020-09-16 11:09:32 -04:00
|
|
|
});
|
|
|
|
|
2017-08-11 11:39:16 -04:00
|
|
|
it('should render access level badge', () => {
|
2021-03-10 04:09:29 -05:00
|
|
|
expect(findUserAccessRoleBadgeText(1)).toBe(props.accessLevel);
|
2017-08-11 11:39:16 -04:00
|
|
|
});
|
|
|
|
|
2022-01-24 10:11:33 -05:00
|
|
|
it('should render contributor badge', async () => {
|
2020-09-16 11:09:32 -04:00
|
|
|
wrapper.setProps({
|
|
|
|
accessLevel: null,
|
|
|
|
isContributor: true,
|
|
|
|
});
|
|
|
|
|
2022-01-24 10:11:33 -05:00
|
|
|
await nextTick();
|
|
|
|
expect(findUserAccessRoleBadgeText(1)).toBe('Contributor');
|
2020-09-16 11:09:32 -04:00
|
|
|
});
|
|
|
|
|
2017-08-11 11:39:16 -04:00
|
|
|
it('should render emoji link', () => {
|
2022-03-23 11:08:38 -04:00
|
|
|
expect(wrapper.find('[data-testid="note-emoji-button"]').exists()).toBe(true);
|
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
|
|
|
});
|
|
|
|
|
2022-01-24 10:11:33 -05:00
|
|
|
it('should not show copy link action when `noteUrl` prop is empty', async () => {
|
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: '',
|
|
|
|
});
|
|
|
|
|
2022-01-24 10:11:33 -05:00
|
|
|
await nextTick();
|
|
|
|
expect(wrapper.find('.js-btn-copy-note-link').exists()).toBe(false);
|
2018-09-07 09:39:20 -04:00
|
|
|
});
|
|
|
|
|
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
|
|
|
|
2022-01-24 10:11:33 -05:00
|
|
|
it('closes tooltip when dropdown opens', async () => {
|
2019-01-09 18:46:43 -05:00
|
|
|
wrapper.find('.more-actions-toggle').trigger('click');
|
|
|
|
|
|
|
|
const rootWrapper = createWrapper(wrapper.vm.$root);
|
2022-01-24 10:11:33 -05:00
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
const emitted = Object.keys(rootWrapper.emitted());
|
|
|
|
|
|
|
|
expect(emitted).toEqual([BV_HIDE_TOOLTIP]);
|
2019-01-09 18:46:43 -05:00
|
|
|
});
|
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);
|
|
|
|
});
|
2021-04-19 08:09:04 -04:00
|
|
|
|
|
|
|
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-06-30 05:08:37 -04:00
|
|
|
});
|
|
|
|
});
|
2020-06-16 17:08:20 -04:00
|
|
|
|
2022-07-26 11:10:26 -04:00
|
|
|
describe('when a user can set metadata of an issue', () => {
|
2020-06-30 05:08:37 -04:00
|
|
|
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: {
|
2022-07-26 11:10:26 -04:00
|
|
|
can_set_issue_metadata: true,
|
2020-06-30 05:08:37 -04:00
|
|
|
},
|
|
|
|
};
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2022-07-26 11:10:26 -04:00
|
|
|
describe('when a user can update but not set metadata of an issue', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = mountNoteActions(props, {
|
|
|
|
targetType: () => 'issue',
|
|
|
|
});
|
|
|
|
store.state.noteableData = {
|
|
|
|
current_user: {
|
|
|
|
can_update: true,
|
|
|
|
can_set_issue_metadata: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
store.state.userData = userDataMock;
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
axiosMock.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not be possible to assign or unassign the comment author', () => {
|
|
|
|
const assignUserButton = wrapper.find('[data-testid="assign-user"]');
|
|
|
|
expect(assignUserButton.exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-06-30 05:08:37 -04:00
|
|
|
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', () => {
|
2022-08-17 05:11:44 -04:00
|
|
|
const replyButton = wrapper.findComponent({ 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', () => {
|
2022-08-17 05:11:44 -04:00
|
|
|
const replyButton = wrapper.findComponent({ 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', () => {
|
2022-08-17 05:11:44 -04:00
|
|
|
const resolveButton = wrapper.findComponent({ ref: 'resolveButton' });
|
2020-06-01 02:08:21 -04:00
|
|
|
|
|
|
|
expect(resolveButton.exists()).toBe(true);
|
|
|
|
expect(resolveButton.attributes('title')).toBe('Thread stays unresolved');
|
|
|
|
});
|
|
|
|
});
|
2017-08-09 15:13:00 -04:00
|
|
|
});
|