Skip to content

Commit

Permalink
Add snapshot. Export index pattern validator function for test
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Caldwell committed Jun 14, 2021
1 parent 0086091 commit a276cfc
Show file tree
Hide file tree
Showing 3 changed files with 266 additions and 1 deletion.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* 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 { mount } from 'enzyme';
import { EntityByExpression, getValidIndexPatternFields } from './entity_by_expression';

const defaultProps = {
errors: {
index: [],
indexId: [],
geoField: [],
entity: [],
dateField: [],
boundaryType: [],
boundaryIndexTitle: [],
boundaryIndexId: [],
boundaryGeoField: [],
name: ['Name is required.'],
interval: [],
alertTypeId: [],
actionConnectors: [],
},
entity: 'FlightNum',
setAlertParamsEntity: (arg: string) => {},
indexFields: [
{
count: 0,
name: 'DestLocation',
type: 'geo_point',
esTypes: ['geo_point'],
scripted: false,
searchable: true,
aggregatable: true,
readFromDocValues: true,
},
{
count: 0,
name: 'FlightNum',
type: 'string',
esTypes: ['keyword'],
scripted: false,
searchable: true,
aggregatable: true,
readFromDocValues: true,
},
{
count: 0,
name: 'OriginLocation',
type: 'geo_point',
esTypes: ['geo_point'],
scripted: false,
searchable: true,
aggregatable: true,
readFromDocValues: true,
},
{
count: 0,
name: 'timestamp',
type: 'date',
esTypes: ['date'],
scripted: false,
searchable: true,
aggregatable: true,
readFromDocValues: true,
},
],
isInvalid: false,
};

test('should render entity by expression with aggregatable field options for entity', async () => {
const component = mount(<EntityByExpression {...defaultProps} />);
expect(component).toMatchSnapshot();
});
//

test('should only use valid index fields', async () => {
// Only the string index field should match
const indexFields = getValidIndexPatternFields(defaultProps.indexFields);
expect(indexFields.length).toEqual(1);

// Set all agg fields to false, invalidating them for use
const invalidIndexFields = defaultProps.indexFields.map((field) => ({
...field,
aggregatable: false,
}));

const noIndexFields = getValidIndexPatternFields(invalidIndexFields);
expect(noIndexFields.length).toEqual(0);
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface Props {
}

const ENTITY_TYPES = ['string', 'number', 'ip'];
function getValidIndexPatternFields(fields: IFieldType[]): IFieldType[] {
export function getValidIndexPatternFields(fields: IFieldType[]): IFieldType[] {
return fields.filter((field) => {
const isSpecifiedSupportedField = ENTITY_TYPES.includes(field.type);
const hasLeadingUnderscore = field.name.startsWith('_');
Expand Down

0 comments on commit a276cfc

Please sign in to comment.