-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This is a manual backport.
- Loading branch information
1 parent
4a773f1
commit 519b374
Showing
3 changed files
with
141 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
x-pack/plugins/maps/public/layers/styles/vector/properties/dynamic_size_property.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
jest.mock('ui/new_platform'); | ||
jest.mock('../components/vector_style_editor', () => ({ | ||
VectorStyleEditor: () => { | ||
return <div>mockVectorStyleEditor</div>; | ||
}, | ||
})); | ||
|
||
import React from 'react'; | ||
|
||
// @ts-ignore | ||
import { DynamicSizeProperty } from './dynamic_size_property'; | ||
import { VECTOR_STYLES } from '../../../../../common/constants'; | ||
import { IField } from '../../../fields/field'; | ||
import { MockMbMap } from './__tests__/test_util'; | ||
|
||
import { mockField, MockLayer, MockStyle } from './__tests__/test_util'; | ||
|
||
const makeProperty = (options: object, mockStyle: MockStyle, field: IField = mockField) => { | ||
return new DynamicSizeProperty( | ||
options, | ||
VECTOR_STYLES.ICON_SIZE, | ||
field, | ||
new MockLayer(mockStyle), | ||
() => { | ||
return (x: string) => x + '_format'; | ||
} | ||
); | ||
}; | ||
|
||
describe('syncSize', () => { | ||
test('Should sync with circle-radius prop', async () => { | ||
const sizeProp = makeProperty({ minSize: 8, maxSize: 32 }, new MockStyle({ min: 0, max: 100 })); | ||
const mockMbMap = new MockMbMap(); | ||
|
||
sizeProp.syncCircleRadiusWithMb('foobar', mockMbMap); | ||
|
||
expect(mockMbMap.getPaintPropertyCalls()).toEqual([ | ||
[ | ||
'foobar', | ||
'circle-radius', | ||
[ | ||
'interpolate', | ||
['linear'], | ||
[ | ||
'coalesce', | ||
[ | ||
'case', | ||
['==', ['feature-state', 'foobar'], null], | ||
-1, | ||
['max', ['min', ['to-number', ['feature-state', 'foobar']], 100], 0], | ||
], | ||
0, | ||
], | ||
0, | ||
8, | ||
100, | ||
32, | ||
], | ||
], | ||
]); | ||
}); | ||
|
||
test('Should truncate interpolate expression to max when no delta', async () => { | ||
const sizeProp = makeProperty( | ||
{ minSize: 8, maxSize: 32 }, | ||
new MockStyle({ min: 100, max: 100 }) | ||
); | ||
const mockMbMap = new MockMbMap(); | ||
|
||
sizeProp.syncCircleRadiusWithMb('foobar', mockMbMap); | ||
|
||
expect(mockMbMap.getPaintPropertyCalls()).toEqual([ | ||
[ | ||
'foobar', | ||
'circle-radius', | ||
[ | ||
'interpolate', | ||
['linear'], | ||
[ | ||
'coalesce', | ||
[ | ||
'case', | ||
['==', ['feature-state', 'foobar'], null], | ||
99, | ||
['max', ['min', ['to-number', ['feature-state', 'foobar']], 100], 100], | ||
], | ||
0, | ||
], | ||
100, | ||
32, | ||
], | ||
], | ||
]); | ||
}); | ||
}); |