Move mockFields and mockIndexPatterns to relevant directories (#50012)

* Move mockFields and mockIndexPatterns to relevant directories

* Restructure stubs store

* Remove test code from production files

* Restructure stubs store
This commit is contained in:
Artyom Gospodarsky 2019-11-13 17:26:30 +04:00 committed by GitHub
parent 167dd7f5a0
commit 3a2e865b2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 158 additions and 98 deletions

View file

@ -17,7 +17,8 @@
* under the License.
*/
import { mockFields, mockIndexPattern } from '../../../../index_patterns';
/* eslint-disable @kbn/eslint/no-restricted-paths */
import { stubIndexPattern, stubFields } from '../../../../../../../../plugins/data/public/stubs';
import { IndexPattern, Field } from '../../../../index';
import {
buildFilter,
@ -45,8 +46,8 @@ import { esFilters } from '../../../../../../../../plugins/data/public';
jest.mock('ui/new_platform');
const mockedFields = mockFields as Field[];
const mockedIndexPattern = mockIndexPattern as IndexPattern;
const mockedFields = stubFields as Field[];
const mockedIndexPattern = stubIndexPattern as IndexPattern;
describe('Filter editor utils', () => {
describe('getQueryDslFromFilter', () => {
@ -171,14 +172,14 @@ describe('Filter editor utils', () => {
describe('getOperatorOptions', () => {
it('returns range for number fields', () => {
const [field] = mockFields.filter(({ type }) => type === 'number');
const [field] = stubFields.filter(({ type }) => type === 'number');
const operatorOptions = getOperatorOptions(field as Field);
const rangeOperator = operatorOptions.find(operator => operator.type === 'range');
expect(rangeOperator).not.toBeUndefined();
});
it('does not return range for string fields', () => {
const [field] = mockFields.filter(({ type }) => type === 'string');
const [field] = stubFields.filter(({ type }) => type === 'string');
const operatorOptions = getOperatorOptions(field as Field);
const rangeOperator = operatorOptions.find(operator => operator.type === 'range');
expect(rangeOperator).toBeUndefined();

View file

@ -58,6 +58,4 @@ export {
IndexPatternMissingIndices,
NoDefaultIndexPattern,
NoDefinedIndexPatterns,
mockFields,
mockIndexPattern,
} from './index_patterns';

View file

@ -24,11 +24,11 @@ import {
NotificationsStart,
} from 'src/core/public';
import { Field, FieldList, FieldListInterface, FieldType } from './fields';
import { createFlattenHitWrapper } from './index_patterns';
import { createIndexPatternSelect } from './components';
import { setNotifications } from './services';
import {
createFlattenHitWrapper,
formatHitProvider,
IndexPattern,
IndexPatterns,
@ -92,8 +92,6 @@ export {
INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE,
isFilterable,
validateIndexPattern,
mockFields,
mockIndexPattern,
} from './utils';
/** @public */

View file

@ -19,8 +19,7 @@
import { find, get } from 'lodash';
import { Field, FieldType } from './fields';
import { StaticIndexPattern } from './index_patterns';
import { Field } from './fields';
import { getFilterableKbnTypeNames } from '../../../../../plugins/data/public';
import { SavedObjectsClientContract, SimpleSavedObject } from '../../../../../core/public';
@ -139,69 +138,3 @@ export function getRoutes() {
sourceFilters: '/management/kibana/index_patterns/{{id}}?_a=(tab:sourceFilters)',
};
}
export const mockFields: FieldType[] = [
{
name: 'machine.os',
esTypes: ['text'],
type: 'string',
aggregatable: false,
searchable: false,
filterable: true,
},
{
name: 'machine.os.raw',
type: 'string',
esTypes: ['keyword'],
aggregatable: true,
searchable: true,
filterable: true,
},
{
name: 'not.filterable',
type: 'string',
esTypes: ['text'],
aggregatable: true,
searchable: false,
filterable: false,
},
{
name: 'bytes',
type: 'number',
esTypes: ['long'],
aggregatable: true,
searchable: true,
filterable: true,
},
{
name: '@timestamp',
type: 'date',
esTypes: ['date'],
aggregatable: true,
searchable: true,
filterable: true,
},
{
name: 'clientip',
type: 'ip',
esTypes: ['ip'],
aggregatable: true,
searchable: true,
filterable: true,
},
{
name: 'bool.field',
type: 'boolean',
esTypes: ['boolean'],
aggregatable: true,
searchable: true,
filterable: true,
},
];
export const mockIndexPattern: StaticIndexPattern = {
id: 'logstash-*',
fields: mockFields,
title: 'logstash-*',
timeFieldName: '@timestamp',
};

View file

@ -45,6 +45,4 @@ export {
IndexPatternMissingIndices,
NoDefaultIndexPattern,
NoDefinedIndexPatterns,
mockFields,
mockIndexPattern,
} from '../../../../core_plugins/data/public';

View file

@ -47,8 +47,6 @@ export {
IndexPatternMissingIndices,
NoDefaultIndexPattern,
NoDefinedIndexPatterns,
mockFields,
mockIndexPattern,
} from '../../../core_plugins/data/public';
// types

View file

@ -21,3 +21,9 @@ export * from './field_formats/types';
export * from './timefilter/types';
export * from './query/types';
export * from './kbn_field_types/types';
// We can't import the real types from the data plugin, so need to either duplicate
// them here or figure out another solution, perhaps housing them in this package
// will be replaces after Fieds / IndexPattern will be moved into new platform
export type Field = any;
export type IndexPattern = any;

View file

@ -0,0 +1,79 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { Field } from '../../common';
export const stubFields: Field[] = [
{
name: 'machine.os',
esTypes: ['text'],
type: 'string',
aggregatable: false,
searchable: false,
filterable: true,
},
{
name: 'machine.os.raw',
type: 'string',
esTypes: ['keyword'],
aggregatable: true,
searchable: true,
filterable: true,
},
{
name: 'not.filterable',
type: 'string',
esTypes: ['text'],
aggregatable: true,
searchable: false,
filterable: false,
},
{
name: 'bytes',
type: 'number',
esTypes: ['long'],
aggregatable: true,
searchable: true,
filterable: true,
},
{
name: '@timestamp',
type: 'date',
esTypes: ['date'],
aggregatable: true,
searchable: true,
filterable: true,
},
{
name: 'clientip',
type: 'ip',
esTypes: ['ip'],
aggregatable: true,
searchable: true,
filterable: true,
},
{
name: 'bool.field',
type: 'boolean',
esTypes: ['boolean'],
aggregatable: true,
searchable: true,
filterable: true,
},
];

View file

@ -0,0 +1,28 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { IndexPattern } from '../../common';
import { stubFields } from './field.stub';
export const stubIndexPattern: IndexPattern = {
id: 'logstash-*',
fields: stubFields,
title: 'logstash-*',
timeFieldName: '@timestamp',
};

View file

@ -0,0 +1,21 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
export { stubIndexPattern } from './index_patterns/index_pattern.stub';
export { stubFields } from './index_patterns/field.stub';

View file

@ -21,7 +21,7 @@
jest.mock('ui/new_platform');
jest.mock('ui/index_patterns');
import { mockFields, mockIndexPattern } from 'ui/index_patterns';
import { stubIndexPattern, stubFields } from '../stubs';
import { getSuggestionsProvider } from './value_suggestions';
import { UiSettingsClientContract } from 'kibana/public';
@ -37,8 +37,8 @@ describe('getSuggestions', () => {
});
it('should return an empty array', async () => {
const index = mockIndexPattern.id;
const [field] = mockFields;
const index = stubIndexPattern.id;
const [field] = stubFields;
const query = '';
const suggestions = await getSuggestions(index, field, query);
expect(suggestions).toEqual([]);
@ -54,8 +54,8 @@ describe('getSuggestions', () => {
});
it('should return true/false for boolean fields', async () => {
const index = mockIndexPattern.id;
const [field] = mockFields.filter(({ type }) => type === 'boolean');
const index = stubIndexPattern.id;
const [field] = stubFields.filter(({ type }) => type === 'boolean');
const query = '';
const suggestions = await getSuggestions(index, field, query);
expect(suggestions).toEqual([true, false]);
@ -63,8 +63,8 @@ describe('getSuggestions', () => {
});
it('should return an empty array if the field type is not a string or boolean', async () => {
const index = mockIndexPattern.id;
const [field] = mockFields.filter(({ type }) => type !== 'string' && type !== 'boolean');
const index = stubIndexPattern.id;
const [field] = stubFields.filter(({ type }) => type !== 'string' && type !== 'boolean');
const query = '';
const suggestions = await getSuggestions(index, field, query);
expect(suggestions).toEqual([]);
@ -72,8 +72,8 @@ describe('getSuggestions', () => {
});
it('should return an empty array if the field is not aggregatable', async () => {
const index = mockIndexPattern.id;
const [field] = mockFields.filter(({ aggregatable }) => !aggregatable);
const index = stubIndexPattern.id;
const [field] = stubFields.filter(({ aggregatable }) => !aggregatable);
const query = '';
const suggestions = await getSuggestions(index, field, query);
expect(suggestions).toEqual([]);
@ -81,8 +81,8 @@ describe('getSuggestions', () => {
});
it('should otherwise request suggestions', async () => {
const index = mockIndexPattern.id;
const [field] = mockFields.filter(
const index = stubIndexPattern.id;
const [field] = stubFields.filter(
({ type, aggregatable }) => type === 'string' && aggregatable
);
const query = '';
@ -91,8 +91,8 @@ describe('getSuggestions', () => {
});
it('should cache results if using the same index/field/query/filter', async () => {
const index = mockIndexPattern.id;
const [field] = mockFields.filter(
const index = stubIndexPattern.id;
const [field] = stubFields.filter(
({ type, aggregatable }) => type === 'string' && aggregatable
);
const query = '';
@ -102,8 +102,8 @@ describe('getSuggestions', () => {
});
it('should cache results for only one minute', async () => {
const index = mockIndexPattern.id;
const [field] = mockFields.filter(
const index = stubIndexPattern.id;
const [field] = stubFields.filter(
({ type, aggregatable }) => type === 'string' && aggregatable
);
const query = '';
@ -119,7 +119,7 @@ describe('getSuggestions', () => {
});
it('should not cache results if using a different index/field/query', async () => {
const fields = mockFields.filter(
const fields = stubFields.filter(
({ type, aggregatable }) => type === 'string' && aggregatable
);
await getSuggestions('index', fields[0], '');