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

mr_widget_suggest_pipeline_spec.js « components « vue_mr_widget « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8b0253dc01a7331cc910afa6042c44f3d7a5b59b (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
import { mount } from '@vue/test-utils';
import { GlLink } from '@gitlab/ui';
import suggestPipelineComponent from '~/vue_merge_request_widget/components/mr_widget_suggest_pipeline.vue';
import stubChildren from 'helpers/stub_children';
import PipelineTourState from '~/vue_merge_request_widget/components/states/mr_widget_pipeline_tour.vue';
import MrWidgetIcon from '~/vue_merge_request_widget/components/mr_widget_icon.vue';
import { mockTracking, triggerEvent, unmockTracking } from 'helpers/tracking_helper';

describe('MRWidgetHeader', () => {
  let wrapper;
  const pipelinePath = '/foo/bar/add/pipeline/path';
  const pipelineSvgPath = '/foo/bar/pipeline/svg/path';
  const humanAccess = 'maintainer';
  const iconName = 'status_notfound';

  beforeEach(() => {
    wrapper = mount(suggestPipelineComponent, {
      propsData: { pipelinePath, pipelineSvgPath, humanAccess },
      stubs: {
        ...stubChildren(PipelineTourState),
      },
    });
  });

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

  describe('template', () => {
    it('renders add pipeline file link', () => {
      const link = wrapper.find(GlLink);

      expect(link.exists()).toBe(true);
      expect(link.attributes().href).toBe(pipelinePath);
    });

    it('renders the expected text', () => {
      const messageText = /\s*No pipeline\s*Add the .gitlab-ci.yml file\s*to create one./;

      expect(wrapper.text()).toMatch(messageText);
    });

    it('renders widget icon', () => {
      const icon = wrapper.find(MrWidgetIcon);

      expect(icon.exists()).toBe(true);
      expect(icon.props()).toEqual(
        expect.objectContaining({
          name: iconName,
        }),
      );
    });

    describe('tracking', () => {
      let spy;

      beforeEach(() => {
        spy = mockTracking('_category_', wrapper.element, jest.spyOn);
      });

      afterEach(() => {
        unmockTracking();
      });

      it('send an event when ok button is clicked', () => {
        const link = wrapper.find(GlLink);
        triggerEvent(link.element);

        expect(spy).toHaveBeenCalledWith('_category_', 'click_link', {
          label: 'no_pipeline_noticed',
          property: humanAccess,
          value: '30',
        });
      });
    });
  });
});