debian-mirror-gitlab/spec/frontend/vue_shared/components/clipboard_button_spec.js

58 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-01-01 13:55:28 +05:30
import { shallowMount } from '@vue/test-utils';
2020-03-13 15:44:24 +05:30
import { GlButton, GlIcon } from '@gitlab/ui';
2020-01-01 13:55:28 +05:30
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
describe('clipboard button', () => {
let wrapper;
const createWrapper = propsData => {
wrapper = shallowMount(ClipboardButton, {
propsData,
});
};
afterEach(() => {
wrapper.destroy();
wrapper = null;
});
describe('without gfm', () => {
beforeEach(() => {
createWrapper({
text: 'copy me',
title: 'Copy this value',
cssClass: 'btn-danger',
});
});
it('renders a button for clipboard', () => {
expect(wrapper.find(GlButton).exists()).toBe(true);
expect(wrapper.attributes('data-clipboard-text')).toBe('copy me');
2020-03-13 15:44:24 +05:30
expect(wrapper.find(GlIcon).props('name')).toBe('copy-to-clipboard');
2020-01-01 13:55:28 +05:30
});
it('should have a tooltip with default values', () => {
2020-03-13 15:44:24 +05:30
expect(wrapper.attributes('title')).toBe('Copy this value');
2020-01-01 13:55:28 +05:30
});
it('should render provided classname', () => {
expect(wrapper.classes()).toContain('btn-danger');
});
});
describe('with gfm', () => {
it('sets data-clipboard-text with gfm', () => {
createWrapper({
text: 'copy me',
gfm: '`path/to/file`',
title: 'Copy this value',
cssClass: 'btn-danger',
});
expect(wrapper.attributes('data-clipboard-text')).toBe(
'{"text":"copy me","gfm":"`path/to/file`"}',
);
});
});
});