Welcome to mirror list, hosted at ThFree Co, Russian Federation.

tooltip_spec.js « directives « vue_shared « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9d3dd3c5f756b9a01c1b401bf38628c54117fd50 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import $ from 'jquery';
import { mount } from '@vue/test-utils';
import tooltip from '~/vue_shared/directives/tooltip';

describe('Tooltip directive', () => {
  let vm;

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

  describe('with a single tooltip', () => {
    beforeEach(() => {
      const wrapper = mount(
        {
          directives: {
            tooltip,
          },
          data() {
            return {
              tooltip: 'some text',
            };
          },
          template: '<div v-tooltip :title="tooltip"></div>',
        },
        { attachToDocument: true },
      );

      vm = wrapper.vm;
    });

    it('should have tooltip plugin applied', () => {
      expect($(vm.$el).data('bs.tooltip')).toBeDefined();
    });

    it('displays the title as tooltip', () => {
      $(vm.$el).tooltip('show');
      jest.runOnlyPendingTimers();

      const tooltipElement = document.querySelector('.tooltip-inner');

      expect(tooltipElement.textContent).toContain('some text');
    });

    it('updates a visible tooltip', () => {
      $(vm.$el).tooltip('show');
      jest.runOnlyPendingTimers();

      const tooltipElement = document.querySelector('.tooltip-inner');

      vm.tooltip = 'other text';

      jest.runOnlyPendingTimers();

      return vm.$nextTick().then(() => {
        expect(tooltipElement.textContent).toContain('other text');
      });
    });
  });

  describe('with multiple tooltips', () => {
    beforeEach(() => {
      const wrapper = mount(
        {
          directives: {
            tooltip,
          },
          template: `
            <div>
              <div
                v-tooltip
                class="js-look-for-tooltip"
                title="foo">
              </div>
              <div
                v-tooltip
                title="bar">
              </div>
            </div>
          `,
        },
        { attachToDocument: true },
      );

      vm = wrapper.vm;
    });

    it('should have tooltip plugin applied to all instances', () => {
      expect(
        $(vm.$el)
          .find('.js-look-for-tooltip')
          .data('bs.tooltip'),
      ).toBeDefined();
    });
  });
});