Skip to content

Commit

Permalink
[Lens] Resetting a layer generates new suggestions (#60674)
Browse files Browse the repository at this point in the history
* [Lens] Resetting a layer generates new suggestions

* Include preview in tests
  • Loading branch information
Wylie Conlon authored Mar 20, 2020
1 parent 5d93a08 commit fc24feb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,21 @@ function createTestArgs(initialLayerIds: string[]) {
appendLayer: (layerIds: unknown, layerId: string) => [...(layerIds as string[]), layerId],
};

const datasourceStates = {
ds1: {
isLoading: false,
state: initialLayerIds.slice(0, 1),
},
ds2: {
isLoading: false,
state: initialLayerIds.slice(1),
},
};

return {
state: {
activeDatasourceId: 'ds1',
datasourceStates: {
ds1: {
isLoading: false,
state: initialLayerIds.slice(0, 1),
},
ds2: {
isLoading: false,
state: initialLayerIds.slice(1),
},
},
datasourceStates,
title: 'foo',
visualization: {
activeId: 'vis1',
Expand All @@ -53,6 +55,13 @@ function createTestArgs(initialLayerIds: string[]) {
ds2: testDatasource('ds2'),
},
trackUiEvent,
stagedPreview: {
visualization: {
activeId: 'vis1',
state: initialLayerIds,
},
datasourceStates,
},
};
}

Expand All @@ -70,6 +79,7 @@ describe('removeLayer', () => {
expect(newState.visualization.state).toEqual(['vis_clear_layer1']);
expect(newState.datasourceStates.ds1.state).toEqual(['ds1_clear_layer1']);
expect(newState.datasourceStates.ds2.state).toEqual([]);
expect(newState.stagedPreview).not.toBeDefined();
expect(trackUiEvent).toHaveBeenCalledWith('layer_cleared');
});

Expand All @@ -89,6 +99,7 @@ describe('removeLayer', () => {
expect(newState.visualization.state).toEqual(['layer2']);
expect(newState.datasourceStates.ds1.state).toEqual([]);
expect(newState.datasourceStates.ds2.state).toEqual(['layer2']);
expect(newState.stagedPreview).not.toBeDefined();
expect(trackUiEvent).toHaveBeenCalledWith('layer_removed');
});
});
Expand All @@ -110,6 +121,7 @@ describe('appendLayer', () => {
expect(newState.visualization.state).toEqual(['layer1', 'layer2', 'foo']);
expect(newState.datasourceStates.ds1.state).toEqual(['layer1', 'foo']);
expect(newState.datasourceStates.ds2.state).toEqual(['layer2']);
expect(newState.stagedPreview).not.toBeDefined();
expect(trackUiEvent).toHaveBeenCalledWith('layer_added');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export function removeLayer(opts: RemoveLayerOptions): EditorFrameState {
? activeVisualization.clearLayer(state.visualization.state, layerId)
: activeVisualization.removeLayer(state.visualization.state, layerId),
},
stagedPreview: undefined,
};
}

Expand Down Expand Up @@ -84,5 +85,6 @@ export function appendLayer({
...state.visualization,
state: activeVisualization.appendLayer(state.visualization.state, layerId),
},
stagedPreview: undefined,
};
}

0 comments on commit fc24feb

Please sign in to comment.