mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
parent
391231b419
commit
7d3cf7bc02
2 changed files with 65 additions and 29 deletions
|
@ -4,11 +4,11 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { shallow } from 'enzyme';
|
||||
import numeral from '@elastic/numeral';
|
||||
import { mount, shallow } from 'enzyme';
|
||||
import toJson from 'enzyme-to-json';
|
||||
import { get } from 'lodash/fp';
|
||||
import * as React from 'react';
|
||||
import { mountWithIntl } from 'test_utils/enzyme_helpers';
|
||||
|
||||
import { asArrayIfExists } from '../../lib/helpers';
|
||||
import { getMockNetflowData } from '../../mock';
|
||||
|
@ -103,7 +103,7 @@ describe('SourceDestination', () => {
|
|||
});
|
||||
|
||||
test('it renders a destination label', () => {
|
||||
const wrapper = mountWithIntl(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
const wrapper = mount(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
|
@ -114,7 +114,7 @@ describe('SourceDestination', () => {
|
|||
});
|
||||
|
||||
test('it renders destination.bytes', () => {
|
||||
const wrapper = mountWithIntl(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
const wrapper = mount(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
|
@ -124,8 +124,27 @@ describe('SourceDestination', () => {
|
|||
).toEqual('40B');
|
||||
});
|
||||
|
||||
test('it renders percent destination.bytes', () => {
|
||||
const wrapper = mount(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
const destinationBytes = asArrayIfExists(
|
||||
get(DESTINATION_BYTES_FIELD_NAME, getMockNetflowData())
|
||||
);
|
||||
const sumBytes = asArrayIfExists(get(NETWORK_BYTES_FIELD_NAME, getMockNetflowData()));
|
||||
let percent = '';
|
||||
if (destinationBytes != null && sumBytes != null) {
|
||||
percent = `(${numeral((destinationBytes[0] / sumBytes[0]) * 100).format('0.00')}%)`;
|
||||
}
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
.find('[data-test-subj="destination-bytes-percent"]')
|
||||
.first()
|
||||
.text()
|
||||
).toEqual(percent);
|
||||
});
|
||||
|
||||
test('it renders destination.geo.continent_name', () => {
|
||||
const wrapper = mountWithIntl(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
const wrapper = mount(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
|
@ -136,7 +155,7 @@ describe('SourceDestination', () => {
|
|||
});
|
||||
|
||||
test('it renders destination.geo.country_name', () => {
|
||||
const wrapper = mountWithIntl(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
const wrapper = mount(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
|
@ -147,7 +166,7 @@ describe('SourceDestination', () => {
|
|||
});
|
||||
|
||||
test('it renders destination.geo.country_iso_code', () => {
|
||||
const wrapper = mountWithIntl(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
const wrapper = mount(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
|
@ -158,7 +177,7 @@ describe('SourceDestination', () => {
|
|||
});
|
||||
|
||||
test('it renders destination.geo.region_name', () => {
|
||||
const wrapper = mountWithIntl(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
const wrapper = mount(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
|
@ -169,7 +188,7 @@ describe('SourceDestination', () => {
|
|||
});
|
||||
|
||||
test('it renders destination.geo.city_name', () => {
|
||||
const wrapper = mountWithIntl(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
const wrapper = mount(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
|
@ -180,7 +199,7 @@ describe('SourceDestination', () => {
|
|||
});
|
||||
|
||||
test('it renders the destination ip and port, separated with a colon', () => {
|
||||
const wrapper = mountWithIntl(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
const wrapper = mount(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
|
@ -191,7 +210,7 @@ describe('SourceDestination', () => {
|
|||
});
|
||||
|
||||
test('it renders destination.packets', () => {
|
||||
const wrapper = mountWithIntl(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
const wrapper = mount(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
|
@ -202,7 +221,7 @@ describe('SourceDestination', () => {
|
|||
});
|
||||
|
||||
test('it hyperlinks links destination.port to an external service that describes the purpose of the port', () => {
|
||||
const wrapper = mountWithIntl(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
const wrapper = mount(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
|
@ -216,7 +235,7 @@ describe('SourceDestination', () => {
|
|||
});
|
||||
|
||||
test('it renders network.bytes', () => {
|
||||
const wrapper = mountWithIntl(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
const wrapper = mount(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
|
@ -227,7 +246,7 @@ describe('SourceDestination', () => {
|
|||
});
|
||||
|
||||
test('it renders network.community_id', () => {
|
||||
const wrapper = mountWithIntl(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
const wrapper = mount(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
|
@ -238,7 +257,7 @@ describe('SourceDestination', () => {
|
|||
});
|
||||
|
||||
test('it renders network.direction', () => {
|
||||
const wrapper = mountWithIntl(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
const wrapper = mount(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
|
@ -249,7 +268,7 @@ describe('SourceDestination', () => {
|
|||
});
|
||||
|
||||
test('it renders network.packets', () => {
|
||||
const wrapper = mountWithIntl(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
const wrapper = mount(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
|
@ -260,7 +279,7 @@ describe('SourceDestination', () => {
|
|||
});
|
||||
|
||||
test('it renders network.protocol', () => {
|
||||
const wrapper = mountWithIntl(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
const wrapper = mount(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
|
@ -271,7 +290,7 @@ describe('SourceDestination', () => {
|
|||
});
|
||||
|
||||
test('it renders a source label', () => {
|
||||
const wrapper = mountWithIntl(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
const wrapper = mount(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
|
@ -282,7 +301,7 @@ describe('SourceDestination', () => {
|
|||
});
|
||||
|
||||
test('it renders source.bytes', () => {
|
||||
const wrapper = mountWithIntl(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
const wrapper = mount(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
|
@ -292,8 +311,25 @@ describe('SourceDestination', () => {
|
|||
).toEqual('60B');
|
||||
});
|
||||
|
||||
test('it renders percent source.bytes', () => {
|
||||
const wrapper = mount(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
const sourceBytes = asArrayIfExists(get(SOURCE_BYTES_FIELD_NAME, getMockNetflowData()));
|
||||
const sumBytes = asArrayIfExists(get(NETWORK_BYTES_FIELD_NAME, getMockNetflowData()));
|
||||
let percent = '';
|
||||
if (sourceBytes != null && sumBytes != null) {
|
||||
percent = `(${numeral((sourceBytes[0] / sumBytes[0]) * 100).format('0.00')}%)`;
|
||||
}
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
.find('[data-test-subj="source-bytes-percent"]')
|
||||
.first()
|
||||
.text()
|
||||
).toEqual(percent);
|
||||
});
|
||||
|
||||
test('it renders source.geo.continent_name', () => {
|
||||
const wrapper = mountWithIntl(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
const wrapper = mount(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
|
@ -304,7 +340,7 @@ describe('SourceDestination', () => {
|
|||
});
|
||||
|
||||
test('it renders source.geo.country_name', () => {
|
||||
const wrapper = mountWithIntl(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
const wrapper = mount(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
|
@ -315,7 +351,7 @@ describe('SourceDestination', () => {
|
|||
});
|
||||
|
||||
test('it renders source.geo.country_iso_code', () => {
|
||||
const wrapper = mountWithIntl(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
const wrapper = mount(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
|
@ -326,7 +362,7 @@ describe('SourceDestination', () => {
|
|||
});
|
||||
|
||||
test('it renders source.geo.region_name', () => {
|
||||
const wrapper = mountWithIntl(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
const wrapper = mount(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
|
@ -337,7 +373,7 @@ describe('SourceDestination', () => {
|
|||
});
|
||||
|
||||
test('it renders source.geo.city_name', () => {
|
||||
const wrapper = mountWithIntl(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
const wrapper = mount(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
|
@ -348,7 +384,7 @@ describe('SourceDestination', () => {
|
|||
});
|
||||
|
||||
test('it renders the source ip and port, separated with a colon', () => {
|
||||
const wrapper = mountWithIntl(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
const wrapper = mount(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
|
@ -359,7 +395,7 @@ describe('SourceDestination', () => {
|
|||
});
|
||||
|
||||
test('it renders source.packets', () => {
|
||||
const wrapper = mountWithIntl(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
const wrapper = mount(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
|
@ -370,7 +406,7 @@ describe('SourceDestination', () => {
|
|||
});
|
||||
|
||||
test('it renders network.transport', () => {
|
||||
const wrapper = mountWithIntl(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
const wrapper = mount(<TestProviders>{getSourceDestinationInstance()}</TestProviders>);
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
|
|
|
@ -214,8 +214,8 @@ export const SourceDestinationArrows = pure<{
|
|||
const maybeSourceBytesPercent =
|
||||
maybeSourceBytes != null && maybeDestinationBytes != null
|
||||
? getPercent({
|
||||
numerator: Math.min(Number(maybeSourceBytes), Number(maybeDestinationBytes)),
|
||||
denominator: Math.max(Number(maybeSourceBytes), Number(maybeDestinationBytes)),
|
||||
numerator: Number(maybeSourceBytes),
|
||||
denominator: Number(maybeSourceBytes) + Number(maybeDestinationBytes),
|
||||
})
|
||||
: undefined;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue