1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
import Vue from 'vue';
import { statusIconEntityMap } from '~/vue_shared/ci_status_icons';
import pipelineComponent from '~/vue_merge_request_widget/components/mr_widget_pipeline';
import mockData from '../mock_data';
const createComponent = (mr) => {
const Component = Vue.extend(pipelineComponent);
return new Component({
el: document.createElement('div'),
propsData: { mr },
});
};
describe('MRWidgetPipeline', () => {
describe('props', () => {
it('should have props', () => {
const { mr } = pipelineComponent.props;
expect(mr.type instanceof Object).toBeTruthy();
expect(mr.required).toBeTruthy();
});
});
describe('components', () => {
it('should have components added', () => {
expect(pipelineComponent.components['pipeline-stage']).toBeDefined();
expect(pipelineComponent.components.ciIcon).toBeDefined();
});
});
describe('computed', () => {
describe('svg', () => {
it('should have the proper SVG icon', () => {
const vm = createComponent({ pipeline: mockData.pipeline });
expect(vm.svg).toEqual(statusIconEntityMap.icon_status_failed);
});
});
describe('hasCIError', () => {
it('should return false when there is no CI error', () => {
const vm = createComponent({
pipeline: mockData.pipeline,
hasCI: true,
ciStatus: 'success',
});
expect(vm.hasCIError).toBeFalsy();
});
it('should return true when there is a CI error', () => {
const vm = createComponent({
pipeline: mockData.pipeline,
hasCI: true,
ciStatus: null,
});
expect(vm.hasCIError).toBeTruthy();
});
});
});
describe('template', () => {
let vm;
let el;
const { pipeline } = mockData;
const mr = {
hasCI: true,
ciStatus: 'success',
pipelineDetailedStatus: pipeline.details.status,
pipeline,
};
beforeEach(() => {
vm = createComponent(mr);
el = vm.$el;
});
it('should render template elements correctly', () => {
expect(el.classList.contains('mr-widget-heading')).toBeTruthy();
expect(el.querySelectorAll('.ci-status-icon.ci-status-icon-success').length).toEqual(1);
expect(el.querySelector('.pipeline-id').textContent).toContain(`#${pipeline.id}`);
expect(el.innerText).toContain('passed');
expect(el.querySelector('.pipeline-id').getAttribute('href')).toEqual(pipeline.path);
expect(el.querySelectorAll('.stage-container').length).toEqual(2);
expect(el.querySelector('.js-ci-error')).toEqual(null);
expect(el.querySelector('.js-commit-link').getAttribute('href')).toEqual(pipeline.commit.commit_path);
expect(el.querySelector('.js-commit-link').textContent).toContain(pipeline.commit.short_id);
expect(el.querySelector('.js-mr-coverage').textContent).toContain(`Coverage ${pipeline.coverage}%`);
});
it('should list single stage', (done) => {
pipeline.details.stages.splice(0, 1);
Vue.nextTick(() => {
expect(el.querySelectorAll('.stage-container button').length).toEqual(1);
done();
});
});
it('should not have stages when there is no stage', (done) => {
vm.mr.pipeline.details.stages = [];
Vue.nextTick(() => {
expect(el.querySelectorAll('.stage-container button').length).toEqual(0);
done();
});
});
it('should not have coverage text when pipeline has no coverage info', (done) => {
vm.mr.pipeline.coverage = null;
Vue.nextTick(() => {
expect(el.querySelector('.js-mr-coverage')).toEqual(null);
done();
});
});
it('should show CI error when there is a CI error', (done) => {
vm.mr.ciStatus = null;
Vue.nextTick(() => {
expect(el.querySelectorAll('.js-ci-error').length).toEqual(1);
expect(el.innerText).toContain('Could not connect to the CI server');
done();
});
});
});
});
|