Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Solution] Data Quality dashboard storage metrics #155581

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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 { render, screen } from '@testing-library/react';
import React from 'react';

import { mockAllowedValues } from '../../mock/allowed_values/mock_allowed_values';
import { TestProviders } from '../../mock/test_providers/test_providers';
import { EcsAllowedValues } from '.';

describe('EcsAllowedValues', () => {
describe('when `allowedValues` exists', () => {
beforeEach(() => {
render(
<TestProviders>
<EcsAllowedValues allowedValues={mockAllowedValues} />
</TestProviders>
);
});

test('it renders the allowed values', () => {
expect(screen.getByTestId('ecsAllowedValues')).toHaveTextContent(
mockAllowedValues.map(({ name }) => `${name}`).join('')
);
});

test('it does NOT render the placeholder', () => {
expect(screen.queryByTestId('ecsAllowedValuesEmpty')).not.toBeInTheDocument();
});
});

describe('when `allowedValues` is undefined', () => {
beforeEach(() => {
render(
<TestProviders>
<EcsAllowedValues allowedValues={undefined} />
</TestProviders>
);
});

test('it does NOT render the allowed values', () => {
expect(screen.queryByTestId('ecsAllowedValues')).not.toBeInTheDocument();
});

test('it renders the placeholder', () => {
expect(screen.getByTestId('ecsAllowedValuesEmpty')).toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,57 +10,57 @@ import { omit } from 'lodash/fp';
import React from 'react';

import { SAME_FAMILY } from '../../data_quality_panel/same_family/translations';
import { TestProviders } from '../../mock/test_providers';
import {
eventCategory,
eventCategoryWithUnallowedValues,
} from '../../mock/enriched_field_metadata';
} from '../../mock/enriched_field_metadata/mock_enriched_field_metadata';
import { TestProviders } from '../../mock/test_providers/test_providers';
import {
DOCUMENT_VALUES_ACTUAL,
ECS_DESCRIPTION,
ECS_MAPPING_TYPE_EXPECTED,
ECS_VALUES_EXPECTED,
FIELD,
INDEX_MAPPING_TYPE_ACTUAL,
} from '../translations';
import { EnrichedFieldMetadata } from '../../types';
import { EMPTY_PLACEHOLDER, getCommonTableColumns } from '.';

describe('getCommonTableColumns', () => {
test('it returns the expected column configuration', () => {
const columns = getCommonTableColumns().map((x) => omit('render', x));

expect(columns).toEqual([
{
field: 'indexFieldName',
name: 'Field',
sortable: true,
truncateText: false,
width: '20%',
},
expect(getCommonTableColumns().map((x) => omit('render', x))).toEqual([
{ field: 'indexFieldName', name: FIELD, sortable: true, truncateText: false, width: '20%' },
{
field: 'type',
name: 'ECS mapping type (expected)',
name: ECS_MAPPING_TYPE_EXPECTED,
sortable: true,
truncateText: false,
width: '15%',
},
{
field: 'indexFieldType',
name: 'Index mapping type (actual)',
name: INDEX_MAPPING_TYPE_ACTUAL,
sortable: true,
truncateText: false,
width: '15%',
},
{
field: 'allowed_values',
name: 'ECS values (expected)',
name: ECS_VALUES_EXPECTED,
sortable: false,
truncateText: false,
width: '15%',
},
{
field: 'indexInvalidValues',
name: 'Document values (actual)',
name: DOCUMENT_VALUES_ACTUAL,
sortable: false,
truncateText: false,
width: '15%',
},
{
field: 'description',
name: 'ECS description',
name: ECS_DESCRIPTION,
sortable: false,
truncateText: false,
width: '20%',
Expand Down Expand Up @@ -141,7 +141,7 @@ describe('getCommonTableColumns', () => {
const withTypeMismatchDifferentFamily: EnrichedFieldMetadata = {
...eventCategory, // `event.category` is a `keyword` per the ECS spec
indexFieldType, // this index has a mapping of `text` instead of `keyword`
isInSameFamily: false, // `text` and `keyword` are not in the same family
isInSameFamily: false, // `text` and `wildcard` are not in the same family
};

render(
Expand All @@ -159,29 +159,18 @@ describe('getCommonTableColumns', () => {
});

describe('when the index field matches the ECS type', () => {
const indexFieldType = 'keyword';

test('it renders the expected type with success styling', () => {
const columns = getCommonTableColumns();
const indexFieldTypeColumnRender = columns[2].render;

const withTypeMismatchDifferentFamily: EnrichedFieldMetadata = {
...eventCategory, // `event.category` is a `keyword` per the ECS spec
indexFieldType, // exactly matches the ECS spec
isInSameFamily: true, // `keyword` is a member of the `keyword` family
};

render(
<TestProviders>
{indexFieldTypeColumnRender != null &&
indexFieldTypeColumnRender(
withTypeMismatchDifferentFamily.indexFieldType,
withTypeMismatchDifferentFamily
)}
indexFieldTypeColumnRender(eventCategory.indexFieldType, eventCategory)}
</TestProviders>
);

expect(screen.getByTestId('codeSuccess')).toHaveTextContent(indexFieldType);
expect(screen.getByTestId('codeSuccess')).toHaveTextContent(eventCategory.indexFieldType);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { omit } from 'lodash/fp';
import React from 'react';

import { SAME_FAMILY } from '../../data_quality_panel/same_family/translations';
import { TestProviders } from '../../mock/test_providers';
import { eventCategory } from '../../mock/enriched_field_metadata';
import { TestProviders } from '../../mock/test_providers/test_providers';
import { eventCategory } from '../../mock/enriched_field_metadata/mock_enriched_field_metadata';
import { EnrichedFieldMetadata } from '../../types';
import { EMPTY_PLACEHOLDER, getIncompatibleMappingsTableColumns } from '.';

Expand Down
Loading