2017-03-17 17:30:32 +00:00
|
|
|
import Vue from 'vue';
|
2017-05-29 10:02:06 +00:00
|
|
|
import pipelineUrlComp from '~/pipelines/components/pipeline_url.vue';
|
2017-03-17 17:30:32 +00:00
|
|
|
|
|
|
|
describe('Pipeline Url Component', () => {
|
|
|
|
let PipelineUrlComponent;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
PipelineUrlComponent = Vue.extend(pipelineUrlComp);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render a table cell', () => {
|
|
|
|
const component = new PipelineUrlComponent({
|
|
|
|
propsData: {
|
|
|
|
pipeline: {
|
|
|
|
id: 1,
|
|
|
|
path: 'foo',
|
|
|
|
flags: {},
|
|
|
|
},
|
2017-09-01 10:20:14 +00:00
|
|
|
autoDevopsHelpPath: 'foo',
|
2017-03-17 17:30:32 +00:00
|
|
|
},
|
|
|
|
}).$mount();
|
|
|
|
|
2017-06-16 12:00:28 +00:00
|
|
|
expect(component.$el.getAttribute('class')).toContain('table-section');
|
2017-03-17 17:30:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render a link the provided path and id', () => {
|
|
|
|
const component = new PipelineUrlComponent({
|
|
|
|
propsData: {
|
|
|
|
pipeline: {
|
|
|
|
id: 1,
|
|
|
|
path: 'foo',
|
|
|
|
flags: {},
|
|
|
|
},
|
2017-09-01 10:20:14 +00:00
|
|
|
autoDevopsHelpPath: 'foo',
|
2017-03-17 17:30:32 +00:00
|
|
|
},
|
|
|
|
}).$mount();
|
|
|
|
|
2018-08-07 06:04:33 +00:00
|
|
|
expect(component.$el.querySelector('.js-pipeline-url-link').getAttribute('href')).toEqual(
|
|
|
|
'foo',
|
|
|
|
);
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2017-03-17 17:30:32 +00:00
|
|
|
expect(component.$el.querySelector('.js-pipeline-url-link span').textContent).toEqual('#1');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render user information when a user is provided', () => {
|
|
|
|
const mockData = {
|
|
|
|
pipeline: {
|
|
|
|
id: 1,
|
|
|
|
path: 'foo',
|
|
|
|
flags: {},
|
|
|
|
user: {
|
|
|
|
web_url: '/',
|
|
|
|
name: 'foo',
|
|
|
|
avatar_url: '/',
|
2017-06-02 13:24:42 +00:00
|
|
|
path: '/',
|
2017-03-17 17:30:32 +00:00
|
|
|
},
|
|
|
|
},
|
2017-09-01 10:20:14 +00:00
|
|
|
autoDevopsHelpPath: 'foo',
|
2017-03-17 17:30:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const component = new PipelineUrlComponent({
|
|
|
|
propsData: mockData,
|
|
|
|
}).$mount();
|
|
|
|
|
|
|
|
const image = component.$el.querySelector('.js-pipeline-url-user img');
|
|
|
|
|
2018-08-07 06:04:33 +00:00
|
|
|
expect(component.$el.querySelector('.js-pipeline-url-user').getAttribute('href')).toEqual(
|
|
|
|
mockData.pipeline.user.web_url,
|
|
|
|
);
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2017-04-15 23:38:07 +00:00
|
|
|
expect(image.getAttribute('data-original-title')).toEqual(mockData.pipeline.user.name);
|
2018-08-07 06:04:33 +00:00
|
|
|
expect(image.getAttribute('src')).toEqual(`${mockData.pipeline.user.avatar_url}?width=20`);
|
2017-03-17 17:30:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render "API" when no user is provided', () => {
|
|
|
|
const component = new PipelineUrlComponent({
|
|
|
|
propsData: {
|
|
|
|
pipeline: {
|
|
|
|
id: 1,
|
|
|
|
path: 'foo',
|
|
|
|
flags: {},
|
|
|
|
},
|
2017-09-01 10:20:14 +00:00
|
|
|
autoDevopsHelpPath: 'foo',
|
2017-03-17 17:30:32 +00:00
|
|
|
},
|
|
|
|
}).$mount();
|
|
|
|
|
|
|
|
expect(component.$el.querySelector('.js-pipeline-url-api').textContent).toContain('API');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render latest, yaml invalid and stuck flags when provided', () => {
|
|
|
|
const component = new PipelineUrlComponent({
|
|
|
|
propsData: {
|
|
|
|
pipeline: {
|
|
|
|
id: 1,
|
|
|
|
path: 'foo',
|
|
|
|
flags: {
|
|
|
|
latest: true,
|
|
|
|
yaml_errors: true,
|
|
|
|
stuck: true,
|
|
|
|
},
|
|
|
|
},
|
2017-09-01 10:20:14 +00:00
|
|
|
autoDevopsHelpPath: 'foo',
|
2017-03-17 17:30:32 +00:00
|
|
|
},
|
|
|
|
}).$mount();
|
|
|
|
|
2017-06-16 12:00:28 +00:00
|
|
|
expect(component.$el.querySelector('.js-pipeline-url-latest').textContent).toContain('latest');
|
2018-08-07 06:04:33 +00:00
|
|
|
expect(component.$el.querySelector('.js-pipeline-url-yaml').textContent).toContain(
|
|
|
|
'yaml invalid',
|
|
|
|
);
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2017-03-17 17:30:32 +00:00
|
|
|
expect(component.$el.querySelector('.js-pipeline-url-stuck').textContent).toContain('stuck');
|
|
|
|
});
|
2017-09-01 09:46:08 +00:00
|
|
|
|
|
|
|
it('should render a badge for autodevops', () => {
|
|
|
|
const component = new PipelineUrlComponent({
|
|
|
|
propsData: {
|
|
|
|
pipeline: {
|
|
|
|
id: 1,
|
|
|
|
path: 'foo',
|
|
|
|
flags: {
|
|
|
|
latest: true,
|
|
|
|
yaml_errors: true,
|
|
|
|
stuck: true,
|
|
|
|
auto_devops: true,
|
|
|
|
},
|
|
|
|
},
|
2017-09-01 10:20:14 +00:00
|
|
|
autoDevopsHelpPath: 'foo',
|
2017-09-01 09:46:08 +00:00
|
|
|
},
|
|
|
|
}).$mount();
|
|
|
|
|
2018-08-07 06:04:33 +00:00
|
|
|
expect(component.$el.querySelector('.js-pipeline-url-autodevops').textContent.trim()).toEqual(
|
|
|
|
'Auto DevOps',
|
|
|
|
);
|
2017-09-01 09:46:08 +00:00
|
|
|
});
|
2017-10-04 07:32:22 +00:00
|
|
|
|
|
|
|
it('should render error badge when pipeline has a failure reason set', () => {
|
|
|
|
const component = new PipelineUrlComponent({
|
|
|
|
propsData: {
|
|
|
|
pipeline: {
|
|
|
|
id: 1,
|
|
|
|
path: 'foo',
|
|
|
|
flags: {
|
|
|
|
failure_reason: true,
|
|
|
|
},
|
2017-10-04 09:02:52 +00:00
|
|
|
failure_reason: 'some reason',
|
2017-10-04 07:32:22 +00:00
|
|
|
},
|
2017-10-04 09:02:52 +00:00
|
|
|
autoDevopsHelpPath: 'foo',
|
2017-10-04 07:32:22 +00:00
|
|
|
},
|
|
|
|
}).$mount();
|
|
|
|
|
|
|
|
expect(component.$el.querySelector('.js-pipeline-url-failure').textContent).toContain('error');
|
2018-08-07 06:04:33 +00:00
|
|
|
expect(
|
|
|
|
component.$el.querySelector('.js-pipeline-url-failure').getAttribute('data-original-title'),
|
|
|
|
).toContain('some reason');
|
2017-10-04 07:32:22 +00:00
|
|
|
});
|
2017-03-17 17:30:32 +00:00
|
|
|
});
|