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] fix app crash where layer details panel calls getId on undefin…
…ed (elastic#31816) * [Maps] fix app crash where details panel calls getId on undefined * add jest test ensuring no errors when selectedLayer is undefined
- Loading branch information
Showing
5 changed files
with
232 additions
and
9 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
130 changes: 130 additions & 0 deletions
130
x-pack/plugins/maps/public/components/layer_panel/__snapshots__/view.test.js.snap
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,130 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`LayerPanel is rendered 1`] = ` | ||
<EuiFlexGroup | ||
alignItems="stretch" | ||
component="div" | ||
direction="column" | ||
gutterSize="none" | ||
justifyContent="flexStart" | ||
responsive={true} | ||
wrap={false} | ||
> | ||
<EuiFlyoutHeader | ||
className="mapLayerPanel__header" | ||
hasBorder={true} | ||
> | ||
<EuiFlexGroup | ||
alignItems="center" | ||
component="div" | ||
direction="row" | ||
gutterSize="s" | ||
justifyContent="flexStart" | ||
responsive={false} | ||
wrap={false} | ||
> | ||
<EuiFlexItem | ||
component="div" | ||
grow={false} | ||
> | ||
<EuiButtonIcon | ||
aria-label="Fit to bounds" | ||
color="primary" | ||
iconSize="m" | ||
iconType="vector" | ||
onClick={[Function]} | ||
type="button" | ||
> | ||
Fit | ||
</EuiButtonIcon> | ||
</EuiFlexItem> | ||
<EuiFlexItem | ||
component="div" | ||
grow={true} | ||
> | ||
<EuiTitle | ||
size="s" | ||
textTransform="none" | ||
> | ||
<h2> | ||
layer 1 | ||
</h2> | ||
</EuiTitle> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
<EuiSpacer | ||
size="xs" | ||
/> | ||
<div | ||
className="mapLayerPanel__sourceDetails" | ||
> | ||
<EuiAccordion | ||
buttonContent="Source details" | ||
id="accordion1" | ||
initialIsOpen={false} | ||
paddingSize="none" | ||
> | ||
<EuiText | ||
color="subdued" | ||
grow={true} | ||
size="s" | ||
> | ||
<EuiSpacer | ||
size="xs" | ||
/> | ||
<p | ||
className="mapLayerPanel__sourceDetail" | ||
key="source prop1" | ||
> | ||
<strong> | ||
source prop1 | ||
</strong> | ||
<span> | ||
you get one chance to set me | ||
</span> | ||
</p> | ||
</EuiText> | ||
</EuiAccordion> | ||
</div> | ||
</EuiFlyoutHeader> | ||
<EuiFlyoutBody | ||
className="mapLayerPanel__body" | ||
> | ||
<SettingsPanel /> | ||
<EuiSpacer | ||
size="s" | ||
/> | ||
<EuiPanel | ||
grow={true} | ||
hasShadow={false} | ||
paddingSize="m" | ||
> | ||
<JoinEditor /> | ||
</EuiPanel> | ||
<EuiSpacer | ||
size="s" | ||
/> | ||
<StyleTabs | ||
layer={ | ||
Object { | ||
"getDisplayName": [Function], | ||
"getId": [Function], | ||
"getImmutableSourceProperties": [Function], | ||
"getLayerTypeIconName": [Function], | ||
"isJoinable": [Function], | ||
} | ||
} | ||
/> | ||
</EuiFlyoutBody> | ||
<EuiFlyoutFooter | ||
className="mapLayerPanel__footer" | ||
> | ||
<FlyoutFooter | ||
hasStateChanged={[Function]} | ||
/> | ||
</EuiFlyoutFooter> | ||
</EuiFlexGroup> | ||
`; | ||
|
||
exports[`LayerPanel should render empty panel when selectedLayer is null 1`] = `""`; |
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
87 changes: 87 additions & 0 deletions
87
x-pack/plugins/maps/public/components/layer_panel/view.test.js
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,87 @@ | ||
/* | ||
* 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('./style_tabs', () => ({ | ||
StyleTabs: () => { | ||
return (<div>mockStyleTabs</div>); | ||
} | ||
})); | ||
|
||
jest.mock('./join_editor', () => ({ | ||
JoinEditor: () => { | ||
return (<div>mockJoinEditor</div>); | ||
} | ||
})); | ||
|
||
jest.mock('./flyout_footer', () => ({ | ||
FlyoutFooter: () => { | ||
return (<div>mockFlyoutFooter</div>); | ||
} | ||
})); | ||
|
||
jest.mock('./settings_panel', () => ({ | ||
SettingsPanel: () => { | ||
return (<div>mockSettingsPanel</div>); | ||
} | ||
})); | ||
|
||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import { LayerPanel } from './view'; | ||
|
||
const mockLayer = { | ||
getId: () => { return '1'; }, | ||
getDisplayName: () => { return 'layer 1'; }, | ||
getImmutableSourceProperties: () => { | ||
return [ | ||
{ label: 'source prop1', value: 'you get one chance to set me' } | ||
]; | ||
}, | ||
isJoinable: () => { return true; }, | ||
getLayerTypeIconName: () => { return 'vector'; } | ||
}; | ||
|
||
const defaultProps = { | ||
selectedLayer: mockLayer, | ||
hasStateChanged: () => {}, | ||
fitToBounds: () => {}, | ||
}; | ||
|
||
describe('LayerPanel', () => { | ||
test('is rendered', async () => { | ||
const component = shallow( | ||
<LayerPanel | ||
{...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 empty panel when selectedLayer is null', async () => { | ||
const component = shallow( | ||
<LayerPanel | ||
{...defaultProps} | ||
selectedLayer={undefined} | ||
/> | ||
); | ||
|
||
// Ensure all promises resolve | ||
await new Promise(resolve => process.nextTick(resolve)); | ||
// Ensure the state changes are reflected | ||
component.update(); | ||
|
||
expect(component) | ||
.toMatchSnapshot(); | ||
}); | ||
}); |