Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions ui/packages/app/web/src/components/Targets/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,19 @@ describe('getHealthStatus', () => {
colorVariant: 'danger',
});
});

it('falls back to Unspecified for out-of-range or invalid numeric values', () => {
expect(getHealthStatus(3)).toEqual({
label: 'Unspecified',
colorVariant: 'neutral',
});
expect(getHealthStatus(-1)).toEqual({
label: 'Unspecified',
colorVariant: 'neutral',
});
expect(getHealthStatus(NaN)).toEqual({
label: 'Unspecified',
colorVariant: 'neutral',
});
});
});
5 changes: 3 additions & 2 deletions ui/packages/app/web/src/components/Targets/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ const HealthStatus = {

type HealthStatusType = (typeof HealthStatus)[keyof typeof HealthStatus];

export const getHealthStatus = (numericValue: number) => {
const label = Object.values(HealthStatus)[numericValue];
export const getHealthStatus = (numericValue: number): {label: HealthStatusType; colorVariant: PillVariant} => {
const values = Object.values(HealthStatus);
const label: HealthStatusType = values[numericValue] ?? HealthStatus.Unspecified;

const colorVariants: Record<HealthStatusType, PillVariant> = {
Unspecified: 'neutral',
Expand Down