Commit 67209d3a authored by Filipa Lacerda's avatar Filipa Lacerda Committed by Phil Hughes

Resolve "Cannot read property 'commit_path' of null"

parent d391a218
<script> <script>
/* eslint-disable vue/require-default-prop */ /* eslint-disable vue/require-default-prop */
import pipelineStage from '~/pipelines/components/stage.vue'; import PipelineStage from '~/pipelines/components/stage.vue';
import ciIcon from '~/vue_shared/components/ci_icon.vue'; import CiIcon from '~/vue_shared/components/ci_icon.vue';
import icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
import linkedPipelinesMiniList from 'ee/vue_shared/components/linked_pipelines_mini_list.vue'; import LinkedPipelinesMiniList from 'ee/vue_shared/components/linked_pipelines_mini_list.vue';
export default { export default {
name: 'MRWidgetPipeline', name: 'MRWidgetPipeline',
components: { components: {
pipelineStage, PipelineStage,
ciIcon, CiIcon,
icon, Icon,
linkedPipelinesMiniList, LinkedPipelinesMiniList,
}, },
props: { props: {
pipeline: { pipeline: {
...@@ -37,15 +37,20 @@ ...@@ -37,15 +37,20 @@
return this.hasCi && !this.ciStatus; return this.hasCi && !this.ciStatus;
}, },
status() { status() {
return this.pipeline.details && return this.pipeline.details && this.pipeline.details.status
this.pipeline.details.status ? this.pipeline.details.status : {}; ? this.pipeline.details.status
: {};
}, },
hasStages() { hasStages() {
return this.pipeline.details && return (
this.pipeline.details &&
this.pipeline.details.stages && this.pipeline.details.stages &&
this.pipeline.details.stages.length; this.pipeline.details.stages.length
);
},
hasCommitInfo() {
return this.pipeline.commit && Object.keys(this.pipeline.commit).length > 0;
}, },
/* We typically set defaults ([]) in the store or prop declarations, but because triggered /* We typically set defaults ([]) in the store or prop declarations, but because triggered
* and triggeredBy are appended to `pipeline`, we can't set defaults in the store, and we * and triggeredBy are appended to `pipeline`, we can't set defaults in the store, and we
* need to check their length here to prevent initializing linked-pipeline-mini-lists * need to check their length here to prevent initializing linked-pipeline-mini-lists
...@@ -63,7 +68,8 @@ ...@@ -63,7 +68,8 @@
<template> <template>
<div <div
v-if="hasPipeline || hasCIError" v-if="hasPipeline || hasCIError"
class="mr-widget-heading"> class="mr-widget-heading"
>
<div class="ci-widget media"> <div class="ci-widget media">
<template v-if="hasCIError"> <template v-if="hasCIError">
<div class="ci-status-icon ci-status-icon-failed ci-error js-ci-error append-right-10"> <div class="ci-status-icon ci-status-icon-failed ci-error js-ci-error append-right-10">
...@@ -90,13 +96,17 @@ ...@@ -90,13 +96,17 @@
#{{ pipeline.id }} #{{ pipeline.id }}
</a> </a>
{{ pipeline.details.status.label }} for {{ pipeline.details.status.label }}
<a <template v-if="hasCommitInfo">
:href="pipeline.commit.commit_path" for
class="commit-sha js-commit-link"
> <a
{{ pipeline.commit.short_id }}</a>. :href="pipeline.commit.commit_path"
class="commit-sha js-commit-link"
>
{{ pipeline.commit.short_id }}</a>.
</template>
<span class="mr-widget-pipeline-graph"> <span class="mr-widget-pipeline-graph">
<span class="stage-cell"> <span class="stage-cell">
......
---
title: Verifiy if pipeline has commit idetails and render information in MR widget
when branch is deleted
merge_request:
author:
type: fixed
...@@ -114,6 +114,46 @@ describe('MRWidgetPipeline', () => { ...@@ -114,6 +114,46 @@ describe('MRWidgetPipeline', () => {
}); });
}); });
describe('without commit path', () => {
beforeEach(() => {
const mockCopy = Object.assign({}, mockData);
delete mockCopy.pipeline.commit;
vm = mountComponent(Component, {
pipeline: mockCopy.pipeline,
hasCi: true,
ciStatus: 'success',
});
});
it('should render pipeline ID', () => {
expect(
vm.$el.querySelector('.pipeline-id').textContent.trim(),
).toEqual(`#${mockData.pipeline.id}`);
});
it('should render pipeline status', () => {
expect(
vm.$el.querySelector('.media-body').textContent.trim(),
).toContain(mockData.pipeline.details.status.label);
expect(
vm.$el.querySelector('.js-commit-link'),
).toBeNull();
});
it('should render pipeline graph', () => {
expect(vm.$el.querySelector('.mr-widget-pipeline-graph')).toBeDefined();
expect(vm.$el.querySelectorAll('.stage-container').length).toEqual(mockData.pipeline.details.stages.length);
});
it('should render coverage information', () => {
expect(
vm.$el.querySelector('.media-body').textContent,
).toContain(`Coverage ${mockData.pipeline.coverage}`);
});
});
describe('without coverage', () => { describe('without coverage', () => {
it('should not render a coverage', () => { it('should not render a coverage', () => {
const mockCopy = Object.assign({}, mockData); const mockCopy = Object.assign({}, mockData);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment