Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
maxcold committed Jan 14, 2025
1 parent 2d511a6 commit 3886bc3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ import {
MISCONFIGURATION_STATUS,
} from '@kbn/cloud-security-posture-common';

const isBorealis = (euiThemeName: string) => {
return euiThemeName?.toLowerCase().includes('borealis');
};

const isAmsterdam = (euiThemeName: string) => {
return euiThemeName?.toLowerCase().includes('amsterdam');
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,45 @@
* 2.0.
*/

import { euiThemeVars } from '@kbn/ui-theme';
import { getVulnerabilityStats } from './vulnerability_helpers';
import { i18n } from '@kbn/i18n';
import { getSeverityStatusColor as getSeverityStatusColorUtil } from './get_finding_colors';
import type { VulnSeverity } from '@kbn/cloud-security-posture-common';

const getSeverityStatusColor = (status: VulnSeverity) => {
const euiTheme = {
themeName: 'borealis',
colors: {
vis: {
euiColorVis0: 'low',
euiColorSeverity7: 'medium',
euiColorSeverity11: 'high',
euiColorSeverity14: 'critical',
euiColorSeverity0: 'unknown',
},
},
};

return getSeverityStatusColorUtil(status, euiTheme);
};

import { getVulnerabilityStats } from './vulnerability_helpers';

describe('getVulnerabilitiesAggregationCount', () => {
const mockFilterFunction = jest.fn();
it('should return empty array when all severity count is 0', () => {
const result = getVulnerabilityStats({ critical: 0, high: 0, medium: 0, low: 0, none: 0 });
const result = getVulnerabilityStats(
{ critical: 0, high: 0, medium: 0, low: 0, none: 0 },
getSeverityStatusColor
);
expect(result).toEqual([]);
});

it('should return stats for low, medium, high, and critical vulnerabilities', () => {
const result = getVulnerabilityStats({ critical: 1, high: 2, medium: 3, low: 4, none: 5 });
const result = getVulnerabilityStats(
{ critical: 1, high: 2, medium: 3, low: 4, none: 5 },
getSeverityStatusColor
);

const resultWithoutFunctions = result.map((item) => {
const { filter, reset, ...rest } = item;
return rest;
Expand All @@ -32,7 +58,7 @@ describe('getVulnerabilitiesAggregationCount', () => {
}
),
count: 5,
color: '#aaa',
color: 'unknown',
isCurrentFilter: false,
},
{
Expand All @@ -43,7 +69,7 @@ describe('getVulnerabilitiesAggregationCount', () => {
}
),
count: 4,
color: euiThemeVars.euiColorVis0,
color: 'low',
isCurrentFilter: false,
},
{
Expand All @@ -54,7 +80,7 @@ describe('getVulnerabilitiesAggregationCount', () => {
}
),
count: 3,
color: euiThemeVars.euiColorVis5_behindText,
color: 'medium',
isCurrentFilter: false,
},
{
Expand All @@ -65,7 +91,7 @@ describe('getVulnerabilitiesAggregationCount', () => {
}
),
count: 2,
color: euiThemeVars.euiColorVis9_behindText,
color: 'high',
isCurrentFilter: false,
},
{
Expand All @@ -76,7 +102,7 @@ describe('getVulnerabilitiesAggregationCount', () => {
}
),
count: 1,
color: euiThemeVars.euiColorDanger,
color: 'critical',
isCurrentFilter: false,
},
]);
Expand All @@ -85,6 +111,7 @@ describe('getVulnerabilitiesAggregationCount', () => {
it('should return correct stats with correct onClick functions', () => {
const result = getVulnerabilityStats(
{ critical: 1, high: 2, medium: 3, low: 4, none: 5 },
getSeverityStatusColor,
mockFilterFunction
);
const event = { stopPropagation: jest.fn() } as unknown as React.MouseEvent<
Expand All @@ -101,6 +128,7 @@ describe('getVulnerabilitiesAggregationCount', () => {
const currentFilter = 'LOW';
const result = getVulnerabilityStats(
{ critical: 1, high: 2, medium: 3, low: 4, none: 5 },
getSeverityStatusColor,
mockFilterFunction,
currentFilter
);
Expand Down

0 comments on commit 3886bc3

Please sign in to comment.