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

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', () => {
      spyOn(component, '$on');

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

      expect(component.$on).toHaveBeenCalledWith('postAction', 'foo');
    });
  });
});