grafana/public/app/features/variables/custom/actions.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

67 lines
2.2 KiB
TypeScript

import { reduxTester } from '../../../../test/core/redux/reduxTester';
import { variableAdapters } from '../adapters';
import { getRootReducer, RootReducerType } from '../state/helpers';
import { toKeyedAction } from '../state/keyedVariablesReducer';
import { addVariable, setCurrentVariableValue } from '../state/sharedReducer';
import { CustomVariableModel, initialVariableModelState, VariableOption } from '../types';
import { toKeyedVariableIdentifier, toVariablePayload } from '../utils';
import { updateCustomVariableOptions } from './actions';
import { createCustomVariableAdapter } from './adapter';
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',
rootStateKey: 'key',
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<RootReducerType>()
.givenRootReducer(getRootReducer())
.whenActionIsDispatched(
toKeyedAction('key', addVariable(toVariablePayload(variable, { global: false, index: 0, model: variable })))
)
.whenAsyncActionIsDispatched(updateCustomVariableOptions(toKeyedVariableIdentifier(variable)), true);
tester.thenDispatchedActionsShouldEqual(
toKeyedAction('key', createCustomOptionsFromQuery(toVariablePayload(variable))),
toKeyedAction('key', setCurrentVariableValue(toVariablePayload(variable, { option })))
);
});
});
});