2021-03-11 19:13:27 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-01-01 13:55:28 +05:30
|
|
|
import { trimText } from 'helpers/text_helper';
|
2020-07-28 23:09:34 +05:30
|
|
|
import PipelineUrlComponent from '~/pipelines/components/pipelines_list/pipeline_url.vue';
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
const projectPath = 'test/test';
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
describe('Pipeline Url Component', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
const findTableCell = () => wrapper.find('[data-testid="pipeline-url-table-cell"]');
|
2020-07-28 23:09:34 +05:30
|
|
|
const findPipelineUrlLink = () => wrapper.find('[data-testid="pipeline-url-link"]');
|
|
|
|
const findScheduledTag = () => wrapper.find('[data-testid="pipeline-url-scheduled"]');
|
|
|
|
const findLatestTag = () => wrapper.find('[data-testid="pipeline-url-latest"]');
|
|
|
|
const findYamlTag = () => wrapper.find('[data-testid="pipeline-url-yaml"]');
|
|
|
|
const findFailureTag = () => wrapper.find('[data-testid="pipeline-url-failure"]');
|
|
|
|
const findAutoDevopsTag = () => wrapper.find('[data-testid="pipeline-url-autodevops"]');
|
2021-04-17 20:07:23 +05:30
|
|
|
const findAutoDevopsTagLink = () => wrapper.find('[data-testid="pipeline-url-autodevops-link"]');
|
2020-07-28 23:09:34 +05:30
|
|
|
const findStuckTag = () => wrapper.find('[data-testid="pipeline-url-stuck"]');
|
|
|
|
const findDetachedTag = () => wrapper.find('[data-testid="pipeline-url-detached"]');
|
2021-02-22 17:27:13 +05:30
|
|
|
const findForkTag = () => wrapper.find('[data-testid="pipeline-url-fork"]');
|
2021-03-11 19:13:27 +05:30
|
|
|
const findTrainTag = () => wrapper.find('[data-testid="pipeline-url-train"]');
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
pipeline: {
|
|
|
|
id: 1,
|
|
|
|
path: 'foo',
|
2021-04-17 20:07:23 +05:30
|
|
|
project: { full_path: `/${projectPath}` },
|
2020-07-28 23:09:34 +05:30
|
|
|
flags: {},
|
|
|
|
},
|
|
|
|
pipelineScheduleUrl: 'foo',
|
2021-10-27 15:23:28 +05:30
|
|
|
pipelineKey: 'id',
|
2020-07-28 23:09:34 +05:30
|
|
|
};
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const createComponent = (props) => {
|
2020-01-01 13:55:28 +05:30
|
|
|
wrapper = shallowMount(PipelineUrlComponent, {
|
2020-07-28 23:09:34 +05:30
|
|
|
propsData: { ...defaultProps, ...props },
|
2021-02-22 17:27:13 +05:30
|
|
|
provide: {
|
2021-04-17 20:07:23 +05:30
|
|
|
targetProjectFullPath: projectPath,
|
2021-02-22 17:27:13 +05:30
|
|
|
},
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
2020-07-28 23:09:34 +05:30
|
|
|
wrapper = null;
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it('should render pipeline url table cell', () => {
|
2020-07-28 23:09:34 +05:30
|
|
|
createComponent();
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(findTableCell().exists()).toBe(true);
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should render a link the provided path and id', () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
expect(findPipelineUrlLink().attributes('href')).toBe('foo');
|
|
|
|
|
|
|
|
expect(findPipelineUrlLink().text()).toBe('#1');
|
|
|
|
});
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it('should not render tags when flags are not set', () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
expect(findStuckTag().exists()).toBe(false);
|
|
|
|
expect(findLatestTag().exists()).toBe(false);
|
|
|
|
expect(findYamlTag().exists()).toBe(false);
|
|
|
|
expect(findAutoDevopsTag().exists()).toBe(false);
|
|
|
|
expect(findFailureTag().exists()).toBe(false);
|
|
|
|
expect(findScheduledTag().exists()).toBe(false);
|
|
|
|
expect(findForkTag().exists()).toBe(false);
|
|
|
|
expect(findTrainTag().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
it('should render the stuck tag when flag is provided', () => {
|
2020-01-01 13:55:28 +05:30
|
|
|
createComponent({
|
|
|
|
pipeline: {
|
2020-07-28 23:09:34 +05:30
|
|
|
flags: {
|
|
|
|
stuck: true,
|
|
|
|
},
|
2020-01-01 13:55:28 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(findStuckTag().text()).toContain('stuck');
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
it('should render latest tag when flag is provided', () => {
|
2020-01-01 13:55:28 +05:30
|
|
|
createComponent({
|
|
|
|
pipeline: {
|
2020-07-28 23:09:34 +05:30
|
|
|
flags: {
|
|
|
|
latest: true,
|
|
|
|
},
|
2020-01-01 13:55:28 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(findLatestTag().text()).toContain('latest');
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
it('should render a yaml badge when it is invalid', () => {
|
2020-01-01 13:55:28 +05:30
|
|
|
createComponent({
|
|
|
|
pipeline: {
|
|
|
|
flags: {
|
|
|
|
yaml_errors: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(findYamlTag().text()).toContain('yaml invalid');
|
|
|
|
});
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
it('should render an autodevops badge when flag is provided', () => {
|
|
|
|
createComponent({
|
|
|
|
pipeline: {
|
2021-04-17 20:07:23 +05:30
|
|
|
...defaultProps.pipeline,
|
2020-07-28 23:09:34 +05:30
|
|
|
flags: {
|
|
|
|
auto_devops: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(trimText(findAutoDevopsTag().text())).toBe('Auto DevOps');
|
2021-04-17 20:07:23 +05:30
|
|
|
|
|
|
|
expect(findAutoDevopsTagLink().attributes()).toMatchObject({
|
|
|
|
href: '/help/topics/autodevops/index.md',
|
|
|
|
target: '_blank',
|
|
|
|
});
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
it('should render a detached badge when flag is provided', () => {
|
2020-01-01 13:55:28 +05:30
|
|
|
createComponent({
|
|
|
|
pipeline: {
|
|
|
|
flags: {
|
2020-07-28 23:09:34 +05:30
|
|
|
detached_merge_request_pipeline: true,
|
2020-01-01 13:55:28 +05:30
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(findDetachedTag().text()).toContain('detached');
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should render error badge when pipeline has a failure reason set', () => {
|
|
|
|
createComponent({
|
|
|
|
pipeline: {
|
|
|
|
flags: {
|
|
|
|
failure_reason: true,
|
|
|
|
},
|
|
|
|
failure_reason: 'some reason',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(findFailureTag().text()).toContain('error');
|
|
|
|
expect(findFailureTag().attributes('title')).toContain('some reason');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render scheduled badge when pipeline was triggered by a schedule', () => {
|
|
|
|
createComponent({
|
|
|
|
pipeline: {
|
|
|
|
flags: {},
|
|
|
|
source: 'schedule',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(findScheduledTag().exists()).toBe(true);
|
|
|
|
expect(findScheduledTag().text()).toContain('Scheduled');
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it('should render the fork badge when the pipeline was run in a fork', () => {
|
|
|
|
createComponent({
|
|
|
|
pipeline: {
|
|
|
|
flags: {},
|
2021-04-17 20:07:23 +05:30
|
|
|
project: { fullPath: '/test/forked' },
|
2021-02-22 17:27:13 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(findForkTag().exists()).toBe(true);
|
|
|
|
expect(findForkTag().text()).toBe('fork');
|
|
|
|
});
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
it('should render the train badge when the pipeline is a merge train pipeline', () => {
|
|
|
|
createComponent({
|
|
|
|
pipeline: {
|
|
|
|
flags: {
|
|
|
|
merge_train_pipeline: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(findTrainTag().text()).toContain('train');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render the train badge when the pipeline is not a merge train pipeline', () => {
|
|
|
|
createComponent({
|
|
|
|
pipeline: {
|
|
|
|
flags: {
|
|
|
|
merge_train_pipeline: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(findTrainTag().exists()).toBe(false);
|
|
|
|
});
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|