keyedVariablesReducer.test.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import { reducerTester } from '../../../../test/core/redux/reducerTester';
  2. import { TransactionStatus } from '../types';
  3. import {
  4. initialKeyedVariablesState,
  5. keyedVariablesReducer,
  6. KeyedVariablesState,
  7. toKeyedAction,
  8. } from './keyedVariablesReducer';
  9. import { getInitialTemplatingState } from './reducers';
  10. import { initialTransactionState, variablesCompleteTransaction, variablesInitTransaction } from './transactionReducer';
  11. describe('dashboardVariablesReducer', () => {
  12. describe('when an toUidAction is dispatched', () => {
  13. it('then state should be correct', () => {
  14. const key = 'key';
  15. reducerTester<KeyedVariablesState>()
  16. .givenReducer(keyedVariablesReducer, {
  17. ...initialKeyedVariablesState,
  18. lastKey: key,
  19. keys: {
  20. [key]: {
  21. ...getInitialTemplatingState(),
  22. transaction: {
  23. ...initialTransactionState,
  24. uid: key,
  25. },
  26. },
  27. },
  28. })
  29. .whenActionIsDispatched(toKeyedAction(key, variablesCompleteTransaction({ uid: key })))
  30. .thenStateShouldEqual({
  31. ...initialKeyedVariablesState,
  32. lastKey: key,
  33. keys: {
  34. [key]: {
  35. ...getInitialTemplatingState(),
  36. transaction: {
  37. ...initialTransactionState,
  38. uid: key,
  39. status: TransactionStatus.Completed,
  40. },
  41. },
  42. },
  43. });
  44. });
  45. });
  46. describe('when an toUidAction with variablesInitTransaction is dispatched', () => {
  47. it('then lastUid property should be correct', () => {
  48. const lastUid = 'lastUid';
  49. const key = 'key';
  50. reducerTester<KeyedVariablesState>()
  51. .givenReducer(keyedVariablesReducer, {
  52. ...initialKeyedVariablesState,
  53. lastKey: lastUid,
  54. keys: {
  55. [lastUid]: {
  56. ...getInitialTemplatingState(),
  57. transaction: {
  58. ...initialTransactionState,
  59. uid: lastUid,
  60. status: TransactionStatus.Completed,
  61. },
  62. },
  63. },
  64. })
  65. .whenActionIsDispatched(toKeyedAction(key, variablesInitTransaction({ uid: key })))
  66. .thenStateShouldEqual({
  67. ...initialKeyedVariablesState,
  68. lastKey: key,
  69. keys: {
  70. [key]: {
  71. ...getInitialTemplatingState(),
  72. transaction: {
  73. ...initialTransactionState,
  74. uid: key,
  75. status: TransactionStatus.Fetching,
  76. },
  77. },
  78. [lastUid]: {
  79. ...getInitialTemplatingState(),
  80. transaction: {
  81. ...initialTransactionState,
  82. uid: lastUid,
  83. status: TransactionStatus.Completed,
  84. },
  85. },
  86. },
  87. });
  88. });
  89. });
  90. describe('when action other than toUidAction is dispatched', () => {
  91. it('then state should not be affected', () => {
  92. const key = 'key';
  93. reducerTester<KeyedVariablesState>()
  94. .givenReducer(keyedVariablesReducer, {
  95. ...initialKeyedVariablesState,
  96. lastKey: key,
  97. keys: {
  98. [key]: {
  99. ...getInitialTemplatingState(),
  100. transaction: {
  101. ...initialTransactionState,
  102. uid: key,
  103. status: TransactionStatus.Completed,
  104. },
  105. },
  106. },
  107. })
  108. .whenActionIsDispatched(variablesInitTransaction({ uid: 'newUid' }))
  109. .thenStateShouldEqual({
  110. ...initialKeyedVariablesState,
  111. lastKey: key,
  112. keys: {
  113. [key]: {
  114. ...getInitialTemplatingState(),
  115. transaction: {
  116. ...initialTransactionState,
  117. uid: key,
  118. status: TransactionStatus.Completed,
  119. },
  120. },
  121. },
  122. });
  123. });
  124. });
  125. });