actions.test.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 { CustomVariableModel, initialVariableModelState, VariableOption } from '../types';
  7. import { toKeyedVariableIdentifier, toVariablePayload } from '../utils';
  8. import { updateCustomVariableOptions } from './actions';
  9. import { createCustomVariableAdapter } from './adapter';
  10. import { createCustomOptionsFromQuery } from './reducer';
  11. describe('custom actions', () => {
  12. variableAdapters.setInit(() => [createCustomVariableAdapter()]);
  13. describe('when updateCustomVariableOptions 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: CustomVariableModel = {
  21. ...initialVariableModelState,
  22. id: '0',
  23. rootStateKey: 'key',
  24. index: 0,
  25. type: 'custom',
  26. name: 'Custom',
  27. current: {
  28. value: '',
  29. text: '',
  30. selected: false,
  31. },
  32. options: [
  33. {
  34. text: 'A',
  35. value: 'A',
  36. selected: false,
  37. },
  38. {
  39. text: 'B',
  40. value: 'B',
  41. selected: false,
  42. },
  43. ],
  44. query: 'A,B',
  45. multi: true,
  46. includeAll: false,
  47. };
  48. const tester = await reduxTester<RootReducerType>()
  49. .givenRootReducer(getRootReducer())
  50. .whenActionIsDispatched(
  51. toKeyedAction('key', addVariable(toVariablePayload(variable, { global: false, index: 0, model: variable })))
  52. )
  53. .whenAsyncActionIsDispatched(updateCustomVariableOptions(toKeyedVariableIdentifier(variable)), true);
  54. tester.thenDispatchedActionsShouldEqual(
  55. toKeyedAction('key', createCustomOptionsFromQuery(toVariablePayload(variable))),
  56. toKeyedAction('key', setCurrentVariableValue(toVariablePayload(variable, { option })))
  57. );
  58. });
  59. });
  60. });