forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Maps] Get number of categories from palette (elastic#66454)
- Loading branch information
1 parent
36ab9d3
commit 0157d7e
Showing
8 changed files
with
225 additions
and
60 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
78 changes: 78 additions & 0 deletions
78
...public/classes/styles/vector/properties/__snapshots__/dynamic_icon_property.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
x-pack/plugins/maps/public/classes/styles/vector/properties/__tests__/test_util.ts
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,75 @@ | ||
/* | ||
* 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'; | ||
import { | ||
CategoryFieldMeta, | ||
GeometryTypes, | ||
RangeFieldMeta, | ||
StyleMetaDescriptor, | ||
} from '../../../../../../common/descriptor_types'; | ||
import { AbstractField, IField } from '../../../../fields/field'; | ||
|
||
class MockField extends AbstractField { | ||
async getLabel(): Promise<string> { | ||
return this.getName() + '_label'; | ||
} | ||
supportsFieldMeta(): boolean { | ||
return true; | ||
} | ||
} | ||
|
||
export const mockField: IField = new MockField({ | ||
fieldName: 'foobar', | ||
origin: FIELD_ORIGIN.SOURCE, | ||
}); | ||
|
||
class MockStyle { | ||
getStyleMeta(): StyleMeta { | ||
const geomTypes: GeometryTypes = { | ||
isPointsOnly: false, | ||
isLinesOnly: false, | ||
isPolygonsOnly: false, | ||
}; | ||
const rangeFieldMeta: RangeFieldMeta = { min: 0, max: 100, delta: 100 }; | ||
const catFieldMeta: CategoryFieldMeta = { | ||
categories: [ | ||
{ | ||
key: 'US', | ||
count: 10, | ||
}, | ||
{ | ||
key: 'CN', | ||
count: 8, | ||
}, | ||
], | ||
}; | ||
|
||
const styleMetaDescriptor: StyleMetaDescriptor = { | ||
geometryTypes: geomTypes, | ||
fieldMeta: { | ||
foobar: { | ||
range: rangeFieldMeta, | ||
categories: catFieldMeta, | ||
}, | ||
}, | ||
}; | ||
|
||
return new StyleMeta(styleMetaDescriptor); | ||
} | ||
} | ||
|
||
export class MockLayer { | ||
getStyle() { | ||
return new MockStyle(); | ||
} | ||
|
||
getDataRequest() { | ||
return null; | ||
} | ||
} |
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
61 changes: 61 additions & 0 deletions
61
x-pack/plugins/maps/public/classes/styles/vector/properties/dynamic_icon_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,61 @@ | ||
/* | ||
* 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 { shallow } from 'enzyme'; | ||
|
||
jest.mock('ui/new_platform'); | ||
jest.mock('../components/vector_style_editor', () => ({ | ||
VectorStyleEditor: () => { | ||
return <div>mockVectorStyleEditor</div>; | ||
}, | ||
})); | ||
|
||
import React from 'react'; | ||
import { VECTOR_STYLES } from '../../../../../common/constants'; | ||
// @ts-ignore | ||
import { DynamicIconProperty } from './dynamic_icon_property'; | ||
import { mockField, MockLayer } from './__tests__/test_util'; | ||
import { IconDynamicOptions } from '../../../../../common/descriptor_types'; | ||
import { IField } from '../../../fields/field'; | ||
|
||
const makeProperty = (options: Partial<IconDynamicOptions>, field: IField = mockField) => { | ||
return new DynamicIconProperty( | ||
{ ...options, fieldMetaOptions: { isEnabled: false } }, | ||
VECTOR_STYLES.ICON, | ||
field, | ||
new MockLayer(), | ||
() => { | ||
return (x: string) => x + '_format'; | ||
} | ||
); | ||
}; | ||
|
||
describe('DynamicIconProperty', () => { | ||
it('should derive category number from palettes', async () => { | ||
const filled = makeProperty({ | ||
iconPaletteId: 'filledShapes', | ||
}); | ||
expect(filled.getNumberOfCategories()).toEqual(6); | ||
const hollow = makeProperty({ | ||
iconPaletteId: 'hollowShapes', | ||
}); | ||
expect(hollow.getNumberOfCategories()).toEqual(5); | ||
}); | ||
}); | ||
|
||
test('Should render categorical legend with breaks', async () => { | ||
const iconStyle = makeProperty({ | ||
iconPaletteId: 'filledShapes', | ||
}); | ||
|
||
const legendRow = iconStyle.renderLegendDetailRow({ isPointsOnly: true, isLinesOnly: false }); | ||
const component = shallow(legendRow); | ||
await new Promise(resolve => process.nextTick(resolve)); | ||
component.update(); | ||
|
||
expect(component).toMatchSnapshot(); | ||
}); |
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