Skip to content

Commit

Permalink
move filedFotmats inside opt fro AggConfigs
Browse files Browse the repository at this point in the history
  • Loading branch information
VladLasitsa committed Apr 9, 2020
1 parent 6a532fa commit 0d16960
Show file tree
Hide file tree
Showing 31 changed files with 142 additions and 307 deletions.
14 changes: 4 additions & 10 deletions src/legacy/ui/public/new_platform/new_platform.karma_mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,16 +445,10 @@ export const npStart = {
aggs: {
calculateAutoTimeExpression: sinon.fake(),
createAggConfigs: (indexPattern, configStates = []) => {
return new AggConfigs(
indexPattern,
configStates,
{
typesRegistry: aggTypesRegistry.start(),
},
{
fieldFormats: getFieldFormatsRegistry(mockCoreStart),
}
);
return new AggConfigs(indexPattern, configStates, {
typesRegistry: aggTypesRegistry.start(),
fieldFormats: getFieldFormatsRegistry(mockCoreStart),
});
},
types: aggTypesRegistry.start(),
},
Expand Down
88 changes: 18 additions & 70 deletions src/plugins/data/public/search/aggs/agg_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { identity } from 'lodash';

import { AggConfig, IAggConfig } from './agg_config';
import { AggConfigs, CreateAggConfigParams, AggConfigsDependencies } from './agg_configs';
import { AggConfigs, CreateAggConfigParams } from './agg_configs';
import { AggType } from './agg_type';
import { AggTypesRegistryStart } from './agg_types_registry';
import { mockDataServices, mockAggTypesRegistry } from './test_helpers';
Expand All @@ -31,9 +31,7 @@ import { fieldFormatsServiceMock } from '../../field_formats/mocks';
describe('AggConfig', () => {
let indexPattern: IndexPattern;
let typesRegistry: AggTypesRegistryStart;
const aggConfigsDependencies: AggConfigsDependencies = {
fieldFormats: fieldFormatsServiceMock.createStartContract(),
};
const fieldFormats = fieldFormatsServiceMock.createStartContract();

beforeEach(() => {
jest.restoreAllMocks();
Expand All @@ -44,7 +42,7 @@ describe('AggConfig', () => {

describe('#toDsl', () => {
it('calls #write()', () => {
const ac = new AggConfigs(indexPattern, [], { typesRegistry }, aggConfigsDependencies);
const ac = new AggConfigs(indexPattern, [], { typesRegistry, fieldFormats });
const configStates = {
enabled: true,
type: 'date_histogram',
Expand All @@ -59,7 +57,7 @@ describe('AggConfig', () => {
});

it('uses the type name as the agg name', () => {
const ac = new AggConfigs(indexPattern, [], { typesRegistry }, aggConfigsDependencies);
const ac = new AggConfigs(indexPattern, [], { typesRegistry, fieldFormats });
const configStates = {
enabled: true,
type: 'date_histogram',
Expand All @@ -74,7 +72,7 @@ describe('AggConfig', () => {
});

it('uses the params from #write() output as the agg params', () => {
const ac = new AggConfigs(indexPattern, [], { typesRegistry }, aggConfigsDependencies);
const ac = new AggConfigs(indexPattern, [], { typesRegistry, fieldFormats });
const configStates = {
enabled: true,
type: 'date_histogram',
Expand Down Expand Up @@ -104,12 +102,7 @@ describe('AggConfig', () => {
params: {},
},
];
const ac = new AggConfigs(
indexPattern,
configStates,
{ typesRegistry },
aggConfigsDependencies
);
const ac = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });

const histoConfig = ac.byName('date_histogram')[0];
const avgConfig = ac.byName('avg')[0];
Expand Down Expand Up @@ -219,18 +212,8 @@ describe('AggConfig', () => {

testsIdentical.forEach((configState, index) => {
it(`identical aggregations (${index})`, () => {
const ac1 = new AggConfigs(
indexPattern,
configState,
{ typesRegistry },
aggConfigsDependencies
);
const ac2 = new AggConfigs(
indexPattern,
configState,
{ typesRegistry },
aggConfigsDependencies
);
const ac1 = new AggConfigs(indexPattern, configState, { typesRegistry, fieldFormats });
const ac2 = new AggConfigs(indexPattern, configState, { typesRegistry, fieldFormats });
expect(ac1.jsonDataEquals(ac2.aggs)).toBe(true);
});
});
Expand Down Expand Up @@ -270,18 +253,8 @@ describe('AggConfig', () => {

testsIdenticalDifferentOrder.forEach((test, index) => {
it(`identical aggregations (${index}) - init json is in different order`, () => {
const ac1 = new AggConfigs(
indexPattern,
test.config1,
{ typesRegistry },
aggConfigsDependencies
);
const ac2 = new AggConfigs(
indexPattern,
test.config2,
{ typesRegistry },
aggConfigsDependencies
);
const ac1 = new AggConfigs(indexPattern, test.config1, { typesRegistry, fieldFormats });
const ac2 = new AggConfigs(indexPattern, test.config2, { typesRegistry, fieldFormats });
expect(ac1.jsonDataEquals(ac2.aggs)).toBe(true);
});
});
Expand Down Expand Up @@ -345,26 +318,16 @@ describe('AggConfig', () => {

testsDifferent.forEach((test, index) => {
it(`different aggregations (${index})`, () => {
const ac1 = new AggConfigs(
indexPattern,
test.config1,
{ typesRegistry },
aggConfigsDependencies
);
const ac2 = new AggConfigs(
indexPattern,
test.config2,
{ typesRegistry },
aggConfigsDependencies
);
const ac1 = new AggConfigs(indexPattern, test.config1, { typesRegistry, fieldFormats });
const ac2 = new AggConfigs(indexPattern, test.config2, { typesRegistry, fieldFormats });
expect(ac1.jsonDataEquals(ac2.aggs)).toBe(false);
});
});
});

describe('#toJSON', () => {
it('includes the aggs id, params, type and schema', () => {
const ac = new AggConfigs(indexPattern, [], { typesRegistry }, aggConfigsDependencies);
const ac = new AggConfigs(indexPattern, [], { typesRegistry, fieldFormats });
const configStates = {
enabled: true,
type: 'date_histogram',
Expand Down Expand Up @@ -395,18 +358,8 @@ describe('AggConfig', () => {
params: {},
},
];
const ac1 = new AggConfigs(
indexPattern,
configStates,
{ typesRegistry },
aggConfigsDependencies
);
const ac2 = new AggConfigs(
indexPattern,
configStates,
{ typesRegistry },
aggConfigsDependencies
);
const ac1 = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });
const ac2 = new AggConfigs(indexPattern, configStates, { typesRegistry, fieldFormats });

// 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.
Expand All @@ -418,7 +371,7 @@ describe('AggConfig', () => {
let aggConfig: AggConfig;

beforeEach(() => {
const ac = new AggConfigs(indexPattern, [], { typesRegistry }, aggConfigsDependencies);
const ac = new AggConfigs(indexPattern, [], { typesRegistry, fieldFormats });
aggConfig = ac.createAggConfig({ type: 'count' } as CreateAggConfigParams);
});

Expand Down Expand Up @@ -447,7 +400,7 @@ describe('AggConfig', () => {

describe('#fieldFormatter - custom getFormat handler', () => {
it('returns formatter from getFormat handler', () => {
const ac = new AggConfigs(indexPattern, [], { typesRegistry }, aggConfigsDependencies);
const ac = new AggConfigs(indexPattern, [], { typesRegistry, fieldFormats });
const configStates = {
enabled: true,
type: 'count',
Expand Down Expand Up @@ -488,12 +441,7 @@ describe('AggConfig', () => {
},
},
};
const ac = new AggConfigs(
indexPattern,
[configStates],
{ typesRegistry },
aggConfigsDependencies
);
const ac = new AggConfigs(indexPattern, [configStates], { typesRegistry, fieldFormats });
aggConfig = ac.createAggConfig(configStates);
});

Expand Down
Loading

0 comments on commit 0d16960

Please sign in to comment.