gitlab-org--gitlab-foss/spec/frontend/pipelines/graph/job_item_spec.js

158 lines
4.1 KiB
JavaScript
Raw Normal View History

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: {
2018-07-18 12:56:19 -04:00
icon: 'status_success',
text: 'passed',
label: 'passed',
tooltip: 'passed',
group: 'success',
details_path: '/root/ci-mock/builds/4256',
has_details: true,
action: {
2017-10-05 17:16:37 -04:00
icon: 'retry',
title: 'Retry',
path: '/root/ci-mock/builds/4256/retry',
method: 'post',
},
},
};
afterEach(() => {
wrapper.destroy();
});
describe('name with link', () => {
2018-10-17 03:13:26 -04:00
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);
2017-05-24 07:42:23 -04:00
done();
});
});
});
describe('name without link', () => {
beforeEach(() => {
createWrapper({
job: {
2018-01-23 04:37:07 -05:00
id: 4257,
name: 'test',
status: {
2018-07-18 12:56:19 -04:00
icon: 'status_success',
text: 'passed',
label: 'passed',
group: 'success',
2018-01-23 04:37:07 -05:00
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');
});
2017-12-11 15:13:39 -05:00
describe('status label', () => {
it('should not render status label when it is not provided', () => {
createWrapper({
2017-12-11 15:13:39 -05:00
job: {
2018-01-23 04:37:07 -05:00
id: 4258,
2017-12-11 15:13:39 -05:00
name: 'test',
status: {
2018-07-18 12:56:19 -04:00
icon: 'status_success',
2017-12-11 15:13:39 -05:00
},
},
});
expect(wrapper.find('.js-job-component-tooltip').attributes('title')).toBe('test');
2017-12-11 15:13:39 -05:00
});
it('should not render status label when it is provided', () => {
createWrapper({
2017-12-11 15:13:39 -05:00
job: {
2018-01-23 04:37:07 -05:00
id: 4259,
2017-12-11 15:13:39 -05:00
name: 'test',
status: {
2018-07-18 12:56:19 -04:00
icon: 'status_success',
2017-12-11 15:13:39 -05:00
label: 'success',
tooltip: 'success',
2017-12-11 15:13:39 -05:00
},
},
});
expect(wrapper.find('.js-job-component-tooltip').attributes('title')).toEqual(
'test - success',
);
2017-12-11 15:13:39 -05:00
});
});
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})`,
);
});
});
});