grafana/public/app/features/explore/state/datasource.test.ts
Giordano Ricci 7b5a9cefc1
Chore: Fix intermittent time-related test failure in explore datasource instance update (#30109)
* Chore: Ensure base time is the same when calculating default time range

* Chore: Fix intermittent test failure due to timing
2021-01-07 14:39:23 +00:00

51 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: {
ExploreStartPage: 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,
latency: 0,
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);
});
});