summaryrefslogtreecommitdiff
path: root/spec/javascripts/vue_shared/components/clipboard_button_spec.js
blob: ea525b1e44fc0f6fca33bb6aaf28fc8c5d946bab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import Vue from 'vue';
import clipboardButton from '~/vue_shared/components/clipboard_button.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';

describe('clipboard button', () => {
  const Component = Vue.extend(clipboardButton);
  let vm;

  afterEach(() => {
    vm.$destroy();
  });

  describe('without gfm', () => {
    beforeEach(() => {
      vm = mountComponent(Component, {
        text: 'copy me',
        title: 'Copy this value into Clipboard!',
        cssClass: 'btn-danger',
      });
    });

    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!');
      expect(vm.$el.getAttribute('data-placement')).toEqual('top');
      expect(vm.$el.getAttribute('data-container')).toEqual(null);
    });

    it('should render provided classname', () => {
      expect(vm.$el.classList).toContain('btn-danger');
    });
  });

  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',
      });
      expect(vm.$el.getAttribute('data-clipboard-text')).toEqual(
        '{"text":"copy me","gfm":"`path/to/file`"}',
      );
    });
  });
});