Explore: Run remaining queries when one is removed from a pane (#69643)
This commit is contained in:
@@ -16,7 +16,7 @@ import {
|
|||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
import { config } from '@grafana/runtime';
|
import { config } from '@grafana/runtime';
|
||||||
import { DataQuery, DataSourceRef } from '@grafana/schema';
|
import { DataQuery, DataSourceRef } from '@grafana/schema';
|
||||||
import { ExploreId, ExploreItemState, StoreState, ThunkDispatch } from 'app/types';
|
import { createAsyncThunk, ExploreId, ExploreItemState, StoreState, ThunkDispatch } from 'app/types';
|
||||||
|
|
||||||
import { reducerTester } from '../../../../test/core/redux/reducerTester';
|
import { reducerTester } from '../../../../test/core/redux/reducerTester';
|
||||||
import { configureStore } from '../../../store/configureStore';
|
import { configureStore } from '../../../store/configureStore';
|
||||||
@@ -246,12 +246,12 @@ describe('running queries', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('changeQueries', () => {
|
describe('changeQueries', () => {
|
||||||
|
afterEach(() => {
|
||||||
|
jest.restoreAllMocks();
|
||||||
|
});
|
||||||
// Due to how spyOn works (it removes `type`, `match` and `toString` from the spied function, on which we rely on in the reducer),
|
// Due to how spyOn works (it removes `type`, `match` and `toString` from the spied function, on which we rely on in the reducer),
|
||||||
// we are repeating the following tests twice, once to chck the resulting state and once to check that the correct actions are dispatched.
|
// we are repeating the following tests twice, once to chck the resulting state and once to check that the correct actions are dispatched.
|
||||||
describe('calls the correct actions', () => {
|
describe('calls the correct actions', () => {
|
||||||
afterEach(() => {
|
|
||||||
jest.restoreAllMocks();
|
|
||||||
});
|
|
||||||
it('should import queries when datasource is changed', async () => {
|
it('should import queries when datasource is changed', async () => {
|
||||||
jest.spyOn(actions, 'importQueries');
|
jest.spyOn(actions, 'importQueries');
|
||||||
jest.spyOn(actions, 'changeQueriesAction');
|
jest.spyOn(actions, 'changeQueriesAction');
|
||||||
@@ -375,6 +375,37 @@ describe('changeQueries', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('runs remaining queries when one query is removed', async () => {
|
||||||
|
jest.spyOn(actions, 'runQueries').mockImplementation(createAsyncThunk('@explore/runQueries', () => {}));
|
||||||
|
|
||||||
|
const originalQueries = [
|
||||||
|
{ refId: 'A', datasource: datasources[0].getRef() },
|
||||||
|
{ refId: 'B', datasource: datasources[0].getRef() },
|
||||||
|
];
|
||||||
|
|
||||||
|
const { dispatch } = configureStore({
|
||||||
|
...defaultInitialState,
|
||||||
|
explore: {
|
||||||
|
panes: {
|
||||||
|
left: {
|
||||||
|
...defaultInitialState.explore.panes.left,
|
||||||
|
datasourceInstance: datasources[0],
|
||||||
|
queries: originalQueries,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} as unknown as Partial<StoreState>);
|
||||||
|
|
||||||
|
await dispatch(
|
||||||
|
changeQueries({
|
||||||
|
queries: [originalQueries[0]],
|
||||||
|
exploreId: ExploreId.left,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(actions.runQueries).toHaveBeenCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('importing queries', () => {
|
describe('importing queries', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user