summaryrefslogtreecommitdiff
path: root/spec/frontend/pipelines/empty_state/ci_templates_spec.js
blob: 606fdc9cac12bca41b6e736cd8ccbd9c95f67cb2 (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
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import { mockTracking, unmockTracking } from 'helpers/tracking_helper';
import CiTemplates from '~/pipelines/components/pipelines_list/empty_state/ci_templates.vue';

const pipelineEditorPath = '/-/ci/editor';
const suggestedCiTemplates = [
  { name: 'Android', logo: '/assets/illustrations/logos/android.svg' },
  { name: 'Bash', logo: '/assets/illustrations/logos/bash.svg' },
  { name: 'C++', logo: '/assets/illustrations/logos/c_plus_plus.svg' },
];

describe('CI Templates', () => {
  let wrapper;
  let trackingSpy;

  const createWrapper = () => {
    return shallowMountExtended(CiTemplates, {
      provide: {
        pipelineEditorPath,
        suggestedCiTemplates,
      },
    });
  };

  const findTemplateDescription = () => wrapper.findByTestId('template-description');
  const findTemplateLink = () => wrapper.findByTestId('template-link');
  const findTemplateName = () => wrapper.findByTestId('template-name');
  const findTemplateLogo = () => wrapper.findByTestId('template-logo');

  beforeEach(() => {
    wrapper = createWrapper();
  });

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

  describe('renders template list', () => {
    it('renders all suggested templates', () => {
      const content = wrapper.text();

      expect(content).toContain('Android', 'Bash', 'C++');
    });

    it('has the correct template name', () => {
      expect(findTemplateName().text()).toBe('Android');
    });

    it('links to the correct template', () => {
      expect(findTemplateLink().attributes('href')).toBe(
        pipelineEditorPath.concat('?template=Android'),
      );
    });

    it('has the description of the template', () => {
      expect(findTemplateDescription().text()).toBe(
        'CI/CD template to test and deploy your Android project.',
      );
    });

    it('has the right logo of the template', () => {
      expect(findTemplateLogo().attributes('src')).toBe('/assets/illustrations/logos/android.svg');
    });
  });

  describe('tracking', () => {
    beforeEach(() => {
      trackingSpy = mockTracking(undefined, wrapper.element, jest.spyOn);
    });

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

    it('sends an event when template is clicked', () => {
      findTemplateLink().vm.$emit('click');

      expect(trackingSpy).toHaveBeenCalledTimes(1);
      expect(trackingSpy).toHaveBeenCalledWith(undefined, 'template_clicked', {
        label: 'Android',
      });
    });
  });
});