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

215 lines
5.7 KiB
JavaScript
Raw Normal View History

2021-02-22 17:27:13 +05:30
import { mount, shallowMount } from '@vue/test-utils';
import JobItem from '~/pipelines/components/graph/job_item.vue';
import StageColumnComponent from '~/pipelines/components/graph/stage_column_component.vue';
2021-04-29 21:17:54 +05:30
import ActionComponent from '~/pipelines/components/jobs_shared/action_component.vue';
2020-04-22 19:07:51 +05:30
2021-02-22 17:27:13 +05:30
const mockJob = {
id: 4250,
name: 'test',
status: {
icon: 'status_success',
text: 'passed',
label: 'passed',
group: 'success',
details_path: '/root/ci-mock/builds/4250',
action: {
icon: 'retry',
title: 'Retry',
path: '/root/ci-mock/builds/4250/retry',
method: 'post',
2020-04-22 19:07:51 +05:30
},
2021-02-22 17:27:13 +05:30
},
};
2020-04-22 19:07:51 +05:30
2021-02-22 17:27:13 +05:30
const mockGroups = Array(4)
.fill(0)
.map((item, idx) => {
2021-04-29 21:17:54 +05:30
return { ...mockJob, jobs: [mockJob], id: idx, name: `fish-${idx}` };
2021-02-22 17:27:13 +05:30
});
const defaultProps = {
2021-04-29 21:17:54 +05:30
name: 'Fish',
2021-02-22 17:27:13 +05:30
groups: mockGroups,
2021-03-08 18:12:59 +05:30
pipelineId: 159,
2021-02-22 17:27:13 +05:30
};
describe('stage column component', () => {
2020-04-22 19:07:51 +05:30
let wrapper;
2021-02-22 17:27:13 +05:30
const findStageColumnTitle = () => wrapper.find('[data-testid="stage-column-title"]');
const findStageColumnGroup = () => wrapper.find('[data-testid="stage-column-group"]');
const findAllStageColumnGroups = () => wrapper.findAll('[data-testid="stage-column-group"]');
const findJobItem = () => wrapper.find(JobItem);
const findActionComponent = () => wrapper.find(ActionComponent);
2020-04-22 19:07:51 +05:30
2021-02-22 17:27:13 +05:30
const createComponent = ({ method = shallowMount, props = {} } = {}) => {
wrapper = method(StageColumnComponent, {
2020-04-22 19:07:51 +05:30
propsData: {
2021-02-22 17:27:13 +05:30
...defaultProps,
...props,
2020-04-22 19:07:51 +05:30
},
});
2021-02-22 17:27:13 +05:30
};
afterEach(() => {
wrapper.destroy();
wrapper = null;
2020-04-22 19:07:51 +05:30
});
2021-02-22 17:27:13 +05:30
describe('when mounted', () => {
beforeEach(() => {
createComponent({ method: mount });
});
it('should render provided title', () => {
2021-04-29 21:17:54 +05:30
expect(findStageColumnTitle().text()).toBe(defaultProps.name);
2021-02-22 17:27:13 +05:30
});
it('should render the provided groups', () => {
expect(findAllStageColumnGroups().length).toBe(mockGroups.length);
});
2021-03-11 19:13:27 +05:30
it('should emit updateMeasurements event on mount', () => {
expect(wrapper.emitted().updateMeasurements).toHaveLength(1);
});
2020-04-22 19:07:51 +05:30
});
2021-02-22 17:27:13 +05:30
describe('when job notifies action is complete', () => {
beforeEach(() => {
createComponent({
method: mount,
props: {
groups: [
{
title: 'Fish',
size: 1,
jobs: [mockJob],
},
],
},
});
findJobItem().vm.$emit('pipelineActionRequestComplete');
});
it('emits refreshPipelineGraph', () => {
expect(wrapper.emitted().refreshPipelineGraph).toHaveLength(1);
});
2020-04-22 19:07:51 +05:30
});
2021-02-22 17:27:13 +05:30
describe('job', () => {
2021-03-08 18:12:59 +05:30
describe('text handling', () => {
beforeEach(() => {
createComponent({
method: mount,
props: {
groups: [
{
2021-04-29 21:17:54 +05:30
...mockJob,
2021-03-08 18:12:59 +05:30
name: '<img src=x onerror=alert(document.domain)>',
2021-04-29 21:17:54 +05:30
jobs: [
{
id: 4259,
name: '<img src=x onerror=alert(document.domain)>',
status: {
icon: 'status_success',
label: 'success',
tooltip: '<img src=x onerror=alert(document.domain)>',
},
},
],
2020-04-22 19:07:51 +05:30
},
2021-03-08 18:12:59 +05:30
],
2021-04-29 21:17:54 +05:30
name: 'test <img src=x onerror=alert(document.domain)>',
2021-03-08 18:12:59 +05:30
},
});
2020-04-22 19:07:51 +05:30
});
2021-03-08 18:12:59 +05:30
it('capitalizes and escapes name', () => {
expect(findStageColumnTitle().text()).toBe(
'Test &lt;img src=x onerror=alert(document.domain)&gt;',
);
});
it('escapes id', () => {
expect(findStageColumnGroup().attributes('id')).toBe(
'ci-badge-&lt;img src=x onerror=alert(document.domain)&gt;',
);
});
2021-02-22 17:27:13 +05:30
});
2021-03-08 18:12:59 +05:30
describe('interactions', () => {
beforeEach(() => {
createComponent({ method: mount });
});
it('emits jobHovered event on mouseenter and mouseleave', async () => {
await findStageColumnGroup().trigger('mouseenter');
expect(wrapper.emitted().jobHover).toEqual([[defaultProps.groups[0].name]]);
await findStageColumnGroup().trigger('mouseleave');
expect(wrapper.emitted().jobHover).toEqual([[defaultProps.groups[0].name], ['']]);
});
2020-04-22 19:07:51 +05:30
});
});
describe('with action', () => {
2021-02-22 17:27:13 +05:30
beforeEach(() => {
createComponent({
method: mount,
props: {
2020-04-22 19:07:51 +05:30
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)>',
},
2021-04-29 21:17:54 +05:30
jobs: [mockJob],
2020-04-22 19:07:51 +05:30
},
],
title: 'test',
hasTriggeredBy: false,
action: {
icon: 'play',
title: 'Play all',
path: 'action',
},
},
});
2021-02-22 17:27:13 +05:30
});
2020-04-22 19:07:51 +05:30
2021-02-22 17:27:13 +05:30
it('renders action button', () => {
expect(findActionComponent().exists()).toBe(true);
2020-04-22 19:07:51 +05:30
});
});
describe('without action', () => {
2021-02-22 17:27:13 +05:30
beforeEach(() => {
createComponent({
method: mount,
props: {
2020-04-22 19:07:51 +05:30
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)>',
},
2021-04-29 21:17:54 +05:30
jobs: [mockJob],
2020-04-22 19:07:51 +05:30
},
],
title: 'test',
hasTriggeredBy: false,
},
});
2021-02-22 17:27:13 +05:30
});
2020-04-22 19:07:51 +05:30
2021-02-22 17:27:13 +05:30
it('does not render action button', () => {
expect(findActionComponent().exists()).toBe(false);
2020-04-22 19:07:51 +05:30
});
});
});