Commit b9e9f856 authored by Zack Cuddy's avatar Zack Cuddy

Null safe percentages

Tests and linting

Changelog

Changes based on @nfriend feedback

Rename test
parent 25a97e59
...@@ -71,6 +71,10 @@ export default { ...@@ -71,6 +71,10 @@ export default {
}, },
methods: { methods: {
getPercent(count) { getPercent(count) {
if (!this.totalCount) {
return 0;
}
const percent = roundOffFloat((count / this.totalCount) * 100, 1); const percent = roundOffFloat((count / this.totalCount) * 100, 1);
if (percent > 0 && percent < 1) { if (percent > 0 && percent < 1) {
return '< 1'; return '< 1';
......
---
title: Fix Infinity % / Infinity % on Stacked Progress Bar
merge_request: 21437
author:
type: fixed
...@@ -53,6 +53,12 @@ describe('StackedProgressBarComponent', () => { ...@@ -53,6 +53,12 @@ describe('StackedProgressBarComponent', () => {
it('returns percentage as `< 1` from provided count based on `totalCount` when evaluated value is less than 1', () => { it('returns percentage as `< 1` from provided count based on `totalCount` when evaluated value is less than 1', () => {
expect(vm.getPercent(10)).toBe('< 1'); expect(vm.getPercent(10)).toBe('< 1');
}); });
it('returns 0 if totalCount is falsy', () => {
vm = createComponent({ totalCount: 0 });
expect(vm.getPercent(100)).toBe(0);
});
}); });
describe('barStyle', () => { describe('barStyle', () => {
......
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