Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enhancement] pass dataset to renderLayer function (#1341)
* pass dataset to renderLayer function * add layer configurator tests Signed-off-by: Shan He <heshan0131@gmail.com>
- Loading branch information
1 parent
524fc59
commit 06ea669
Showing
3 changed files
with
138 additions
and
2 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
131 changes: 131 additions & 0 deletions
131
test/browser/components/side-panel/layer-configurator-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,131 @@ | ||
// Copyright (c) 2020 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
/* eslint-disable max-statements */ | ||
|
||
import React from 'react'; | ||
import test from 'tape'; | ||
import sinon from 'sinon'; | ||
|
||
import {LayerConfiguratorFactory} from 'components'; | ||
import {StateWFiles, testCsvDataId} from 'test/helpers/mock-state'; | ||
import {appInjector} from 'components/container'; | ||
import {IntlWrapper, mountWithTheme} from 'test/helpers/component-utils'; | ||
|
||
// components | ||
const LayerConfigurator = appInjector.get(LayerConfiguratorFactory); | ||
|
||
// components | ||
const openModal = () => {}; | ||
const updateLayerColorUI = () => {}; | ||
const updateLayerConfig = () => {}; | ||
const updateLayerVisualChannelConfig = () => {}; | ||
const updateLayerType = () => {}; | ||
const updateLayerTextLabel = () => {}; | ||
const updateLayerVisConfig = () => {}; | ||
|
||
const defaultProps = { | ||
layer: StateWFiles.visState.layers[0], | ||
datasets: StateWFiles.visState.datasets, | ||
layerTypeOptions: [], | ||
openModal, | ||
updateLayerColorUI, | ||
updateLayerConfig, | ||
updateLayerVisualChannelConfig, | ||
updateLayerType, | ||
updateLayerTextLabel, | ||
updateLayerVisConfig | ||
}; | ||
|
||
test('Components -> LayerConfigurator.mount -> defaut prop', t => { | ||
// mount | ||
let wrapper; | ||
t.doesNotThrow(() => { | ||
wrapper = mountWithTheme( | ||
<IntlWrapper> | ||
<LayerConfigurator {...defaultProps} /> | ||
</IntlWrapper> | ||
); | ||
}, 'LayerConfigurator should not fail without props'); | ||
|
||
const component = wrapper.find(LayerConfigurator).instance(); | ||
|
||
const spy = sinon.spy(component, '_renderScatterplotLayerConfig'); | ||
component.forceUpdate(); | ||
wrapper.update(); | ||
t.ok(spy.calledOnce, 'should call _renderScatterplotLayerConfig'); | ||
|
||
const expectedDataset = StateWFiles.visState.datasets[testCsvDataId]; | ||
const expectedLayer = StateWFiles.visState.layers[0]; | ||
|
||
const expectedArgs = { | ||
layer: expectedLayer, | ||
dataset: expectedDataset, | ||
visConfiguratorProps: { | ||
layer: expectedLayer, | ||
fields: expectedDataset.fields, | ||
onChange: updateLayerVisConfig, | ||
setColorUI: updateLayerColorUI | ||
}, | ||
layerConfiguratorProps: { | ||
layer: expectedLayer, | ||
fields: expectedDataset.fields, | ||
onChange: updateLayerConfig, | ||
setColorUI: updateLayerColorUI | ||
}, | ||
layerChannelConfigProps: { | ||
layer: expectedLayer, | ||
fields: expectedDataset.fields, | ||
onChange: updateLayerVisualChannelConfig | ||
} | ||
}; | ||
|
||
const args = spy.args[0][0]; | ||
|
||
t.deepEqual( | ||
Object.keys(args).sort(), | ||
Object.keys(expectedArgs).sort(), | ||
'render layer method should receive 5 arguments' | ||
); | ||
|
||
t.equal(args.layer, expectedArgs.layer, 'render layer method should receive corrent layer arg'); | ||
t.equal( | ||
args.dataset, | ||
expectedArgs.dataset, | ||
'render layer method should receive corrent dataset arg' | ||
); | ||
t.deepEqual( | ||
args.visConfiguratorProps, | ||
expectedArgs.visConfiguratorProps, | ||
'render layer method should receive corrent visConfiguratorProps arg' | ||
); | ||
t.deepEqual( | ||
args.layerConfiguratorProps, | ||
expectedArgs.layerConfiguratorProps, | ||
'render layer method should receive corrent layerConfiguratorProps arg' | ||
); | ||
t.deepEqual( | ||
args.layerChannelConfigProps, | ||
expectedArgs.layerChannelConfigProps, | ||
'render layer method should receive corrent layerChannelConfigProps arg' | ||
); | ||
|
||
t.end(); | ||
}); |