summaryrefslogtreecommitdiff
path: root/spec/frontend/pipelines/graph/job_item_spec.js
blob: 2c5e7a1f6e9e2ac5e4b2d4cd00d79fb12a7190b5 (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import { mount } from '@vue/test-utils';
import { trimText } from 'helpers/text_helper';
import JobItem from '~/pipelines/components/graph/job_item.vue';

describe('pipeline graph job item', () => {
  let wrapper;

  const findJobWithoutLink = () => wrapper.find('[data-testid="job-without-link"]');

  const createWrapper = propsData => {
    wrapper = mount(JobItem, {
      propsData,
    });
  };

  const delayedJobFixture = getJSONFixture('jobs/delayed.json');
  const mockJob = {
    id: 4256,
    name: 'test',
    status: {
      icon: 'status_success',
      text: 'passed',
      label: 'passed',
      tooltip: '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',
      },
    },
  };

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

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

      wrapper.vm.$nextTick(() => {
        const link = wrapper.find('a');

        expect(link.attributes('href')).toBe(mockJob.status.details_path);

        expect(link.attributes('title')).toEqual(`${mockJob.name} - ${mockJob.status.label}`);

        expect(wrapper.find('.ci-status-icon-success').exists()).toBe(true);

        expect(trimText(wrapper.find('.ci-status-text').text())).toBe(mockJob.name);

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

  describe('name without link', () => {
    beforeEach(() => {
      createWrapper({
        job: {
          id: 4257,
          name: 'test',
          status: {
            icon: 'status_success',
            text: 'passed',
            label: 'passed',
            group: 'success',
            details_path: '/root/ci-mock/builds/4257',
            has_details: false,
          },
        },
        cssClassJobName: 'css-class-job-name',
        jobHovered: 'test',
      });
    });

    it('it should render status and name', () => {
      expect(wrapper.find('.ci-status-icon-success').exists()).toBe(true);
      expect(wrapper.find('a').exists()).toBe(false);

      expect(trimText(wrapper.find('.ci-status-text').text())).toEqual(mockJob.name);
    });

    it('should apply hover class and provided class name', () => {
      expect(findJobWithoutLink().classes()).toContain('gl-inset-border-1-blue-500');
      expect(findJobWithoutLink().classes()).toContain('css-class-job-name');
    });
  });

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

      expect(wrapper.find('.ci-action-icon-container').exists()).toBe(true);
      expect(wrapper.find('.ci-action-icon-wrapper').exists()).toBe(true);
    });
  });

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

    expect(wrapper.find('a').classes()).toContain('css-class-job-name');
  });

  describe('status label', () => {
    it('should not render status label when it is not provided', () => {
      createWrapper({
        job: {
          id: 4258,
          name: 'test',
          status: {
            icon: 'status_success',
          },
        },
      });

      expect(wrapper.find('.js-job-component-tooltip').attributes('title')).toBe('test');
    });

    it('should not render status label when it is  provided', () => {
      createWrapper({
        job: {
          id: 4259,
          name: 'test',
          status: {
            icon: 'status_success',
            label: 'success',
            tooltip: 'success',
          },
        },
      });

      expect(wrapper.find('.js-job-component-tooltip').attributes('title')).toEqual(
        'test - success',
      );
    });
  });

  describe('for delayed job', () => {
    it('displays remaining time in tooltip', () => {
      createWrapper({
        job: delayedJobFixture,
      });

      expect(wrapper.find('.js-pipeline-graph-job-link').attributes('title')).toEqual(
        `delayed job - delayed manual action (${wrapper.vm.remainingTime})`,
      );
    });
  });
});