grafana/public/app/features/explore/state/datasource.test.ts
Josh Hunt 3c6e0e8ef8
Chore: ESlint import order (#44959)
* Add and configure eslint-plugin-import

* Fix the lint:ts npm command

* Autofix + prettier all the files

* Manually fix remaining files

* Move jquery code in jest-setup to external file to safely reorder imports

* Resolve issue caused by circular dependencies within Prometheus

* Update .betterer.results

* Fix missing // @ts-ignore

* ignore iconBundle.ts

* Fix missing // @ts-ignore
2022-04-22 14:33:13 +01:00

51 lines
1.6 KiB
TypeScript

import { DataQuery, DataSourceApi } from '@grafana/data';
import { ExploreId, ExploreItemState } from 'app/types';
import { updateDatasourceInstanceAction, datasourceReducer } from './datasource';
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);
});
});