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

job_item_spec.js « graph « pipelines « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 06f1fa4c8274ce43dd259167566cfe05909581cc (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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
import { mount } from '@vue/test-utils';
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 findJobWithLink = () => wrapper.find('[data-testid="job-with-link"]');

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

  const triggerActiveClass = 'gl-shadow-x0-y0-b3-s1-blue-500';

  const delayedJob = {
    __typename: 'CiJob',
    name: 'delayed job',
    scheduledAt: '2015-07-03T10:01:00.000Z',
    needs: [],
    status: {
      __typename: 'DetailedStatus',
      icon: 'status_scheduled',
      tooltip: 'delayed manual action (%{remainingTime})',
      hasDetails: true,
      detailsPath: '/root/kinder-pipe/-/jobs/5339',
      group: 'scheduled',
      action: {
        __typename: 'StatusAction',
        icon: 'time-out',
        title: 'Unschedule',
        path: '/frontend-fixtures/builds-project/-/jobs/142/unschedule',
        buttonTitle: 'Unschedule job',
      },
    },
  };

  const mockJob = {
    id: 4256,
    name: 'test',
    status: {
      icon: 'status_success',
      text: 'passed',
      label: 'passed',
      tooltip: 'passed',
      group: 'success',
      detailsPath: '/root/ci-mock/builds/4256',
      hasDetails: true,
      action: {
        icon: 'retry',
        title: 'Retry',
        path: '/root/ci-mock/builds/4256/retry',
        method: 'post',
      },
    },
  };
  const mockJobWithoutDetails = {
    id: 4257,
    name: 'job_without_details',
    status: {
      icon: 'status_success',
      text: 'passed',
      label: 'passed',
      group: 'success',
      detailsPath: '/root/ci-mock/builds/4257',
      hasDetails: false,
    },
  };

  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.detailsPath);

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

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

        expect(wrapper.text()).toBe(mockJob.name);

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

  describe('name without link', () => {
    beforeEach(() => {
      createWrapper({
        job: mockJobWithoutDetails,
        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(wrapper.text()).toBe(mockJobWithoutDetails.name);
    });

    it('should apply hover class and provided class name', () => {
      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(findJobWithoutLink().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(findJobWithoutLink().attributes('title')).toBe('test - success');
    });
  });

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

      expect(findJobWithLink().attributes('title')).toBe(
        `delayed job - delayed manual action (${wrapper.vm.remainingTime})`,
      );
    });
  });

  describe('trigger job highlighting', () => {
    it.each`
      job                      | jobName                       | expanded | link
      ${mockJob}               | ${mockJob.name}               | ${true}  | ${true}
      ${mockJobWithoutDetails} | ${mockJobWithoutDetails.name} | ${true}  | ${false}
    `(
      `trigger job should stay highlighted when downstream is expanded`,
      ({ job, jobName, expanded, link }) => {
        createWrapper({ job, pipelineExpanded: { jobName, expanded } });
        const findJobEl = link ? findJobWithLink : findJobWithoutLink;

        expect(findJobEl().classes()).toContain(triggerActiveClass);
      },
    );

    it.each`
      job                      | jobName                       | expanded | link
      ${mockJob}               | ${mockJob.name}               | ${false} | ${true}
      ${mockJobWithoutDetails} | ${mockJobWithoutDetails.name} | ${false} | ${false}
    `(
      `trigger job should not be highlighted when downstream is not expanded`,
      ({ job, jobName, expanded, link }) => {
        createWrapper({ job, pipelineExpanded: { jobName, expanded } });
        const findJobEl = link ? findJobWithLink : findJobWithoutLink;

        expect(findJobEl().classes()).not.toContain(triggerActiveClass);
      },
    );
  });

  describe('job classes', () => {
    it('job class is shown', () => {
      createWrapper({
        job: mockJob,
        cssClassJobName: 'my-class',
      });

      expect(wrapper.find('a').classes()).toContain('my-class');

      expect(wrapper.find('a').classes()).not.toContain(triggerActiveClass);
    });

    it('job class is shown, along with hover', () => {
      createWrapper({
        job: mockJob,
        cssClassJobName: 'my-class',
        sourceJobHovered: mockJob.name,
      });

      expect(wrapper.find('a').classes()).toContain('my-class');
      expect(wrapper.find('a').classes()).toContain(triggerActiveClass);
    });

    it('multiple job classes are shown', () => {
      createWrapper({
        job: mockJob,
        cssClassJobName: ['my-class-1', 'my-class-2'],
      });

      expect(wrapper.find('a').classes()).toContain('my-class-1');
      expect(wrapper.find('a').classes()).toContain('my-class-2');

      expect(wrapper.find('a').classes()).not.toContain(triggerActiveClass);
    });

    it('multiple job classes are shown conditionally', () => {
      createWrapper({
        job: mockJob,
        cssClassJobName: { 'my-class-1': true, 'my-class-2': true },
      });

      expect(wrapper.find('a').classes()).toContain('my-class-1');
      expect(wrapper.find('a').classes()).toContain('my-class-2');

      expect(wrapper.find('a').classes()).not.toContain(triggerActiveClass);
    });

    it('multiple job classes are shown, along with a hover', () => {
      createWrapper({
        job: mockJob,
        cssClassJobName: ['my-class-1', 'my-class-2'],
        sourceJobHovered: mockJob.name,
      });

      expect(wrapper.find('a').classes()).toContain('my-class-1');
      expect(wrapper.find('a').classes()).toContain('my-class-2');
      expect(wrapper.find('a').classes()).toContain(triggerActiveClass);
    });
  });
});