Commit b8b3e4dc authored by Filipa Lacerda's avatar Filipa Lacerda

Resolve conflicts

parent 387f2e04
<script>
import statusIcon from '~/vue_merge_request_widget/components/mr_widget_status_icon';
import loadingIcon from '~/vue_shared/components/loading_icon.vue';
import { pluralize } from '~/lib/utils/text_utility';
import issuesBlock from './mr_widget_code_quality_issues.vue';
export default {
name: 'MRWidgetCodeQuality',
props: {
mr: {
type: Object,
required: true,
},
service: {
type: Object,
required: true,
},
},
components: {
issuesBlock,
loadingIcon,
statusIcon,
},
data() {
return {
collapseText: 'Expand',
isCollapsed: true,
isLoading: false,
loadingFailed: false,
};
},
computed: {
status() {
if (this.loadingFailed || this.mr.codeclimateMetrics.newIssues.length) {
return 'warning';
}
return 'success';
},
hasNoneIssues() {
const { newIssues, resolvedIssues } = this.mr.codeclimateMetrics;
return !newIssues.length && !resolvedIssues.length;
},
hasIssues() {
const { newIssues, resolvedIssues } = this.mr.codeclimateMetrics;
return newIssues.length || resolvedIssues.length;
},
codeText() {
const { newIssues, resolvedIssues } = this.mr.codeclimateMetrics;
let newIssuesText;
let resolvedIssuesText;
let text = [];
if (this.hasNoneIssues) {
text.push('No changes to code quality');
} else if (this.hasIssues) {
if (newIssues.length) {
newIssuesText = ` degraded on ${newIssues.length} ${this.pointsText(newIssues)}`;
}
if (resolvedIssues.length) {
resolvedIssuesText = ` improved on ${resolvedIssues.length} ${this.pointsText(resolvedIssues)}`;
}
const connector = (newIssues.length > 0 && resolvedIssues.length > 0) ? ' and' : null;
text = ['Code quality'];
if (resolvedIssuesText) {
text.push(resolvedIssuesText);
}
if (connector) {
text.push(connector);
}
if (newIssuesText) {
text.push(newIssuesText);
}
}
return text.join('');
},
},
methods: {
pointsText(issues) {
return pluralize('point', issues.length);
},
toggleCollapsed() {
this.isCollapsed = !this.isCollapsed;
const text = this.isCollapsed ? 'Expand' : 'Collapse';
this.collapseText = text;
},
handleError() {
this.isLoading = false;
this.loadingFailed = true;
},
},
created() {
const { head_path, head_blob_path, base_path, base_blob_path } = this.mr.codeclimate;
this.isLoading = true;
Promise.all([
this.service.fetchCodeclimate(head_path)
.then(resp => resp.json()),
this.service.fetchCodeclimate(base_path)
.then(resp => resp.json()),
])
.then((values) => {
this.mr.compareCodeclimateMetrics(values[0], values[1], head_blob_path, base_blob_path);
this.isLoading = false;
})
.catch(() => this.handleError());
},
};
</script>
<template>
<section class="mr-widget-code-quality mr-widget-section">
<div
v-if="isLoading"
class="media">
<div class="mr-widget-icon">
<loading-icon />
</div>
<div class="media-body">
Loading codeclimate report
</div>
</div>
<div
v-else-if="!isLoading && !loadingFailed"
class="media">
<status-icon :status="status" />
<div class="media-body space-children">
<span class="js-code-text">
{{codeText}}
</span>
<button
type="button"
class="btn-link btn-blank"
v-if="hasIssues"
@click="toggleCollapsed">
{{collapseText}}
</button>
</div>
</div>
<div
class="code-quality-container"
v-if="hasIssues"
v-show="!isCollapsed">
<issues-block
class="js-mr-code-resolved-issues"
v-if="mr.codeclimateMetrics.resolvedIssues.length"
type="success"
:issues="mr.codeclimateMetrics.resolvedIssues"
/>
<issues-block
class="js-mr-code-new-issues"
v-if="mr.codeclimateMetrics.newIssues.length"
type="failed"
:issues="mr.codeclimateMetrics.newIssues"
/>
</div>
<div
v-else-if="loadingFailed"
class="media">
<status-icon status="failed" />
<div class="media-body">
Failed to load codeclimate report
</div>
</div>
</section>
</template>
<script> <script>
import statusIcon from '~/vue_merge_request_widget/components/mr_widget_status_icon'; import statusIcon from '~/vue_merge_request_widget/components/mr_widget_status_icon';
import loadingIcon from '~/vue_shared/components/loading_icon.vue'; import loadingIcon from '~/vue_shared/components/loading_icon.vue';
import '~/lib/utils/text_utility';
import issuesBlock from './mr_widget_report_issues.vue'; import issuesBlock from './mr_widget_report_issues.vue';
export default { export default {
......
import Vue from 'vue'; import Vue from 'vue';
<<<<<<< HEAD
import mrWidgetOptions from 'ee/vue_merge_request_widget/mr_widget_options'; import mrWidgetOptions from 'ee/vue_merge_request_widget/mr_widget_options';
import MRWidgetService from 'ee/vue_merge_request_widget/services/mr_widget_service'; import MRWidgetService from 'ee/vue_merge_request_widget/services/mr_widget_service';
import MRWidgetStore from 'ee/vue_merge_request_widget/stores/mr_widget_store'; import MRWidgetStore from 'ee/vue_merge_request_widget/stores/mr_widget_store';
import mockData, { baseIssues, headIssues, securityIssues } from './mock_data'; import mockData, { baseIssues, headIssues, securityIssues } from './mock_data';
import mountComponent from '../helpers/vue_mount_component_helper';
describe('ee merge request widget options', () => { describe('ee merge request widget options', () => {
let vm; let vm;
let Component; let Component;
let mountComponent;
beforeEach(() => { beforeEach(() => {
delete mrWidgetOptions.extends.el; // Prevent component mounting delete mrWidgetOptions.extends.el; // Prevent component mounting
Component = Vue.extend(mrWidgetOptions); Component = Vue.extend(mrWidgetOptions);
mountComponent = () => new Component().$mount();
=======
import mrWidgetOptionsEE from 'ee/vue_merge_request_widget/mr_widget_options';
import mockData from './mock_data';
import mountComponent from '../helpers/vue_mount_component_helper';
describe('EE mrWidgetOptions', () => {
let vm;
let MrWidgetOptions;
beforeEach(() => {
// Prevent component mounting
delete mrWidgetOptionsEE.extends.el;
MrWidgetOptions = Vue.extend(mrWidgetOptionsEE);
>>>>>>> ee-com/master
}); });
afterEach(() => { afterEach(() => {
vm.$destroy(); vm.$destroy();
}); });
<<<<<<< HEAD
describe('security widget', () => { describe('security widget', () => {
beforeEach(() => { beforeEach(() => {
gl.mrWidgetData = { gl.mrWidgetData = {
...@@ -54,7 +35,7 @@ describe('EE mrWidgetOptions', () => { ...@@ -54,7 +35,7 @@ describe('EE mrWidgetOptions', () => {
describe('when it is loading', () => { describe('when it is loading', () => {
it('should render loading indicator', () => { it('should render loading indicator', () => {
vm = mountComponent(); vm = mountComponent(Component);
expect( expect(
vm.$el.querySelector('.js-sast-widget').textContent.trim(), vm.$el.querySelector('.js-sast-widget').textContent.trim(),
).toContain('Loading security report'); ).toContain('Loading security report');
...@@ -72,7 +53,7 @@ describe('EE mrWidgetOptions', () => { ...@@ -72,7 +53,7 @@ describe('EE mrWidgetOptions', () => {
beforeEach(() => { beforeEach(() => {
Vue.http.interceptors.push(interceptor); Vue.http.interceptors.push(interceptor);
vm = mountComponent(); vm = mountComponent(Component);
}); });
afterEach(() => { afterEach(() => {
...@@ -100,7 +81,7 @@ describe('EE mrWidgetOptions', () => { ...@@ -100,7 +81,7 @@ describe('EE mrWidgetOptions', () => {
beforeEach(() => { beforeEach(() => {
Vue.http.interceptors.push(emptyInterceptor); Vue.http.interceptors.push(emptyInterceptor);
vm = mountComponent(); vm = mountComponent(Component);
}); });
afterEach(() => { afterEach(() => {
...@@ -128,7 +109,7 @@ describe('EE mrWidgetOptions', () => { ...@@ -128,7 +109,7 @@ describe('EE mrWidgetOptions', () => {
beforeEach(() => { beforeEach(() => {
Vue.http.interceptors.push(errorInterceptor); Vue.http.interceptors.push(errorInterceptor);
vm = mountComponent(); vm = mountComponent(Component);
}); });
afterEach(() => { afterEach(() => {
...@@ -162,7 +143,7 @@ describe('EE mrWidgetOptions', () => { ...@@ -162,7 +143,7 @@ describe('EE mrWidgetOptions', () => {
describe('when it is loading', () => { describe('when it is loading', () => {
it('should render loading indicator', () => { it('should render loading indicator', () => {
vm = mountComponent(); vm = mountComponent(Component);
expect( expect(
vm.$el.querySelector('.js-codequality-widget').textContent.trim(), vm.$el.querySelector('.js-codequality-widget').textContent.trim(),
).toContain('Loading codeclimate report'); ).toContain('Loading codeclimate report');
...@@ -186,7 +167,7 @@ describe('EE mrWidgetOptions', () => { ...@@ -186,7 +167,7 @@ describe('EE mrWidgetOptions', () => {
beforeEach(() => { beforeEach(() => {
Vue.http.interceptors.push(interceptor); Vue.http.interceptors.push(interceptor);
vm = mountComponent(); vm = mountComponent(Component);
}); });
afterEach(() => { afterEach(() => {
...@@ -247,7 +228,7 @@ describe('EE mrWidgetOptions', () => { ...@@ -247,7 +228,7 @@ describe('EE mrWidgetOptions', () => {
beforeEach(() => { beforeEach(() => {
Vue.http.interceptors.push(emptyInterceptor); Vue.http.interceptors.push(emptyInterceptor);
vm = mountComponent(); vm = mountComponent(Component);
}); });
afterEach(() => { afterEach(() => {
...@@ -281,7 +262,7 @@ describe('EE mrWidgetOptions', () => { ...@@ -281,7 +262,7 @@ describe('EE mrWidgetOptions', () => {
beforeEach(() => { beforeEach(() => {
Vue.http.interceptors.push(errorInterceptor); Vue.http.interceptors.push(errorInterceptor);
vm = mountComponent(); vm = mountComponent(Component);
}); });
afterEach(() => { afterEach(() => {
...@@ -293,11 +274,14 @@ describe('EE mrWidgetOptions', () => { ...@@ -293,11 +274,14 @@ describe('EE mrWidgetOptions', () => {
expect(vm.$el.querySelector('.js-codequality-widget').textContent.trim()).toContain('Failed to load codeclimate report'); expect(vm.$el.querySelector('.js-codequality-widget').textContent.trim()).toContain('Failed to load codeclimate report');
done(); done();
}, 0); }, 0);
======= });
});
});
describe('computed', () => { describe('computed', () => {
describe('shouldRenderApprovals', () => { describe('shouldRenderApprovals', () => {
it('should return false when no approvals', () => { it('should return false when no approvals', () => {
vm = mountComponent(MrWidgetOptions, { vm = mountComponent(Component, {
mrData: { mrData: {
...mockData, ...mockData,
approvalsRequired: false, approvalsRequired: false,
...@@ -309,7 +293,7 @@ describe('EE mrWidgetOptions', () => { ...@@ -309,7 +293,7 @@ describe('EE mrWidgetOptions', () => {
}); });
it('should return false when in empty state', () => { it('should return false when in empty state', () => {
vm = mountComponent(MrWidgetOptions, { vm = mountComponent(Component, {
mrData: { mrData: {
...mockData, ...mockData,
approvalsRequired: true, approvalsRequired: true,
...@@ -321,7 +305,7 @@ describe('EE mrWidgetOptions', () => { ...@@ -321,7 +305,7 @@ describe('EE mrWidgetOptions', () => {
}); });
it('should return true when requiring approvals and in non-empty state', () => { it('should return true when requiring approvals and in non-empty state', () => {
vm = mountComponent(MrWidgetOptions, { vm = mountComponent(Component, {
mrData: { mrData: {
...mockData, ...mockData,
approvalsRequired: true, approvalsRequired: true,
...@@ -330,7 +314,6 @@ describe('EE mrWidgetOptions', () => { ...@@ -330,7 +314,6 @@ describe('EE mrWidgetOptions', () => {
vm.mr.state = 'readyToMerge'; vm.mr.state = 'readyToMerge';
expect(vm.shouldRenderApprovals).toBeTruthy(); expect(vm.shouldRenderApprovals).toBeTruthy();
>>>>>>> ee-com/master
}); });
}); });
}); });
......
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