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

161 lines
4.3 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';
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';
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;
2019-07-07 11:18:12 +05:30
const shallowMountNoteActions = propsData => {
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,
});
};
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',
2020-03-13 15:44:24 +05:30
noteUrl: `${TEST_HOST}/group/project/-/merge_requests/1#note_1`,
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,
};
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-07-07 11:18:12 +05:30
wrapper = shallowMountNoteActions(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);
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,
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);
});
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
});
});
});