summaryrefslogtreecommitdiff
path: root/spec/frontend/blob/pipeline_tour_success_modal_spec.js
blob: 6d4e5e46cb860bdc54c185a8710e0e5be2bebc05 (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
import pipelineTourSuccess from '~/blob/pipeline_tour_success_modal.vue';
import { shallowMount } from '@vue/test-utils';
import Cookies from 'js-cookie';
import { GlSprintf, GlModal } from '@gitlab/ui';
import { mockTracking, triggerEvent, unmockTracking } from 'helpers/tracking_helper';
import modalProps from './pipeline_tour_success_mock_data';

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

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

    wrapper = shallowMount(pipelineTourSuccess, {
      propsData: modalProps,
      stubs: {
        GlModal,
      },
    });

    cookieSpy = jest.spyOn(Cookies, 'remove');
  });

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

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

    expect(modal.attributes('title')).toContain("That's it, well done!");
    expect(sprintf.exists()).toBe(true);
  });

  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: 'goto' });
      triggerEvent(goToBtn.element);

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