summaryrefslogtreecommitdiff
path: root/spec/frontend/pipelines/pipeline_url_spec.js
blob: 70b94f2c8e162589aba09ecfa5ff4aaccbcd096e (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import $ from 'jquery';
import { trimText } from 'helpers/text_helper';
import { shallowMount } from '@vue/test-utils';
import PipelineUrlComponent from '~/pipelines/components/pipeline_url.vue';

$.fn.popover = () => {};

describe('Pipeline Url Component', () => {
  let wrapper;

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

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

  it('should render a table cell', () => {
    createComponent({
      pipeline: {
        id: 1,
        path: 'foo',
        flags: {},
      },
      autoDevopsHelpPath: 'foo',
    });

    expect(wrapper.attributes('class')).toContain('table-section');
  });

  it('should render a link the provided path and id', () => {
    createComponent({
      pipeline: {
        id: 1,
        path: 'foo',
        flags: {},
      },
      autoDevopsHelpPath: 'foo',
    });

    expect(wrapper.find('.js-pipeline-url-link').attributes('href')).toBe('foo');

    expect(wrapper.find('.js-pipeline-url-link span').text()).toBe('#1');
  });

  it('should render latest, yaml invalid, merge request, and stuck flags when provided', () => {
    createComponent({
      pipeline: {
        id: 1,
        path: 'foo',
        flags: {
          latest: true,
          yaml_errors: true,
          stuck: true,
          merge_request_pipeline: true,
          detached_merge_request_pipeline: true,
        },
      },
      autoDevopsHelpPath: 'foo',
    });

    expect(wrapper.find('.js-pipeline-url-latest').text()).toContain('latest');

    expect(wrapper.find('.js-pipeline-url-yaml').text()).toContain('yaml invalid');

    expect(wrapper.find('.js-pipeline-url-stuck').text()).toContain('stuck');

    expect(wrapper.find('.js-pipeline-url-detached').text()).toContain('detached');
  });

  it('should render a badge for autodevops', () => {
    createComponent({
      pipeline: {
        id: 1,
        path: 'foo',
        flags: {
          latest: true,
          yaml_errors: true,
          stuck: true,
          auto_devops: true,
        },
      },
      autoDevopsHelpPath: 'foo',
    });

    expect(trimText(wrapper.find('.js-pipeline-url-autodevops').text())).toEqual('Auto DevOps');
  });

  it('should render error badge when pipeline has a failure reason set', () => {
    createComponent({
      pipeline: {
        id: 1,
        path: 'foo',
        flags: {
          failure_reason: true,
        },
        failure_reason: 'some reason',
      },
      autoDevopsHelpPath: 'foo',
    });

    expect(wrapper.find('.js-pipeline-url-failure').text()).toContain('error');
    expect(wrapper.find('.js-pipeline-url-failure').attributes('title')).toContain('some reason');
  });
});