2018-03-17 18:26:18 +05:30
|
|
|
import Vue from 'vue';
|
2019-03-02 22:35:43 +05:30
|
|
|
import { shallowMount, createLocalVue } from '@vue/test-utils';
|
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';
|
2019-03-02 22:35:43 +05:30
|
|
|
import { TEST_HOST } from 'spec/test_constants';
|
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;
|
|
|
|
|
|
|
|
const createWrapper = propsData => {
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
return shallowMount(noteActions, {
|
|
|
|
store,
|
|
|
|
propsData,
|
|
|
|
localVue,
|
|
|
|
sync: false,
|
|
|
|
});
|
|
|
|
};
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
2018-11-08 19:23:39 +05:30
|
|
|
store = createStore();
|
2019-03-02 22:35:43 +05:30
|
|
|
props = {
|
|
|
|
accessLevel: 'Maintainer',
|
|
|
|
authorId: 26,
|
|
|
|
canDelete: true,
|
|
|
|
canEdit: true,
|
|
|
|
canAwardEmoji: true,
|
|
|
|
canReportAsAbuse: true,
|
|
|
|
noteId: '539',
|
|
|
|
noteUrl: `${TEST_HOST}/group/project/merge_requests/1#note_1`,
|
|
|
|
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,
|
|
|
|
};
|
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
|
|
|
});
|
|
|
|
|
|
|
|
describe('user is logged in', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
store.dispatch('setUserData', userDataMock);
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper = createWrapper(props);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should render access level badge', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('.note-role')
|
|
|
|
.text()
|
|
|
|
.trim(),
|
|
|
|
).toEqual(props.accessLevel);
|
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);
|
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
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('should be possible to report abuse to GitLab', () => {
|
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,
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('user is not logged in', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
store.dispatch('setUserData', {});
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper = createWrapper({
|
|
|
|
...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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with feature flag replyToIndividualNotes enabled', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
gon.features = {
|
|
|
|
replyToIndividualNotes: true,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
gon.features = {};
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('for showReply = true', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createWrapper({
|
|
|
|
...props,
|
|
|
|
showReply: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows a reply button', () => {
|
|
|
|
const replyButton = wrapper.find({ ref: 'replyButton' });
|
|
|
|
|
|
|
|
expect(replyButton.exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('for showReply = false', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createWrapper({
|
|
|
|
...props,
|
|
|
|
showReply: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not show a reply button', () => {
|
|
|
|
const replyButton = wrapper.find({ ref: 'replyButton' });
|
|
|
|
|
|
|
|
expect(replyButton.exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with feature flag replyToIndividualNotes disabled', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
gon.features = {
|
|
|
|
replyToIndividualNotes: false,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
gon.features = {};
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('for showReply = true', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createWrapper({
|
|
|
|
...props,
|
|
|
|
showReply: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not show a reply button', () => {
|
|
|
|
const replyButton = wrapper.find({ ref: 'replyButton' });
|
|
|
|
|
|
|
|
expect(replyButton.exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('for showReply = false', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createWrapper({
|
|
|
|
...props,
|
|
|
|
showReply: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not show a reply button', () => {
|
|
|
|
const replyButton = wrapper.find({ ref: 'replyButton' });
|
|
|
|
|
|
|
|
expect(replyButton.exists()).toBe(false);
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|