diff --git a/src/legacy/ui/public/new_platform/new_platform.karma_mock.js b/src/legacy/ui/public/new_platform/new_platform.karma_mock.js index f70ef069dd134..c8bf2d1e88595 100644 --- a/src/legacy/ui/public/new_platform/new_platform.karma_mock.js +++ b/src/legacy/ui/public/new_platform/new_platform.karma_mock.js @@ -430,9 +430,16 @@ export const npStart = { aggs: { calculateAutoTimeExpression: sinon.fake(), createAggConfigs: (indexPattern, configStates = []) => { - return new AggConfigs(indexPattern, configStates, { - typesRegistry: aggTypesRegistry.start(), - }); + return new AggConfigs( + indexPattern, + configStates, + { + typesRegistry: aggTypesRegistry.start(), + }, + { + fieldFormats: getFieldFormatsRegistry(mockCoreStart), + } + ); }, types: aggTypesRegistry.start(), }, diff --git a/src/plugins/data/public/search/aggs/agg_config.test.ts b/src/plugins/data/public/search/aggs/agg_config.test.ts index 41d943ef0c94b..9fdd7f2736676 100644 --- a/src/plugins/data/public/search/aggs/agg_config.test.ts +++ b/src/plugins/data/public/search/aggs/agg_config.test.ts @@ -20,16 +20,20 @@ import { identity } from 'lodash'; import { AggConfig, IAggConfig } from './agg_config'; -import { AggConfigs, CreateAggConfigParams } from './agg_configs'; +import { AggConfigs, CreateAggConfigParams, AggConfigsDependencies } from './agg_configs'; import { AggType } from './agg_type'; import { AggTypesRegistryStart } from './agg_types_registry'; import { mockDataServices, mockAggTypesRegistry } from './test_helpers'; import { Field as IndexPatternField, IndexPattern } from '../../index_patterns'; import { stubIndexPatternWithFields } from '../../../public/stubs'; +import { fieldFormatsServiceMock } from '../../field_formats/mocks'; describe('AggConfig', () => { let indexPattern: IndexPattern; let typesRegistry: AggTypesRegistryStart; + const aggConfigsDependencies: AggConfigsDependencies = { + fieldFormats: fieldFormatsServiceMock.createStartContract(), + }; beforeEach(() => { jest.restoreAllMocks(); @@ -40,7 +44,7 @@ describe('AggConfig', () => { describe('#toDsl', () => { it('calls #write()', () => { - const ac = new AggConfigs(indexPattern, [], { typesRegistry }); + const ac = new AggConfigs(indexPattern, [], { typesRegistry }, aggConfigsDependencies); const configStates = { enabled: true, type: 'date_histogram', @@ -55,7 +59,7 @@ describe('AggConfig', () => { }); it('uses the type name as the agg name', () => { - const ac = new AggConfigs(indexPattern, [], { typesRegistry }); + const ac = new AggConfigs(indexPattern, [], { typesRegistry }, aggConfigsDependencies); const configStates = { enabled: true, type: 'date_histogram', @@ -70,7 +74,7 @@ describe('AggConfig', () => { }); it('uses the params from #write() output as the agg params', () => { - const ac = new AggConfigs(indexPattern, [], { typesRegistry }); + const ac = new AggConfigs(indexPattern, [], { typesRegistry }, aggConfigsDependencies); const configStates = { enabled: true, type: 'date_histogram', @@ -100,7 +104,12 @@ describe('AggConfig', () => { params: {}, }, ]; - const ac = new AggConfigs(indexPattern, configStates, { typesRegistry }); + const ac = new AggConfigs( + indexPattern, + configStates, + { typesRegistry }, + aggConfigsDependencies + ); const histoConfig = ac.byName('date_histogram')[0]; const avgConfig = ac.byName('avg')[0]; @@ -210,8 +219,18 @@ describe('AggConfig', () => { testsIdentical.forEach((configState, index) => { it(`identical aggregations (${index})`, () => { - const ac1 = new AggConfigs(indexPattern, configState, { typesRegistry }); - const ac2 = new AggConfigs(indexPattern, configState, { typesRegistry }); + const ac1 = new AggConfigs( + indexPattern, + configState, + { typesRegistry }, + aggConfigsDependencies + ); + const ac2 = new AggConfigs( + indexPattern, + configState, + { typesRegistry }, + aggConfigsDependencies + ); expect(ac1.jsonDataEquals(ac2.aggs)).toBe(true); }); }); @@ -251,8 +270,18 @@ describe('AggConfig', () => { testsIdenticalDifferentOrder.forEach((test, index) => { it(`identical aggregations (${index}) - init json is in different order`, () => { - const ac1 = new AggConfigs(indexPattern, test.config1, { typesRegistry }); - const ac2 = new AggConfigs(indexPattern, test.config2, { typesRegistry }); + const ac1 = new AggConfigs( + indexPattern, + test.config1, + { typesRegistry }, + aggConfigsDependencies + ); + const ac2 = new AggConfigs( + indexPattern, + test.config2, + { typesRegistry }, + aggConfigsDependencies + ); expect(ac1.jsonDataEquals(ac2.aggs)).toBe(true); }); }); @@ -316,8 +345,18 @@ describe('AggConfig', () => { testsDifferent.forEach((test, index) => { it(`different aggregations (${index})`, () => { - const ac1 = new AggConfigs(indexPattern, test.config1, { typesRegistry }); - const ac2 = new AggConfigs(indexPattern, test.config2, { typesRegistry }); + const ac1 = new AggConfigs( + indexPattern, + test.config1, + { typesRegistry }, + aggConfigsDependencies + ); + const ac2 = new AggConfigs( + indexPattern, + test.config2, + { typesRegistry }, + aggConfigsDependencies + ); expect(ac1.jsonDataEquals(ac2.aggs)).toBe(false); }); }); @@ -325,7 +364,7 @@ describe('AggConfig', () => { describe('#toJSON', () => { it('includes the aggs id, params, type and schema', () => { - const ac = new AggConfigs(indexPattern, [], { typesRegistry }); + const ac = new AggConfigs(indexPattern, [], { typesRegistry }, aggConfigsDependencies); const configStates = { enabled: true, type: 'date_histogram', @@ -356,8 +395,18 @@ describe('AggConfig', () => { params: {}, }, ]; - const ac1 = new AggConfigs(indexPattern, configStates, { typesRegistry }); - const ac2 = new AggConfigs(indexPattern, configStates, { typesRegistry }); + const ac1 = new AggConfigs( + indexPattern, + configStates, + { typesRegistry }, + aggConfigsDependencies + ); + const ac2 = new AggConfigs( + indexPattern, + configStates, + { typesRegistry }, + aggConfigsDependencies + ); // this relies on the assumption that js-engines consistently loop over properties in insertion order. // most likely the case, but strictly speaking not guaranteed by the JS and JSON specifications. @@ -369,7 +418,7 @@ describe('AggConfig', () => { let aggConfig: AggConfig; beforeEach(() => { - const ac = new AggConfigs(indexPattern, [], { typesRegistry }); + const ac = new AggConfigs(indexPattern, [], { typesRegistry }, aggConfigsDependencies); aggConfig = ac.createAggConfig({ type: 'count' } as CreateAggConfigParams); }); @@ -398,7 +447,7 @@ describe('AggConfig', () => { describe('#fieldFormatter - custom getFormat handler', () => { it('returns formatter from getFormat handler', () => { - const ac = new AggConfigs(indexPattern, [], { typesRegistry }); + const ac = new AggConfigs(indexPattern, [], { typesRegistry }, aggConfigsDependencies); const configStates = { enabled: true, type: 'count', @@ -439,7 +488,12 @@ describe('AggConfig', () => { }, }, }; - const ac = new AggConfigs(indexPattern, [configStates], { typesRegistry }); + const ac = new AggConfigs( + indexPattern, + [configStates], + { typesRegistry }, + aggConfigsDependencies + ); aggConfig = ac.createAggConfig(configStates); }); diff --git a/src/plugins/data/public/search/aggs/agg_config.ts b/src/plugins/data/public/search/aggs/agg_config.ts index c9a1cb841e006..9c9ca623e366b 100644 --- a/src/plugins/data/public/search/aggs/agg_config.ts +++ b/src/plugins/data/public/search/aggs/agg_config.ts @@ -25,7 +25,6 @@ import { IAggConfigs } from './agg_configs'; import { FetchOptions } from '../fetch'; import { ISearchSource } from '../search_source'; import { FieldFormatsContentType, KBN_FIELD_TYPES } from '../../../common'; -import { getFieldFormats } from '../../../public/services'; import { FieldFormatsStart } from '../../field_formats'; export interface AggConfigOptions { @@ -40,12 +39,6 @@ export interface AggConfigDependencies { fieldFormats: FieldFormatsStart; } -const tempAggConfigDependencies = () => { - return { - fieldFormats: getFieldFormats(), - }; -}; - /** * @name AggConfig * @@ -109,7 +102,7 @@ export class AggConfig { constructor( aggConfigs: IAggConfigs, opts: AggConfigOptions, - { fieldFormats }: AggConfigDependencies = tempAggConfigDependencies() + { fieldFormats }: AggConfigDependencies ) { this.aggConfigs = aggConfigs; this.id = String(opts.id || AggConfig.nextId(aggConfigs.aggs as any)); diff --git a/src/plugins/data/public/search/aggs/agg_configs.test.ts b/src/plugins/data/public/search/aggs/agg_configs.test.ts index e20e6de6112a8..72e8ee4af4778 100644 --- a/src/plugins/data/public/search/aggs/agg_configs.test.ts +++ b/src/plugins/data/public/search/aggs/agg_configs.test.ts @@ -19,15 +19,19 @@ import { indexBy } from 'lodash'; import { AggConfig } from './agg_config'; -import { AggConfigs } from './agg_configs'; +import { AggConfigs, AggConfigsDependencies } from './agg_configs'; import { AggTypesRegistryStart } from './agg_types_registry'; import { mockDataServices, mockAggTypesRegistry } from './test_helpers'; import { Field as IndexPatternField, IndexPattern } from '../../index_patterns'; import { stubIndexPattern, stubIndexPatternWithFields } from '../../../public/stubs'; +import { fieldFormatsServiceMock } from '../../field_formats/mocks'; describe('AggConfigs', () => { let indexPattern: IndexPattern; let typesRegistry: AggTypesRegistryStart; + const aggConfigsDependencies: AggConfigsDependencies = { + fieldFormats: fieldFormatsServiceMock.createStartContract(), + }; beforeEach(() => { mockDataServices(); @@ -45,7 +49,12 @@ describe('AggConfigs', () => { }, ]; - const ac = new AggConfigs(indexPattern, configStates, { typesRegistry }); + const ac = new AggConfigs( + indexPattern, + configStates, + { typesRegistry }, + aggConfigsDependencies + ); expect(ac.aggs).toHaveLength(1); }); @@ -70,7 +79,7 @@ describe('AggConfigs', () => { ]; const spy = jest.spyOn(AggConfig, 'ensureIds'); - new AggConfigs(indexPattern, configStates, { typesRegistry }); + new AggConfigs(indexPattern, configStates, { typesRegistry }, aggConfigsDependencies); expect(spy).toHaveBeenCalledTimes(1); expect(spy.mock.calls[0]).toEqual([configStates]); spy.mockRestore(); @@ -92,16 +101,25 @@ describe('AggConfigs', () => { }, ]; - const ac = new AggConfigs(indexPattern, configStates, { typesRegistry }); + const ac = new AggConfigs( + indexPattern, + configStates, + { typesRegistry }, + aggConfigsDependencies + ); expect(ac.aggs).toHaveLength(2); ac.createAggConfig( - new AggConfig(ac, { - enabled: true, - type: typesRegistry.get('terms'), - params: {}, - schema: 'split', - }) + new AggConfig( + ac, + { + enabled: true, + type: typesRegistry.get('terms'), + params: {}, + schema: 'split', + }, + aggConfigsDependencies + ) ); expect(ac.aggs).toHaveLength(3); }); @@ -115,7 +133,12 @@ describe('AggConfigs', () => { }, ]; - const ac = new AggConfigs(indexPattern, configStates, { typesRegistry }); + const ac = new AggConfigs( + indexPattern, + configStates, + { typesRegistry }, + aggConfigsDependencies + ); expect(ac.aggs).toHaveLength(1); ac.createAggConfig({ @@ -136,7 +159,12 @@ describe('AggConfigs', () => { }, ]; - const ac = new AggConfigs(indexPattern, configStates, { typesRegistry }); + const ac = new AggConfigs( + indexPattern, + configStates, + { typesRegistry }, + aggConfigsDependencies + ); expect(ac.aggs).toHaveLength(1); ac.createAggConfig( @@ -164,7 +192,12 @@ describe('AggConfigs', () => { { type: 'percentiles', enabled: true, params: {}, schema: 'metric' }, ]; - const ac = new AggConfigs(indexPattern, configStates, { typesRegistry }); + const ac = new AggConfigs( + indexPattern, + configStates, + { typesRegistry }, + aggConfigsDependencies + ); const sorted = ac.getRequestAggs(); const aggs = indexBy(ac.aggs, agg => agg.type.name); @@ -187,7 +220,12 @@ describe('AggConfigs', () => { { type: 'count', enabled: true, params: {}, schema: 'metric' }, ]; - const ac = new AggConfigs(indexPattern, configStates, { typesRegistry }); + const ac = new AggConfigs( + indexPattern, + configStates, + { typesRegistry }, + aggConfigsDependencies + ); const sorted = ac.getResponseAggs(); const aggs = indexBy(ac.aggs, agg => agg.type.name); @@ -204,7 +242,12 @@ describe('AggConfigs', () => { { type: 'percentiles', enabled: true, params: { percents: [1, 2, 3] }, schema: 'metric' }, ]; - const ac = new AggConfigs(indexPattern, configStates, { typesRegistry }); + const ac = new AggConfigs( + indexPattern, + configStates, + { typesRegistry }, + aggConfigsDependencies + ); const sorted = ac.getResponseAggs(); const aggs = indexBy(ac.aggs, agg => agg.type.name); @@ -225,7 +268,12 @@ describe('AggConfigs', () => { it('uses the sorted aggs', () => { const configStates = [{ enabled: true, type: 'avg', params: { field: 'bytes' } }]; - const ac = new AggConfigs(indexPattern, configStates, { typesRegistry }); + const ac = new AggConfigs( + indexPattern, + configStates, + { typesRegistry }, + aggConfigsDependencies + ); const spy = jest.spyOn(AggConfigs.prototype, 'getRequestAggs'); ac.toDsl(); expect(spy).toHaveBeenCalledTimes(1); @@ -239,9 +287,14 @@ describe('AggConfigs', () => { { enabled: true, type: 'count', params: {} }, ]; - const ac = new AggConfigs(indexPattern, configStates, { - typesRegistry, - }); + const ac = new AggConfigs( + indexPattern, + configStates, + { + typesRegistry, + }, + aggConfigsDependencies + ); const aggInfos = ac.aggs.map(aggConfig => { const football = {}; @@ -284,7 +337,12 @@ describe('AggConfigs', () => { }, ]; - const ac = new AggConfigs(indexPattern, configStates, { typesRegistry }); + const ac = new AggConfigs( + indexPattern, + configStates, + { typesRegistry }, + aggConfigsDependencies + ); const dsl = ac.toDsl(); const histo = ac.byName('date_histogram')[0]; const count = ac.byName('count')[0]; @@ -309,9 +367,14 @@ describe('AggConfigs', () => { { enabled: true, type: 'max', schema: 'metric', params: { field: 'bytes' } }, ]; - const ac = new AggConfigs(indexPattern, configStates, { - typesRegistry, - }); + const ac = new AggConfigs( + indexPattern, + configStates, + { + typesRegistry, + }, + aggConfigsDependencies + ); const dsl = ac.toDsl(); const histo = ac.byName('date_histogram')[0]; const metrics = ac.bySchemaName('metrics'); @@ -336,7 +399,12 @@ describe('AggConfigs', () => { { enabled: true, type: 'max', schema: 'metric', params: { field: 'bytes' } }, ]; - const ac = new AggConfigs(indexPattern, configStates, { typesRegistry }); + const ac = new AggConfigs( + indexPattern, + configStates, + { typesRegistry }, + aggConfigsDependencies + ); const topLevelDsl = ac.toDsl(true); const buckets = ac.bySchemaName('buckets'); const metrics = ac.bySchemaName('metrics'); @@ -406,7 +474,12 @@ describe('AggConfigs', () => { }, ]; - const ac = new AggConfigs(indexPattern, configStates, { typesRegistry }); + const ac = new AggConfigs( + indexPattern, + configStates, + { typesRegistry }, + aggConfigsDependencies + ); const topLevelDsl = ac.toDsl(true)['2']; expect(Object.keys(topLevelDsl.aggs)).toContain('1'); diff --git a/src/plugins/data/public/search/aggs/agg_configs.ts b/src/plugins/data/public/search/aggs/agg_configs.ts index d311cb6e88fd7..36e47b14b072d 100644 --- a/src/plugins/data/public/search/aggs/agg_configs.ts +++ b/src/plugins/data/public/search/aggs/agg_configs.ts @@ -29,7 +29,6 @@ import { ISearchSource } from '../search_source'; import { FetchOptions } from '../fetch'; import { TimeRange } from '../../../common'; import { FieldFormatsStart } from '../../field_formats'; -import { getFieldFormats } from '../../../public/services'; function removeParentAggs(obj: any) { for (const prop in obj) { @@ -55,12 +54,6 @@ export interface AggConfigsDependencies { fieldFormats: FieldFormatsStart; } -const tempAggConfigsDependencies = () => { - return { - fieldFormats: getFieldFormats(), - }; -}; - export type CreateAggConfigParams = Assign; /** @@ -89,7 +82,7 @@ export class AggConfigs { indexPattern: IndexPattern, configStates: CreateAggConfigParams[] = [], opts: AggConfigsOptions, - { fieldFormats }: AggConfigsDependencies = tempAggConfigsDependencies() + { fieldFormats }: AggConfigsDependencies ) { this.typesRegistry = opts.typesRegistry; diff --git a/src/plugins/data/public/search/aggs/buckets/_terms_other_bucket_helper.test.ts b/src/plugins/data/public/search/aggs/buckets/_terms_other_bucket_helper.test.ts index c664325a168b1..59922bfd91ed3 100644 --- a/src/plugins/data/public/search/aggs/buckets/_terms_other_bucket_helper.test.ts +++ b/src/plugins/data/public/search/aggs/buckets/_terms_other_bucket_helper.test.ts @@ -22,10 +22,11 @@ import { mergeOtherBucketAggResponse, updateMissingBucket, } from './_terms_other_bucket_helper'; -import { AggConfigs, CreateAggConfigParams } from '../agg_configs'; +import { AggConfigs, CreateAggConfigParams, AggConfigsDependencies } from '../agg_configs'; import { BUCKET_TYPES } from './bucket_agg_types'; import { IBucketAggConfig } from './bucket_agg_type'; import { mockAggTypesRegistry } from '../test_helpers'; +import { fieldFormatsServiceMock } from '../../../field_formats/mocks'; const indexPattern = { id: '1234', @@ -219,8 +220,11 @@ const nestedOtherResponse = { describe('Terms Agg Other bucket helper', () => { const typesRegistry = mockAggTypesRegistry(); + const aggConfigsDependencies: AggConfigsDependencies = { + fieldFormats: fieldFormatsServiceMock.createStartContract(), + }; const getAggConfigs = (aggs: CreateAggConfigParams[] = []) => { - return new AggConfigs(indexPattern, [...aggs], { typesRegistry }); + return new AggConfigs(indexPattern, [...aggs], { typesRegistry }, aggConfigsDependencies); }; describe('buildOtherBucketAgg', () => { diff --git a/src/plugins/data/public/search/aggs/buckets/create_filter/date_histogram.test.ts b/src/plugins/data/public/search/aggs/buckets/create_filter/date_histogram.test.ts index 97c940b4ff4b1..85016795d8f4f 100644 --- a/src/plugins/data/public/search/aggs/buckets/create_filter/date_histogram.test.ts +++ b/src/plugins/data/public/search/aggs/buckets/create_filter/date_histogram.test.ts @@ -78,7 +78,8 @@ describe('AggConfig Filters', () => { params: { field: field.name, interval, customInterval: '5d' }, }, ], - { typesRegistry: mockAggTypesRegistry([getDateHistogramBucketAgg(aggTypesDependencies)]) } + { typesRegistry: mockAggTypesRegistry([getDateHistogramBucketAgg(aggTypesDependencies)]) }, + { fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats } ); const bucketKey = 1422579600000; diff --git a/src/plugins/data/public/search/aggs/buckets/create_filter/date_range.test.ts b/src/plugins/data/public/search/aggs/buckets/create_filter/date_range.test.ts index 8c0466b769a7e..e187340fecea6 100644 --- a/src/plugins/data/public/search/aggs/buckets/create_filter/date_range.test.ts +++ b/src/plugins/data/public/search/aggs/buckets/create_filter/date_range.test.ts @@ -72,7 +72,8 @@ describe('AggConfig Filters', () => { }, }, ], - { typesRegistry: mockAggTypesRegistry([getDateRangeBucketAgg(aggTypesDependencies)]) } + { typesRegistry: mockAggTypesRegistry([getDateRangeBucketAgg(aggTypesDependencies)]) }, + { fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats } ); }; diff --git a/src/plugins/data/public/search/aggs/buckets/create_filter/filters.test.ts b/src/plugins/data/public/search/aggs/buckets/create_filter/filters.test.ts index f5a0b5a7b9094..26bf71651d000 100644 --- a/src/plugins/data/public/search/aggs/buckets/create_filter/filters.test.ts +++ b/src/plugins/data/public/search/aggs/buckets/create_filter/filters.test.ts @@ -69,7 +69,8 @@ describe('AggConfig Filters', () => { }, }, ], - { typesRegistry: mockAggTypesRegistry([getFiltersBucketAgg(aggTypesDependencies)]) } + { typesRegistry: mockAggTypesRegistry([getFiltersBucketAgg(aggTypesDependencies)]) }, + { fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats } ); }; diff --git a/src/plugins/data/public/search/aggs/buckets/create_filter/histogram.test.ts b/src/plugins/data/public/search/aggs/buckets/create_filter/histogram.test.ts index 18b388be74877..845412035e28c 100644 --- a/src/plugins/data/public/search/aggs/buckets/create_filter/histogram.test.ts +++ b/src/plugins/data/public/search/aggs/buckets/create_filter/histogram.test.ts @@ -18,15 +18,19 @@ */ import { createFilterHistogram } from './histogram'; -import { AggConfigs } from '../../agg_configs'; +import { AggConfigs, AggConfigsDependencies } from '../../agg_configs'; import { mockAggTypesRegistry } from '../../test_helpers'; import { BUCKET_TYPES } from '../bucket_agg_types'; import { IBucketAggConfig } from '../bucket_agg_type'; import { BytesFormat, FieldFormatsGetConfigFn } from '../../../../../common'; +import { fieldFormatsServiceMock } from '../../../../field_formats/mocks'; describe('AggConfig Filters', () => { describe('histogram', () => { const getConfig = (() => {}) as FieldFormatsGetConfigFn; + const aggConfigsDependencies: AggConfigsDependencies = { + fieldFormats: fieldFormatsServiceMock.createStartContract(), + }; const getAggConfigs = () => { const field = { name: 'bytes', @@ -55,7 +59,8 @@ describe('AggConfig Filters', () => { }, }, ], - { typesRegistry: mockAggTypesRegistry() } + { typesRegistry: mockAggTypesRegistry() }, + aggConfigsDependencies ); }; diff --git a/src/plugins/data/public/search/aggs/buckets/create_filter/ip_range.test.ts b/src/plugins/data/public/search/aggs/buckets/create_filter/ip_range.test.ts index b528313b080d0..0466536c057b1 100644 --- a/src/plugins/data/public/search/aggs/buckets/create_filter/ip_range.test.ts +++ b/src/plugins/data/public/search/aggs/buckets/create_filter/ip_range.test.ts @@ -19,7 +19,7 @@ import { getIpRangeBucketAgg } from '../ip_range'; import { createFilterIpRange } from './ip_range'; -import { AggConfigs, CreateAggConfigParams } from '../../agg_configs'; +import { AggConfigs, CreateAggConfigParams, AggConfigsDependencies } from '../../agg_configs'; import { mockAggTypesRegistry } from '../../test_helpers'; import { IpFormat } from '../../../../../common'; import { BUCKET_TYPES } from '../bucket_agg_types'; @@ -29,10 +29,13 @@ import { notificationServiceMock } from '../../../../../../../core/public/mocks' describe('AggConfig Filters', () => { describe('IP range', () => { + const aggConfigsDependencies: AggConfigsDependencies = { + fieldFormats: fieldFormatsServiceMock.createStartContract(), + }; const typesRegistry = mockAggTypesRegistry([ getIpRangeBucketAgg({ getInternalStartServices: () => ({ - fieldFormats: fieldFormatsServiceMock.createStartContract(), + fieldFormats: aggConfigsDependencies.fieldFormats, notifications: notificationServiceMock.createStartContract(), }), }), @@ -52,7 +55,7 @@ describe('AggConfig Filters', () => { }, } as any; - return new AggConfigs(indexPattern, aggs, { typesRegistry }); + return new AggConfigs(indexPattern, aggs, { typesRegistry }, aggConfigsDependencies); }; test('should return a range filter for ip_range agg', () => { diff --git a/src/plugins/data/public/search/aggs/buckets/create_filter/range.test.ts b/src/plugins/data/public/search/aggs/buckets/create_filter/range.test.ts index 14a7538aa95a4..7605ff7d98d32 100644 --- a/src/plugins/data/public/search/aggs/buckets/create_filter/range.test.ts +++ b/src/plugins/data/public/search/aggs/buckets/create_filter/range.test.ts @@ -71,7 +71,8 @@ describe('AggConfig Filters', () => { }, }, ], - { typesRegistry: mockAggTypesRegistry([getRangeBucketAgg(aggTypesDependencies)]) } + { typesRegistry: mockAggTypesRegistry([getRangeBucketAgg(aggTypesDependencies)]) }, + { fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats } ); }; diff --git a/src/plugins/data/public/search/aggs/buckets/create_filter/terms.test.ts b/src/plugins/data/public/search/aggs/buckets/create_filter/terms.test.ts index c11a7d1a4e6b8..7871c5d339084 100644 --- a/src/plugins/data/public/search/aggs/buckets/create_filter/terms.test.ts +++ b/src/plugins/data/public/search/aggs/buckets/create_filter/terms.test.ts @@ -56,9 +56,14 @@ describe('AggConfig Filters', () => { indexPattern, }; - return new AggConfigs(indexPattern, aggs, { - typesRegistry: mockAggTypesRegistry([getTermsBucketAgg(aggTypesDependencies)]), - }); + return new AggConfigs( + indexPattern, + aggs, + { + typesRegistry: mockAggTypesRegistry([getTermsBucketAgg(aggTypesDependencies)]), + }, + { fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats } + ); }; test('should return a match_phrase filter for terms', () => { diff --git a/src/plugins/data/public/search/aggs/buckets/date_range.test.ts b/src/plugins/data/public/search/aggs/buckets/date_range.test.ts index c050620c3a856..3ec48189d0795 100644 --- a/src/plugins/data/public/search/aggs/buckets/date_range.test.ts +++ b/src/plugins/data/public/search/aggs/buckets/date_range.test.ts @@ -74,7 +74,8 @@ describe('date_range params', () => { params, }, ], - { typesRegistry: mockAggTypesRegistry([getDateRangeBucketAgg(aggTypesDependencies)]) } + { typesRegistry: mockAggTypesRegistry([getDateRangeBucketAgg(aggTypesDependencies)]) }, + { fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats } ); }; diff --git a/src/plugins/data/public/search/aggs/buckets/geo_hash.test.ts b/src/plugins/data/public/search/aggs/buckets/geo_hash.test.ts index 24270dd33a576..226fdcc1fb85b 100644 --- a/src/plugins/data/public/search/aggs/buckets/geo_hash.test.ts +++ b/src/plugins/data/public/search/aggs/buckets/geo_hash.test.ts @@ -77,7 +77,8 @@ describe('Geohash Agg', () => { }, }, ], - { typesRegistry: mockAggTypesRegistry() } + { typesRegistry: mockAggTypesRegistry() }, + { fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats } ); }; diff --git a/src/plugins/data/public/search/aggs/buckets/histogram.test.ts b/src/plugins/data/public/search/aggs/buckets/histogram.test.ts index bbfc263df4268..7a84293499ae4 100644 --- a/src/plugins/data/public/search/aggs/buckets/histogram.test.ts +++ b/src/plugins/data/public/search/aggs/buckets/histogram.test.ts @@ -70,7 +70,8 @@ describe('Histogram Agg', () => { params, }, ], - { typesRegistry: mockAggTypesRegistry([getHistogramBucketAgg(aggTypesDependencies)]) } + { typesRegistry: mockAggTypesRegistry([getHistogramBucketAgg(aggTypesDependencies)]) }, + { fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats } ); }; diff --git a/src/plugins/data/public/search/aggs/buckets/range.test.ts b/src/plugins/data/public/search/aggs/buckets/range.test.ts index a1f0ab6a2326a..70adb75328971 100644 --- a/src/plugins/data/public/search/aggs/buckets/range.test.ts +++ b/src/plugins/data/public/search/aggs/buckets/range.test.ts @@ -95,7 +95,8 @@ describe('Range Agg', () => { }, }, ], - { typesRegistry: mockAggTypesRegistry([getRangeBucketAgg(aggTypesDependencies)]) } + { typesRegistry: mockAggTypesRegistry([getRangeBucketAgg(aggTypesDependencies)]) }, + { fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats } ); }; diff --git a/src/plugins/data/public/search/aggs/buckets/significant_terms.test.ts b/src/plugins/data/public/search/aggs/buckets/significant_terms.test.ts index 761d0ced6a114..64e3f1bfb1814 100644 --- a/src/plugins/data/public/search/aggs/buckets/significant_terms.test.ts +++ b/src/plugins/data/public/search/aggs/buckets/significant_terms.test.ts @@ -70,7 +70,8 @@ describe('Significant Terms Agg', () => { typesRegistry: mockAggTypesRegistry([ getSignificantTermsBucketAgg(aggTypesDependencies), ]), - } + }, + { fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats } ); }; diff --git a/src/plugins/data/public/search/aggs/buckets/terms.test.ts b/src/plugins/data/public/search/aggs/buckets/terms.test.ts index 5afe7d0b0c35c..5eaae663f80a2 100644 --- a/src/plugins/data/public/search/aggs/buckets/terms.test.ts +++ b/src/plugins/data/public/search/aggs/buckets/terms.test.ts @@ -17,12 +17,16 @@ * under the License. */ -import { AggConfigs } from '../agg_configs'; +import { AggConfigs, AggConfigsDependencies } from '../agg_configs'; import { mockAggTypesRegistry } from '../test_helpers'; import { BUCKET_TYPES } from './bucket_agg_types'; +import { fieldFormatsServiceMock } from '../../../field_formats/mocks'; describe('Terms Agg', () => { describe('order agg editor UI', () => { + const aggConfigsDependencies: AggConfigsDependencies = { + fieldFormats: fieldFormatsServiceMock.createStartContract(), + }; const getAggConfigs = (params: Record = {}) => { const indexPattern = { id: '1234', @@ -47,7 +51,8 @@ describe('Terms Agg', () => { type: BUCKET_TYPES.TERMS, }, ], - { typesRegistry: mockAggTypesRegistry() } + { typesRegistry: mockAggTypesRegistry() }, + aggConfigsDependencies ); }; diff --git a/src/plugins/data/public/search/aggs/metrics/median.test.ts b/src/plugins/data/public/search/aggs/metrics/median.test.ts index f80c46026f50a..c5787b9d4b833 100644 --- a/src/plugins/data/public/search/aggs/metrics/median.test.ts +++ b/src/plugins/data/public/search/aggs/metrics/median.test.ts @@ -59,7 +59,8 @@ describe('AggTypeMetricMedianProvider class', () => { }, }, ], - { typesRegistry } + { typesRegistry }, + { fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats } ); }); diff --git a/src/plugins/data/public/search/aggs/metrics/parent_pipeline.test.ts b/src/plugins/data/public/search/aggs/metrics/parent_pipeline.test.ts index af983a50f6c23..46005535610b2 100644 --- a/src/plugins/data/public/search/aggs/metrics/parent_pipeline.test.ts +++ b/src/plugins/data/public/search/aggs/metrics/parent_pipeline.test.ts @@ -110,7 +110,8 @@ describe('parent pipeline aggs', function() { schema: 'metric', }, ], - { typesRegistry } + { typesRegistry }, + { fieldFormats: getInternalStartServices().fieldFormats } ); // Grab the aggConfig off the vis (we don't actually use the vis for anything else) diff --git a/src/plugins/data/public/search/aggs/metrics/percentile_ranks.test.ts b/src/plugins/data/public/search/aggs/metrics/percentile_ranks.test.ts index 2944fc8c11b23..dd292dbc2781e 100644 --- a/src/plugins/data/public/search/aggs/metrics/percentile_ranks.test.ts +++ b/src/plugins/data/public/search/aggs/metrics/percentile_ranks.test.ts @@ -70,7 +70,8 @@ describe('AggTypesMetricsPercentileRanksProvider class', function() { }, }, ], - { typesRegistry } + { typesRegistry }, + { fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats } ); }); diff --git a/src/plugins/data/public/search/aggs/metrics/percentiles.test.ts b/src/plugins/data/public/search/aggs/metrics/percentiles.test.ts index 33bd42df74cc7..7a132b5c21fd2 100644 --- a/src/plugins/data/public/search/aggs/metrics/percentiles.test.ts +++ b/src/plugins/data/public/search/aggs/metrics/percentiles.test.ts @@ -70,7 +70,8 @@ describe('AggTypesMetricsPercentilesProvider class', () => { }, }, ], - { typesRegistry } + { typesRegistry }, + { fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats } ); }); diff --git a/src/plugins/data/public/search/aggs/metrics/sibling_pipeline.test.ts b/src/plugins/data/public/search/aggs/metrics/sibling_pipeline.test.ts index ab480fe44227e..282a2cc4a1527 100644 --- a/src/plugins/data/public/search/aggs/metrics/sibling_pipeline.test.ts +++ b/src/plugins/data/public/search/aggs/metrics/sibling_pipeline.test.ts @@ -111,7 +111,8 @@ describe('sibling pipeline aggs', () => { }, }, ], - { typesRegistry } + { typesRegistry }, + { fieldFormats: getInternalStartServices().fieldFormats } ); // Grab the aggConfig off the vis (we don't actually use the vis for anything else) diff --git a/src/plugins/data/public/search/aggs/metrics/std_deviation.test.ts b/src/plugins/data/public/search/aggs/metrics/std_deviation.test.ts index 6bbff3009cc11..c19965d40e83d 100644 --- a/src/plugins/data/public/search/aggs/metrics/std_deviation.test.ts +++ b/src/plugins/data/public/search/aggs/metrics/std_deviation.test.ts @@ -64,7 +64,8 @@ describe('AggTypeMetricStandardDeviationProvider class', () => { }, }, ], - { typesRegistry } + { typesRegistry }, + { fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats } ); }; diff --git a/src/plugins/data/public/search/aggs/metrics/top_hit.test.ts b/src/plugins/data/public/search/aggs/metrics/top_hit.test.ts index 8294ad09bae22..f685c45d5001a 100644 --- a/src/plugins/data/public/search/aggs/metrics/top_hit.test.ts +++ b/src/plugins/data/public/search/aggs/metrics/top_hit.test.ts @@ -89,7 +89,8 @@ describe('Top hit metric', () => { params, }, ], - { typesRegistry } + { typesRegistry }, + { fieldFormats: aggTypesDependencies.getInternalStartServices().fieldFormats } ); // Grab the aggConfig off the vis (we don't actually use the vis for anything else) diff --git a/src/plugins/data/public/search/aggs/mocks.ts b/src/plugins/data/public/search/aggs/mocks.ts index 7a5dcc9be4592..c78a486855dad 100644 --- a/src/plugins/data/public/search/aggs/mocks.ts +++ b/src/plugins/data/public/search/aggs/mocks.ts @@ -27,6 +27,7 @@ import { } from './'; import { SearchAggsSetup, SearchAggsStart } from './types'; import { mockAggTypesRegistry } from './test_helpers'; +import { fieldFormatsServiceMock } from '../../field_formats/mocks'; const aggTypeBaseParamMock = () => ({ name: 'some_param', @@ -70,9 +71,16 @@ export const searchAggsSetupMock = (): SearchAggsSetup => ({ export const searchAggsStartMock = (): SearchAggsStart => ({ calculateAutoTimeExpression: getCalculateAutoTimeExpression(coreMock.createStart().uiSettings), createAggConfigs: jest.fn().mockImplementation((indexPattern, configStates = [], schemas) => { - return new AggConfigs(indexPattern, configStates, { - typesRegistry: mockAggTypesRegistry(), - }); + return new AggConfigs( + indexPattern, + configStates, + { + typesRegistry: mockAggTypesRegistry(), + }, + { + fieldFormats: fieldFormatsServiceMock.createStartContract(), + } + ); }), types: mockAggTypesRegistry(), }); diff --git a/src/plugins/data/public/search/expressions/create_filter.test.ts b/src/plugins/data/public/search/expressions/create_filter.test.ts index 23da060cba203..37a045b3fa60b 100644 --- a/src/plugins/data/public/search/expressions/create_filter.test.ts +++ b/src/plugins/data/public/search/expressions/create_filter.test.ts @@ -18,14 +18,18 @@ */ import { createFilter } from './create_filter'; -import { AggConfigs, IAggConfig } from '../aggs'; +import { AggConfigs, IAggConfig, AggConfigsDependencies } from '../aggs'; import { TabbedTable } from '../tabify'; import { isRangeFilter, BytesFormat, FieldFormatsGetConfigFn } from '../../../common'; import { mockDataServices, mockAggTypesRegistry } from '../aggs/test_helpers'; +import { fieldFormatsServiceMock } from '../../field_formats/mocks'; describe('createFilter', () => { let table: TabbedTable; let aggConfig: IAggConfig; + const aggConfigsDependencies: AggConfigsDependencies = { + fieldFormats: fieldFormatsServiceMock.createStartContract(), + }; const typesRegistry = mockAggTypesRegistry(); @@ -58,7 +62,8 @@ describe('createFilter', () => { params, }, ], - { typesRegistry } + { typesRegistry }, + aggConfigsDependencies ); }; diff --git a/src/plugins/data/public/search/tabify/get_columns.test.ts b/src/plugins/data/public/search/tabify/get_columns.test.ts index b7dadc3f65d82..c30f3183511d3 100644 --- a/src/plugins/data/public/search/tabify/get_columns.test.ts +++ b/src/plugins/data/public/search/tabify/get_columns.test.ts @@ -19,8 +19,9 @@ import { tabifyGetColumns } from './get_columns'; import { TabbedAggColumn } from './types'; -import { AggConfigs } from '../aggs'; +import { AggConfigs, AggConfigsDependencies } from '../aggs'; import { mockAggTypesRegistry, mockDataServices } from '../aggs/test_helpers'; +import { fieldFormatsServiceMock } from '../../field_formats/mocks'; describe('get columns', () => { beforeEach(() => { @@ -28,6 +29,9 @@ describe('get columns', () => { }); const typesRegistry = mockAggTypesRegistry(); + const aggConfigsDependencies: AggConfigsDependencies = { + fieldFormats: fieldFormatsServiceMock.createStartContract(), + }; const createAggConfigs = (aggs: any[] = []) => { const field = { @@ -43,9 +47,14 @@ describe('get columns', () => { }, } as any; - return new AggConfigs(indexPattern, aggs, { - typesRegistry, - }); + return new AggConfigs( + indexPattern, + aggs, + { + typesRegistry, + }, + aggConfigsDependencies + ); }; test('should inject the metric after each bucket if the vis is hierarchical', () => { diff --git a/src/plugins/data/public/search/tabify/response_writer.test.ts b/src/plugins/data/public/search/tabify/response_writer.test.ts index 52338ae79ccbb..1766f4ab72de5 100644 --- a/src/plugins/data/public/search/tabify/response_writer.test.ts +++ b/src/plugins/data/public/search/tabify/response_writer.test.ts @@ -18,9 +18,10 @@ */ import { TabbedAggResponseWriter } from './response_writer'; -import { AggConfigs, BUCKET_TYPES } from '../aggs'; +import { AggConfigs, BUCKET_TYPES, AggConfigsDependencies } from '../aggs'; import { mockDataServices, mockAggTypesRegistry } from '../aggs/test_helpers'; import { TabbedResponseWriterOptions } from './types'; +import { fieldFormatsServiceMock } from '../../field_formats/mocks'; describe('TabbedAggResponseWriter class', () => { beforeEach(() => { @@ -30,6 +31,9 @@ describe('TabbedAggResponseWriter class', () => { let responseWriter: TabbedAggResponseWriter; const typesRegistry = mockAggTypesRegistry(); + const aggConfigsDependencies: AggConfigsDependencies = { + fieldFormats: fieldFormatsServiceMock.createStartContract(), + }; const splitAggConfig = [ { @@ -72,9 +76,14 @@ describe('TabbedAggResponseWriter class', () => { } as any; return new TabbedAggResponseWriter( - new AggConfigs(indexPattern, aggs, { - typesRegistry, - }), + new AggConfigs( + indexPattern, + aggs, + { + typesRegistry, + }, + aggConfigsDependencies + ), { metricsAtAllLevels: false, partialRows: false, diff --git a/src/plugins/data/public/search/tabify/tabify.test.ts b/src/plugins/data/public/search/tabify/tabify.test.ts index c9bf04ae9f0fc..7c9002bd5aa67 100644 --- a/src/plugins/data/public/search/tabify/tabify.test.ts +++ b/src/plugins/data/public/search/tabify/tabify.test.ts @@ -19,12 +19,16 @@ import { tabifyAggResponse } from './tabify'; import { IndexPattern } from '../../index_patterns'; -import { AggConfigs, IAggConfig, IAggConfigs } from '../aggs'; +import { AggConfigs, IAggConfig, IAggConfigs, AggConfigsDependencies } from '../aggs'; import { mockAggTypesRegistry } from '../aggs/test_helpers'; import { metricOnly, threeTermBuckets } from 'fixtures/fake_hierarchical_data'; +import { fieldFormatsServiceMock } from '../../field_formats/mocks'; describe('tabifyAggResponse Integration', () => { const typesRegistry = mockAggTypesRegistry(); + const aggConfigsDependencies: AggConfigsDependencies = { + fieldFormats: fieldFormatsServiceMock.createStartContract(), + }; const createAggConfigs = (aggs: IAggConfig[] = []) => { const field = { @@ -40,9 +44,14 @@ describe('tabifyAggResponse Integration', () => { }, } as unknown) as IndexPattern; - return new AggConfigs(indexPattern, aggs, { - typesRegistry, - }); + return new AggConfigs( + indexPattern, + aggs, + { + typesRegistry, + }, + aggConfigsDependencies + ); }; const mockAggConfig = (agg: any): IAggConfig => (agg as unknown) as IAggConfig;