Skip to content

Commit

Permalink
jest test to test riskscore returns formatted value when value applie…
Browse files Browse the repository at this point in the history
…d, or does not render when no value applied
  • Loading branch information
CAWilson94 committed Nov 5, 2024
1 parent 2cdba5d commit e53c31f
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useMountAppended } from '../../../../../common/utils/use_mount_appended

import { FormattedFieldValue } from './formatted_field';
import { HOST_NAME_FIELD_NAME } from './constants';
import { formatRiskScore } from '../../../../../entity_analytics/common';

jest.mock('@elastic/eui', () => {
const original = jest.requireActual('@elastic/eui');
Expand Down Expand Up @@ -285,4 +286,39 @@ describe('Events', () => {
);
expect(wrapper.text()).toEqual(getEmptyValue());
});

test('it renders the formatted risk score when fieldName is RISK_SCORE and value is provided', () => {
const riskScoreValue = 85;
const wrapper = mount(
<TestProviders>
<FormattedFieldValue
contextId="test"
eventId={mockTimelineData[0].ecs._id}
fieldName="kibana.alert.risk_score"
value={riskScoreValue}
/>
</TestProviders>
);

expect(
wrapper.find(`[data-test-subj="formatted-field-kibana.alert.risk_score"]`).text()
).toEqual(formatRiskScore(riskScoreValue));
});

test('it does not render anything when fieldName is RISK_SCORE and value is not provided', () => {
const wrapper = mount(
<TestProviders>
<FormattedFieldValue
contextId="test"
eventId={mockTimelineData[0].ecs._id}
fieldName="kibana.alert.risk_score"
value={null}
/>
</TestProviders>
);

expect(
wrapper.find(`[data-test-subj="formatted-field-kibana.alert.risk_score"]`).exists()
).toEqual(false);
});
});

0 comments on commit e53c31f

Please sign in to comment.