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

help_icon_spec.js « security_reports « components « vue_shared « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ae86106d86eb22e45022f24d6e324498661559f8 (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
import { GlLink, GlPopover } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import HelpIcon from '~/vue_shared/security_reports/components/help_icon.vue';

const helpPath = '/docs';
const discoverProjectSecurityPath = '/discoverProjectSecurityPath';

describe('HelpIcon component', () => {
  let wrapper;

  const createWrapper = (props) => {
    wrapper = shallowMount(HelpIcon, {
      propsData: {
        helpPath,
        ...props,
      },
    });
  };

  const findLink = () => wrapper.find(GlLink);
  const findPopover = () => wrapper.find(GlPopover);
  const findPopoverTarget = () => wrapper.find({ ref: 'discoverProjectSecurity' });

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

  describe('given a help path only', () => {
    beforeEach(() => {
      createWrapper();
    });

    it('does not render a popover', () => {
      expect(findPopover().exists()).toBe(false);
    });

    it('renders a help link', () => {
      expect(findLink().attributes()).toMatchObject({
        href: helpPath,
        target: '_blank',
      });
    });
  });

  describe('given a help path and discover project security path', () => {
    beforeEach(() => {
      createWrapper({ discoverProjectSecurityPath });
    });

    it('renders a popover', () => {
      const popover = findPopover();
      expect(popover.props('target')()).toBe(findPopoverTarget().element);
      expect(popover.attributes()).toMatchObject({
        title: HelpIcon.i18n.upgradeToManageVulnerabilities,
        triggers: 'click blur',
      });
      expect(popover.text()).toContain(HelpIcon.i18n.upgradeToInteract);
    });

    it('renders a link to the discover path', () => {
      expect(findLink().attributes()).toMatchObject({
        href: discoverProjectSecurityPath,
        target: '_blank',
      });
    });
  });
});