Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove angular from AggTypes #17681

Merged
merged 3 commits into from
Apr 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { BasicResponseHandlerProvider } from 'ui/vis/response_handlers/basic';
import { DocTitleProvider } from 'ui/doc_title';
import PluginsKibanaDiscoverHitSortFnProvider from 'plugins/kibana/discover/_hit_sort_fn';
import { FilterBarQueryFilterProvider } from 'ui/filter_bar/query_filter';
import { AggTypesBucketsIntervalOptionsProvider } from 'ui/agg_types/buckets/_interval_options';
import { intervalOptions } from 'ui/agg_types/buckets/_interval_options';
import { stateMonitorFactory } from 'ui/state_management/state_monitor_factory';
import uiRoutes from 'ui/routes';
import { uiModules } from 'ui/modules';
Expand Down Expand Up @@ -138,7 +138,7 @@ function discoverController(
});

$scope.getDocLink = getDocLink;
$scope.intervalOptions = Private(AggTypesBucketsIntervalOptionsProvider);
$scope.intervalOptions = intervalOptions;
$scope.showInterval = false;
$scope.minimumVisibleRows = 50;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@ import expect from 'expect.js';
import ngMock from 'ng_mock';
import { VisProvider } from 'ui/vis';
import { AggConfig } from 'ui/vis/agg_config';
import { AggTypesAggTypeProvider } from 'ui/agg_types/agg_type';
import { AggType } from 'ui/agg_types/agg_type';
import { PointSeriesFakeXAxisProvider } from 'ui/agg_response/point_series/_fake_x_aspect';

describe('makeFakeXAspect', function () {

let makeFakeXAspect;
let Vis;
let AggType;
let indexPattern;

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
Vis = Private(VisProvider);
AggType = Private(AggTypesAggTypeProvider);
indexPattern = Private(VisProvider);
makeFakeXAspect = Private(PointSeriesFakeXAxisProvider);
}));
Expand Down
5 changes: 2 additions & 3 deletions src/ui/public/agg_response/point_series/_fake_x_aspect.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { AggConfig } from 'ui/vis/agg_config';
import { AggTypesAggTypeProvider } from 'ui/agg_types/agg_type';
import { AggType } from 'ui/agg_types/agg_type';

