2018-03-17 18:26:18 +05:30
|
|
|
import Vue from 'vue';
|
|
|
|
import clipboardButton from '~/vue_shared/components/clipboard_button.vue';
|
2018-03-27 19:54:05 +05:30
|
|
|
import mountComponent from 'spec/helpers/vue_mount_component_helper';
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
describe('clipboard button', () => {
|
2018-10-15 14:42:47 +05:30
|
|
|
const Component = Vue.extend(clipboardButton);
|
2018-03-17 18:26:18 +05:30
|
|
|
let vm;
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
describe('without gfm', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
vm = mountComponent(Component, {
|
|
|
|
text: 'copy me',
|
|
|
|
title: 'Copy this value into Clipboard!',
|
|
|
|
cssClass: 'btn-danger',
|
|
|
|
});
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
it('renders a button for clipboard', () => {
|
|
|
|
expect(vm.$el.tagName).toEqual('BUTTON');
|
|
|
|
expect(vm.$el.getAttribute('data-clipboard-text')).toEqual('copy me');
|
|
|
|
expect(vm.$el).toHaveSpriteIcon('duplicate');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have a tooltip with default values', () => {
|
|
|
|
expect(vm.$el.getAttribute('data-original-title')).toEqual('Copy this value into Clipboard!');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render provided classname', () => {
|
|
|
|
expect(vm.$el.classList).toContain('btn-danger');
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2018-03-27 19:54:05 +05:30
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
describe('with gfm', () => {
|
|
|
|
it('sets data-clipboard-text with gfm', () => {
|
|
|
|
vm = mountComponent(Component, {
|
|
|
|
text: 'copy me',
|
|
|
|
gfm: '`path/to/file`',
|
|
|
|
title: 'Copy this value into Clipboard!',
|
|
|
|
cssClass: 'btn-danger',
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
expect(vm.$el.getAttribute('data-clipboard-text')).toEqual(
|
|
|
|
'{"text":"copy me","gfm":"`path/to/file`"}',
|
|
|
|
);
|
|
|
|
});
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|