Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set uninitialized state when removeSpec action is called #739

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions src/chart_types/xy_chart/state/chart_state.specs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
* under the License.
*/

import { createStore, Store } from 'redux';
import { Store } from 'redux';

import { MockSeriesSpec } from '../../../mocks/specs';
import { MockStore } from '../../../mocks/store';
import { GlobalChartState, chartStoreReducer } from '../../../state/chart_state';
import { removeSpec, specParsed, upsertSpec } from '../../../state/actions/specs';
import { GlobalChartState } from '../../../state/chart_state';
import { getInternalIsInitializedSelector, InitStatus } from '../../../state/selectors/get_internal_is_intialized';
import { getLegendItemsSelector } from '../../../state/selectors/get_legend_items';

const data = [
Expand All @@ -32,8 +34,7 @@ const data = [
describe('XYChart - specs ordering', () => {
let store: Store<GlobalChartState>;
beforeEach(() => {
const storeReducer = chartStoreReducer('chartId');
store = createStore(storeReducer);
store = MockStore.default({ width: 100, height: 100, left: 0, top: 0 });
});

it('the legend respect the insert [A, B, C] order', () => {
Expand Down Expand Up @@ -98,4 +99,35 @@ describe('XYChart - specs ordering', () => {
names = [...legendItems.values()].map((item) => item.label);
expect(names).toEqual(['B', 'A', 'C']);
});
it('The status should switch to not initialized removing a spec', () => {
MockStore.addSpecs([
MockSeriesSpec.bar({ id: 'A', data }),
MockSeriesSpec.bar({ id: 'B', data }),
MockSeriesSpec.bar({ id: 'C', data }),
], store);
expect(getInternalIsInitializedSelector(store.getState())).toBe(InitStatus.Initialized);
// check on remove
store.dispatch(removeSpec('A'));
expect(getInternalIsInitializedSelector(store.getState())).not.toBe(InitStatus.Initialized);

// initialized again after specParsed action
store.dispatch(specParsed());
expect(getInternalIsInitializedSelector(store.getState())).toBe(InitStatus.Initialized);
});
it('The status should switch to not initialized when upserting a spec', () => {
MockStore.addSpecs([
MockSeriesSpec.bar({ id: 'A', data }),
MockSeriesSpec.bar({ id: 'B', data }),
MockSeriesSpec.bar({ id: 'C', data }),
], store);
expect(getInternalIsInitializedSelector(store.getState())).toBe(InitStatus.Initialized);

// check on upsert
store.dispatch(upsertSpec(MockSeriesSpec.bar({ id: 'D', data })));
expect(getInternalIsInitializedSelector(store.getState())).not.toBe(InitStatus.Initialized);

// initialized again after specParsed action
store.dispatch(specParsed());
expect(getInternalIsInitializedSelector(store.getState())).toBe(InitStatus.Initialized);
});
});
3 changes: 3 additions & 0 deletions src/state/chart_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ export const chartStoreReducer = (chartId: string) => {
const { [action.id]: specToRemove, ...rest } = state.specs;
return {
...state,
specsInitialized: false,
chartRendered: false,
specParsing: true,
markov00 marked this conversation as resolved.
Show resolved Hide resolved
specs: {
...rest,
},
Expand Down