Welcome to mirror list, hosted at ThFree Co, Russian Federation.

nav_controls_spec.js « pipelines « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2c4740df174f02ec969f46ddadda997224665eca (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 { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';
import NavControls from '~/pipelines/components/pipelines_list/nav_controls.vue';

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

  const createComponent = (props) => {
    wrapper = shallowMount(NavControls, {
      propsData: {
        ...props,
      },
    });
  };

  const findRunPipeline = () => wrapper.find('.js-run-pipeline');

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

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

    createComponent(mockData);

    const runPipeline = findRunPipeline();
    expect(runPipeline.text()).toContain('Run pipeline');
    expect(runPipeline.attributes('href')).toBe(mockData.newPipelinePath);
  });

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

    createComponent(mockData);

    expect(findRunPipeline().exists()).toBe(false);
  });

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

    createComponent(mockData);

    expect(wrapper.find('.js-ci-lint').text().trim()).toContain('CI lint');
    expect(wrapper.find('.js-ci-lint').attributes('href')).toBe(mockData.ciLintPath);
  });

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

    it('should render button for resetting runner caches', () => {
      expect(wrapper.find('.js-clear-cache').text().trim()).toContain('Clear runner caches');
    });

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

      wrapper.find('.js-clear-cache').vm.$emit('click');
      await nextTick();

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