export function PointSeriesFakeXAxisProvider(Private) {
const AggType = Private(AggTypesAggTypeProvider);
export function PointSeriesFakeXAxisProvider() {

const allAgg = new AggType({
name: 'all',
Expand Down
3 changes: 1 addition & 2 deletions src/ui/public/agg_types/__tests__/agg_param_writer.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import _ from 'lodash';
import { VisProvider } from 'ui/vis';
import { AggTypesIndexProvider } from 'ui/agg_types/index';
import { aggTypes } from 'ui/agg_types/index';
import { VisTypesRegistryProvider } from 'ui/registry/vis_types';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import { AggConfig } from 'ui/vis/agg_config';

// eslint-disable-next-line @elastic/kibana-custom/no-default-export
export default function AggParamWriterHelper(Private) {
const Vis = Private(VisProvider);
const aggTypes = Private(AggTypesIndexProvider);
const visTypes = Private(VisTypesRegistryProvider);
const stubbedLogstashIndexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);

Expand Down
4 changes: 1 addition & 3 deletions src/ui/public/agg_types/__tests__/agg_type.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import 'ui/private';
import { AggParams } from 'ui/agg_types/agg_params';
import { VisProvider } from 'ui/vis';
import { fieldFormats } from 'ui/registry/field_formats';
import { AggTypesAggTypeProvider } from 'ui/agg_types/agg_type';
import { AggType } from 'ui/agg_types/agg_type';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';

describe('AggType Class', function () {
let AggType;
let indexPattern;
let Vis;

Expand All @@ -18,7 +17,6 @@ describe('AggType Class', function () {
beforeEach(ngMock.inject(function (Private) {

Vis = Private(VisProvider);
AggType = Private(AggTypesAggTypeProvider);
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
}));

Expand Down
53 changes: 16 additions & 37 deletions src/ui/public/agg_types/__tests__/buckets/_geo_hash.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import expect from 'expect.js';
import sinon from 'sinon';
import ngMock from 'ng_mock';
import { AggTypesBucketsGeoHashProvider } from 'ui/agg_types/buckets/geo_hash';
import { geoHashBucketAgg } from 'ui/agg_types/buckets/geo_hash';
import * as AggConfigModule from 'ui/vis/agg_config';
import { AggTypesIndexProvider } from 'ui/agg_types/index';
import * as BucketAggTypeModule from 'ui/agg_types/buckets/_bucket_agg_type';
import { aggTypes } from 'ui/agg_types/index';

AggConfigModule.AggConfig.aggTypes = aggTypes;

describe('Geohash Agg', () => {

Expand Down Expand Up @@ -40,27 +42,15 @@ describe('Geohash Agg', () => {
const AggConfigMock = (vis, aggOptions) => {
return aggOptions;
};
const PrivateMock = (provider) => {
switch (provider.name) {
case 'AggTypesBucketsBucketAggTypeProvider':
return BucketAggTypeMock;
break;
default:
return () => {};
}
};
const configMock = {
get: () => {
return 7;//"visualization:tileMap:maxPrecision"
}
};

before(function () {
sinon.stub(AggConfigModule, 'AggConfig', AggConfigMock);
sinon.stub(BucketAggTypeModule, 'BucketAggType', BucketAggTypeMock);
});

after(function () {
AggConfigModule.AggConfig.restore();
BucketAggTypeModule.BucketAggType.restore();
});


Expand Down Expand Up @@ -93,23 +83,12 @@ describe('Geohash Agg', () => {
};
}

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
AggConfigModule.AggConfig.aggTypes = Private(AggTypesIndexProvider);
}));

let geohashAgg;
beforeEach(() => {
geohashAgg = AggTypesBucketsGeoHashProvider(PrivateMock, configMock); // eslint-disable-line new-cap
});


describe('precision parameter', () => {

const PRECISION_PARAM_INDEX = 6;
let precisionParam;
beforeEach(() => {
precisionParam = geohashAgg.params[PRECISION_PARAM_INDEX];
precisionParam = geoHashBucketAgg.params[PRECISION_PARAM_INDEX];
});

it('should select precision parameter', () => {
Expand Down Expand Up @@ -169,7 +148,7 @@ describe('Geohash Agg', () => {
beforeEach(() => {
initVisSessionState();
initAggParams();
requestAggs = geohashAgg.getRequestAggs(aggMock);
requestAggs = geoHashBucketAgg.getRequestAggs(aggMock);
});

it('should create filter, geohash_grid, and geo_centroid aggregations', () => {
Expand All @@ -189,7 +168,7 @@ describe('Geohash Agg', () => {
// there was a bug because of an "&& mapZoom" check which excluded 0 as a valid mapZoom, but it is.
it('should create filter, geohash_grid, and geo_centroid aggregations when zoom level 0', () => {
aggMock.vis.params.mapZoom = 0;
requestAggs = geohashAgg.getRequestAggs(aggMock);
requestAggs = geoHashBucketAgg.getRequestAggs(aggMock);
expect(requestAggs.length).to.equal(3);
expect(requestAggs[0].type).to.equal('filter');
expect(requestAggs[1].type).to.equal('geohash_grid');
Expand All @@ -206,15 +185,15 @@ describe('Geohash Agg', () => {

it('should only create geohash_grid and geo_centroid aggregations when isFilteredByCollar is false', () => {
aggMock.params.isFilteredByCollar = false;
const requestAggs = geohashAgg.getRequestAggs(aggMock);
const requestAggs = geoHashBucketAgg.getRequestAggs(aggMock);
expect(requestAggs.length).to.equal(2);
expect(requestAggs[0].type).to.equal('geohash_grid');
expect(requestAggs[1].type).to.equal('geo_centroid');
});

it('should only create filter and geohash_grid aggregations when useGeocentroid is false', () => {
aggMock.params.useGeocentroid = false;
const requestAggs = geohashAgg.getRequestAggs(aggMock);
const requestAggs = geoHashBucketAgg.getRequestAggs(aggMock);
expect(requestAggs.length).to.equal(2);
expect(requestAggs[0].type).to.equal('filter');
expect(requestAggs[1].type).to.equal('geohash_grid');
Expand All @@ -229,7 +208,7 @@ describe('Geohash Agg', () => {
beforeEach(() => {
resetMap();
initAggParams();
origRequestAggs = geohashAgg.getRequestAggs(aggMock);
origRequestAggs = geoHashBucketAgg.getRequestAggs(aggMock);
origMapCollar = aggMock.vis.sessionState.mapCollar;
});

Expand All @@ -239,7 +218,7 @@ describe('Geohash Agg', () => {
bottom_right: { lat: -0.9, lon: 0.9 }
});

const newRequestAggs = geohashAgg.getRequestAggs(aggMock);
const newRequestAggs = geoHashBucketAgg.getRequestAggs(aggMock);
expect(JSON.stringify(origRequestAggs[0].params, null, '')).to.equal(JSON.stringify(newRequestAggs[0].params, null, ''));

const newMapCollar = aggMock.vis.sessionState.mapCollar;
Expand All @@ -252,7 +231,7 @@ describe('Geohash Agg', () => {
bottom_right: { lat: 9.0, lon: -9.0 }
});

const newRequestAggs = geohashAgg.getRequestAggs(aggMock);
const newRequestAggs = geoHashBucketAgg.getRequestAggs(aggMock);
expect(JSON.stringify(origRequestAggs[0].params, null, '')).not.to.equal(JSON.stringify(newRequestAggs[0].params, null, ''));

const newMapCollar = aggMock.vis.sessionState.mapCollar;
Expand All @@ -262,7 +241,7 @@ describe('Geohash Agg', () => {
it('should change geo_bounding_box filter aggregation and vis session state when map zoom level changes', () => {
zoomMap(-1);

const newRequestAggs = geohashAgg.getRequestAggs(aggMock);
const newRequestAggs = geoHashBucketAgg.getRequestAggs(aggMock);
expect(JSON.stringify(origRequestAggs[0].params, null, '')).not.to.equal(JSON.stringify(newRequestAggs[0].params, null, ''));

const newMapCollar = aggMock.vis.sessionState.mapCollar;
Expand Down
10 changes: 3 additions & 7 deletions src/ui/public/agg_types/__tests__/buckets/_histogram.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import expect from 'expect.js';
import ngMock from 'ng_mock';
import { AggTypesIndexProvider } from 'ui/agg_types/index';
import { aggTypes } from 'ui/agg_types/index';
import AggParamWriterProvider from '../agg_param_writer';

const histogram = aggTypes.byName.histogram;
describe('Histogram Agg', function () {

describe('ordered', function () {
let histogram;

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
histogram = Private(AggTypesIndexProvider).byName.histogram;
}));

it('is ordered', function () {
expect(histogram.ordered).to.be.ok();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import expect from 'expect.js';
import ngMock from 'ng_mock';
import { OtherBucketHelperProvider } from 'ui/agg_types/buckets/_terms_other_bucket_helper';
import { buildOtherBucketAgg, mergeOtherBucketAggResponse, updateMissingBucket } from 'ui/agg_types/buckets/_terms_other_bucket_helper';
import { VisProvider } from 'ui/vis';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';

Expand Down Expand Up @@ -118,15 +118,13 @@ const nestedOtherResponse = {

describe('Terms Agg Other bucket helper', () => {

let otherBucketHelper;
let vis;

function init(aggConfig) {
ngMock.module('kibana');
ngMock.inject((Private) => {
const Vis = Private(VisProvider);
const indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
otherBucketHelper = Private(OtherBucketHelperProvider);

vis = new Vis(indexPattern, aggConfig);
});
Expand All @@ -136,13 +134,13 @@ describe('Terms Agg Other bucket helper', () => {

it('returns a function', () => {
init(visConfigSingleTerm);
const agg = otherBucketHelper.buildOtherBucketAgg(vis.aggs, vis.aggs[0], singleTermResponse);
const agg = buildOtherBucketAgg(vis.aggs, vis.aggs[0], singleTermResponse);
expect(agg).to.be.a('function');
});

it('correctly builds query with single terms agg', () => {
init(visConfigSingleTerm);
const agg = otherBucketHelper.buildOtherBucketAgg(vis.aggs, vis.aggs[0], singleTermResponse)();
const agg = buildOtherBucketAgg(vis.aggs, vis.aggs[0], singleTermResponse)();
const expectedResponse = {
aggs: undefined,
filters: {
Expand Down Expand Up @@ -171,7 +169,7 @@ describe('Terms Agg Other bucket helper', () => {

it('correctly builds query for nested terms agg', () => {
init(visConfigNestedTerm);
const agg = otherBucketHelper.buildOtherBucketAgg(vis.aggs, vis.aggs[1], nestedTermResponse)();
const agg = buildOtherBucketAgg(vis.aggs, vis.aggs[1], nestedTermResponse)();
const expectedResponse = {
'other-filter': {
aggs: undefined,
Expand Down Expand Up @@ -220,19 +218,23 @@ describe('Terms Agg Other bucket helper', () => {
describe('mergeOtherBucketAggResponse', () => {
it('correctly merges other bucket with single terms agg', () => {
init(visConfigSingleTerm);
const otherAggConfig = otherBucketHelper.buildOtherBucketAgg(vis.aggs, vis.aggs[0], singleTermResponse)();
const mergedResponse = otherBucketHelper
.mergeOtherBucketAggResponse(vis.aggs, singleTermResponse, singleOtherResponse, vis.aggs[0], otherAggConfig);
const otherAggConfig = buildOtherBucketAgg(vis.aggs, vis.aggs[0], singleTermResponse)();
const mergedResponse = mergeOtherBucketAggResponse(
vis.aggs,
singleTermResponse,
singleOtherResponse,
vis.aggs[0],
otherAggConfig);

expect(mergedResponse.aggregations['1'].buckets[3].key).to.equal('Other');
expect(mergedResponse.aggregations['1'].buckets[3].filters.length).to.equal(2);
});

it('correctly merges other bucket with nested terms agg', () => {
init(visConfigNestedTerm);
const otherAggConfig = otherBucketHelper.buildOtherBucketAgg(vis.aggs, vis.aggs[1], nestedTermResponse)();
const mergedResponse = otherBucketHelper
.mergeOtherBucketAggResponse(vis.aggs, nestedTermResponse, nestedOtherResponse, vis.aggs[1], otherAggConfig);
const otherAggConfig = buildOtherBucketAgg(vis.aggs, vis.aggs[1], nestedTermResponse)();
const mergedResponse = mergeOtherBucketAggResponse(vis.aggs, nestedTermResponse,
nestedOtherResponse, vis.aggs[1], otherAggConfig);

expect(mergedResponse.aggregations['1'].buckets[1]['2'].buckets[3].key).to.equal('Other');
expect(mergedResponse.aggregations['1'].buckets[1]['2'].buckets[3].filters.length).to.equal(2);
Expand All @@ -243,12 +245,12 @@ describe('Terms Agg Other bucket helper', () => {
describe('updateMissingBucket', () => {
it('correctly updates missing bucket key', () => {
init(visConfigNestedTerm);
const updatedResponse = otherBucketHelper.updateMissingBucket(singleTermResponse, vis.aggs, vis.aggs[0]);
const updatedResponse = updateMissingBucket(singleTermResponse, vis.aggs, vis.aggs[0]);
expect(updatedResponse.aggregations['1'].buckets.find(bucket => bucket.key === 'Missing')).to.not.be('undefined');
});

it('correctly sets the bucket filter', () => {
const updatedResponse = otherBucketHelper.updateMissingBucket(singleTermResponse, vis.aggs, vis.aggs[0]);
const updatedResponse = updateMissingBucket(singleTermResponse, vis.aggs, vis.aggs[0]);
const missingBucket = updatedResponse.aggregations['1'].buckets.find(bucket => bucket.key === 'Missing');
expect(missingBucket.filters).to.not.be('undefined');
expect(missingBucket.filters[0]).to.eql({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import ngMock from 'ng_mock';
import expect from 'expect.js';
import { VisProvider } from 'ui/vis';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import { AggTypesBucketsCreateFilterDateHistogramProvider } from 'ui/agg_types/buckets/create_filter/date_histogram';
import { AggTypesBucketsIntervalOptionsProvider } from 'ui/agg_types/buckets/_interval_options';
import { createFilterDateHistogram } from 'ui/agg_types/buckets/create_filter/date_histogram';
import { intervalOptions } from 'ui/agg_types/buckets/_interval_options';

describe('AggConfig Filters', function () {
describe('date_histogram', function () {
Expand All @@ -16,16 +16,13 @@ describe('AggConfig Filters', function () {
let filter;
let bucketKey;
let bucketStart;
let intervalOptions;

let init;

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
const Vis = Private(VisProvider);
const indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
const createFilter = Private(AggTypesBucketsCreateFilterDateHistogramProvider);
intervalOptions = Private(AggTypesBucketsIntervalOptionsProvider);

init = function (interval, duration) {
interval = interval || 'auto';
Expand Down Expand Up @@ -54,7 +51,7 @@ describe('AggConfig Filters', function () {
});
agg.buckets.setInterval(interval);

filter = createFilter(agg, bucketKey);
filter = createFilterDateHistogram(agg, bucketKey);
};
}));

Expand Down
Loading