summaryrefslogtreecommitdiff
path: root/spec/frontend/pipelines/nav_controls_spec.js
blob: 305dc557b39e13e7306375e99e6fcdc581e104bc (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 Vue from 'vue';
import mountComponent from 'helpers/vue_mount_component_helper';
import navControlsComp from '~/pipelines/components/pipelines_list/nav_controls.vue';

describe('Pipelines Nav Controls', () => {
  let NavControlsComponent;
  let component;

  beforeEach(() => {
    NavControlsComponent = Vue.extend(navControlsComp);
  });

  afterEach(() => {
    component.$destroy();
  });

  it('should render link to create a new pipeline', () => {
    const mockData = {
      newPipelinePath: 'foo',
      ciLintPath: 'foo',
      resetCachePath: 'foo',
    };

    component = mountComponent(NavControlsComponent, mockData);

    expect(component.$el.querySelector('.js-run-pipeline').textContent).toContain('Run Pipeline');
    expect(component.$el.querySelector('.js-run-pipeline').getAttribute('href')).toEqual(
      mockData.newPipelinePath,
    );
  });

  it('should not render link to create pipeline if no path is provided', () => {
    const mockData = {
      helpPagePath: 'foo',
      ciLintPath: 'foo',
      resetCachePath: 'foo',
    };

    component = mountComponent(NavControlsComponent, mockData);

    expect(component.$el.querySelector('.js-run-pipeline')).toEqual(null);
  });

  it('should render link for CI lint', () => {
    const mockData = {
      newPipelinePath: 'foo',
      helpPagePath: 'foo',
      ciLintPath: 'foo',
      resetCachePath: 'foo',
    };

    component = mountComponent(NavControlsComponent, mockData);

    expect(component.$el.querySelector('.js-ci-lint').textContent.trim()).toContain('CI Lint');
    expect(component.$el.querySelector('.js-ci-lint').getAttribute('href')).toEqual(
      mockData.ciLintPath,
    );
  });

  describe('Reset Runners Cache', () => {
    beforeEach(() => {
      const mockData = {
        newPipelinePath: 'foo',
        ciLintPath: 'foo',
        resetCachePath: 'foo',
      };

      component = mountComponent(NavControlsComponent, mockData);
    });

    it('should render button for resetting runner caches', () => {
      expect(component.$el.querySelector('.js-clear-cache').textContent.trim()).toContain(
        'Clear Runner Caches',
      );
    });

    it('should emit postAction event when reset runner cache button is clicked', () => {
      jest.spyOn(component, '$emit').mockImplementation(() => {});

      component.$el.querySelector('.js-clear-cache').click();

      expect(component.$emit).toHaveBeenCalledWith('resetRunnersCache', 'foo');
    });
  });
});