grafana/public/app/features/explore/state/datasource.test.ts
Giordano Ricci f79173c99d
Explore: Reuse Dashboard's QueryRows component (#38942)
* WIP

* Functional without custom wrapper component, needs highlight

* Remove latency from explore

* Sync eventbus

* Some cleanup & removal of unused code

* Avoid clearing queries when running all empty queries

* Run remaining queries when removing one

* Update snapshots

* fix failing tests

* type cleanup

* Refactor QueryRows

* update snapshot

* Remove highlighter expressions

* minor fixes in queryrows

* remove unwanted change

* fix failing e2e test

* Persist refId in explore url state

* make traces test slightly more robust

* add test for query duplication
2021-09-15 16:26:23 +01:00

50 lines
1.6 KiB
TypeScript

import { updateDatasourceInstanceAction, datasourceReducer } from './datasource';
import { ExploreId, ExploreItemState } from 'app/types';
import { DataQuery, DataSourceApi } from '@grafana/data';
import { createEmptyQueryResponse } from './utils';
describe('Datasource reducer', () => {
it('should handle set updateDatasourceInstanceAction correctly', () => {
const StartPage = {};
const datasourceInstance = {
meta: {
metrics: true,
logs: true,
},
components: {
QueryEditorHelp: StartPage,
},
} as DataSourceApi;
const queries: DataQuery[] = [];
const queryKeys: string[] = [];
const initialState: ExploreItemState = ({
datasourceInstance: null,
queries,
queryKeys,
} as unknown) as ExploreItemState;
const result = datasourceReducer(
initialState,
updateDatasourceInstanceAction({ exploreId: ExploreId.left, datasourceInstance, history: [] })
);
const expectedState: Partial<ExploreItemState> = {
datasourceInstance,
queries,
queryKeys,
graphResult: null,
logsResult: null,
tableResult: null,
loading: false,
queryResponse: {
// When creating an empty query response we also create a timeRange object with the current time.
// Copying the range from the reducer here prevents intermittent failures when creating them at different times.
...createEmptyQueryResponse(),
timeRange: result.queryResponse.timeRange,
},
};
expect(result).toMatchObject(expectedState);
});
});