summaryrefslogtreecommitdiff
path: root/spec/frontend/blob/pipeline_tour_success_modal_spec.js
blob: d4562019302487bbb046c528003bab5269d3d33e (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import { shallowMount } from '@vue/test-utils';
import Cookies from 'js-cookie';
import { GlSprintf, GlModal, GlLink } from '@gitlab/ui';
import { mockTracking, triggerEvent, unmockTracking } from 'helpers/tracking_helper';
import { stubComponent } from 'helpers/stub_component';
import pipelineTourSuccess from '~/blob/pipeline_tour_success_modal.vue';
import modalProps from './pipeline_tour_success_mock_data';

describe('PipelineTourSuccessModal', () => {
  let wrapper;
  let cookieSpy;
  let trackingSpy;

  const GlEmoji = { template: '<img/>' };
  const createComponent = () => {
    wrapper = shallowMount(pipelineTourSuccess, {
      propsData: modalProps,
      stubs: {
        GlModal: stubComponent(GlModal, {
          template: `
            <div>
              <slot name="modal-title"></slot>
              <slot></slot>
              <slot name="modal-footer"></slot>
            </div>`,
        }),
        GlSprintf,
        GlEmoji,
      },
    });
  };

  beforeEach(() => {
    document.body.dataset.page = 'projects:blob:show';
    trackingSpy = mockTracking('_category_', undefined, jest.spyOn);
    cookieSpy = jest.spyOn(Cookies, 'remove');
    createComponent();
  });

  afterEach(() => {
    wrapper.destroy();
    unmockTracking();
    Cookies.remove(modalProps.commitCookie);
  });

  describe('when the commitCookie contains the mr path', () => {
    const expectedMrPath = 'expected_mr_path';

    beforeEach(() => {
      Cookies.set(modalProps.commitCookie, expectedMrPath);
      createComponent();
    });

    it('renders the path from the commit cookie for back to the merge request button', () => {
      const goToMrBtn = wrapper.find({ ref: 'goToMergeRequest' });

      expect(goToMrBtn.attributes('href')).toBe(expectedMrPath);
    });
  });

  describe('when the commitCookie does not contain mr path', () => {
    const expectedMrPath = modalProps.projectMergeRequestsPath;

    beforeEach(() => {
      Cookies.set(modalProps.commitCookie, true);
      createComponent();
    });

    it('renders the path from projectMergeRequestsPath for back to the merge request button', () => {
      const goToMrBtn = wrapper.find({ ref: 'goToMergeRequest' });

      expect(goToMrBtn.attributes('href')).toBe(expectedMrPath);
    });
  });

  it('has expected structure', () => {
    const modal = wrapper.find(GlModal);
    const sprintf = modal.find(GlSprintf);
    const emoji = modal.find(GlEmoji);

    expect(wrapper.text()).toContain("That's it, well done!");
    expect(sprintf.exists()).toBe(true);
    expect(emoji.exists()).toBe(true);
  });

  it('renders the link for codeQualityLink', () => {
    expect(wrapper.find(GlLink).attributes('href')).toBe('/code-quality-link');
  });

  it('calls to remove cookie', () => {
    wrapper.vm.disableModalFromRenderingAgain();

    expect(cookieSpy).toHaveBeenCalledWith(modalProps.commitCookie);
  });

  describe('tracking', () => {
    it('send event for basic view of modal', () => {
      expect(trackingSpy).toHaveBeenCalledWith(undefined, undefined, {
        label: 'congratulate_first_pipeline',
        property: modalProps.humanAccess,
      });
    });

    it('send an event when go to pipelines is clicked', () => {
      trackingSpy = mockTracking('_category_', wrapper.element, jest.spyOn);
      const goToBtn = wrapper.find({ ref: 'goToPipelines' });
      triggerEvent(goToBtn.element);

      expect(trackingSpy).toHaveBeenCalledWith('_category_', 'click_button', {
        label: 'congratulate_first_pipeline',
        property: modalProps.humanAccess,
        value: '10',
      });
    });

    it('sends an event when back to the merge request is clicked', () => {
      trackingSpy = mockTracking('_category_', wrapper.element, jest.spyOn);
      const goToBtn = wrapper.find({ ref: 'goToMergeRequest' });
      triggerEvent(goToBtn.element);

      expect(trackingSpy).toHaveBeenCalledWith('_category_', 'click_button', {
        label: 'congratulate_first_pipeline',
        property: modalProps.humanAccess,
        value: '20',
      });
    });
  });
});