Skip to content

Commit

Permalink
unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
angorayc committed Dec 19, 2024
1 parent 59bf4fe commit 099e29d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,6 @@ describe.each(chartDataSets)('BarChart with stackByField', () => {
},
];

const expectedColors = ['#1EA593', '#2B70F7', '#CE0060'];

const stackByField = 'process.name';

beforeAll(() => {
Expand All @@ -369,12 +367,6 @@ describe.each(chartDataSets)('BarChart with stackByField', () => {
expect(wrapper.find('[data-test-subj="draggable-legend"]').exists()).toBe(true);
});

expectedColors.forEach((color, i) => {
test(`it renders the expected legend color ${color} for legend item ${i}`, () => {
expect(wrapper.find(`div [color="${color}"]`).exists()).toBe(true);
});
});

data.forEach((datum) => {
test(`it renders the expected draggable legend text for datum ${datum.key}`, () => {
const dataProviderId = `draggableId.content.draggable-legend-item-uuid_v4()-${escapeDataProviderId(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { FormattedCount } from '../../../../../common/components/formatted_numbe
import { getIsChartCollapseData } from './helpers';
import * as i18n from './translations';

import { SEVERITY_COLOR } from '../../../../../overview/components/detection_response/utils';
import { getSeverityColor as getAlertsSeverityColor } from '../../../../../overview/components/detection_response/utils';

const DETECTIONS_ALERTS_COLLAPSED_CHART_ID = 'detectioin-alerts-collapsed-chart';

Expand Down Expand Up @@ -97,15 +97,16 @@ export const ChartCollapse: React.FC<Props> = ({
const topGroup = useMemo(() => data.at(0)?.group ?? i18n.NO_RESULT_MESSAGE, [data]);
const severities = useMemo(() => {
const severityData = data.at(0)?.severities ?? [];
return Object.keys(SEVERITY_COLOR).map((severity) => {
const severityColors = getAlertsSeverityColor(euiTheme);
return Object.keys(severityColors).map((severity) => {
const obj = severityData.find((s) => s.key === severity);
if (obj) {
return { key: obj.key, label: obj.label, value: obj.value };
} else {
return { key: severity, label: capitalize(severity), value: 0 };
}
});
}, [data]);
}, [data, euiTheme]);
const groupBy = useMemo(() => getGroupByLabel(groupBySelection), [groupBySelection]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { TestProviders } from '../../../../common/mock';
import { AlertCountInsight, getFormattedAlertStats } from './alert_count_insight';
import { useAlertsByStatus } from '../../../../overview/components/detection_response/alerts_by_status/use_alerts_by_status';
import type { ParsedAlertsData } from '../../../../overview/components/detection_response/alerts_by_status/types';
import { SEVERITY_COLOR } from '../../../../overview/components/detection_response/utils';
import { getSeverityColor } from '../../../../overview/components/detection_response/utils';
import type { EuiThemeComputed } from '@elastic/eui';

jest.mock('../../../../common/lib/kibana');
Expand All @@ -24,7 +24,7 @@ jest.mock('@kbn/cloud-security-posture/src/hooks/use_misconfiguration_preview');
jest.mock(
'../../../../overview/components/detection_response/alerts_by_status/use_alerts_by_status'
);

const mockEuiTheme = { colors: { vis: {} } } as EuiThemeComputed;
const fieldName = 'host.name';
const name = 'test host';
const testId = 'test';
Expand Down Expand Up @@ -111,14 +111,14 @@ describe('AlertCountInsight', () => {
});

describe('getFormattedAlertStats', () => {
const mockEuiTheme = {} as EuiThemeComputed;
it('should return alert stats', () => {
const severityColors = getSeverityColor(mockEuiTheme);
const alertStats = getFormattedAlertStats(mockAlertData, mockEuiTheme);
expect(alertStats).toEqual([
{ key: 'High', count: 2, color: SEVERITY_COLOR.high },
{ key: 'Low', count: 2, color: SEVERITY_COLOR.low },
{ key: 'Medium', count: 2, color: SEVERITY_COLOR.medium },
{ key: 'Critical', count: 2, color: SEVERITY_COLOR.critical },
{ key: 'High', count: 2, color: severityColors.high },
{ key: 'Low', count: 2, color: severityColors.low },
{ key: 'Medium', count: 2, color: severityColors.medium },
{ key: 'Critical', count: 2, color: severityColors.critical },
]);
});

Expand Down

0 comments on commit 099e29d

Please sign in to comment.