Skip to content

Commit

Permalink
Fix tests, eslint, and conflicts with elastic#58679!
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeelmers committed Mar 11, 2020
1 parent f9b9a6e commit badc77f
Show file tree
Hide file tree
Showing 100 changed files with 268 additions and 292 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ import React, { useState, useMemo, useCallback } from 'react';
import { EuiFormRow, EuiIconTip, EuiCodeEditor, EuiScreenReaderOnly } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

<<<<<<< HEAD
=======
import { isValidJson } from '../../utils';
>>>>>>> Fix TS!
import { AggParamEditorProps } from '../agg_param_props';

function RawJsonParamEditor({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,21 @@
*/

/* `ui/agg_types` dependencies */
export { BUCKET_TYPES, METRIC_TYPES } from '../../../../plugins/data/public';
export {
AggGroupNames,
aggGroupNamesMap,
AggParam,
AggParamType,
AggType,
aggTypes,
BUCKET_TYPES,
createAggConfigs,
FieldParamType,
IAggConfig,
IAggConfigs,
IAggGroupNames,
IAggType,
IFieldParamType,
METRIC_TYPES,
termsAggFilter,
} from 'ui/agg_types';
export { aggTypeFilters, propFilter } from 'ui/agg_types';
Expand Down
29 changes: 1 addition & 28 deletions src/legacy/core_plugins/vis_default_editor/public/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { groupAndSortBy, isValidJson } from './utils';
import { groupAndSortBy } from './utils';
import { AggGroupNames } from './legacy_imports';

jest.mock('ui/new_platform');
Expand Down Expand Up @@ -195,30 +195,3 @@ describe('Default Editor groupAggregationsBy', () => {
expect(groupAndSortBy(aggs, 'subtype', 'title')).toEqual(groupedAggs);
});
});

describe('DefaultEditor isValidJson', () => {
const input = {
valid: '{ "test": "json input" }',
invalid: 'strings are not json',
};

it('should return true when empty string', () => {
expect(isValidJson('')).toBeTruthy();
});

it('should return true when undefine', () => {
expect(isValidJson(undefined as any)).toBeTruthy();
});

it('should return false when invalid string', () => {
expect(isValidJson(input.invalid)).toBeFalsy();
});

it('should return true when valid string', () => {
expect(isValidJson(input.valid)).toBeTruthy();
});

it('should return false if a number', () => {
expect(isValidJson('0')).toBeFalsy();
});
});
29 changes: 0 additions & 29 deletions src/legacy/core_plugins/vis_default_editor/public/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,32 +78,3 @@ export function groupAndSortBy<
function sortByLabel<T>(a: GroupOrOption<T>, b: GroupOrOption<T>) {
return (a.label || '').toLowerCase().localeCompare((b.label || '').toLowerCase());
}

