Skip to content

Commit

Permalink
add test utils
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck committed May 13, 2020
1 parent a963cae commit 12cfcf3
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,65 +15,8 @@ import React from 'react';
import { shallow } from 'enzyme';

import { DynamicColorProperty } from './dynamic_color_property';
import { StyleMeta } from '../style_meta';
import { COLOR_MAP_TYPE, FIELD_ORIGIN, VECTOR_STYLES } from '../../../../../common/constants';

const mockField = {
async getLabel() {
return 'foobar_label';
},
getName() {
return 'foobar';
},
getRootName() {
return 'foobar';
},
getOrigin() {
return FIELD_ORIGIN.SOURCE;
},
supportsFieldMeta() {
return true;
},
};

class MockStyle {
getStyleMeta() {
return new StyleMeta({
geometryTypes: {
isPointsOnly: false,
isLinesOnly: false,
isPolygonsOnly: false,
},
fieldMeta: {
foobar: {
range: { min: 0, max: 100 },
categories: {
categories: [
{
key: 'US',
count: 10,
},
{
key: 'CN',
count: 8,
},
],
},
},
},
});
}
}

class MockLayer {
getStyle() {
return new MockStyle();
}

getDataRequest() {
return null;
}
}
import { COLOR_MAP_TYPE, VECTOR_STYLES } from '../../../../../common/constants';
import { mockField, MockLayer } from './test_util';

const makeProperty = (options, field = mockField) => {
return new DynamicColorProperty(options, VECTOR_STYLES.LINE_COLOR, field, new MockLayer(), () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,70 +14,11 @@ jest.mock('../components/vector_style_editor', () => ({
},
}));

import { COLOR_MAP_TYPE, FIELD_ORIGIN, VECTOR_STYLES } from '../../../../../common/constants';

import React from 'react';
import { VECTOR_STYLES } from '../../../../../common/constants';
// @ts-ignore
import { DynamicIconProperty } from './dynamic_icon_property';

import React from 'react';
import { StyleMeta } from '../style_meta';

const mockField = {
async getLabel() {
return 'foobar_label';
},
getName() {
return 'foobar';
},
getRootName() {
return 'foobar';
},
getOrigin() {
return FIELD_ORIGIN.SOURCE;
},
supportsFieldMeta() {
return true;
},
};

class MockStyle {
getStyleMeta() {
return new StyleMeta({
geometryTypes: {
isPointsOnly: false,
isLinesOnly: false,
isPolygonsOnly: false,
},
fieldMeta: {
foobar: {
range: { min: 0, max: 100 },
categories: {
categories: [
{
key: 'US',
count: 10,
},
{
key: 'CN',
count: 8,
},
],
},
},
},
});
}
}

class MockLayer {
getStyle() {
return new MockStyle();
}

getDataRequest() {
return null;
}
}
import { mockField, MockLayer } from './test_util';

const makeProperty = (options, field = mockField) => {
return new DynamicIconProperty(options, VECTOR_STYLES.ICON, field, new MockLayer(), () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

// eslint-disable-next-line max-classes-per-file
import { FIELD_ORIGIN } from '../../../../../common/constants';
import { StyleMeta } from '../style_meta';

export const mockField = {
async getLabel() {
return 'foobar_label';
},
getName() {
return 'foobar';
},
getRootName() {
return 'foobar';
},
getOrigin() {
return FIELD_ORIGIN.SOURCE;
},
supportsFieldMeta() {
return true;
},
};

class MockStyle {
getStyleMeta() {
return new StyleMeta({
geometryTypes: {
isPointsOnly: false,
isLinesOnly: false,
isPolygonsOnly: false,
},
fieldMeta: {
foobar: {
range: { min: 0, max: 100 },
categories: {
categories: [
{
key: 'US',
count: 10,
},
{
key: 'CN',
count: 8,
},
],
},
},
},
});
}
}

export class MockLayer {
getStyle() {
return new MockStyle();
}

getDataRequest() {
return null;
}
}

0 comments on commit 12cfcf3

Please sign in to comment.