mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Variables: move state tree into a keyed state * Update public/app/features/variables/state/transactionReducer.ts Co-authored-by: kay delaney <45561153+kaydelaney@users.noreply.github.com> * Chore: fix prettier error * Chore: renamed slices and lastUid * Chore: rename toUidAction * Chore: rename dashboardVariableReducer * Chore: rename state prop back to templating * Chore renames variable.dashboardUid * Chore: rename toDashboardVariableIdentifier * Chore: rename getDashboardVariable * Chore: rename getDashboardVariablesState * Chore: rename getDashboardVariables * Chore: some more renames * Chore: small clean up * Chore: small rename * Chore: removes unused function * Chore: rename VariableModel.stateKey * Chore: rename KeyedVariableIdentifier.stateKey * user essentials mob! 🔱 * user essentials mob! 🔱 * user essentials mob! 🔱 * user essentials mob! 🔱 Co-authored-by: kay delaney <45561153+kaydelaney@users.noreply.github.com> Co-authored-by: kay delaney <kay@grafana.com> Co-authored-by: Alexandra Vargas <alexa1866@gmail.com> Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>
53 lines
2.0 KiB
TypeScript
53 lines
2.0 KiB
TypeScript
import { variableAdapters } from '../adapters';
|
|
import { createConstantVariableAdapter } from './adapter';
|
|
import { reduxTester } from '../../../../test/core/redux/reduxTester';
|
|
import { updateConstantVariableOptions } from './actions';
|
|
import { getRootReducer, RootReducerType } from '../state/helpers';
|
|
import { ConstantVariableModel, initialVariableModelState, VariableOption } from '../types';
|
|
import { createConstantOptionsFromQuery } from './reducer';
|
|
import { addVariable, setCurrentVariableValue } from '../state/sharedReducer';
|
|
import { toKeyedAction } from '../state/keyedVariablesReducer';
|
|
import { toKeyedVariableIdentifier, toVariablePayload } from '../utils';
|
|
|
|
describe('constant actions', () => {
|
|
variableAdapters.setInit(() => [createConstantVariableAdapter()]);
|
|
|
|
describe('when updateConstantVariableOptions is dispatched', () => {
|
|
it('then correct actions are dispatched', async () => {
|
|
const option: VariableOption = {
|
|
value: 'A',
|
|
text: 'A',
|
|
selected: false,
|
|
};
|
|
|
|
const variable: ConstantVariableModel = {
|
|
...initialVariableModelState,
|
|
id: '0',
|
|
rootStateKey: 'key',
|
|
index: 0,
|
|
type: 'constant',
|
|
name: 'Constant',
|
|
current: {
|
|
value: '',
|
|
text: '',
|
|
selected: false,
|
|
},
|
|
options: [],
|
|
query: 'A',
|
|
};
|
|
|
|
const tester = await reduxTester<RootReducerType>()
|
|
.givenRootReducer(getRootReducer())
|
|
.whenActionIsDispatched(
|
|
toKeyedAction('key', addVariable(toVariablePayload(variable, { global: false, index: 0, model: variable })))
|
|
)
|
|
.whenAsyncActionIsDispatched(updateConstantVariableOptions(toKeyedVariableIdentifier(variable)), true);
|
|
|
|
tester.thenDispatchedActionsShouldEqual(
|
|
toKeyedAction('key', createConstantOptionsFromQuery(toVariablePayload(variable))),
|
|
toKeyedAction('key', setCurrentVariableValue(toVariablePayload(variable, { option })))
|
|
);
|
|
});
|
|
});
|
|
});
|