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

123 lines
3.3 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
import Vue from 'vue';
2018-10-15 14:42:47 +05:30
import mountComponent from 'spec/helpers/vue_mount_component_helper';
2020-01-01 13:55:28 +05:30
import stageColumnComponent from '~/pipelines/components/graph/stage_column_component.vue';
2017-08-17 22:00:37 +05:30
describe('stage column component', () => {
let component;
2018-10-15 14:42:47 +05:30
const StageColumnComponent = Vue.extend(stageColumnComponent);
2017-08-17 22:00:37 +05:30
const mockJob = {
2018-03-17 18:26:18 +05:30
id: 4250,
2017-08-17 22:00:37 +05:30
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',
group: 'success',
2018-03-17 18:26:18 +05:30
details_path: '/root/ci-mock/builds/4250',
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',
2018-03-17 18:26:18 +05:30
path: '/root/ci-mock/builds/4250/retry',
2017-08-17 22:00:37 +05:30
method: 'post',
},
},
};
beforeEach(() => {
2018-12-13 13:39:08 +05:30
const mockGroups = [];
2018-03-17 18:26:18 +05:30
for (let i = 0; i < 3; i += 1) {
const mockedJob = Object.assign({}, mockJob);
mockedJob.id += i;
2018-12-13 13:39:08 +05:30
mockGroups.push(mockedJob);
2018-03-17 18:26:18 +05:30
}
2018-10-15 14:42:47 +05:30
component = mountComponent(StageColumnComponent, {
title: 'foo',
2018-12-13 13:39:08 +05:30
groups: mockGroups,
2019-07-07 11:18:12 +05:30
hasTriggeredBy: false,
2018-10-15 14:42:47 +05:30
});
2017-08-17 22:00:37 +05:30
});
it('should render provided title', () => {
expect(component.$el.querySelector('.stage-name').textContent.trim()).toEqual('foo');
});
2018-12-13 13:39:08 +05:30
it('should render the provided groups', () => {
2017-08-17 22:00:37 +05:30
expect(component.$el.querySelectorAll('.builds-container > ul > li').length).toEqual(3);
});
2018-10-15 14:42:47 +05:30
describe('jobId', () => {
it('escapes job name', () => {
component = mountComponent(StageColumnComponent, {
2018-12-13 13:39:08 +05:30
groups: [
2018-10-15 14:42:47 +05:30
{
id: 4259,
name: '<img src=x onerror=alert(document.domain)>',
status: {
2019-07-07 11:18:12 +05:30
icon: 'status_success',
2018-10-15 14:42:47 +05:30
label: 'success',
tooltip: '<img src=x onerror=alert(document.domain)>',
},
},
],
title: 'test',
2019-07-07 11:18:12 +05:30
hasTriggeredBy: false,
2018-10-15 14:42:47 +05:30
});
2018-12-13 13:39:08 +05:30
expect(component.$el.querySelector('.builds-container li').getAttribute('id')).toEqual(
'ci-badge-&lt;img src=x onerror=alert(document.domain)&gt;',
);
2018-10-15 14:42:47 +05:30
});
});
2019-07-31 22:56:46 +05:30
describe('with action', () => {
it('renders action button', () => {
component = mountComponent(StageColumnComponent, {
groups: [
{
id: 4259,
name: '<img src=x onerror=alert(document.domain)>',
status: {
icon: 'status_success',
label: 'success',
tooltip: '<img src=x onerror=alert(document.domain)>',
},
},
],
title: 'test',
hasTriggeredBy: false,
action: {
icon: 'play',
title: 'Play all',
path: 'action',
},
});
expect(component.$el.querySelector('.js-stage-action')).not.toBeNull();
});
});
describe('without action', () => {
it('does not render action button', () => {
component = mountComponent(StageColumnComponent, {
groups: [
{
id: 4259,
name: '<img src=x onerror=alert(document.domain)>',
status: {
icon: 'status_success',
label: 'success',
tooltip: '<img src=x onerror=alert(document.domain)>',
},
},
],
title: 'test',
hasTriggeredBy: false,
});
expect(component.$el.querySelector('.js-stage-action')).toBeNull();
});
});
2017-08-17 22:00:37 +05:30
});