debian-mirror-gitlab/spec/frontend/pipelines/graph/job_item_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

294 lines
8.5 KiB
JavaScript
Raw Normal View History

2020-01-01 13:55:28 +05:30
import { mount } from '@vue/test-utils';
2022-04-04 11:22:00 +05:30
import { nextTick } from 'vue';
2018-12-13 13:39:08 +05:30
import JobItem from '~/pipelines/components/graph/job_item.vue';
2017-08-17 22:00:37 +05:30
2018-12-13 13:39:08 +05:30
describe('pipeline graph job item', () => {
2020-01-01 13:55:28 +05:30
let wrapper;
2020-07-28 23:09:34 +05:30
const findJobWithoutLink = () => wrapper.find('[data-testid="job-without-link"]');
2020-11-24 15:15:51 +05:30
const findJobWithLink = () => wrapper.find('[data-testid="job-with-link"]');
2022-04-04 11:22:00 +05:30
const findActionComponent = () => wrapper.find('[data-testid="ci-action-component"]');
2020-07-28 23:09:34 +05:30
2021-03-08 18:12:59 +05:30
const createWrapper = (propsData) => {
2020-03-13 15:44:24 +05:30
wrapper = mount(JobItem, {
propsData,
});
2020-01-01 13:55:28 +05:30
};
2017-08-17 22:00:37 +05:30
2020-11-24 15:15:51 +05:30
const triggerActiveClass = 'gl-shadow-x0-y0-b3-s1-blue-500';
2021-11-11 11:23:49 +05:30
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',
},
},
};
2017-08-17 22:00:37 +05:30
const mockJob = {
id: 4256,
name: 'test',
status: {
2018-11-18 11:00:15 +05:30
icon: 'status_success',
2017-08-17 22:00:37 +05:30
text: 'passed',
label: 'passed',
2018-05-09 12:01:36 +05:30
tooltip: 'passed',
2017-08-17 22:00:37 +05:30
group: 'success',
2021-11-11 11:23:49 +05:30
detailsPath: '/root/ci-mock/builds/4256',
hasDetails: true,
2017-08-17 22:00:37 +05:30
action: {
2018-03-17 18:26:18 +05:30
icon: 'retry',
2017-08-17 22:00:37 +05:30
title: 'Retry',
path: '/root/ci-mock/builds/4256/retry',
method: 'post',
},
},
};
2020-11-24 15:15:51 +05:30
const mockJobWithoutDetails = {
id: 4257,
name: 'job_without_details',
status: {
icon: 'status_success',
text: 'passed',
label: 'passed',
group: 'success',
2021-11-11 11:23:49 +05:30
detailsPath: '/root/ci-mock/builds/4257',
hasDetails: false,
2020-11-24 15:15:51 +05:30
},
};
2022-04-04 11:22:00 +05:30
const mockJobWithUnauthorizedAction = {
id: 4258,
name: 'stop-environment',
status: {
icon: 'status_manual',
label: 'manual stop action (not allowed)',
tooltip: 'manual action',
group: 'manual',
detailsPath: '/root/ci-mock/builds/4258',
hasDetails: true,
action: null,
},
};
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
afterEach(() => {
2020-01-01 13:55:28 +05:30
wrapper.destroy();
2018-03-17 18:26:18 +05:30
});
2017-08-17 22:00:37 +05:30
describe('name with link', () => {
2022-04-04 11:22:00 +05:30
it('should render the job name and status with a link', async () => {
2020-01-01 13:55:28 +05:30
createWrapper({ job: mockJob });
2017-08-17 22:00:37 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
const link = wrapper.find('a');
2017-08-17 22:00:37 +05:30
2022-04-04 11:22:00 +05:30
expect(link.attributes('href')).toBe(mockJob.status.detailsPath);
2017-08-17 22:00:37 +05:30
2022-04-04 11:22:00 +05:30
expect(link.attributes('title')).toBe(`${mockJob.name} - ${mockJob.status.label}`);
2017-08-17 22:00:37 +05:30
2022-04-04 11:22:00 +05:30
expect(wrapper.find('.ci-status-icon-success').exists()).toBe(true);
2017-09-10 17:25:29 +05:30
2022-04-04 11:22:00 +05:30
expect(wrapper.text()).toBe(mockJob.name);
2017-08-17 22:00:37 +05:30
});
});
describe('name without link', () => {
2020-07-28 23:09:34 +05:30
beforeEach(() => {
2020-01-01 13:55:28 +05:30
createWrapper({
2020-11-24 15:15:51 +05:30
job: mockJobWithoutDetails,
2020-07-28 23:09:34 +05:30
cssClassJobName: 'css-class-job-name',
jobHovered: 'test',
2018-03-17 18:26:18 +05:30
});
2020-07-28 23:09:34 +05:30
});
2017-08-17 22:00:37 +05:30
2020-07-28 23:09:34 +05:30
it('it should render status and name', () => {
2020-04-22 19:07:51 +05:30
expect(wrapper.find('.ci-status-icon-success').exists()).toBe(true);
2020-01-01 13:55:28 +05:30
expect(wrapper.find('a').exists()).toBe(false);
2017-08-17 22:00:37 +05:30
2021-01-03 14:25:43 +05:30
expect(wrapper.text()).toBe(mockJobWithoutDetails.name);
2017-08-17 22:00:37 +05:30
});
2020-07-28 23:09:34 +05:30
it('should apply hover class and provided class name', () => {
expect(findJobWithoutLink().classes()).toContain('css-class-job-name');
});
2017-08-17 22:00:37 +05:30
});
describe('action icon', () => {
it('it should render the action icon', () => {
2020-01-01 13:55:28 +05:30
createWrapper({ job: mockJob });
2017-08-17 22:00:37 +05:30
2022-04-04 11:22:00 +05:30
const actionComponent = findActionComponent();
expect(actionComponent.exists()).toBe(true);
expect(actionComponent.props('actionIcon')).toBe('retry');
expect(actionComponent.attributes('disabled')).not.toBe('disabled');
});
it('it should render disabled action icon when user cannot run the action', () => {
createWrapper({ job: mockJobWithUnauthorizedAction });
const actionComponent = findActionComponent();
expect(actionComponent.exists()).toBe(true);
expect(actionComponent.props('actionIcon')).toBe('stop');
expect(actionComponent.attributes('disabled')).toBe('disabled');
2017-08-17 22:00:37 +05:30
});
});
it('should render provided class name', () => {
2020-01-01 13:55:28 +05:30
createWrapper({
2018-03-17 18:26:18 +05:30
job: mockJob,
cssClassJobName: 'css-class-job-name',
});
2017-08-17 22:00:37 +05:30
2020-01-01 13:55:28 +05:30
expect(wrapper.find('a').classes()).toContain('css-class-job-name');
2017-08-17 22:00:37 +05:30
});
2018-03-17 18:26:18 +05:30
describe('status label', () => {
it('should not render status label when it is not provided', () => {
2020-01-01 13:55:28 +05:30
createWrapper({
2018-03-17 18:26:18 +05:30
job: {
id: 4258,
name: 'test',
status: {
2018-11-18 11:00:15 +05:30
icon: 'status_success',
2018-03-17 18:26:18 +05:30
},
},
});
2021-04-29 21:17:54 +05:30
expect(findJobWithoutLink().attributes('title')).toBe('test');
2018-03-17 18:26:18 +05:30
});
it('should not render status label when it is provided', () => {
2020-01-01 13:55:28 +05:30
createWrapper({
2018-03-17 18:26:18 +05:30
job: {
id: 4259,
name: 'test',
status: {
2018-11-18 11:00:15 +05:30
icon: 'status_success',
2018-03-17 18:26:18 +05:30
label: 'success',
2018-05-09 12:01:36 +05:30
tooltip: 'success',
2018-03-17 18:26:18 +05:30
},
},
});
2021-04-29 21:17:54 +05:30
expect(findJobWithoutLink().attributes('title')).toBe('test - success');
2018-03-17 18:26:18 +05:30
});
});
2018-10-15 14:42:47 +05:30
2018-12-13 13:39:08 +05:30
describe('for delayed job', () => {
2019-02-15 15:39:39 +05:30
it('displays remaining time in tooltip', () => {
2020-01-01 13:55:28 +05:30
createWrapper({
2021-11-11 11:23:49 +05:30
job: delayedJob,
2018-12-13 13:39:08 +05:30
});
2020-11-24 15:15:51 +05:30
expect(findJobWithLink().attributes('title')).toBe(
2020-01-01 13:55:28 +05:30
`delayed job - delayed manual action (${wrapper.vm.remainingTime})`,
);
2018-12-13 13:39:08 +05:30
});
});
2020-11-24 15:15:51 +05:30
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);
},
);
});
2021-11-18 22:05:49 +05:30
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);
});
});
2017-08-17 22:00:37 +05:30
});