Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VladLasitsa committed Apr 6, 2020
1 parent b9e08ba commit 0ec6f9e
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 26 deletions.
18 changes: 14 additions & 4 deletions src/plugins/data/public/search/aggs/agg_params.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,22 @@ import { BaseParamType } from './param_types/base';
import { FieldParamType } from './param_types/field';
import { OptionedParamType } from './param_types/optioned';
import { AggParamType } from '../aggs/param_types/agg';
import { fieldFormatsServiceMock } from '../../field_formats/mocks';
import { notificationServiceMock } from '../../../../../../src/core/public/mocks';
import { AggTypeDependencies } from './agg_type';

describe('AggParams class', () => {
const aggTypesDependencies: AggTypeDependencies = {
getInternalStartServices: () => ({
fieldFormats: fieldFormatsServiceMock.createStartContract(),
notifications: notificationServiceMock.createStartContract(),
}),
};

describe('constructor args', () => {
it('accepts an array of param defs', () => {
const params = [{ name: 'one' }, { name: 'two' }] as AggParamType[];
const aggParams = initParams(params);
const aggParams = initParams(params, aggTypesDependencies);

expect(aggParams).toHaveLength(params.length);
expect(Array.isArray(aggParams)).toBeTruthy();
Expand All @@ -37,7 +47,7 @@ describe('AggParams class', () => {
describe('AggParam creation', () => {
it('Uses the FieldParamType class for params with the name "field"', () => {
const params = [{ name: 'field', type: 'field' }] as AggParamType[];
const aggParams = initParams(params);
const aggParams = initParams(params, aggTypesDependencies);

expect(aggParams).toHaveLength(params.length);
expect(aggParams[0] instanceof FieldParamType).toBeTruthy();
Expand All @@ -50,7 +60,7 @@ describe('AggParams class', () => {
type: 'optioned',
},
] as AggParamType[];
const aggParams = initParams(params);
const aggParams = initParams(params, aggTypesDependencies);

expect(aggParams).toHaveLength(params.length);
expect(aggParams[0] instanceof OptionedParamType).toBeTruthy();
Expand All @@ -72,7 +82,7 @@ describe('AggParams class', () => {
},
] as AggParamType[];

const aggParams = initParams(params);
const aggParams = initParams(params, aggTypesDependencies);

expect(aggParams).toHaveLength(params.length);

Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/public/search/aggs/agg_type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import { AggType, AggTypeConfig, AggTypeDependencies } from './agg_type';
import { IAggConfig } from './agg_config';
import { fieldFormatsServiceMock } from '../../field_formats/mocks';
import { notificationServiceMock } from '../../../../../../src/core/public/mocks';

describe('AggType Class', () => {
let dependencies: AggTypeDependencies;
Expand All @@ -31,6 +32,7 @@ describe('AggType Class', () => {
...fieldFormatsServiceMock.createStartContract(),
getDefaultInstance: jest.fn(() => 'default') as any,
},
notifications: notificationServiceMock.createStartContract(),
}),
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
} from '../date_histogram';
import { BUCKET_TYPES } from '../bucket_agg_types';
import { RangeFilter } from '../../../../../common';
import { coreMock } from '../../../../../../../core/public/mocks';
import { coreMock, notificationServiceMock } from '../../../../../../../core/public/mocks';
import { queryServiceMock } from '../../../../query/mocks';
import { fieldFormatsServiceMock } from '../../../../field_formats/mocks';

Expand All @@ -49,6 +49,7 @@ describe('AggConfig Filters', () => {
query: queryServiceMock.createSetupContract(),
getInternalStartServices: () => ({
fieldFormats: fieldFormatsServiceMock.createStartContract(),
notifications: notificationServiceMock.createStartContract(),
}),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { AggConfigs } from '../../agg_configs';
import { mockAggTypesRegistry } from '../../test_helpers';
import { BUCKET_TYPES } from '../bucket_agg_types';
import { IBucketAggConfig } from '../bucket_agg_type';
import { coreMock } from '../../../../../../../core/public/mocks';
import { coreMock, notificationServiceMock } from '../../../../../../../core/public/mocks';
import { fieldFormatsServiceMock } from '../../../../field_formats/mocks';

describe('AggConfig Filters', () => {
Expand All @@ -40,6 +40,7 @@ describe('AggConfig Filters', () => {
uiSettings,
getInternalStartServices: () => ({
fieldFormats: fieldFormatsServiceMock.createStartContract(),
notifications: notificationServiceMock.createStartContract(),
}),
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { createFilterFilters } from './filters';
import { AggConfigs } from '../../agg_configs';
import { mockAggTypesRegistry } from '../../test_helpers';
import { IBucketAggConfig } from '../bucket_agg_type';
import { coreMock } from '../../../../../../../core/public/mocks';
import { coreMock, notificationServiceMock } from '../../../../../../../core/public/mocks';
import { fieldFormatsServiceMock } from '../../../../field_formats/mocks';

describe('AggConfig Filters', () => {
Expand All @@ -36,6 +36,7 @@ describe('AggConfig Filters', () => {
uiSettings,
getInternalStartServices: () => ({
fieldFormats: fieldFormatsServiceMock.createStartContract(),
notifications: notificationServiceMock.createStartContract(),
}),
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ import { IpFormat } from '../../../../../common';
import { BUCKET_TYPES } from '../bucket_agg_types';
import { IBucketAggConfig } from '../bucket_agg_type';
import { fieldFormatsServiceMock } from '../../../../field_formats/mocks';
import { notificationServiceMock } from '../../../../../../../core/public/mocks';

describe('AggConfig Filters', () => {
describe('IP range', () => {
const typesRegistry = mockAggTypesRegistry([
getIpRangeBucketAgg({
getInternalStartServices: () => ({
fieldFormats: fieldFormatsServiceMock.createStartContract(),
notifications: notificationServiceMock.createStartContract(),
}),
}),
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { mockDataServices, mockAggTypesRegistry } from '../../test_helpers';
import { BUCKET_TYPES } from '../bucket_agg_types';
import { IBucketAggConfig } from '../bucket_agg_type';
import { fieldFormatsServiceMock } from '../../../../field_formats/mocks';
import { notificationServiceMock } from '../../../../../../../core/public/mocks';

describe('AggConfig Filters', () => {
describe('range', () => {
Expand All @@ -34,6 +35,7 @@ describe('AggConfig Filters', () => {
aggTypesDependencies = {
getInternalStartServices: () => ({
fieldFormats: fieldFormatsServiceMock.createStartContract(),
notifications: notificationServiceMock.createStartContract(),
}),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { IBucketAggConfig } from '../bucket_agg_type';
import { Filter, ExistsFilter } from '../../../../../common';
import { RangeBucketAggDependencies } from '../range';
import { fieldFormatsServiceMock } from '../../../../field_formats/mocks';
import { notificationServiceMock } from '../../../../../../../core/public/mocks';

describe('AggConfig Filters', () => {
describe('terms', () => {
Expand All @@ -35,6 +36,7 @@ describe('AggConfig Filters', () => {
aggTypesDependencies = {
getInternalStartServices: () => ({
fieldFormats: fieldFormatsServiceMock.createStartContract(),
notifications: notificationServiceMock.createStartContract(),
}),
};
});
Expand Down
55 changes: 38 additions & 17 deletions src/plugins/data/public/search/aggs/param_types/field.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,20 @@
*/

import { BaseParamType } from './base';
import { FieldParamType } from './field';
import { FieldParamType, FieldParamTypeDependencies } from './field';
import { ES_FIELD_TYPES, KBN_FIELD_TYPES } from '../../../../common';
import { IAggConfig } from '../agg_config';
import { fieldFormatsServiceMock } from '../../../field_formats/mocks';
import { notificationServiceMock } from '../../../../../../../src/core/public/mocks';

describe('Field', () => {
const fieldParamTypeDependencies: FieldParamTypeDependencies = {
getInternalStartServices: () => ({
fieldFormats: fieldFormatsServiceMock.createStartContract(),
notifications: notificationServiceMock.createStartContract(),
}),
};

const indexPattern = {
id: '1234',
title: 'logstash-*',
Expand Down Expand Up @@ -52,21 +61,27 @@ describe('Field', () => {

describe('constructor', () => {
it('it is an instance of BaseParamType', () => {
const aggParam = new FieldParamType({
name: 'field',
type: 'field',
});
const aggParam = new FieldParamType(
{
name: 'field',
type: 'field',
},
fieldParamTypeDependencies
);

expect(aggParam instanceof BaseParamType).toBeTruthy();
});
});

describe('getAvailableFields', () => {
it('should return only aggregatable fields by default', () => {
const aggParam = new FieldParamType({
name: 'field',
type: 'field',
});
const aggParam = new FieldParamType(
{
name: 'field',
type: 'field',
},
fieldParamTypeDependencies
);

const fields = aggParam.getAvailableFields(agg);

Expand All @@ -78,10 +93,13 @@ describe('Field', () => {
});

it('should return all fields if onlyAggregatable is false', () => {
const aggParam = new FieldParamType({
name: 'field',
type: 'field',
});
const aggParam = new FieldParamType(
{
name: 'field',
type: 'field',
},
fieldParamTypeDependencies
);

aggParam.onlyAggregatable = false;

Expand All @@ -91,10 +109,13 @@ describe('Field', () => {
});

it('should return all fields if filterFieldTypes was not specified', () => {
const aggParam = new FieldParamType({
name: 'field',
type: 'field',
});
const aggParam = new FieldParamType(
{
name: 'field',
type: 'field',
},
fieldParamTypeDependencies
);

indexPattern.fields[1].aggregatable = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { coreMock } from '../../../../../../../src/core/public/mocks';
import { coreMock, notificationServiceMock } from '../../../../../../../src/core/public/mocks';
import { AggTypesRegistry, AggTypesRegistryStart } from '../agg_types_registry';
import { getAggTypes } from '../agg_types';
import { BucketAggType } from '../buckets/bucket_agg_type';
Expand Down Expand Up @@ -56,10 +56,10 @@ export function mockAggTypesRegistry<T extends BucketAggType<any> | MetricAggTyp
const core = coreMock.createSetup();
const aggTypes = getAggTypes({
uiSettings: core.uiSettings,
notifications: core.notifications,
query: queryServiceMock.createSetupContract(),
getInternalStartServices: () => ({
fieldFormats: fieldFormatsServiceMock.createStartContract(),
notifications: notificationServiceMock.createStartContract(),
}),
});

Expand Down

0 comments on commit 0ec6f9e

Please sign in to comment.