/**
* Check a string if it's a valid JSON.
*
* @param {string} value a string that should be validated
* @returns {boolean} true if value is a valid JSON or if value is an empty string, or a string with whitespaces, otherwise false
*/
export function isValidJson(value: string): boolean {
if (!value || value.length === 0) {
return true;
}

const trimmedValue = value.trim();

if (trimmedValue.length === 0) {
return true;
}

if (trimmedValue[0] === '{' || trimmedValue[0] === '[') {
try {
JSON.parse(trimmedValue);
return true;
} catch (e) {
return false;
}
} else {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
import moment from 'moment';
import { i18n } from '@kbn/i18n';
import { get } from 'lodash';
import { parseEsInterval } from '../../../../../../plugins/data/public';
import { search } from '../../../../../../plugins/data/public';
const { parseEsInterval } = search.aggs;
import { GTE_INTERVAL_RE } from '../../../../../../plugins/vis_type_timeseries/common/interval_regexp';

export const AUTO_INTERVAL = 'auto';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

import { GTE_INTERVAL_RE } from '../../../../../plugins/vis_type_timeseries/common/interval_regexp';
import { i18n } from '@kbn/i18n';
import { parseInterval } from '../../../../../plugins/data/public';
import { search } from '../../../../../plugins/data/public';
const { parseInterval } = search.aggs;

export function validateInterval(bounds, panel, maxBuckets) {
const { interval } = panel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

// eslint-disable-next-line
import { npSetup, npStart } from 'ui/new_platform';
import { PluginInitializerContext } from '../../../../../../core/public';
import { plugin } from '.';
Expand Down
1 change: 0 additions & 1 deletion src/legacy/ui/public/agg_types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export const {
isStringType,
isType,
isValidInterval,
OptionedParamType,
parentPipelineType,
propFilter,
siblingPipelineType,
Expand Down
40 changes: 36 additions & 4 deletions src/legacy/ui/public/new_platform/new_platform.karma_mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,19 @@ export const npSetup = {
getSavedQueryCount: sinon.fake(),
},
},
__LEGACY: {
esClient: {
search: sinon.fake(),
msearch: sinon.fake(),
search: {
aggs: {
calculateAutoTimeExpression: sinon.fake(),
types: {
registerBucket: sinon.fake(),
registerMetric: sinon.fake(),
},
},
__LEGACY: {
esClient: {
search: sinon.fake(),
msearch: sinon.fake(),
},
},
},
fieldFormats: getFieldFormatsRegistry(mockCore),
Expand Down Expand Up @@ -284,6 +293,9 @@ export const npStart = {
},
},
data: {
actions: {
createFiltersFromEvent: Promise.resolve(['yes']),
},
autocomplete: {
getProvider: sinon.fake(),
},
Expand Down Expand Up @@ -355,7 +367,27 @@ export const npStart = {
},
},
search: {
aggs: {
calculateAutoTimeExpression: sinon.fake(),
createAggConfigs: sinon.fake(),
types: {
get: sinon.fake(),
getBuckets: sinon.fake(),
getMetrics: sinon.fake(),
getAll: sinon.fake(),
},
},
__LEGACY: {
AggConfig: sinon.fake(),
AggType: sinon.fake(),
aggTypeFieldFilters: {
addFilter: sinon.fake(),
filter: sinon.fake(),
},
FieldParamType: sinon.fake(),
MetricAggType: sinon.fake(),
parentPipelineAggHelper: sinon.fake(),
siblingPipelineAggHelper: sinon.fake(),
esClient: {
search: sinon.fake(),
msearch: sinon.fake(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,8 @@ export class TypeAutocompleteComponent extends ListComponent {
return false;
}

<<<<<<< HEAD:src/plugins/console/public/lib/autocomplete/components/type_autocomplete_component.js
return !_.find(tokens, nonValidIndexType);
}
=======
import { isValidJson } from './is_valid_json';
>>>>>>> Clean up utils & exports!:src/plugins/data/public/search/aggs/utils/is_valid_json.test.ts

getDefaultTermMeta() {
return 'type';
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/data/common/index_patterns/fields/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
* under the License.
*/

import { getFilterableKbnTypeNames, IFieldType } from '../..';
import { getFilterableKbnTypeNames } from '../../kbn_field_types';
import { IFieldType } from './types';

const filterableTypes = getFilterableKbnTypeNames();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import { setIndexPatterns } from '../../../public/services';
import { mockDataServices } from '../../../public/search/aggs/test_helpers';
import { createFiltersFromEvent, EventData } from './create_filters_from_event';

jest.mock('ui/new_platform');

const mockField = {
name: 'bytes',
indexPattern: {
Expand Down
29 changes: 20 additions & 9 deletions src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ import {
isPhrasesFilter,
isQueryStringFilter,
isRangeFilter,
isValidEsInterval,
isValidInterval,
toAbsoluteDates,
toggleFilterNegated,
} from '../common';

Expand Down Expand Up @@ -291,15 +288,13 @@ import {
AggConfigs,
aggTypeFilters,
aggGroupNamesMap,
BUCKET_TYPES,
CidrMask,
convertDateRangeToString,
convertIPRangeToString,
intervalOptions, // only used in Discover
isDateHistogramBucketAggConfig,
isStringType,
isType,
METRIC_TYPES,
parentPipelineType,
propFilter,
siblingPipelineType,
Expand All @@ -312,6 +307,19 @@ import {
tabifyGetColumns,
} from './search';

import {
dateHistogramInterval,
InvalidEsCalendarIntervalError,
InvalidEsIntervalFormatError,
isValidEsInterval,
isValidInterval,
parseEsInterval,
parseInterval,
toAbsoluteDates,
} from '../common';

export { ParsedInterval } from '../common';

export {
// aggs
AggGroupNames,
Expand All @@ -320,6 +328,7 @@ export {
AggParamType,
AggTypeFieldFilters, // TODO convert to interface
AggTypeFilters, // TODO convert to interface
BUCKET_TYPES,
DateRangeKey, // only used in field formatter deserialization, which will live in data
IAggConfig,
IAggConfigs,
Expand All @@ -328,6 +337,7 @@ export {
IFieldParamType,
IMetricAggType,
IpRangeKey, // only used in field formatter deserialization, which will live in data
METRIC_TYPES,
OptionedParamEditorProps, // only type is used externally
OptionedParamType,
OptionedValueProp, // only type is used externally
Expand Down Expand Up @@ -371,18 +381,21 @@ export const search = {
AggConfigs,
aggGroupNamesMap,
aggTypeFilters,
BUCKET_TYPES,
CidrMask,
convertDateRangeToString,
convertIPRangeToString,
dateHistogramInterval,
intervalOptions, // only used in Discover
InvalidEsCalendarIntervalError,
InvalidEsIntervalFormatError,
isDateHistogramBucketAggConfig,
isStringType,
isType,
isValidEsInterval,
isValidInterval,
METRIC_TYPES,
parentPipelineType,
parseEsInterval,
parseInterval,
propFilter,
siblingPipelineType,
termsAggFilter,
Expand Down Expand Up @@ -435,8 +448,6 @@ export {
// kbn field types
castEsToKbnFieldTypeName,
getKbnTypeNames,
// utils
parseInterval,
} from '../common';

/*
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/data/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import { Plugin, DataPublicPluginSetup, DataPublicPluginStart, IndexPatternsContract } from '.';
import { fieldFormatsMock } from '../common/field_formats/mocks';
import { searchSetupMock } from './search/mocks';
import { AggTypeFieldFilters } from './search/aggs';
import { searchAggsStartMock } from './search/aggs/mocks';
import { queryServiceMock } from './query/mocks';

Expand Down Expand Up @@ -64,7 +65,7 @@ const createStartContract = (): Start => {
__LEGACY: {
AggConfig: jest.fn() as any,
AggType: jest.fn(),
aggTypeFieldFilters: jest.fn() as any,
aggTypeFieldFilters: new AggTypeFieldFilters(),
FieldParamType: jest.fn(),
MetricAggType: jest.fn(),
parentPipelineAggHelper: jest.fn() as any,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/public/search/aggs/agg_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { AggConfigs, CreateAggConfigParams } from './agg_configs';
import { AggType } from './agg_type';
import { AggTypesRegistryStart } from './agg_types_registry';
import { mockDataServices, mockAggTypesRegistry } from './test_helpers';
import { IndexPatternField, IndexPattern } from '../../../public';
import { Field as IndexPatternField, IndexPattern } from '../../index_patterns';
import { stubIndexPatternWithFields } from '../../../public/stubs';
import { dataPluginMock } from '../../../public/mocks';
import { setFieldFormats } from '../../../public/services';
Expand Down
9 changes: 3 additions & 6 deletions src/plugins/data/public/search/aggs/agg_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@ import { i18n } from '@kbn/i18n';
import { IAggType } from './agg_type';
import { writeParams } from './agg_params';
import { IAggConfigs } from './agg_configs';
import {
ISearchSource,
FetchOptions,
FieldFormatsContentType,
KBN_FIELD_TYPES,
} from '../../../public';
import { FetchOptions } from '../fetch';
import { ISearchSource } from '../search_source';
import { FieldFormatsContentType, KBN_FIELD_TYPES } from '../../../common';
import { getFieldFormats } from '../../../public/services';

export interface AggConfigOptions {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/public/search/aggs/agg_configs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { AggConfig } from './agg_config';
import { AggConfigs } from './agg_configs';
import { AggTypesRegistryStart } from './agg_types_registry';
import { mockDataServices, mockAggTypesRegistry } from './test_helpers';
import { IndexPatternField, IndexPattern } from '../../../public';
import { Field as IndexPatternField, IndexPattern } from '../../index_patterns';
import { stubIndexPattern, stubIndexPatternWithFields } from '../../../public/stubs';

describe('AggConfigs', () => {
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/data/public/search/aggs/agg_configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import { AggConfig, AggConfigOptions, IAggConfig } from './agg_config';
import { IAggType } from './agg_type';
import { AggTypesRegistryStart } from './agg_types_registry';
import { AggGroupNames } from './agg_groups';
import { IndexPattern, ISearchSource, FetchOptions, TimeRange } from '../../../public';
import { IndexPattern } from '../../index_patterns';
import { ISearchSource } from '../search_source';
import { FetchOptions } from '../fetch';
import { TimeRange } from '../../../common';

function removeParentAggs(obj: any) {
for (const prop in obj) {
Expand Down
Loading

0 comments on commit badc77f

Please sign in to comment.