1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-28 19:06:12 +01:00

fix: render small values in project health (#6663)

This commit is contained in:
Mateusz Kwasniewski 2024-03-21 15:46:17 +01:00 committed by GitHub
parent 9be15d4976
commit 7ca95295bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 2 deletions

View File

@ -109,4 +109,35 @@ describe('ProjectHealthChart', () => {
expect(screen.queryByText('3 flags')).toBeInTheDocument();
expect(screen.queryByText('50%')).toBeInTheDocument();
});
test('renders small values without negative stroke dasharray', () => {
const { container } = render(
<ProjectHealthChart
active={1000}
stale={1}
potentiallyStale={1}
health={50}
/>,
);
const activeCircle = container.querySelector(
'circle[data-testid="active-circle"]',
);
const staleCircle = container.querySelector(
'circle[data-testid="stale-circle"]',
);
const potentiallyStaleCircle = container.querySelector(
'circle[data-testid="potentially-stale-circle"]',
);
expect(
activeCircle?.getAttribute('stroke-dasharray')?.charAt(0),
).not.toBe('-');
expect(
staleCircle?.getAttribute('stroke-dasharray')?.charAt(0),
).not.toBe('-');
expect(
potentiallyStaleCircle?.getAttribute('stroke-dasharray')?.charAt(0),
).not.toBe('-');
});
});

View File

@ -29,8 +29,14 @@ export const ProjectHealthChart: React.FC<ProgressComponentProps> = ({
const potentiallyStalePercentage =
active === 0 ? 0 : (potentiallyStale / active) * 100;
const activeLength = (activePercentage / 100) * circumference - gap;
const staleLength = (stalePercentage / 100) * circumference - gap;
const activeLength = Math.max(
(activePercentage / 100) * circumference - gap,
1,
);
const staleLength = Math.max(
(stalePercentage / 100) * circumference - gap,
1,
);
const potentiallyStaleLength =
(potentiallyStalePercentage / 100) * activeLength;