mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
71 lines
2.4 KiB
TypeScript
71 lines
2.4 KiB
TypeScript
import { variableAdapters } from '../adapters';
|
|
import { updateCustomVariableOptions } from './actions';
|
|
import { createCustomVariableAdapter } from './adapter';
|
|
import { reduxTester } from '../../../../test/core/redux/reduxTester';
|
|
import { getTemplatingRootReducer } from '../state/helpers';
|
|
import { CustomVariableModel, VariableHide, VariableOption } from '../../templating/variable';
|
|
import { toVariablePayload } from '../state/types';
|
|
import { setCurrentVariableValue } from '../state/sharedReducer';
|
|
import { initDashboardTemplating } from '../state/actions';
|
|
import { TemplatingState } from '../state/reducers';
|
|
import { createCustomOptionsFromQuery } from './reducer';
|
|
|
|
describe('custom actions', () => {
|
|
variableAdapters.setInit(() => [createCustomVariableAdapter()]);
|
|
|
|
describe('when updateCustomVariableOptions is dispatched', () => {
|
|
it('then correct actions are dispatched', async () => {
|
|
const option: VariableOption = {
|
|
value: 'A',
|
|
text: 'A',
|
|
selected: false,
|
|
};
|
|
|
|
const variable: CustomVariableModel = {
|
|
type: 'custom',
|
|
id: '0',
|
|
global: false,
|
|
current: {
|
|
value: '',
|
|
text: '',
|
|
selected: false,
|
|
},
|
|
options: [
|
|
{
|
|
text: 'A',
|
|
value: 'A',
|
|
selected: false,
|
|
},
|
|
{
|
|
text: 'B',
|
|
value: 'B',
|
|
selected: false,
|
|
},
|
|
],
|
|
query: 'A,B',
|
|
name: 'Custom',
|
|
label: '',
|
|
hide: VariableHide.dontHide,
|
|
skipUrlSync: false,
|
|
index: 0,
|
|
multi: true,
|
|
includeAll: false,
|
|
};
|
|
|
|
const tester = await reduxTester<{ templating: TemplatingState }>()
|
|
.givenRootReducer(getTemplatingRootReducer())
|
|
.whenActionIsDispatched(initDashboardTemplating([variable]))
|
|
.whenAsyncActionIsDispatched(updateCustomVariableOptions(toVariablePayload(variable)), true);
|
|
|
|
tester.thenDispatchedActionsPredicateShouldEqual(actions => {
|
|
const [createAction, setCurrentAction] = actions;
|
|
const expectedNumberOfActions = 2;
|
|
|
|
expect(createAction).toEqual(createCustomOptionsFromQuery(toVariablePayload(variable)));
|
|
expect(setCurrentAction).toEqual(setCurrentVariableValue(toVariablePayload(variable, { option })));
|
|
return actions.length === expectedNumberOfActions;
|
|
});
|
|
});
|
|
});
|
|
});
|