From e86d30d1d2823e3967f4e77336c865962a1e59bc Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Thu, 17 Dec 2020 16:54:27 -0700 Subject: [PATCH] [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 --- .../vector_style_editor.test.tsx.snap | 319 ++++++++++++++++++ .../components/vector_style_editor.test.tsx | 100 ++++++ .../vector/components/vector_style_editor.tsx | 5 +- 3 files changed, 423 insertions(+), 1 deletion(-) create mode 100644 x-pack/plugins/maps/public/classes/styles/vector/components/__snapshots__/vector_style_editor.test.tsx.snap create mode 100644 x-pack/plugins/maps/public/classes/styles/vector/components/vector_style_editor.test.tsx diff --git a/x-pack/plugins/maps/public/classes/styles/vector/components/__snapshots__/vector_style_editor.test.tsx.snap b/x-pack/plugins/maps/public/classes/styles/vector/components/__snapshots__/vector_style_editor.test.tsx.snap new file mode 100644 index 0000000000000..312f8e5d91ffa --- /dev/null +++ b/x-pack/plugins/maps/public/classes/styles/vector/components/__snapshots__/vector_style_editor.test.tsx.snap @@ -0,0 +1,319 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render 1`] = ` + + + + + + + + + + +`; + +exports[`should render with no style fields 1`] = ` + + + + + + + + + + +`; diff --git a/x-pack/plugins/maps/public/classes/styles/vector/components/vector_style_editor.test.tsx b/x-pack/plugins/maps/public/classes/styles/vector/components/vector_style_editor.test.tsx new file mode 100644 index 0000000000000..982ffe53d6147 --- /dev/null +++ b/x-pack/plugins/maps/public/classes/styles/vector/components/vector_style_editor.test.tsx @@ -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(); + + // 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( + + ); + + // Ensure all promises resolve + await new Promise((resolve) => process.nextTick(resolve)); + // Ensure the state changes are reflected + component.update(); + + expect(component).toMatchSnapshot(); +}); diff --git a/x-pack/plugins/maps/public/classes/styles/vector/components/vector_style_editor.tsx b/x-pack/plugins/maps/public/classes/styles/vector/components/vector_style_editor.tsx index 95e32f0e9969b..5d5ba2143677c 100644 --- a/x-pack/plugins/maps/public/classes/styles/vector/components/vector_style_editor.tsx +++ b/x-pack/plugins/maps/public/classes/styles/vector/components/vector_style_editor.tsx @@ -117,7 +117,10 @@ export class VectorStyleEditor extends Component { await this.props.layer.getStyleEditorFields() ); const styleFields = styleFieldsHelper.getStyleFields(); - if (!this._isMounted || _.isEqual(styleFields, this.state.styleFields)) { + if ( + !this._isMounted || + (_.isEqual(styleFields, this.state.styleFields) && this.state.styleFieldsHelper !== undefined) + ) { return; }