Skip to content

Commit

Permalink
more conversionts
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Aug 5, 2020
1 parent b6226ee commit 41bde06
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const EMPTY_VALUE = '';

interface Break {
color: string;
label: ReactElement<any> | string;
label: ReactElement<any> | string | number;
symbolId: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,24 @@ import { shallow } from 'enzyme';
import { DynamicColorProperty } from './dynamic_color_property';
import { COLOR_MAP_TYPE, VECTOR_STYLES } from '../../../../../common/constants';
import { mockField, MockLayer, MockStyle } from './__tests__/test_util';
import { ColorDynamicOptions } from '../../../../../common/descriptor_types';
import { IVectorLayer } from '../../../layers/vector_layer/vector_layer';
import { IField } from '../../../fields/field';

const makeProperty = (options, mockStyle, field = mockField) => {
const defaultMockStyle = new MockStyle();

const makeProperty = (
options: ColorDynamicOptions,
mockStyle?: MockStyle = defaultMockStyle,
field?: IField = mockField
) => {
return new DynamicColorProperty(
options,
VECTOR_STYLES.LINE_COLOR,
field,
new MockLayer(mockStyle),
(new MockLayer(mockStyle) as unknown) as IVectorLayer,
() => {
return (x) => x + '_format';
return (value: string | number | undefined) => value + '_format';
}
);
};
Expand All @@ -35,11 +44,14 @@ const defaultLegendParams = {
isLinesOnly: false,
};

const fieldMetaOptions = { isEnabled: true };

describe('ordinal', () => {
test('Should render ordinal legend as bands', async () => {
const colorStyle = makeProperty({
color: 'Blues',
type: undefined,
fieldMetaOptions,
});

const legendRow = colorStyle.renderLegendDetailRow(defaultLegendParams);
Expand All @@ -59,6 +71,7 @@ describe('ordinal', () => {
{
color: 'Blues',
type: undefined,
fieldMetaOptions,
},
new MockStyle({ min: 100, max: 100 })
);
Expand Down Expand Up @@ -89,6 +102,7 @@ describe('ordinal', () => {
color: '#00FF00',
},
],
fieldMetaOptions,
});

const legendRow = colorStyle.renderLegendDetailRow(defaultLegendParams);
Expand All @@ -110,6 +124,7 @@ describe('categorical', () => {
type: COLOR_MAP_TYPE.CATEGORICAL,
useCustomColorPalette: false,
colorCategory: 'palette_0',
fieldMetaOptions,
});

const legendRow = colorStyle.renderLegendDetailRow(defaultLegendParams);
Expand All @@ -130,7 +145,7 @@ describe('categorical', () => {
useCustomColorPalette: true,
customColorPalette: [
{
stop: null, //should include the default stop
stop: null, // should include the default stop
color: '#FFFF00',
},
{
Expand All @@ -142,6 +157,7 @@ describe('categorical', () => {
color: '#00FF00',
},
],
fieldMetaOptions,
});

const legendRow = colorStyle.renderLegendDetailRow(defaultLegendParams);
Expand All @@ -167,6 +183,7 @@ test('Should pluck the categorical style-meta', async () => {
const colorStyle = makeProperty({
type: COLOR_MAP_TYPE.CATEGORICAL,
colorCategory: 'palette_0',
fieldMetaOptions,
});

const features = makeFeatures(['CN', 'CN', 'US', 'CN', 'US', 'IN']);
Expand All @@ -185,6 +202,7 @@ test('Should pluck the categorical style-meta from fieldmeta', async () => {
const colorStyle = makeProperty({
type: COLOR_MAP_TYPE.CATEGORICAL,
colorCategory: 'palette_0',
fieldMetaOptions,
});

const meta = colorStyle._pluckCategoricalStyleMetaFromFieldMetaData({
Expand Down Expand Up @@ -213,6 +231,7 @@ describe('supportsFieldMeta', () => {
test('should support it when field does for ordinals', () => {
const dynamicStyleOptions = {
type: COLOR_MAP_TYPE.ORDINAL,
fieldMetaOptions,
};
const styleProp = makeProperty(dynamicStyleOptions);

Expand All @@ -222,6 +241,7 @@ describe('supportsFieldMeta', () => {
test('should support it when field does for categories', () => {
const dynamicStyleOptions = {
type: COLOR_MAP_TYPE.CATEGORICAL,
fieldMetaOptions,
};
const styleProp = makeProperty(dynamicStyleOptions);

Expand All @@ -236,6 +256,7 @@ describe('supportsFieldMeta', () => {

const dynamicStyleOptions = {
type: COLOR_MAP_TYPE.ORDINAL,
fieldMetaOptions,
};
const styleProp = makeProperty(dynamicStyleOptions, undefined, field);

Expand All @@ -245,6 +266,7 @@ describe('supportsFieldMeta', () => {
test('should not support it when field config not complete', () => {
const dynamicStyleOptions = {
type: COLOR_MAP_TYPE.ORDINAL,
fieldMetaOptions,
};
const styleProp = makeProperty(dynamicStyleOptions, undefined, null);

Expand All @@ -256,6 +278,7 @@ describe('supportsFieldMeta', () => {
type: COLOR_MAP_TYPE.ORDINAL,
useCustomColorRamp: true,
customColorRamp: [],
fieldMetaOptions,
};
const styleProp = makeProperty(dynamicStyleOptions);

Expand All @@ -267,6 +290,7 @@ describe('supportsFieldMeta', () => {
type: COLOR_MAP_TYPE.CATEGORICAL,
useCustomColorPalette: true,
customColorPalette: [],
fieldMetaOptions,
};
const styleProp = makeProperty(dynamicStyleOptions);

Expand All @@ -279,6 +303,7 @@ describe('get mapbox color expression (via internal _getMbColor)', () => {
test('should return null when field is not provided', async () => {
const dynamicStyleOptions = {
type: COLOR_MAP_TYPE.ORDINAL,
fieldMetaOptions,
};
const colorProperty = makeProperty(dynamicStyleOptions);
expect(colorProperty._getMbColor()).toBeNull();
Expand All @@ -288,6 +313,7 @@ describe('get mapbox color expression (via internal _getMbColor)', () => {
const dynamicStyleOptions = {
type: COLOR_MAP_TYPE.ORDINAL,
field: {},
fieldMetaOptions,
};
const colorProperty = makeProperty(dynamicStyleOptions);
expect(colorProperty._getMbColor()).toBeNull();
Expand All @@ -297,6 +323,7 @@ describe('get mapbox color expression (via internal _getMbColor)', () => {
test('should return null when color ramp is not provided', async () => {
const dynamicStyleOptions = {
type: COLOR_MAP_TYPE.ORDINAL,
fieldMetaOptions,
};
const colorProperty = makeProperty(dynamicStyleOptions);
expect(colorProperty._getMbColor()).toBeNull();
Expand All @@ -305,6 +332,7 @@ describe('get mapbox color expression (via internal _getMbColor)', () => {
const dynamicStyleOptions = {
type: COLOR_MAP_TYPE.ORDINAL,
color: 'Blues',
fieldMetaOptions,
};
const colorProperty = makeProperty(dynamicStyleOptions);
expect(colorProperty._getMbColor()).toEqual([
Expand Down Expand Up @@ -343,19 +371,11 @@ describe('get mapbox color expression (via internal _getMbColor)', () => {
});

describe('custom color ramp', () => {
const dynamicStyleOptions = {
type: COLOR_MAP_TYPE.ORDINAL,
useCustomColorRamp: true,
customColorRamp: [
{ stop: 10, color: '#f7faff' },
{ stop: 100, color: '#072f6b' },
],
};

test('should return null when customColorRamp is not provided', async () => {
const dynamicStyleOptions = {
type: COLOR_MAP_TYPE.ORDINAL,
useCustomColorRamp: true,
fieldMetaOptions,
};
const colorProperty = makeProperty(dynamicStyleOptions);
expect(colorProperty._getMbColor()).toBeNull();
Expand All @@ -366,12 +386,22 @@ describe('get mapbox color expression (via internal _getMbColor)', () => {
type: COLOR_MAP_TYPE.ORDINAL,
useCustomColorRamp: true,
customColorRamp: [],
fieldMetaOptions,
};
const colorProperty = makeProperty(dynamicStyleOptions);
expect(colorProperty._getMbColor()).toBeNull();
});

test('should use `feature-state` by default', async () => {
const dynamicStyleOptions = {
type: COLOR_MAP_TYPE.ORDINAL,
useCustomColorRamp: true,
customColorRamp: [
{ stop: 10, color: '#f7faff' },
{ stop: 100, color: '#072f6b' },
],
fieldMetaOptions,
};
const colorProperty = makeProperty(dynamicStyleOptions);
expect(colorProperty._getMbColor()).toEqual([
'step',
Expand All @@ -389,6 +419,15 @@ describe('get mapbox color expression (via internal _getMbColor)', () => {
field.canReadFromGeoJson = function () {
return false;
};
const dynamicStyleOptions = {
type: COLOR_MAP_TYPE.ORDINAL,
useCustomColorRamp: true,
customColorRamp: [
{ stop: 10, color: '#f7faff' },
{ stop: 100, color: '#072f6b' },
],
fieldMetaOptions,
};
const colorProperty = makeProperty(dynamicStyleOptions, undefined, field);
expect(colorProperty._getMbColor()).toEqual([
'step',
Expand All @@ -407,6 +446,7 @@ describe('get mapbox color expression (via internal _getMbColor)', () => {
test('should return null when field is not provided', async () => {
const dynamicStyleOptions = {
type: COLOR_MAP_TYPE.CATEGORICAL,
fieldMetaOptions,
};
const colorProperty = makeProperty(dynamicStyleOptions);
expect(colorProperty._getMbColor()).toBeNull();
Expand Down Expand Up @@ -453,6 +493,7 @@ describe('get mapbox color expression (via internal _getMbColor)', () => {
const dynamicStyleOptions = {
type: COLOR_MAP_TYPE.CATEGORICAL,
useCustomColorPalette: true,
fieldMetaOptions,
};
const colorProperty = makeProperty(dynamicStyleOptions);
expect(colorProperty._getMbColor()).toBeNull();
Expand All @@ -463,6 +504,7 @@ describe('get mapbox color expression (via internal _getMbColor)', () => {
type: COLOR_MAP_TYPE.CATEGORICAL,
useCustomColorPalette: true,
customColorPalette: [],
fieldMetaOptions,
};
const colorProperty = makeProperty(dynamicStyleOptions);
expect(colorProperty._getMbColor()).toBeNull();
Expand All @@ -476,6 +518,7 @@ describe('get mapbox color expression (via internal _getMbColor)', () => {
{ stop: null, color: '#f7faff' },
{ stop: 'MX', color: '#072f6b' },
],
fieldMetaOptions,
};
const colorProperty = makeProperty(dynamicStyleOptions);
expect(colorProperty._getMbColor()).toEqual([
Expand All @@ -494,6 +537,7 @@ test('isCategorical should return true when type is categorical', async () => {
const categoricalColorStyle = makeProperty({
type: COLOR_MAP_TYPE.CATEGORICAL,
colorCategory: 'palette_0',
fieldMetaOptions,
});

expect(categoricalColorStyle.isOrdinal()).toEqual(false);
Expand All @@ -504,6 +548,7 @@ test('isOrdinal should return true when type is ordinal', async () => {
const ordinalColorStyle = makeProperty({
type: undefined,
color: 'Blues',
fieldMetaOptions,
});

expect(ordinalColorStyle.isOrdinal()).toEqual(true);
Expand All @@ -514,6 +559,7 @@ test('Should read out ordinal type correctly', async () => {
const ordinalColorStyle2 = makeProperty({
type: COLOR_MAP_TYPE.ORDINAL,
colorCategory: 'palette_0',
fieldMetaOptions,
});

expect(ordinalColorStyle2.isOrdinal()).toEqual(true);
Expand Down
Loading

0 comments on commit 41bde06

Please sign in to comment.