summaryrefslogtreecommitdiff
path: root/spec/frontend/vue_shared/components/help_popover_spec.js
blob: baf80a8a04eafae5df7ce8630ee0626cbd265f87 (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
import { GlButton, GlPopover } from '@gitlab/ui';
import { mount } from '@vue/test-utils';
import HelpPopover from '~/vue_shared/components/help_popover.vue';

describe('HelpPopover', () => {
  let wrapper;
  const title = 'popover <strong>title</strong>';
  const content = 'popover <b>content</b>';

  const findQuestionButton = () => wrapper.find(GlButton);
  const findPopover = () => wrapper.find(GlPopover);
  const buildWrapper = (options = {}) => {
    wrapper = mount(HelpPopover, {
      propsData: {
        options: {
          title,
          content,
          ...options,
        },
      },
    });
  };

  beforeEach(() => {
    buildWrapper();
  });

  afterEach(() => {
    wrapper.destroy();
    wrapper = null;
  });

  it('renders a link button with an icon question', () => {
    expect(findQuestionButton().props()).toMatchObject({
      icon: 'question',
      variant: 'link',
    });
    expect(findQuestionButton().attributes().tabindex).toBe('0');
  });

  it('renders popover that uses the question button as target', () => {
    expect(findPopover().props().target()).toBe(findQuestionButton().vm.$el);
  });

  it('triggers popover on hover and focus', () => {
    expect(findPopover().props().triggers).toBe('hover focus');
  });

  it('allows rendering title with HTML tags', () => {
    expect(findPopover().find('strong').exists()).toBe(true);
  });

  it('allows rendering content with HTML tags', () => {
    expect(findPopover().find('b').exists()).toBe(true);
  });

  it('binds other popover options to the popover instance', () => {
    const placement = 'bottom';

    wrapper.destroy();
    buildWrapper({ placement });

    expect(findPopover().props().placement).toBe(placement);
  });
});