@@ -13,6 +13,7 @@ jest.mock('../components/vector_style_editor', () => ({
1313
1414import React from 'react' ;
1515import { shallow } from 'enzyme' ;
16+ import { Feature , Point } from 'geojson' ;
1617
1718import { DynamicColorProperty } from './dynamic_color_property' ;
1819import { COLOR_MAP_TYPE , VECTOR_STYLES } from '../../../../../common/constants' ;
@@ -21,18 +22,12 @@ import { ColorDynamicOptions } from '../../../../../common/descriptor_types';
2122import { IVectorLayer } from '../../../layers/vector_layer/vector_layer' ;
2223import { IField } from '../../../fields/field' ;
2324
24- const defaultMockStyle = new MockStyle ( ) ;
25-
26- const makeProperty = (
27- options : ColorDynamicOptions ,
28- mockStyle ?: MockStyle = defaultMockStyle ,
29- field ?: IField = mockField
30- ) => {
25+ const makeProperty = ( options : ColorDynamicOptions , style ?: MockStyle , field ?: IField ) => {
3126 return new DynamicColorProperty (
3227 options ,
3328 VECTOR_STYLES . LINE_COLOR ,
34- field ,
35- ( new MockLayer ( mockStyle ) as unknown ) as IVectorLayer ,
29+ field ? field : mockField ,
30+ ( new MockLayer ( style ? style : new MockStyle ( ) ) as unknown ) as IVectorLayer ,
3631 ( ) => {
3732 return ( value : string | number | undefined ) => value + '_format' ;
3833 }
@@ -168,14 +163,18 @@ describe('categorical', () => {
168163 } ) ;
169164} ) ;
170165
171- function makeFeatures ( foobarPropValues ) {
172- return foobarPropValues . map ( ( value ) => {
166+ function makeFeatures ( foobarPropValues : string [ ] ) {
167+ return foobarPropValues . map ( ( value : string ) => {
173168 return {
174169 type : 'Feature' ,
170+ geometry : {
171+ type : 'Point' ,
172+ coordinates : [ - 10 , 0 ] ,
173+ } as Point ,
175174 properties : {
176175 foobar : value ,
177176 } ,
178- } ;
177+ } as Feature ;
179178 } ) ;
180179}
181180
@@ -228,7 +227,7 @@ test('Should pluck the categorical style-meta from fieldmeta', async () => {
228227} ) ;
229228
230229describe ( 'supportsFieldMeta' , ( ) => {
231- test ( 'should support it when field does for ordinals ' , ( ) => {
230+ test ( 'should support fieldMeta when ordinal field supports fieldMeta ' , ( ) => {
232231 const dynamicStyleOptions = {
233232 type : COLOR_MAP_TYPE . ORDINAL ,
234233 fieldMetaOptions,
@@ -238,7 +237,7 @@ describe('supportsFieldMeta', () => {
238237 expect ( styleProp . supportsFieldMeta ( ) ) . toEqual ( true ) ;
239238 } ) ;
240239
241- test ( 'should support it when field does for categories ' , ( ) => {
240+ test ( 'should support fieldMeta when categorical field supports fieldMeta ' , ( ) => {
242241 const dynamicStyleOptions = {
243242 type : COLOR_MAP_TYPE . CATEGORICAL ,
244243 fieldMetaOptions,
@@ -248,7 +247,7 @@ describe('supportsFieldMeta', () => {
248247 expect ( styleProp . supportsFieldMeta ( ) ) . toEqual ( true ) ;
249248 } ) ;
250249
251- test ( 'should not support it when field does not' , ( ) => {
250+ test ( 'should not support fieldMeta when field does not support fieldMeta ' , ( ) => {
252251 const field = Object . create ( mockField ) ;
253252 field . supportsFieldMeta = function ( ) {
254253 return false ;
@@ -263,17 +262,26 @@ describe('supportsFieldMeta', () => {
263262 expect ( styleProp . supportsFieldMeta ( ) ) . toEqual ( false ) ;
264263 } ) ;
265264
266- test ( 'should not support it when field config not complete ' , ( ) => {
265+ test ( 'should not support fieldMeta when field is not provided ' , ( ) => {
267266 const dynamicStyleOptions = {
268267 type : COLOR_MAP_TYPE . ORDINAL ,
269268 fieldMetaOptions,
270269 } ;
271- const styleProp = makeProperty ( dynamicStyleOptions , undefined , null ) ;
270+
271+ const styleProp = new DynamicColorProperty (
272+ dynamicStyleOptions ,
273+ VECTOR_STYLES . LINE_COLOR ,
274+ null ,
275+ ( new MockLayer ( new MockStyle ( ) ) as unknown ) as IVectorLayer ,
276+ ( ) => {
277+ return ( value : string | number | undefined ) => value + '_format' ;
278+ }
279+ ) ;
272280
273281 expect ( styleProp . supportsFieldMeta ( ) ) . toEqual ( false ) ;
274282 } ) ;
275283
276- test ( 'should not support it when using custom ramp for ordinals ' , ( ) => {
284+ test ( 'should not support fieldMeta when using custom ramp for ordinal field ' , ( ) => {
277285 const dynamicStyleOptions = {
278286 type : COLOR_MAP_TYPE . ORDINAL ,
279287 useCustomColorRamp : true ,
@@ -285,7 +293,7 @@ describe('supportsFieldMeta', () => {
285293 expect ( styleProp . supportsFieldMeta ( ) ) . toEqual ( false ) ;
286294 } ) ;
287295
288- test ( 'should not support it when using custom palette for categories ' , ( ) => {
296+ test ( 'should not support fieldMeta when using custom palette for categorical field ' , ( ) => {
289297 const dynamicStyleOptions = {
290298 type : COLOR_MAP_TYPE . CATEGORICAL ,
291299 useCustomColorPalette : true ,
@@ -315,6 +323,7 @@ describe('get mapbox color expression (via internal _getMbColor)', () => {
315323 field : { } ,
316324 fieldMetaOptions,
317325 } ;
326+ // @ts -expect-error - test is verifing behavior when field is invalid.
318327 const colorProperty = makeProperty ( dynamicStyleOptions ) ;
319328 expect ( colorProperty . _getMbColor ( ) ) . toBeNull ( ) ;
320329 } ) ;
@@ -456,7 +465,9 @@ describe('get mapbox color expression (via internal _getMbColor)', () => {
456465 const dynamicStyleOptions = {
457466 type : COLOR_MAP_TYPE . CATEGORICAL ,
458467 field : { } ,
468+ fieldMetaOptions,
459469 } ;
470+ // @ts -expect-error - test is verifing behavior when field is invalid.
460471 const colorProperty = makeProperty ( dynamicStyleOptions ) ;
461472 expect ( colorProperty . _getMbColor ( ) ) . toBeNull ( ) ;
462473 } ) ;
@@ -465,6 +476,7 @@ describe('get mapbox color expression (via internal _getMbColor)', () => {
465476 test ( 'should return null when color palette is not provided' , async ( ) => {
466477 const dynamicStyleOptions = {
467478 type : COLOR_MAP_TYPE . CATEGORICAL ,
479+ fieldMetaOptions,
468480 } ;
469481 const colorProperty = makeProperty ( dynamicStyleOptions ) ;
470482 expect ( colorProperty . _getMbColor ( ) ) . toBeNull ( ) ;
@@ -474,6 +486,7 @@ describe('get mapbox color expression (via internal _getMbColor)', () => {
474486 const dynamicStyleOptions = {
475487 type : COLOR_MAP_TYPE . CATEGORICAL ,
476488 colorCategory : 'palette_0' ,
489+ fieldMetaOptions,
477490 } ;
478491 const colorProperty = makeProperty ( dynamicStyleOptions ) ;
479492 expect ( colorProperty . _getMbColor ( ) ) . toEqual ( [
0 commit comments