mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* Update dependency prettier to v2.5.1 * prettier fixes * chore(toolkit): bump prettier to 2.5.1 * style(eslint): bump grafana config to 2.5.2 in core and toolkit * style(mssql-datasource): fix no-inferrable-types eslint errors Co-authored-by: Renovate Bot <bot@renovateapp.com> Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com> Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
50 lines
1.6 KiB
TypeScript
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);
|
|
});
|
|
});
|