Skip to content

Commit

Permalink
More test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
1chandu committed Dec 18, 2019
1 parent 5af9a0c commit e7b26ee
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 4 deletions.
1 change: 0 additions & 1 deletion test/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ test('deck.gl', t => {
require('./modules/aggregation-layers/utils/gpu-grid-aggregator.spec');
require('./modules/aggregation-layers/gpu-cpu-aggregator.spec');
require('./modules/aggregation-layers/gpu-grid-layer/gpu-grid-layer.spec');
// require('./modules/aggregation-layers/grid-aggregation-layer.spec');
require('./modules/aggregation-layers/heatmap-layer/heatmap-layer.spec');
require('./modules/core/lib/pick-layers.spec');

Expand Down
27 changes: 25 additions & 2 deletions test/modules/aggregation-layers/aggregation-layer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ const DIMENSIONS = {
class TestAggregationLayer extends AggregationLayer {
initializeState() {
super.initializeState(DIMENSIONS);
const attributeManager = this.getAttributeManager();
attributeManager.add({
aOne: {
size: 1,
accessor: 'getAOne'
},
aTwo: {
size: 1,
accessor: 'getATwo'
}
});
}

renderLayers() {
Expand All @@ -63,7 +74,9 @@ class TestAggregationLayer extends AggregationLayer {
aggregationDirty: this.isAggregationDirty(opts, {
dimension: this.state.dimensions.data,
compareAll: true
})
}),
anyAttributeChanged: this.isAttributeChanged(),
aOneAttributeChanged: this.isAttributeChanged('aOne')
});
}
updateShaders(shaderOptions) {}
Expand All @@ -88,17 +101,25 @@ test('AggregationLayer#updateState', t => {
{
props: {
data: [0, 1],
getAOne: x => 1,
getATwo: x => 2,
cellSize: 400,
prop1: 10
},
onAfterUpdate({layer}) {
t.ok(layer.getAttributeManager(), 'should create AttributeManager');
t.ok(layer.state.aggregationDirty, 'Aggregation should be dirty on the first update');
t.ok(layer.state.anyAttributeChanged, 'All attributes should change on first update');
t.ok(layer.state.aOneAttributeChanged, 'Attribute should change on first update');
}
},
{
updateProps: {
prop1: 20
prop1: 20,
// change attribute two
updateTriggers: {
getATwo: 1
}
},
spies: ['updateShaders', 'updateAttributes'],
onAfterUpdate({spies, layer}) {
Expand All @@ -108,6 +129,8 @@ test('AggregationLayer#updateState', t => {
'should not call updateShaders when extensions not changed'
);
t.notOk(layer.state.aggregationDirty, 'Aggregation should not be dirty');
t.ok(layer.state.anyAttributeChanged, 'Should change one attribute');
t.notOk(layer.state.aOneAttributeChanged, 'Should not update attribute');
}
},
{
Expand Down
31 changes: 30 additions & 1 deletion test/modules/aggregation-layers/grid-aggregation-layer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ function getTestCases(t, updateProps) {
];
}

test('GridAggregationLayer#CPUvsGPUAggregation', t => {
test('GridAggregationLayer#state updates', t => {
let testCases = [
{
props: {
Expand Down Expand Up @@ -339,6 +339,35 @@ test('GridAggregationLayer#CPUvsGPUAggregation', t => {
}
}
},
{
updateProps: {
updateTriggers: {
all: 1
}
},
spies: ['_updateAggregation', '_updateWeightBins', '_uploadAggregationResults'],
onAfterUpdate({layer, spies}) {
// Should re do the aggregation.
t.ok(spies._updateAggregation.called, 'should call _updateAggregation');
t.ok(spies._updateWeightBins.called, 'should call _updateWeightBins');
t.ok(spies._uploadAggregationResults.called, 'should call _uploadAggregationResults');
t.notOk(layer.state.gpuAggregation, 'gpuAggregation should be set to false');
}
},
{
updateProps: {
// only chnage weight accessor
updateTriggers: {
getWeight: 1
}
},
spies: ['_updateAggregation', '_updateWeightBins'],
onAfterUpdate({layer, spies}) {
t.notOk(spies._updateAggregation.called, 'should not call _updateAggregation');
t.ok(spies._updateWeightBins.called, 'should call _updateWeightBins');
t.notOk(layer.state.gpuAggregation, 'gpuAggregation should be set to false');
}
},
{
updateProps: {
// while in CPU aggregation change weight prop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import test from 'tape-catch';
import {getValueFunc} from '@deck.gl/aggregation-layers/utils/aggregation-operation-utils';

const data = [10, 'a', null, 14, -3, 16, 0.2];
const nonFiniteData = ['a', null, {a: 'a'}];
const accessor = x => x;
const TEST_CASES = [
{
Expand Down Expand Up @@ -61,6 +62,10 @@ test('GridAggregationOperationUtils#getValueFunc', t => {
TEST_CASES.forEach(tc => {
const func = getValueFunc(tc.op, accessor);
t.ok(func(data) === tc.expected, `${tc.name} should return expected result`);
t.ok(
func(nonFiniteData) === null,
`${tc.name} should return expected result on non-finite data`
);
});
t.end();
});

0 comments on commit e7b26ee

Please sign in to comment.