summaryrefslogtreecommitdiff
path: root/spec/javascripts/pipelines/graph/job_component_spec.js
blob: 23c87610d83181080abf494c3d62db0826a9e86a (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
109
110
111
112
113
114
115
116
import Vue from 'vue';
import jobComponent from '~/pipelines/components/graph/job_component.vue';
import mountComponent from '../../helpers/vue_mount_component_helper';

describe('pipeline graph job component', () => {
  let JobComponent;
  let component;

  const mockJob = {
    id: 4256,
    name: 'test',
    status: {
      icon: 'icon_status_success',
      text: 'passed',
      label: 'passed',
      group: 'success',
      details_path: '/root/ci-mock/builds/4256',
      has_details: true,
      action: {
        icon: 'retry',
        title: 'Retry',
        path: '/root/ci-mock/builds/4256/retry',
        method: 'post',
      },
    },
  };

  beforeEach(() => {
    JobComponent = Vue.extend(jobComponent);
  });

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

  describe('name with link', () => {
    it('should render the job name and status with a link', (done) => {
      component = mountComponent(JobComponent, { job: mockJob });

      Vue.nextTick(() => {
        const link = component.$el.querySelector('a');

        expect(link.getAttribute('href')).toEqual(mockJob.status.details_path);

        expect(
          link.getAttribute('data-original-title'),
        ).toEqual(`${mockJob.name} - ${mockJob.status.label}`);

        expect(component.$el.querySelector('.js-status-icon-success')).toBeDefined();

        expect(
          component.$el.querySelector('.ci-status-text').textContent.trim(),
        ).toEqual(mockJob.name);

        done();
      });
    });
  });

  describe('name without link', () => {
    it('it should render status and name', () => {
      component = mountComponent(JobComponent, {
        job: {
          id: 4256,
          name: 'test',
          status: {
            icon: 'icon_status_success',
            text: 'passed',
            label: 'passed',
            group: 'success',
            details_path: '/root/ci-mock/builds/4256',
            has_details: false,
          },
        },
      });

      expect(component.$el.querySelector('.js-status-icon-success')).toBeDefined();
      expect(component.$el.querySelector('a')).toBeNull();

      expect(
        component.$el.querySelector('.ci-status-text').textContent.trim(),
      ).toEqual(mockJob.name);
    });
  });

  describe('action icon', () => {
    it('it should render the action icon', () => {
      component = mountComponent(JobComponent, { job: mockJob });

      expect(component.$el.querySelector('a.ci-action-icon-container')).toBeDefined();
      expect(component.$el.querySelector('i.ci-action-icon-wrapper')).toBeDefined();
    });
  });

  describe('dropdown', () => {
    it('should render the dropdown action icon', () => {
      component = mountComponent(JobComponent, {
        job: mockJob,
        isDropdown: true,
      });

      expect(component.$el.querySelector('a.ci-action-icon-wrapper')).toBeDefined();
    });
  });

  it('should render provided class name', () => {
    component = mountComponent(JobComponent, {
      job: mockJob,
      cssClassJobName: 'css-class-job-name',
    });

    expect(
      component.$el.querySelector('a').classList.contains('css-class-job-name'),
    ).toBe(true);
  });
});