debian-mirror-gitlab/spec/frontend/vue_shared/components/markdown/toolbar_spec.js

76 lines
2.2 KiB
JavaScript
Raw Normal View History

2021-04-29 21:17:54 +05:30
import { mount } from '@vue/test-utils';
import { isExperimentVariant } from '~/experimentation/utils';
import InviteMembersTrigger from '~/invite_members/components/invite_members_trigger.vue';
import { INVITE_MEMBERS_IN_COMMENT } from '~/invite_members/constants';
import Toolbar from '~/vue_shared/components/markdown/toolbar.vue';
jest.mock('~/experimentation/utils', () => ({ isExperimentVariant: jest.fn() }));
2018-03-17 18:26:18 +05:30
describe('toolbar', () => {
2021-04-29 21:17:54 +05:30
let wrapper;
const createMountedWrapper = (props = {}) => {
wrapper = mount(Toolbar, {
propsData: { markdownDocsPath: '', ...props },
stubs: { 'invite-members-trigger': true },
});
2018-03-17 18:26:18 +05:30
};
afterEach(() => {
2021-04-29 21:17:54 +05:30
wrapper.destroy();
isExperimentVariant.mockReset();
2018-03-17 18:26:18 +05:30
});
describe('user can attach file', () => {
beforeEach(() => {
2021-04-29 21:17:54 +05:30
createMountedWrapper();
2018-03-17 18:26:18 +05:30
});
it('should render uploading-container', () => {
2021-04-29 21:17:54 +05:30
expect(wrapper.vm.$el.querySelector('.uploading-container')).not.toBeNull();
2018-03-17 18:26:18 +05:30
});
});
describe('user cannot attach file', () => {
beforeEach(() => {
2021-04-29 21:17:54 +05:30
createMountedWrapper({ canAttachFile: false });
2018-03-17 18:26:18 +05:30
});
it('should not render uploading-container', () => {
2021-04-29 21:17:54 +05:30
expect(wrapper.vm.$el.querySelector('.uploading-container')).toBeNull();
});
});
describe('user can invite member', () => {
const findInviteLink = () => wrapper.find(InviteMembersTrigger);
beforeEach(() => {
isExperimentVariant.mockReturnValue(true);
createMountedWrapper();
});
it('should render the invite members trigger', () => {
expect(findInviteLink().exists()).toBe(true);
});
it('should have correct props', () => {
expect(findInviteLink().props().displayText).toBe('Invite Member');
expect(findInviteLink().props().trackExperiment).toBe(INVITE_MEMBERS_IN_COMMENT);
expect(findInviteLink().props().triggerSource).toBe(INVITE_MEMBERS_IN_COMMENT);
});
});
describe('user can not invite member', () => {
const findInviteLink = () => wrapper.find(InviteMembersTrigger);
beforeEach(() => {
isExperimentVariant.mockReturnValue(false);
createMountedWrapper();
});
it('should render the invite members trigger', () => {
expect(findInviteLink().exists()).toBe(false);
2018-03-17 18:26:18 +05:30
});
});
});