Improve risk score formatting consistency (#145235)

issue: https://github.com/elastic/kibana/issues/145091
## Summary

Update the User and Host page to round risk scores everywhere.
This commit is contained in:
Pablo Machado 2022-11-16 11:34:02 +01:00 committed by GitHub
parent ee5b3613d2
commit f49746a0d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 5 deletions

View file

@ -38,7 +38,7 @@ describe('risk tab', () => {
it('renders the table', () => {
kqlSearch('host.name: "siem-kibana" {enter}');
cy.get(HOST_BY_RISK_TABLE_CELL).eq(3).should('have.text', 'siem-kibana');
cy.get(HOST_BY_RISK_TABLE_CELL).eq(4).should('have.text', '21.00');
cy.get(HOST_BY_RISK_TABLE_CELL).eq(4).should('have.text', '21');
cy.get(HOST_BY_RISK_TABLE_CELL).eq(5).should('have.text', 'Low');
clearSearchBar();
});

View file

@ -0,0 +1,27 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import React from 'react';
import { render } from '@testing-library/react';
import { getHostRiskScoreColumns } from './columns';
import { TestProviders } from '../../../common/mock';
import type { HostRiskScoreColumns } from '.';
describe('getHostRiskScoreColumns', () => {
test('should render host score rounded', () => {
const columns: HostRiskScoreColumns = getHostRiskScoreColumns({
dispatchSeverityUpdate: jest.fn(),
});
const riskScore = 10.11111111;
const riskScoreColumn = columns[1];
const renderedColumn = riskScoreColumn.render!(riskScore, null);
const { queryByTestId } = render(<TestProviders>{renderedColumn}</TestProviders>);
expect(queryByTestId('risk-score-truncate')).toHaveTextContent('10');
});
});

View file

@ -77,7 +77,7 @@ export const getHostRiskScoreColumns = ({
if (riskScore != null) {
return (
<span data-test-subj="risk-score-truncate" title={`${riskScore}`}>
{riskScore.toFixed(2)}
{Math.round(riskScore)}
</span>
);
}

View file

@ -41,7 +41,7 @@ describe('getUserRiskScoreColumns', () => {
expect(queryByTestId('users-link-anchor')).toHaveTextContent(username);
});
test('should render user score truncated', () => {
test('should render user score rounded', () => {
const columns: UserRiskScoreColumns = getUserRiskScoreColumns(defaultProps);
const riskScore = 10.11111111;
@ -50,6 +50,6 @@ describe('getUserRiskScoreColumns', () => {
const { queryByTestId } = render(<TestProviders>{renderedColumn}</TestProviders>);
expect(queryByTestId('risk-score-truncate')).toHaveTextContent('10.11');
expect(queryByTestId('risk-score-truncate')).toHaveTextContent('10');
});
});

View file

@ -78,7 +78,7 @@ export const getUserRiskScoreColumns = ({
if (riskScore != null) {
return (
<span data-test-subj="risk-score-truncate" title={`${riskScore}`}>
{riskScore.toFixed(2)}
{Math.round(riskScore)}
</span>
);
}