Commit 3f441389 authored by Phil Hughes's avatar Phil Hughes

Merge branch '2676-codeclimate-sentence-is-incomplete' into 'master'

Fix bad connector - verify if both new and resolved issues are present before adding the connector.

Closes #2676

See merge request !2187
parents 3b79df47 ad762ceb
...@@ -50,27 +50,40 @@ export default { ...@@ -50,27 +50,40 @@ export default {
codeText() { codeText() {
const { newIssues, resolvedIssues } = this.mr.codeclimateMetrics; const { newIssues, resolvedIssues } = this.mr.codeclimateMetrics;
let newIssuesText = ''; let newIssuesText;
let resolvedIssuesText = ''; let resolvedIssuesText;
let text = ''; let text = [];
if (this.hasNoneIssues) { if (this.hasNoneIssues) {
text = 'No changes to code quality so far.'; text.push('No changes to code quality so far.');
} else if (this.hasIssues) { } else if (this.hasIssues) {
if (newIssues.length) { if (newIssues.length) {
newIssuesText = `degraded on ${newIssues.length} ${this.pointsText(newIssues)}`; newIssuesText = ` degraded on ${newIssues.length} ${this.pointsText(newIssues)}`;
} }
if (resolvedIssues.length) { if (resolvedIssues.length) {
resolvedIssuesText = `improved on ${resolvedIssues.length} ${this.pointsText(resolvedIssues)}`; resolvedIssuesText = ` improved on ${resolvedIssues.length} ${this.pointsText(resolvedIssues)}`;
} }
const connector = this.hasIssues ? 'and' : ''; const connector = (newIssues.length > 0 && resolvedIssues.length > 0) ? ' and' : null;
text = `Code quality ${resolvedIssuesText} ${connector} ${newIssuesText}.`; text = ['Code quality'];
if (resolvedIssuesText) {
text.push(resolvedIssuesText);
} }
return text; if (connector) {
text.push(connector);
}
if (newIssuesText) {
text.push(newIssuesText);
}
text.push('.');
}
return text.join('');
}, },
}, },
......
...@@ -72,6 +72,34 @@ describe('Merge Request Code Quality', () => { ...@@ -72,6 +72,34 @@ describe('Merge Request Code Quality', () => {
}, 0); }, 0);
}); });
describe('text connector', () => {
it('should only render information about fixed issues', (done) => {
setTimeout(() => {
vm.mr.codeclimateMetrics.newIssues = [];
Vue.nextTick(() => {
expect(
vm.$el.querySelector('span:nth-child(2)').textContent.trim(),
).toEqual('Code quality improved on 1 point.');
done();
});
}, 0);
});
it('should only render information about added issues', (done) => {
setTimeout(() => {
vm.mr.codeclimateMetrics.resolvedIssues = [];
Vue.nextTick(() => {
expect(
vm.$el.querySelector('span:nth-child(2)').textContent.trim(),
).toEqual('Code quality degraded on 1 point.');
done();
});
}, 0);
});
});
describe('toggleCollapsed', () => { describe('toggleCollapsed', () => {
it('toggles issues', (done) => { it('toggles issues', (done) => {
setTimeout(() => { setTimeout(() => {
......
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