actions.test.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { reduxTester } from '../../../../test/core/redux/reduxTester';
  2. import { variableAdapters } from '../adapters';
  3. import { getRootReducer, RootReducerType } from '../state/helpers';
  4. import { toKeyedAction } from '../state/keyedVariablesReducer';
  5. import { addVariable, setCurrentVariableValue } from '../state/sharedReducer';
  6. import { ConstantVariableModel, initialVariableModelState, VariableOption } from '../types';
  7. import { toKeyedVariableIdentifier, toVariablePayload } from '../utils';
  8. import { updateConstantVariableOptions } from './actions';
  9. import { createConstantVariableAdapter } from './adapter';
  10. import { createConstantOptionsFromQuery } from './reducer';
  11. describe('constant actions', () => {
  12. variableAdapters.setInit(() => [createConstantVariableAdapter()]);
  13. describe('when updateConstantVariableOptions is dispatched', () => {
  14. it('then correct actions are dispatched', async () => {
  15. const option: VariableOption = {
  16. value: 'A',
  17. text: 'A',
  18. selected: false,
  19. };
  20. const variable: ConstantVariableModel = {
  21. ...initialVariableModelState,
  22. id: '0',
  23. rootStateKey: 'key',
  24. index: 0,
  25. type: 'constant',
  26. name: 'Constant',
  27. current: {
  28. value: '',
  29. text: '',
  30. selected: false,
  31. },
  32. options: [],
  33. query: 'A',
  34. };
  35. const tester = await reduxTester<RootReducerType>()
  36. .givenRootReducer(getRootReducer())
  37. .whenActionIsDispatched(
  38. toKeyedAction('key', addVariable(toVariablePayload(variable, { global: false, index: 0, model: variable })))
  39. )
  40. .whenAsyncActionIsDispatched(updateConstantVariableOptions(toKeyedVariableIdentifier(variable)), true);
  41. tester.thenDispatchedActionsShouldEqual(
  42. toKeyedAction('key', createConstantOptionsFromQuery(toVariablePayload(variable))),
  43. toKeyedAction('key', setCurrentVariableValue(toVariablePayload(variable, { option })))
  44. );
  45. });
  46. });
  47. });