From 7b89eeb31ec1e7c5f30ded185f60dd24ae6b801c Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Thu, 3 Oct 2019 14:32:20 -0600 Subject: [PATCH] [Maps] provide isLoading and hasError feedback when legend is collapsed (#47157) --- .../__snapshots__/view.test.js.snap | 39 +++++++++++- .../widget_overlay/layer_control/index.js | 2 + .../widget_overlay/layer_control/view.js | 50 ++++++++++++---- .../widget_overlay/layer_control/view.test.js | 60 ++++++++++++++----- 4 files changed, 125 insertions(+), 26 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/__snapshots__/view.test.js.snap b/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/__snapshots__/view.test.js.snap index fb352e9c2d9e3..eb30a5c33496e 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/__snapshots__/view.test.js.snap +++ b/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/__snapshots__/view.test.js.snap @@ -76,7 +76,7 @@ exports[`LayerControl is rendered 1`] = ` `; -exports[`LayerControl props Should not render LayerTOC when isLayerTOCOpen is false 1`] = ` +exports[`LayerControl isLayerTOCOpen Should render expand button 1`] = ` `; -exports[`LayerControl props isReadOnly 1`] = ` +exports[`LayerControl isLayerTOCOpen Should render expand button with error icon when layer has error 1`] = ` + + + +`; + +exports[`LayerControl isLayerTOCOpen Should render expand button with loading icon when layer is loading 1`] = ` + + + +`; + +exports[`LayerControl isReadOnly 1`] = ` + + + ); + } + + return ( + + ); +} + +export function LayerControl({ isReadOnly, isLayerTOCOpen, showAddLayerWizard, closeLayerTOC, openLayerTOC, layerList }) { if (!isLayerTOCOpen) { + const hasErrors = layerList.some(layer => { + return layer.hasErrors(); + }); + const isLoading = layerList.some(layer => { + return layer.isLayerLoading(); + }); + return ( - + {renderExpandButton({ hasErrors, isLoading, onClick: openLayerTOC })} ); } diff --git a/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/view.test.js b/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/view.test.js index e4369140d8162..e318606db46fc 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/view.test.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/widget_overlay/layer_control/view.test.js @@ -11,7 +11,7 @@ jest.mock('./layer_toc', () => ({ })); import React from 'react'; -import { shallowWithIntl } from 'test_utils/enzyme_helpers'; +import { shallow } from 'enzyme'; import { LayerControl } from './view'; @@ -20,43 +20,75 @@ const defaultProps = { closeLayerTOC: () => {}, openLayerTOC: () => {}, isLayerTOCOpen: true, + layerList: [], }; describe('LayerControl', () => { test('is rendered', () => { - const component = shallowWithIntl( + const component = shallow( ); - expect(component) - .toMatchSnapshot(); + expect(component).toMatchSnapshot(); }); - describe('props', () => { - test('isReadOnly', () => { - const component = shallowWithIntl( + test('isReadOnly', () => { + const component = shallow( + + ); + + expect(component).toMatchSnapshot(); + }); + + describe('isLayerTOCOpen', () => { + + test('Should render expand button', () => { + const component = shallow( + + ); + + expect(component).toMatchSnapshot(); + }); + + test('Should render expand button with loading icon when layer is loading', () => { + const mockLayerThatIsLoading = { + hasErrors: () => { return false; }, + isLayerLoading: () => { return true; } + }; + const component = shallow( ); - expect(component) - .toMatchSnapshot(); + expect(component).toMatchSnapshot(); }); - test('Should not render LayerTOC when isLayerTOCOpen is false', () => { - const component = shallowWithIntl( + test('Should render expand button with error icon when layer has error', () => { + const mockLayerThatHasError = { + hasErrors: () => { return true; }, + isLayerLoading: () => { return false; } + }; + const component = shallow( ); - expect(component) - .toMatchSnapshot(); + expect(component).toMatchSnapshot(); }); }); + });