Skip to content

Commit

Permalink
Test fixes and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Caldwell committed Mar 17, 2020
1 parent 6335ab4 commit 09557bb
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import _ from 'lodash';
import { KibanaTilemapSource } from '../layers/sources/kibana_tilemap_source';
import { EMSTMSSource } from '../layers/sources/ems_tms_source';
import chrome from 'ui/chrome';
import { getInjectedVarFunc } from '../kibana_services';
import { getKibanaTileMap } from '../meta';

export function getInitialLayers(layerListJSON, initialLayers = []) {
Expand All @@ -22,7 +22,7 @@ export function getInitialLayers(layerListJSON, initialLayers = []) {
return [layer.toLayerDescriptor(), ...initialLayers];
}

const isEmsEnabled = chrome.getInjected('isEmsEnabled', true);
const isEmsEnabled = getInjectedVarFunc()('isEmsEnabled', true);
if (isEmsEnabled) {
const descriptor = EMSTMSSource.createDescriptor({ isAutoSelect: true });
const source = new EMSTMSSource(descriptor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
jest.mock('../meta', () => {
return {};
});

jest.mock('ui/chrome', () => {
return {};
});
jest.mock('../kibana_services');

import { getInitialLayers } from './get_initial_layers';

const layerListNotProvided = undefined;

describe('Saved object has layer list', () => {
beforeEach(() => {
require('../kibana_services').getInjectedVarFunc = () => jest.fn();
});

it('Should get initial layers from saved object', () => {
const layerListFromSavedObject = [
{
Expand Down Expand Up @@ -64,7 +65,7 @@ describe('EMS is enabled', () => {
require('../meta').getKibanaTileMap = () => {
return null;
};
require('ui/chrome').getInjected = key => {
require('../kibana_services').getInjectedVarFunc = () => key => {
switch (key) {
case 'emsTileLayerId':
return {
Expand All @@ -75,7 +76,7 @@ describe('EMS is enabled', () => {
case 'isEmsEnabled':
return true;
default:
throw new Error(`Unexpected call to chrome.getInjected with key ${key}`);
throw new Error(`Unexpected call to getInjectedVarFunc with key ${key}`);
}
};
});
Expand Down Expand Up @@ -109,12 +110,12 @@ describe('EMS is not enabled', () => {
return null;
};

require('ui/chrome').getInjected = key => {
require('../kibana_services').getInjectedVarFunc = () => key => {
switch (key) {
case 'isEmsEnabled':
return false;
default:
throw new Error(`Unexpected call to chrome.getInjected with key ${key}`);
throw new Error(`Unexpected call to getInjectedVarFunc with key ${key}`);
}
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import { InnerJoin } from './inner_join';

jest.mock('../../kibana_services', () => {});
jest.mock('ui/timefilter', () => {});
jest.mock('../vector_layer', () => {});

const rightSource = {
Expand Down
8 changes: 4 additions & 4 deletions x-pack/legacy/plugins/maps/public/layers/sources/es_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import { AbstractVectorSource } from './vector_source';
import {
autocompleteService,
getAutocompleteService,
fetchSearchSourceAndRecordWithInspector,
indexPatternService,
getIndexPatternService,
SearchSource,
getTimeFilter,
} from '../../kibana_services';
Expand Down Expand Up @@ -196,7 +196,7 @@ export class AbstractESSource extends AbstractVectorSource {
}

try {
this.indexPattern = await indexPatternService.get(this._descriptor.indexPatternId);
this.indexPattern = await getIndexPatternService().get(this._descriptor.indexPatternId);
return this.indexPattern;
} catch (error) {
throw new Error(
Expand Down Expand Up @@ -320,7 +320,7 @@ export class AbstractESSource extends AbstractVectorSource {
getValueSuggestions = async (field, query) => {
try {
const indexPattern = await this.getIndexPattern();
return await autocompleteService.getValueSuggestions({
return await getAutocompleteService().getValueSuggestions({
indexPattern,
field: indexPattern.fields.getByName(field.getRootName()),
query,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { DataRequest } from '../../util/data_request';
import { VECTOR_SHAPE_TYPES } from '../../sources/vector_feature_types';
import { FIELD_ORIGIN } from '../../../../common/constants';

jest.mock('../../../kibana_services');
jest.mock('ui/new_platform');

class MockField {
Expand Down Expand Up @@ -65,15 +66,21 @@ describe('getDescriptorWithMissingStylePropsRemoved', () => {
},
};

it('Should return no changes when next oridinal fields contain existing style property fields', () => {
beforeEach(() => {
require('../../../kibana_services').getUiSettings = () => ({
get: jest.fn(),
});
});

it('Should return no changes when next ordinal fields contain existing style property fields', () => {
const vectorStyle = new VectorStyle({ properties }, new MockSource());

const nextFields = [new MockField({ fieldName })];
const { hasChanges } = vectorStyle.getDescriptorWithMissingStylePropsRemoved(nextFields);
expect(hasChanges).toBe(false);
});

it('Should clear missing fields when next oridinal fields do not contain existing style property fields', () => {
it('Should clear missing fields when next ordinal fields do not contain existing style property fields', () => {
const vectorStyle = new VectorStyle({ properties }, new MockSource());

const nextFields = [];
Expand Down

0 comments on commit 09557bb

Please sign in to comment.