Commit 903563ac authored by Nick Kipling's avatar Nick Kipling Committed by Fatih Acet

Changed successPercentage rounding function

Changed from Math.round to Math.floor
Added tests to cover percentage rounding
parent 43fce23e
...@@ -28,7 +28,9 @@ export default { ...@@ -28,7 +28,9 @@ export default {
return this.report.name || __('Summary'); return this.report.name || __('Summary');
}, },
successPercentage() { successPercentage() {
return Math.round((this.report.success_count / this.report.total_count) * 100) || 0; // Returns a full number when the decimals equal .00.
// Otherwise returns a float to two decimal points
return Number(((this.report.success_count / this.report.total_count) * 100 || 0).toFixed(2));
}, },
formattedDuration() { formattedDuration() {
return formatTime(secondsToMilliseconds(this.report.total_time)); return formatTime(secondsToMilliseconds(this.report.total_time));
......
---
title: Junit success percentage no longer displays 100% if there are failures
merge_request: 20835
author:
type: fixed
...@@ -79,4 +79,25 @@ describe('Test reports summary', () => { ...@@ -79,4 +79,25 @@ describe('Test reports summary', () => {
expect(duration().text()).toBe('00:00:00'); expect(duration().text()).toBe('00:00:00');
}); });
}); });
describe('success percentage calculation', () => {
it.each`
name | successCount | totalCount | result
${'displays 0 when there are no tests'} | ${0} | ${0} | ${'0'}
${'displays whole number when possible'} | ${10} | ${50} | ${'20'}
${'rounds to 0.01'} | ${1} | ${16604} | ${'0.01'}
${'correctly rounds to 50'} | ${8302} | ${16604} | ${'50'}
${'rounds down for large close numbers'} | ${16603} | ${16604} | ${'99.99'}
${'correctly displays 100'} | ${16604} | ${16604} | ${'100'}
`('$name', ({ successCount, totalCount, result }) => {
createComponent({
report: {
success_count: successCount,
total_count: totalCount,
},
});
expect(successRate().text()).toBe(`${result}% success rate`);
});
});
}); });
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