-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Maps] fix layer style editor is empty for EMS boundaries layer (#86280…
…) (#86391) * [Maps] fix layer style editor is empty for EMS boundaries layer * remove cruft * tslint
Showing
3 changed files
with
423 additions
and
1 deletion.
There are no files selected for viewing
319 changes: 319 additions & 0 deletions
319
...s/public/classes/styles/vector/components/__snapshots__/vector_style_editor.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
100 changes: 100 additions & 0 deletions
100
x-pack/plugins/maps/public/classes/styles/vector/components/vector_style_editor.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,100 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { StyleProperties, VectorStyleEditor } from './vector_style_editor'; | ||
import { getDefaultStaticProperties } from '../vector_style_defaults'; | ||
import { IVectorLayer } from '../../../layers/vector_layer/vector_layer'; | ||
import { IVectorSource } from '../../../sources/vector_source'; | ||
import { | ||
FIELD_ORIGIN, | ||
LAYER_STYLE_TYPE, | ||
VECTOR_SHAPE_TYPE, | ||
VECTOR_STYLES, | ||
} from '../../../../../common/constants'; | ||
import { AbstractField, IField } from '../../../fields/field'; | ||
import { VectorStyle } from '../vector_style'; | ||
|
||
jest.mock('../../../../kibana_services', () => { | ||
return { | ||
getIsDarkMode() { | ||
return false; | ||
}, | ||
}; | ||
}); | ||
|
||
class MockField extends AbstractField {} | ||
|
||
function createLayerMock(numFields: number, supportedShapeTypes: VECTOR_SHAPE_TYPE[]) { | ||
const fields: IField[] = []; | ||
for (let i = 0; i < numFields; i++) { | ||
fields.push(new MockField({ fieldName: `field${i}`, origin: FIELD_ORIGIN.SOURCE })); | ||
} | ||
return ({ | ||
getStyleEditorFields: async () => { | ||
return fields; | ||
}, | ||
getSource: () => { | ||
return ({ | ||
getSupportedShapeTypes: async () => { | ||
return supportedShapeTypes; | ||
}, | ||
} as unknown) as IVectorSource; | ||
}, | ||
} as unknown) as IVectorLayer; | ||
} | ||
|
||
const vectorStyleDescriptor = { | ||
type: LAYER_STYLE_TYPE.VECTOR, | ||
properties: getDefaultStaticProperties(), | ||
isTimeAware: true, | ||
}; | ||
const vectorStyle = new VectorStyle( | ||
vectorStyleDescriptor, | ||
({} as unknown) as IVectorSource, | ||
({} as unknown) as IVectorLayer | ||
); | ||
const styleProperties: StyleProperties = {}; | ||
vectorStyle.getAllStyleProperties().forEach((styleProperty) => { | ||
styleProperties[styleProperty.getStyleName()] = styleProperty; | ||
}); | ||
|
||
const defaultProps = { | ||
layer: createLayerMock(1, [VECTOR_SHAPE_TYPE.POLYGON]), | ||
isPointsOnly: true, | ||
isLinesOnly: false, | ||
onIsTimeAwareChange: (isTimeAware: boolean) => {}, | ||
handlePropertyChange: (propertyName: VECTOR_STYLES, stylePropertyDescriptor: unknown) => {}, | ||
hasBorder: true, | ||
styleProperties, | ||
isTimeAware: true, | ||
showIsTimeAware: true, | ||
}; | ||
|
||
test('should render', async () => { | ||
const component = shallow(<VectorStyleEditor {...defaultProps} />); | ||
|
||
// Ensure all promises resolve | ||
await new Promise((resolve) => process.nextTick(resolve)); | ||
// Ensure the state changes are reflected | ||
component.update(); | ||
|
||
expect(component).toMatchSnapshot(); | ||
}); | ||
|
||
test('should render with no style fields', async () => { | ||
const component = shallow( | ||
<VectorStyleEditor {...defaultProps} layer={createLayerMock(0, [VECTOR_SHAPE_TYPE.POLYGON])} /> | ||
); | ||
|
||
// Ensure all promises resolve | ||
await new Promise((resolve) => process.nextTick(resolve)); | ||
// Ensure the state changes are reflected | ||
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