Files
grafana/public/app/features/variables/custom/actions.test.ts
Hugo Häggmark 845bc7c444 Variables: Adds loading state and indicators (#27917)
* Refactor: Replaces initLock with state machine

* Refactor: removes some states for now

* Refactor: adds loading state in OptionsPicker

* Refactor: major refactor of load state

* Refactor: fixes updating graph in parallell

* Refactor: moves error handling to updateOptions

* Refactor: fixes the last cases

* Tests: disables variable e2e again

* Chore: removes nova config

* Refactor: small changes when going through the code again

* Refactor: fixes typings

* Refactor: changes after PR comments

* Refactor: split up onTimeRangeUpdated and fixed some error handling

* Tests: removes unused func

* Tests: fixes typing
2020-10-02 07:02:06 +02:00

67 lines
2.3 KiB
TypeScript

import { variableAdapters } from '../adapters';
import { updateCustomVariableOptions } from './actions';
import { createCustomVariableAdapter } from './adapter';
import { reduxTester } from '../../../../test/core/redux/reduxTester';
import { getRootReducer } from '../state/helpers';
import { CustomVariableModel, initialVariableModelState, VariableOption } from '../types';
import { toVariablePayload } from '../state/types';
import { addVariable, setCurrentVariableValue } from '../state/sharedReducer';
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 = {
...initialVariableModelState,
id: '0',
index: 0,
type: 'custom',
name: 'Custom',
current: {
value: '',
text: '',
selected: false,
},
options: [
{
text: 'A',
value: 'A',
selected: false,
},
{
text: 'B',
value: 'B',
selected: false,
},
],
query: 'A,B',
multi: true,
includeAll: false,
};
const tester = await reduxTester<{ templating: TemplatingState }>()
.givenRootReducer(getRootReducer())
.whenActionIsDispatched(addVariable(toVariablePayload(variable, { global: false, index: 0, model: 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;
});
});
});
});