debian-mirror-gitlab/spec/javascripts/pipelines/graph/job_component_spec.js

165 lines
4.5 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
import Vue from 'vue';
import jobComponent from '~/pipelines/components/graph/job_component.vue';
2018-03-27 19:54:05 +05:30
import mountComponent from 'spec/helpers/vue_mount_component_helper';
2017-08-17 22:00:37 +05:30
describe('pipeline graph job component', () => {
2018-10-15 14:42:47 +05:30
const JobComponent = Vue.extend(jobComponent);
2018-03-17 18:26:18 +05:30
let component;
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',
details_path: '/root/ci-mock/builds/4256',
2018-03-17 18:26:18 +05:30
has_details: 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',
},
},
};
2018-03-17 18:26:18 +05:30
afterEach(() => {
component.$destroy();
});
2017-08-17 22:00:37 +05:30
describe('name with link', () => {
2017-09-10 17:25:29 +05:30
it('should render the job name and status with a link', (done) => {
2018-03-17 18:26:18 +05:30
component = mountComponent(JobComponent, { job: mockJob });
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
Vue.nextTick(() => {
const link = component.$el.querySelector('a');
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
expect(link.getAttribute('href')).toEqual(mockJob.status.details_path);
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
expect(
link.getAttribute('data-original-title'),
).toEqual(`${mockJob.name} - ${mockJob.status.label}`);
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
expect(component.$el.querySelector('.js-status-icon-success')).toBeDefined();
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
expect(
component.$el.querySelector('.ci-status-text').textContent.trim(),
).toEqual(mockJob.name);
done();
});
2017-08-17 22:00:37 +05:30
});
});
describe('name without link', () => {
it('it should render status and name', () => {
2018-03-17 18:26:18 +05:30
component = mountComponent(JobComponent, {
job: {
id: 4257,
name: 'test',
status: {
2018-11-18 11:00:15 +05:30
icon: 'status_success',
2018-03-17 18:26:18 +05:30
text: 'passed',
label: 'passed',
group: 'success',
details_path: '/root/ci-mock/builds/4257',
has_details: false,
2017-08-17 22:00:37 +05:30
},
},
2018-03-17 18:26:18 +05:30
});
2017-08-17 22:00:37 +05:30
expect(component.$el.querySelector('.js-status-icon-success')).toBeDefined();
2018-03-17 18:26:18 +05:30
expect(component.$el.querySelector('a')).toBeNull();
2017-08-17 22:00:37 +05:30
expect(
component.$el.querySelector('.ci-status-text').textContent.trim(),
).toEqual(mockJob.name);
});
});
describe('action icon', () => {
it('it should render the action icon', () => {
2018-03-17 18:26:18 +05:30
component = mountComponent(JobComponent, { job: mockJob });
2017-08-17 22:00:37 +05:30
expect(component.$el.querySelector('a.ci-action-icon-container')).toBeDefined();
expect(component.$el.querySelector('i.ci-action-icon-wrapper')).toBeDefined();
});
});
it('should render provided class name', () => {
2018-03-17 18:26:18 +05:30
component = mountComponent(JobComponent, {
job: mockJob,
cssClassJobName: 'css-class-job-name',
});
2017-08-17 22:00:37 +05:30
expect(
component.$el.querySelector('a').classList.contains('css-class-job-name'),
).toBe(true);
});
2018-03-17 18:26:18 +05:30
describe('status label', () => {
it('should not render status label when it is not provided', () => {
component = mountComponent(JobComponent, {
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
},
},
});
expect(component.$el.querySelector('.js-job-component-tooltip').getAttribute('data-original-title')).toEqual('test');
});
it('should not render status label when it is provided', () => {
component = mountComponent(JobComponent, {
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
},
},
});
expect(component.$el.querySelector('.js-job-component-tooltip').getAttribute('data-original-title')).toEqual('test - success');
});
});
2018-10-15 14:42:47 +05:30
2018-11-08 19:23:39 +05:30
describe('tooltip placement', () => {
const tooltipBoundary = 'a[data-boundary="viewport"]';
it('does not set tooltip boundary by default', () => {
2018-10-15 14:42:47 +05:30
component = mountComponent(JobComponent, {
2018-11-08 19:23:39 +05:30
job: mockJob,
2018-10-15 14:42:47 +05:30
});
2018-11-08 19:23:39 +05:30
expect(component.$el.querySelector(tooltipBoundary)).toBeNull();
});
it('sets tooltip boundary to viewport for small dropdowns', () => {
component = mountComponent(JobComponent, {
job: mockJob,
dropdownLength: 1,
});
expect(component.$el.querySelector(tooltipBoundary)).not.toBeNull();
});
it('does not set tooltip boundary for large lists', () => {
component = mountComponent(JobComponent, {
job: mockJob,
dropdownLength: 7,
});
expect(component.$el.querySelector(tooltipBoundary)).toBeNull();
2018-10-15 14:42:47 +05:30
});
});
2017-08-17 22:00:37 +05:30
});