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

287 lines
7.8 KiB
JavaScript
Raw Normal View History

2018-03-17 18:26:18 +05:30
import Vue from 'vue';
2019-07-07 11:18:12 +05:30
import { shallowMount, createLocalVue, createWrapper } from '@vue/test-utils';
2020-01-01 13:55:28 +05:30
import { TEST_HOST } from 'spec/test_constants';
2020-10-24 23:57:45 +05:30
import AxiosMockAdapter from 'axios-mock-adapter';
2018-11-08 19:23:39 +05:30
import createStore from '~/notes/stores';
2018-03-17 18:26:18 +05:30
import noteActions from '~/notes/components/note_actions.vue';
import { userDataMock } from '../mock_data';
2020-06-23 00:09:42 +05:30
import axios from '~/lib/utils/axios_utils';
2018-03-17 18:26:18 +05:30
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
2020-06-23 00:09:42 +05:30
const shallowMountNoteActions = (propsData, computed) => {
2019-03-02 22:35:43 +05:30
const localVue = createLocalVue();
2020-01-01 13:55:28 +05:30
return shallowMount(localVue.extend(noteActions), {
2019-03-02 22:35:43 +05:30
store,
propsData,
localVue,
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,
};
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);
2019-07-07 11:18:12 +05:30
wrapper = shallowMountNoteActions(props);
2018-03-17 18:26:18 +05:30
});
2020-11-24 15:15:51 +05:30
it('should render noteable author badge', () => {
expect(
wrapper
.findAll('.note-role')
.at(0)
.text()
.trim(),
).toEqual('Author');
});
2018-03-17 18:26:18 +05:30
it('should render access level badge', () => {
2019-03-02 22:35:43 +05:30
expect(
wrapper
2020-11-24 15:15:51 +05:30
.findAll('.note-role')
.at(1)
2019-03-02 22:35:43 +05:30
.text()
.trim(),
).toEqual(props.accessLevel);
2018-03-17 18:26:18 +05:30
});
2020-11-24 15:15:51 +05:30
it('should render contributor badge', () => {
wrapper.setProps({
accessLevel: null,
isContributor: true,
});
return wrapper.vm.$nextTick().then(() => {
expect(
wrapper
.findAll('.note-role')
.at(1)
.text()
.trim(),
).toBe('Contributor');
});
});
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
});
it('should not show copy link action when `noteUrl` prop is empty', done => {
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: '',
});
2018-11-20 20:47:30 +05:30
Vue.nextTick()
.then(() => {
2019-03-02 22:35:43 +05:30
expect(wrapper.find('.js-btn-copy-note-link').exists()).toBe(false);
2018-11-20 20:47:30 +05:30
})
.then(done)
.catch(done.fail);
});
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
it('closes tooltip when dropdown opens', done => {
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-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);
});
});
});
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(() => {
wrapper = shallowMountNoteActions(props, {
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(() => {
wrapper = shallowMountNoteActions(props, {
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', {});
2019-07-07 11:18:12 +05:30
wrapper = shallowMountNoteActions({
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(() => {
2019-07-07 11:18:12 +05:30
wrapper = shallowMountNoteActions({
...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(() => {
2019-07-07 11:18:12 +05:30
wrapper = shallowMountNoteActions({
...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);
wrapper = shallowMountNoteActions({ ...props, canResolve: true, isDraft: true });
});
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
});