diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_details_flyout/tabs/risk_inputs/risk_inputs.test.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_details_flyout/tabs/risk_inputs/risk_inputs.test.tsx
index d9088b5fe5bb9..3198ac11ea08c 100644
--- a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_details_flyout/tabs/risk_inputs/risk_inputs.test.tsx
+++ b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_details_flyout/tabs/risk_inputs/risk_inputs.test.tsx
@@ -49,6 +49,12 @@ const riskScore = {
},
};
+const riskScoreWithAssetCriticalityContribution = (contribution: number) => {
+ const score = JSON.parse(JSON.stringify(riskScore));
+ score.user.risk.category_2_score = contribution;
+ return score;
+};
+
describe('RiskInputsTab', () => {
beforeEach(() => {
jest.clearAllMocks();
@@ -119,6 +125,62 @@ describe('RiskInputsTab', () => {
expect(queryByTestId('risk-input-contexts-title')).toBeInTheDocument();
});
+ it('Displays 0.00 for the asset criticality contribution if the contribution value is less than -0.01', () => {
+ mockUseUiSetting.mockReturnValue([true]);
+
+ mockUseRiskScore.mockReturnValue({
+ loading: false,
+ error: false,
+ data: [riskScoreWithAssetCriticalityContribution(-0.0000001)],
+ });
+
+ const { getByTestId } = render(
+
+
+
+ );
+ const contextsTable = getByTestId('risk-input-contexts-table');
+ expect(contextsTable).not.toHaveTextContent('-0.00');
+ expect(contextsTable).toHaveTextContent('0.00');
+ });
+
+ it('Displays 0.00 for the asset criticality contribution if the contribution value is less than 0.01', () => {
+ mockUseUiSetting.mockReturnValue([true]);
+
+ mockUseRiskScore.mockReturnValue({
+ loading: false,
+ error: false,
+ data: [riskScoreWithAssetCriticalityContribution(0.0000001)],
+ });
+
+ const { getByTestId } = render(
+
+
+
+ );
+ const contextsTable = getByTestId('risk-input-contexts-table');
+ expect(contextsTable).not.toHaveTextContent('+0.00');
+ expect(contextsTable).toHaveTextContent('0.00');
+ });
+
+ it('Adds a plus to positive asset criticality contribution scores', () => {
+ mockUseUiSetting.mockReturnValue([true]);
+
+ mockUseRiskScore.mockReturnValue({
+ loading: false,
+ error: false,
+ data: [riskScoreWithAssetCriticalityContribution(2.22)],
+ });
+
+ const { getByTestId } = render(
+
+
+
+ );
+
+ expect(getByTestId('risk-input-contexts-table')).toHaveTextContent('+2.22');
+ });
+
it('shows extra alerts contribution message', () => {
const alerts = times(
(number) => ({
diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_details_flyout/tabs/risk_inputs/risk_inputs_tab.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_details_flyout/tabs/risk_inputs/risk_inputs_tab.tsx
index 5532ec51a1054..4feed2ab3f667 100644
--- a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_details_flyout/tabs/risk_inputs/risk_inputs_tab.tsx
+++ b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_details_flyout/tabs/risk_inputs/risk_inputs_tab.tsx
@@ -14,6 +14,7 @@ import { useUiSetting$ } from '@kbn/kibana-react-plugin/public';
import { ALERT_RULE_NAME } from '@kbn/rule-data-utils';
import { get } from 'lodash/fp';
+import { formatRiskScore } from '../../../../common';
import type {
InputAlert,
UseRiskContributingAlertsResult,
@@ -243,6 +244,7 @@ const ContextsSection: React.FC<{
= ({ riskScore, aler
);
};
-const formatContribution = (value: number) =>
- value > 0 ? `+${value.toFixed(2)}` : value.toFixed(2);
+const formatContribution = (value: number): string => {
+ const fixedValue = formatRiskScore(value);
+
+ // prevent +0.00 for values like 0.0001
+ if (fixedValue === '0.00') {
+ return fixedValue;
+ }
+
+ if (value > 0) {
+ return `+${fixedValue}`;
+ }
+
+ return fixedValue;
+};