@wise/dynamic-flow-client 5.8.1 → 5.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (420) hide show
  1. package/build/DynamicFlowCore.js +5 -0
  2. package/build/common/errorBoundary/ErrorBoundary.js +26 -0
  3. package/build/common/errorBoundary/ErrorBoundary.test.js +29 -0
  4. package/build/common/errorBoundary/ErrorBoundaryAlert.js +11 -0
  5. package/build/common/makeHttpClient/api-utils.js +3 -0
  6. package/build/common/makeHttpClient/index.js +1 -0
  7. package/build/common/makeHttpClient/makeHttpClient.js +10 -0
  8. package/build/common/makeHttpClient/makeHttpClient.test.js +186 -0
  9. package/build/common/messages/external-confirmation.messages.js +23 -0
  10. package/build/common/messages/file-upload.messages.js +13 -0
  11. package/build/common/messages/generic-error.messages.js +18 -0
  12. package/build/common/messages/help.messages.js +8 -0
  13. package/build/common/messages/multi-file-upload.messages.js +18 -0
  14. package/build/common/messages/multi-select.messages.js +8 -0
  15. package/build/common/messages/paragraph.messages.js +13 -0
  16. package/build/common/messages/repeatable.messages.js +23 -0
  17. package/build/common/messages/search.messages.js +8 -0
  18. package/build/common/messages/validation.array.messages.js +13 -0
  19. package/build/common/messages/validation.messages.js +53 -0
  20. package/build/controller/FlowController.js +368 -0
  21. package/build/controller/executePoll.js +49 -0
  22. package/build/controller/executeRefresh.js +39 -0
  23. package/build/controller/executeRequest.js +77 -0
  24. package/build/controller/executeSubmission.js +69 -0
  25. package/build/controller/getErrorMessage.js +7 -0
  26. package/build/controller/getRequestAbortController.js +13 -0
  27. package/build/controller/getResponseType.js +35 -0
  28. package/build/controller/getSafeHttpClient.js +8 -0
  29. package/build/controller/getStepCounter.js +16 -0
  30. package/build/controller/handleErrorResponse.js +26 -0
  31. package/build/controller/makeSafeHttpClient.js +8 -0
  32. package/build/controller/response-utils.js +72 -0
  33. package/build/domain/components/AlertComponent.js +1 -0
  34. package/build/domain/components/AllOfComponent.js +40 -0
  35. package/build/domain/components/BooleanInputComponent.js +50 -0
  36. package/build/domain/components/BoxComponent.js +3 -0
  37. package/build/domain/components/ButtonComponent.js +1 -0
  38. package/build/domain/components/ColumnsComponent.js +3 -0
  39. package/build/domain/components/ConstComponent.js +18 -0
  40. package/build/domain/components/ContainerComponent.js +3 -0
  41. package/build/domain/components/DateInputComponent.js +75 -0
  42. package/build/domain/components/DecisionComponent.js +1 -0
  43. package/build/domain/components/DividerComponent.js +1 -0
  44. package/build/domain/components/FormComponent.js +3 -0
  45. package/build/domain/components/FormattedValueComponent.js +44 -0
  46. package/build/domain/components/HeadingComponent.js +1 -0
  47. package/build/domain/components/ImageComponent.js +1 -0
  48. package/build/domain/components/InstructionsComponent.js +1 -0
  49. package/build/domain/components/IntegerInputComponent.js +74 -0
  50. package/build/domain/components/ListComponent.js +1 -0
  51. package/build/domain/components/LoadingIndicatorComponent.js +1 -0
  52. package/build/domain/components/MarkdownComponent.js +1 -0
  53. package/build/domain/components/MediaComponent.js +1 -0
  54. package/build/domain/components/ModalComponent.js +16 -0
  55. package/build/domain/components/ModalLayoutComponent.js +3 -0
  56. package/build/domain/components/MoneyInputComponent.js +57 -0
  57. package/build/domain/components/MultiSelectInputComponent.js +81 -0
  58. package/build/domain/components/MultiUploadInputComponent.js +88 -0
  59. package/build/domain/components/NumberInputComponent.js +73 -0
  60. package/build/domain/components/ObjectComponent.js +45 -0
  61. package/build/domain/components/ParagraphComponent.js +1 -0
  62. package/build/domain/components/PersistAsyncComponent.js +92 -0
  63. package/build/domain/components/ProgressComponent.js +1 -0
  64. package/build/domain/components/RepeatableComponent.js +103 -0
  65. package/build/domain/components/ReviewComponent.js +1 -0
  66. package/build/domain/components/RootDomainComponent.js +173 -0
  67. package/build/domain/components/SectionComponent.js +5 -0
  68. package/build/domain/components/SelectInputComponent.js +88 -0
  69. package/build/domain/components/StatusListComponent.js +1 -0
  70. package/build/domain/components/SubflowDomainComponent.js +9 -0
  71. package/build/domain/components/TabsComponent.js +1 -0
  72. package/build/domain/components/TextInputComponent.js +76 -0
  73. package/build/domain/components/TupleComponent.js +41 -0
  74. package/build/domain/components/UploadInputComponent.js +83 -0
  75. package/build/domain/components/UpsellComponent.js +25 -0
  76. package/build/domain/components/searchComponent/SearchComponent.js +92 -0
  77. package/build/domain/components/searchComponent/SearchComponent.test.js +190 -0
  78. package/build/domain/components/step/ExternalConfirmationComponent.js +28 -0
  79. package/build/domain/components/step/StepDomainComponent.js +73 -0
  80. package/build/domain/components/step/ToolbarComponent.js +1 -0
  81. package/build/domain/components/utils/WithUpdate.js +1 -0
  82. package/build/domain/components/utils/component-utils.js +12 -0
  83. package/build/domain/components/utils/debounce.js +34 -0
  84. package/build/domain/components/utils/debounce.test.js +67 -0
  85. package/build/domain/components/utils/file-utils.js +21 -0
  86. package/build/domain/components/utils/file-utils.test.js +27 -0
  87. package/build/domain/components/utils/getRandomId.js +1 -0
  88. package/build/domain/components/utils/isExactLocalValueMatch.js +14 -0
  89. package/build/domain/components/utils/isOrWasValid.js +5 -0
  90. package/build/domain/components/utils/isPartialModelMatch.js +18 -0
  91. package/build/domain/components/utils/isPartialModelMatch.test.js +74 -0
  92. package/build/domain/features/eventNames.js +24 -0
  93. package/build/domain/features/events.js +1 -0
  94. package/build/domain/features/persistAsync/getComponentMultiPersistAsync.js +50 -0
  95. package/build/domain/features/persistAsync/getInitialPersistedState.js +7 -0
  96. package/build/domain/features/persistAsync/getPerformPersistAsync.js +43 -0
  97. package/build/domain/features/persistAsync/getPerformPersistAsync.test.js +139 -0
  98. package/build/domain/features/polling/getStepPolling.js +43 -0
  99. package/build/domain/features/polling/getStepPolling.test.js +90 -0
  100. package/build/domain/features/prefetch/getStepPrefetch.js +43 -0
  101. package/build/domain/features/prefetch/request-cache.js +49 -0
  102. package/build/domain/features/prefetch/request-cache.test.js +70 -0
  103. package/build/domain/features/refreshAfter/getStepRefreshAfter.js +24 -0
  104. package/build/domain/features/refreshAfter/getStepRefreshAfter.test.js +40 -0
  105. package/build/domain/features/schema-on-change/getDebouncedSchemaOnChange.js +50 -0
  106. package/build/domain/features/schema-on-change/getSchemaOnChange.js +34 -0
  107. package/build/domain/features/search/getPerformSearchFunction.js +75 -0
  108. package/build/domain/features/search/getPerformSearchFunction.test.js +301 -0
  109. package/build/domain/features/summary/summary-utils.js +40 -0
  110. package/build/domain/features/summary/summary-utils.test.js +125 -0
  111. package/build/domain/features/utils/http-utils.js +21 -0
  112. package/build/domain/features/utils/response-utils.js +9 -0
  113. package/build/domain/features/validation/spec-utils.js +19 -0
  114. package/build/domain/features/validation/validateStringPattern.js +24 -0
  115. package/build/domain/features/validation/validation-functions.js +6 -0
  116. package/build/domain/features/validation/validation-functions.test.js +108 -0
  117. package/build/domain/features/validation/value-checks.js +125 -0
  118. package/build/domain/features/validation/value-checks.test.js +262 -0
  119. package/build/domain/features/validationAsync/getComponentValidationAsync.js +53 -0
  120. package/build/domain/features/validationAsync/getComponentValidationAsync.test.js +67 -0
  121. package/build/domain/features/validationAsync/getInitialValidationAsyncState.js +5 -0
  122. package/build/domain/features/validationAsync/getPerformValidationAsync.js +45 -0
  123. package/build/domain/features/validationAsync/getPerformValidationAsync.test.js +143 -0
  124. package/build/domain/mappers/layout/alertLayoutToComponent.js +16 -0
  125. package/build/domain/mappers/layout/boxLayoutToComponent.js +13 -0
  126. package/build/domain/mappers/layout/buttonLayoutToComponent.js +77 -0
  127. package/build/domain/mappers/layout/columnsLayoutToComponent.js +13 -0
  128. package/build/domain/mappers/layout/decisionLayoutToComponent.js +22 -0
  129. package/build/domain/mappers/layout/deprecatedListLayoutToComponent.js +30 -0
  130. package/build/domain/mappers/layout/dividerLayoutToComponent.js +2 -0
  131. package/build/domain/mappers/layout/formLayoutToComponent.js +19 -0
  132. package/build/domain/mappers/layout/headingLayoutToComponent.js +12 -0
  133. package/build/domain/mappers/layout/imageLayoutToComponent.js +20 -0
  134. package/build/domain/mappers/layout/infoLayoutToComponent.js +12 -0
  135. package/build/domain/mappers/layout/instructionsLayoutToComponent.js +12 -0
  136. package/build/domain/mappers/layout/listLayoutToComponent.js +39 -0
  137. package/build/domain/mappers/layout/loadingIndicatorLayoutToComponent.js +9 -0
  138. package/build/domain/mappers/layout/markdownLayoutToComponent.js +12 -0
  139. package/build/domain/mappers/layout/mediaLayoutToComponent.js +12 -0
  140. package/build/domain/mappers/layout/modalLayoutToComponent.js +17 -0
  141. package/build/domain/mappers/layout/modalToComponent.js +8 -0
  142. package/build/domain/mappers/layout/paragraphLayoutToComponent.js +12 -0
  143. package/build/domain/mappers/layout/progressLayoutToComponent.js +15 -0
  144. package/build/domain/mappers/layout/reviewLayoutToComponent.js +48 -0
  145. package/build/domain/mappers/layout/searchLayoutToComponent.js +44 -0
  146. package/build/domain/mappers/layout/sectionLayoutToComponent.js +15 -0
  147. package/build/domain/mappers/layout/statusListLayoutToComponent.js +15 -0
  148. package/build/domain/mappers/layout/tabsLayoutToComponent.js +16 -0
  149. package/build/domain/mappers/layout/upsellLayoutToComponent.js +25 -0
  150. package/build/domain/mappers/mapLayoutToComponent.js +81 -0
  151. package/build/domain/mappers/mapSchemaToComponent.js +61 -0
  152. package/build/domain/mappers/mapSchemaToComponent.test.js +112 -0
  153. package/build/domain/mappers/mapStepSchemas.js +17 -0
  154. package/build/domain/mappers/mapStepToComponent.js +132 -0
  155. package/build/domain/mappers/mapStepToComponent.test.js +221 -0
  156. package/build/domain/mappers/mapToolbarToComponent.js +15 -0
  157. package/build/domain/mappers/schema/allOfSchemaToComponent.js +16 -0
  158. package/build/domain/mappers/schema/arraySchemaToComponent/arraySchemaToComponent.js +26 -0
  159. package/build/domain/mappers/schema/arraySchemaToComponent/arraySchemaToMultiSelectComponent.js +55 -0
  160. package/build/domain/mappers/schema/arraySchemaToComponent/arraySchemaToMultiUploadComponent.js +67 -0
  161. package/build/domain/mappers/schema/arraySchemaToComponent/arraySchemaToRepeatableComponent.js +57 -0
  162. package/build/domain/mappers/schema/arraySchemaToComponent/arraySchemaToTupleComponent.js +20 -0
  163. package/build/domain/mappers/schema/blobSchemaToComponent.js +15 -0
  164. package/build/domain/mappers/schema/booleanSchemaToComponent.js +29 -0
  165. package/build/domain/mappers/schema/constSchemaToComponent.js +23 -0
  166. package/build/domain/mappers/schema/integerSchemaToComponent.js +28 -0
  167. package/build/domain/mappers/schema/numberSchemaToComponent.js +26 -0
  168. package/build/domain/mappers/schema/objectSchemaToComponent/assertDisplayOrder.js +23 -0
  169. package/build/domain/mappers/schema/objectSchemaToComponent/objectSchemaToFormattedValueComponent.js +9 -0
  170. package/build/domain/mappers/schema/objectSchemaToComponent/objectSchemaToMoneyInputComponent.js +119 -0
  171. package/build/domain/mappers/schema/objectSchemaToComponent/objectSchemaToMoneyInputComponent.test.js +96 -0
  172. package/build/domain/mappers/schema/objectSchemaToComponent/objectSchemaToObjectComponent.js +31 -0
  173. package/build/domain/mappers/schema/objectSchemaToComponent/objectSchemaToObjectComponent.test.js +99 -0
  174. package/build/domain/mappers/schema/oneOfSchemaToComponent/oneOfSchemaToComponent.js +76 -0
  175. package/build/domain/mappers/schema/oneOfSchemaToComponent/oneOfSchemaToComponent.test.js +265 -0
  176. package/build/domain/mappers/schema/persistAsyncSchemaToComponent.js +29 -0
  177. package/build/domain/mappers/schema/stringSchemaToComponent/stringSchemaToComponent.js +18 -0
  178. package/build/domain/mappers/schema/stringSchemaToComponent/stringSchemaToComponent.test.js +133 -0
  179. package/build/domain/mappers/schema/stringSchemaToComponent/stringSchemaToDateInputComponent.js +48 -0
  180. package/build/domain/mappers/schema/stringSchemaToComponent/stringSchemaToTextInputComponent.js +37 -0
  181. package/build/domain/mappers/schema/stringSchemaToComponent/stringSchemaToUploadInputComponent.js +28 -0
  182. package/build/domain/mappers/schema/tests/test-utils.js +16 -0
  183. package/build/domain/mappers/schema/types.js +1 -0
  184. package/build/domain/mappers/schema/utils/getPerformPersistAsyncFn.js +19 -0
  185. package/build/domain/mappers/schema/utils/getValidationAsyncInitialState.js +23 -0
  186. package/build/domain/mappers/schema/utils/mapCommonSchemaProps.js +16 -0
  187. package/build/domain/mappers/types.js +1 -0
  188. package/build/domain/mappers/utils/FeatureFlags.js +22 -0
  189. package/build/domain/mappers/utils/behavior-utils.js +44 -0
  190. package/build/domain/mappers/utils/call-to-action-utils.js +21 -0
  191. package/build/domain/mappers/utils/getAutocompleteString.js +76 -0
  192. package/build/domain/mappers/utils/getAutocompleteString.test.js +21 -0
  193. package/build/domain/mappers/utils/groupLayoutByPinned.js +38 -0
  194. package/build/domain/mappers/utils/groupLayoutByPinned.test.js +166 -0
  195. package/build/domain/mappers/utils/image.js +9 -0
  196. package/build/domain/mappers/utils/layout-utils.js +11 -0
  197. package/build/domain/mappers/utils/legacy-utils.js +49 -0
  198. package/build/domain/mappers/utils/media-utils.js +14 -0
  199. package/build/domain/mappers/utils/suggestions-utils.js +26 -0
  200. package/build/domain/mappers/utils/suggestions-utils.test.js +36 -0
  201. package/build/domain/mappers/utils/tags-utils.js +1 -0
  202. package/build/domain/mappers/utils/utils.js +35 -0
  203. package/build/domain/types.js +1 -0
  204. package/build/getSubflowCallbacks.js +38 -0
  205. package/build/i18n/index.js +40 -0
  206. package/build/index.js +8 -0
  207. package/build/main.js +112 -54
  208. package/build/main.mjs +111 -53
  209. package/build/renderers/CoreContainerRenderer.js +5 -0
  210. package/build/renderers/CoreRootRenderer.js +12 -0
  211. package/build/renderers/EmptyLoadingStateRenderer.js +5 -0
  212. package/build/renderers/getRenderFunction.js +24 -0
  213. package/build/renderers/getSchemaErrorMessageFunction.js +97 -0
  214. package/build/renderers/mappers/alertComponentToProps.js +2 -0
  215. package/build/renderers/mappers/allOfComponentToProps.js +6 -0
  216. package/build/renderers/mappers/booleanInputComponentToProps.js +5 -0
  217. package/build/renderers/mappers/boxComponentToProps.js +13 -0
  218. package/build/renderers/mappers/buttonComponentToProps.js +4 -0
  219. package/build/renderers/mappers/columnsComponentToProps.js +11 -0
  220. package/build/renderers/mappers/componentToRendererProps.js +164 -0
  221. package/build/renderers/mappers/constComponentToProps.js +5 -0
  222. package/build/renderers/mappers/containerComponentToProps.js +7 -0
  223. package/build/renderers/mappers/dateInputComponentToProps.js +2 -0
  224. package/build/renderers/mappers/decisionComponentToProps.js +16 -0
  225. package/build/renderers/mappers/dividerComponentToProps.js +2 -0
  226. package/build/renderers/mappers/externalComponentToProps.js +3 -0
  227. package/build/renderers/mappers/formComponentToProps.js +12 -0
  228. package/build/renderers/mappers/formattedValueComponentToProps.js +5 -0
  229. package/build/renderers/mappers/headingComponentToProps.js +2 -0
  230. package/build/renderers/mappers/hiddenComponentToProps.js +4 -0
  231. package/build/renderers/mappers/imageComponentToProps.js +2 -0
  232. package/build/renderers/mappers/instructionsComponentToProps.js +2 -0
  233. package/build/renderers/mappers/integerInputComponentToProps.js +2 -0
  234. package/build/renderers/mappers/listComponentToProps.js +2 -0
  235. package/build/renderers/mappers/loadingIndicatorComponentToProps.js +2 -0
  236. package/build/renderers/mappers/markdownComponentToProps.js +2 -0
  237. package/build/renderers/mappers/mediaComponentToProps.js +2 -0
  238. package/build/renderers/mappers/modalComponentToProps.js +11 -0
  239. package/build/renderers/mappers/modalLayoutComponentToProps.js +16 -0
  240. package/build/renderers/mappers/moneyInputComponentToProps.js +36 -0
  241. package/build/renderers/mappers/multiSelectComponentToProps.js +23 -0
  242. package/build/renderers/mappers/multiUploadInputComponentToProps.js +12 -0
  243. package/build/renderers/mappers/numberInputComponentToProps.js +2 -0
  244. package/build/renderers/mappers/objectComponentToProps.js +8 -0
  245. package/build/renderers/mappers/paragraphComponentToProps.js +2 -0
  246. package/build/renderers/mappers/persistAsyncComponentToProps.js +8 -0
  247. package/build/renderers/mappers/progressComponentToProps.js +2 -0
  248. package/build/renderers/mappers/repeatableComponentToProps.js +30 -0
  249. package/build/renderers/mappers/reviewComponentToProps.js +2 -0
  250. package/build/renderers/mappers/rootComponentToProps.js +21 -0
  251. package/build/renderers/mappers/searchComponentToProps.js +57 -0
  252. package/build/renderers/mappers/sectionComponentToProps.js +6 -0
  253. package/build/renderers/mappers/selectInputComponentToProps.js +26 -0
  254. package/build/renderers/mappers/statusListComponentToProps.js +2 -0
  255. package/build/renderers/mappers/subflowComponentToRendererProps.js +4 -0
  256. package/build/renderers/mappers/tabsComponentToProps.js +14 -0
  257. package/build/renderers/mappers/textInputComponentToProps.js +2 -0
  258. package/build/renderers/mappers/tupleComponentToProps.js +8 -0
  259. package/build/renderers/mappers/uploadInputComponentToProps.js +8 -0
  260. package/build/renderers/mappers/upsellComponentToProps.js +2 -0
  261. package/build/renderers/mappers/utils/getValidationState.js +12 -0
  262. package/build/renderers/mappers/utils/inputComponentToProps.js +26 -0
  263. package/build/renderers/mappers/utils/mapErrorsToValidationState.js +9 -0
  264. package/build/renderers/mappers/utils/pick.js +8 -0
  265. package/build/renderers/mappers/utils/selectInputOptionsToProps.js +11 -0
  266. package/build/renderers/stepComponentToProps.js +32 -0
  267. package/build/renderers/utils.js +69 -0
  268. package/build/renderers/utils.test.js +70 -0
  269. package/build/stories/dev-tools/ContainerQueries.story.js +66 -0
  270. package/build/stories/dev-tools/Debugger.story.js +38 -0
  271. package/build/stories/dev-tools/FixtureSelect.story.js +23 -0
  272. package/build/stories/dev-tools/TestServer.story.js +32 -0
  273. package/build/stories/examples/NativeFlow.story.js +80 -0
  274. package/build/stories/examples/Recipients.story.js +568 -0
  275. package/build/stories/spec/behavior/Copy.story.js +59 -0
  276. package/build/stories/spec/behavior/Modal.story.js +76 -0
  277. package/build/stories/spec/behavior/Subflow.story.js +267 -0
  278. package/build/stories/spec/layouts/Decision.story.js +241 -0
  279. package/build/stories/spec/layouts/Image.story.js +42 -0
  280. package/build/stories/spec/layouts/Modal.story.js +81 -0
  281. package/build/stories/spec/layouts/Search.story.js +325 -0
  282. package/build/stories/spec/layouts/Upsell.story.js +55 -0
  283. package/build/stories/spec/layouts/button/Button.story.js +100 -0
  284. package/build/stories/spec/layouts/button/PinnedButton.story.js +81 -0
  285. package/build/stories/spec/response/ActionResponse.story.js +66 -0
  286. package/build/stories/spec/schemas/MultiSelect.story.js +148 -0
  287. package/build/stories/spec/schemas/Upload.story.js +168 -0
  288. package/build/stories/spec/schemas/const/ConstLayout.story.js +159 -0
  289. package/build/stories/spec/schemas/const/ObjectConst.story.js +94 -0
  290. package/build/stories/spec/schemas/features/PersistAsync.story.js +176 -0
  291. package/build/stories/spec/schemas/features/ValidationAsync.story.js +103 -0
  292. package/build/stories/spec/schemas/object/FormattedValue.story.js +92 -0
  293. package/build/stories/spec/schemas/object/MoneyInput.story.js +240 -0
  294. package/build/stories/spec/schemas/oneOf/OneOfInitialisation.story.js +55 -0
  295. package/build/stories/spec/step/Controls.story.js +109 -0
  296. package/build/stories/spec/step/DFModal.story.js +58 -0
  297. package/build/stories/spec/step/Footer.story.js +70 -0
  298. package/build/stories/spec/step/Navigation.story.js +20 -0
  299. package/build/stories/spec/step/Tags.story.js +39 -0
  300. package/build/stories/spec/step/ToolBar.story.js +60 -0
  301. package/build/stories/spec/step/features/ErrorHandling.story.js +92 -0
  302. package/build/stories/spec/step/features/External.story.js +44 -0
  303. package/build/stories/spec/step/features/Polling.story.js +108 -0
  304. package/build/stories/spec/step/features/RefreshAfter.story.js +92 -0
  305. package/build/stories/spec/step/features/refresh/Refresh.story.js +258 -0
  306. package/build/stories/spec/step/features/refresh/RefreshWithPersistAsync.story.js +958 -0
  307. package/build/stories/types.js +1 -0
  308. package/build/stories/utils/fixtureHttpClient.js +70 -0
  309. package/build/stories/utils/getBasicStep.js +223 -0
  310. package/build/stories/utils/mockSearchHandler.js +71 -0
  311. package/build/stories/utils/render-utils.js +41 -0
  312. package/build/stories/visual-tests/layouts/NotUsingListItem.story.js +17 -0
  313. package/build/test-utils/DynamicFlowWise.js +32 -0
  314. package/build/test-utils/DynamicFlowWiseModal.js +34 -0
  315. package/build/test-utils/NeptuneProviders.js +11 -0
  316. package/build/test-utils/component-utils.js +5 -0
  317. package/build/test-utils/fetch-utils.js +45 -0
  318. package/build/test-utils/getMergedTestRenderers.js +34 -0
  319. package/build/test-utils/getRandomId.js +1 -0
  320. package/build/test-utils/index.js +3 -0
  321. package/build/test-utils/rtl-utils.js +7 -0
  322. package/build/test-utils/step-utils.js +6 -0
  323. package/build/test-utils/wait.js +3 -0
  324. package/build/tests/AlertLayout.test.js +78 -0
  325. package/build/tests/ArrayTuple.test.js +118 -0
  326. package/build/tests/ButtonLayout.test.js +308 -0
  327. package/build/tests/ConstLayout.test.js +95 -0
  328. package/build/tests/DateInput.test.js +163 -0
  329. package/build/tests/DecisionLayout.test.js +146 -0
  330. package/build/tests/DynamicFlow.test.js +147 -0
  331. package/build/tests/External.test.js +169 -0
  332. package/build/tests/Flow.test.js +328 -0
  333. package/build/tests/FormLayout.test.js +28 -0
  334. package/build/tests/FormattedValue.test.js +107 -0
  335. package/build/tests/ImageRenderer.test.js +78 -0
  336. package/build/tests/InitialAction.test.js +179 -0
  337. package/build/tests/InitialStep.test.js +168 -0
  338. package/build/tests/InstructionsLayout.test.js +45 -0
  339. package/build/tests/ListLayout.test.js +145 -0
  340. package/build/tests/Logging.test.js +53 -0
  341. package/build/tests/ModalBehavior.test.js +149 -0
  342. package/build/tests/MoneyInput.test.js +316 -0
  343. package/build/tests/MultiUpload.test.js +293 -0
  344. package/build/tests/NativeBack.test.js +267 -0
  345. package/build/tests/OneOfInitialisation.test.js +571 -0
  346. package/build/tests/PersistAsync.test.js +653 -0
  347. package/build/tests/Polling.test.js +617 -0
  348. package/build/tests/Prefetching.test.js +230 -0
  349. package/build/tests/RefreshAfter.test.js +63 -0
  350. package/build/tests/RefreshOnChange.ResponseHandling.test.js +205 -0
  351. package/build/tests/RefreshOnChange.test.js +233 -0
  352. package/build/tests/RefreshOnChange.with.Segmented.test.js +348 -0
  353. package/build/tests/RefreshOnChange.with.Tabs.test.js +358 -0
  354. package/build/tests/RefreshOnChangePreserve.test.js +224 -0
  355. package/build/tests/RendererProps.test.js +342 -0
  356. package/build/tests/Repeatable.test.js +107 -0
  357. package/build/tests/Rerendering.test.js +67 -0
  358. package/build/tests/ReviewLayout.test.js +274 -0
  359. package/build/tests/SchemaOnChange.test.js +133 -0
  360. package/build/tests/ScrollToError.test.js +217 -0
  361. package/build/tests/SegmentedControl.test.js +49 -0
  362. package/build/tests/SingleFileUpload.test.js +88 -0
  363. package/build/tests/StatusList.test.js +85 -0
  364. package/build/tests/Subflow.test.js +710 -0
  365. package/build/tests/Submission.ResponseHandling.test.js +557 -0
  366. package/build/tests/Submission.merging.test.js +202 -0
  367. package/build/tests/Submission.test.js +523 -0
  368. package/build/tests/Tags.test.js +475 -0
  369. package/build/tests/Upsell.test.js +126 -0
  370. package/build/tests/ValidationAsync.test.js +295 -0
  371. package/build/tests/legacy/Actions.test.js +158 -0
  372. package/build/tests/legacy/BackButton.test.js +114 -0
  373. package/build/tests/legacy/HiddenSchemas.test.js +246 -0
  374. package/build/tests/legacy/MultiSelect.test.js +497 -0
  375. package/build/tests/legacy/MultipleFileUploadSchema.test.js +341 -0
  376. package/build/tests/legacy/PersistAsync.blob-schema.test.js +224 -0
  377. package/build/tests/legacy/PersistAsync.string-schema.test.js +211 -0
  378. package/build/tests/legacy/RefreshStepOnChange.debouncing.test.js +209 -0
  379. package/build/tests/legacy/RefreshStepOnChange.test.js +424 -0
  380. package/build/tests/legacy/Search.test.js +437 -0
  381. package/build/tests/renderers/MultiSelectInputRendererProps.test.js +58 -0
  382. package/build/tests/renderers/SelectInputRendererProps.test.js +42 -0
  383. package/build/tests/renderers/TextInputRenderer.test.js +51 -0
  384. package/build/types/domain/components/UpsellComponent.d.ts +2 -3
  385. package/build/types/domain/components/UpsellComponent.d.ts.map +1 -1
  386. package/build/types/domain/components/searchComponent/SearchComponent.d.ts +5 -4
  387. package/build/types/domain/components/searchComponent/SearchComponent.d.ts.map +1 -1
  388. package/build/types/domain/features/search/getPerformSearchFunction.d.ts +1 -1
  389. package/build/types/domain/features/search/getPerformSearchFunction.d.ts.map +1 -1
  390. package/build/types/domain/mappers/layout/searchLayoutToComponent.d.ts +2 -1
  391. package/build/types/domain/mappers/layout/searchLayoutToComponent.d.ts.map +1 -1
  392. package/build/types/domain/mappers/layout/upsellLayoutToComponent.d.ts +1 -1
  393. package/build/types/domain/mappers/layout/upsellLayoutToComponent.d.ts.map +1 -1
  394. package/build/types/renderers/EmptyLoadingStateRenderer.d.ts +3 -0
  395. package/build/types/renderers/EmptyLoadingStateRenderer.d.ts.map +1 -0
  396. package/build/types/renderers/mappers/rootComponentToProps.d.ts.map +1 -1
  397. package/build/types/renderers/mappers/searchComponentToProps.d.ts +1 -1
  398. package/build/types/renderers/mappers/searchComponentToProps.d.ts.map +1 -1
  399. package/build/types/renderers/mappers/upsellComponentToProps.d.ts +2 -2
  400. package/build/types/renderers/mappers/upsellComponentToProps.d.ts.map +1 -1
  401. package/build/types/test-utils/getMergedTestRenderers.d.ts +1 -1
  402. package/build/types/test-utils/getMergedTestRenderers.d.ts.map +1 -1
  403. package/build/types/useDynamicFlow.d.ts.map +1 -1
  404. package/build/types.js +1 -0
  405. package/build/useDynamicFlow.js +104 -0
  406. package/build/useDynamicFlowModal.js +58 -0
  407. package/build/utils/analyse-step.js +14 -0
  408. package/build/utils/component-utils.js +8 -0
  409. package/build/utils/component-utils.test.js +113 -0
  410. package/build/utils/getScrollToTop.js +12 -0
  411. package/build/utils/normalise-flow-id.js +1 -0
  412. package/build/utils/normalise-flow-id.test.js +24 -0
  413. package/build/utils/openLinkInNewTab.js +10 -0
  414. package/build/utils/recursiveMerge.js +40 -0
  415. package/build/utils/recursiveMerge.test.js +93 -0
  416. package/build/utils/type-utils.js +21 -0
  417. package/build/utils/type-validators.js +11 -0
  418. package/build/utils/type-validators.test.js +180 -0
  419. package/build/utils/useStableCallback.js +15 -0
  420. package/package.json +4 -4
@@ -0,0 +1,295 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { act, screen, waitFor } from '@testing-library/react';
3
+ import { userEvent } from '@testing-library/user-event';
4
+ import { vi } from 'vitest';
5
+ import { renderWithProviders } from '../test-utils';
6
+ import DynamicFlowWise from '../test-utils/DynamicFlowWise';
7
+ const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime });
8
+ describe('Validation Async', () => {
9
+ const getRootSchema = (validationAsync) => ({
10
+ $id: '#schema',
11
+ type: 'object',
12
+ displayOrder: ['iban'],
13
+ properties: {
14
+ iban: {
15
+ $id: '#iban-string-schema',
16
+ type: 'string',
17
+ maxLength: 18,
18
+ title: 'IBAN',
19
+ validationAsync,
20
+ },
21
+ },
22
+ });
23
+ const getInitialStep = (validationAsync) => ({
24
+ id: 'validation-async-step-id',
25
+ title: 'Validation Async',
26
+ schemas: [getRootSchema(validationAsync)],
27
+ layout: [
28
+ { type: 'form', schemaId: '#schema' },
29
+ {
30
+ type: 'button',
31
+ title: 'Submit',
32
+ action: { url: '/submit', method: 'POST' },
33
+ },
34
+ ],
35
+ });
36
+ const getProps = (initialStep) => ({
37
+ flowId: 'flow-id',
38
+ initialStep,
39
+ httpClient: vi.fn(),
40
+ onCompletion: vi.fn(),
41
+ onError: vi.fn(),
42
+ onEvent: vi.fn(),
43
+ onLog: vi.fn(),
44
+ });
45
+ describe('when a value is entered and focus remains on the input', () => {
46
+ it('triggers validation async after a debounce', async () => {
47
+ const props = getProps(getInitialStep({ method: 'POST', url: '/validate', param: 'myParameter' }));
48
+ const { httpClient } = props;
49
+ renderWithProviders(_jsx(DynamicFlowWise, Object.assign({}, props)));
50
+ const input = screen.getByLabelText('IBAN');
51
+ await user.type(input, 'AB123456789');
52
+ await waitFor(() => {
53
+ expect(httpClient).not.toHaveBeenCalled();
54
+ });
55
+ await act(async () => vi.advanceTimersByTimeAsync(1000));
56
+ await waitFor(() => {
57
+ expect(httpClient).toHaveBeenCalledWith('/validate', expect.objectContaining({ body: `{"myParameter":"AB123456789"}` }));
58
+ });
59
+ });
60
+ });
61
+ describe('when a value is entered and then the field is blurred', () => {
62
+ it('flushes the pending validation async', async () => {
63
+ const props = getProps(getInitialStep({ method: 'POST', url: '/validate', param: 'myParameter' }));
64
+ const { httpClient } = props;
65
+ renderWithProviders(_jsx(DynamicFlowWise, Object.assign({}, props)));
66
+ await waitFor(() => {
67
+ expect(screen.getByLabelText('IBAN')).toBeInTheDocument();
68
+ });
69
+ const input = screen.getByLabelText('IBAN');
70
+ await user.type(input, 'AB123456789');
71
+ await waitFor(() => {
72
+ expect(httpClient).not.toHaveBeenCalled();
73
+ });
74
+ await act(async () => vi.advanceTimersByTimeAsync(200));
75
+ await waitFor(() => {
76
+ expect(httpClient).not.toHaveBeenCalled();
77
+ });
78
+ await user.tab();
79
+ await waitFor(() => {
80
+ expect(httpClient).toHaveBeenCalledWith('/validate', expect.objectContaining({ body: `{"myParameter":"AB123456789"}` }));
81
+ });
82
+ });
83
+ });
84
+ describe('when the input is blurred and has null value', () => {
85
+ it('does NOT trigger validation async', async () => {
86
+ const props = getProps(getInitialStep({ method: 'POST', url: '/validate', param: 'myParameter' }));
87
+ const { httpClient } = props;
88
+ renderWithProviders(_jsx(DynamicFlowWise, Object.assign({}, props)));
89
+ await waitFor(() => {
90
+ expect(screen.getByLabelText('IBAN')).toBeInTheDocument();
91
+ });
92
+ const input = screen.getByLabelText('IBAN');
93
+ await user.clear(input);
94
+ await user.tab();
95
+ await waitFor(() => {
96
+ expect(httpClient).not.toHaveBeenCalled();
97
+ });
98
+ });
99
+ });
100
+ describe('when the input is blurred and has an invalid value', () => {
101
+ it('does NOT trigger validation async', async () => {
102
+ const props = getProps(getInitialStep({ method: 'POST', url: '/validate', param: 'myParameter' }));
103
+ const { httpClient } = props;
104
+ renderWithProviders(_jsx(DynamicFlowWise, Object.assign({}, props)));
105
+ const input = screen.getByLabelText('IBAN');
106
+ await user.type(input, '12345678901234567890'); // longer than 18 characters
107
+ await user.tab();
108
+ await waitFor(() => {
109
+ expect(httpClient).not.toHaveBeenCalled();
110
+ });
111
+ });
112
+ });
113
+ describe('when the input is blurred and has a valid value', () => {
114
+ it('triggers validation async with the specified method, url and parameter', async () => {
115
+ const httpClient = vi
116
+ .fn()
117
+ .mockResolvedValue(new Response(JSON.stringify({ message: 'IBAN is valid' })));
118
+ const props = getProps(getInitialStep({ method: 'POST', url: '/validate', param: 'myParameter' }));
119
+ renderWithProviders(_jsx(DynamicFlowWise, Object.assign({}, props, { httpClient: httpClient })));
120
+ const input = screen.getByLabelText('IBAN');
121
+ await user.type(input, '123456789012345678');
122
+ await user.tab();
123
+ await waitFor(() => {
124
+ expect(httpClient).toHaveBeenCalledWith('/validate', expect.objectContaining({ body: `{"myParameter":"123456789012345678"}` }));
125
+ });
126
+ });
127
+ describe.skip('when the validation-async config does not provide a method property', () => {
128
+ // I've removed these tests as zod will barf if method is not provided
129
+ });
130
+ describe('when the validation-async config specifies the "GET" method', () => {
131
+ it('calls fetch without a "body" payload', async () => {
132
+ const props = getProps(getInitialStep({ method: 'GET', url: '/validate', param: 'myParameter' }));
133
+ renderWithProviders(_jsx(DynamicFlowWise, Object.assign({}, props)));
134
+ const input = screen.getByLabelText('IBAN');
135
+ await user.type(input, '123456789012345678');
136
+ await user.tab();
137
+ await waitFor(() => {
138
+ expect(props.httpClient).toHaveBeenCalledWith('/validate', expect.objectContaining({ method: `GET` }));
139
+ });
140
+ });
141
+ });
142
+ describe('when the validation response is successful with a "message" property', () => {
143
+ it('displays the validation success message', async () => {
144
+ const httpClient = vi
145
+ .fn()
146
+ .mockResolvedValue(new Response(JSON.stringify({ message: 'IBAN is valid' })));
147
+ const props = getProps(getInitialStep({ method: 'POST', url: '/validate', param: 'myParameter' }));
148
+ renderWithProviders(_jsx(DynamicFlowWise, Object.assign({}, props, { httpClient: httpClient })));
149
+ const input = screen.getByLabelText('IBAN');
150
+ await user.type(input, '123456789012345678');
151
+ await user.tab();
152
+ await waitFor(() => {
153
+ expect(screen.getByText('IBAN is valid')).toBeInTheDocument();
154
+ });
155
+ });
156
+ });
157
+ describe('when the validation response fails with 422', () => {
158
+ it('displays the validation error message', async () => {
159
+ const httpClient = vi.fn().mockResolvedValue(new Response(JSON.stringify({ message: 'Invalid IBAN (422)' }), {
160
+ status: 422,
161
+ }));
162
+ const props = getProps(getInitialStep({ method: 'POST', url: '/validate', param: 'myParameter' }));
163
+ renderWithProviders(_jsx(DynamicFlowWise, Object.assign({}, props, { httpClient: httpClient })));
164
+ const input = screen.getByLabelText('IBAN');
165
+ await user.type(input, '123456789012345678');
166
+ await user.tab();
167
+ await waitFor(() => {
168
+ expect(screen.getByText('Invalid IBAN (422)')).toBeInTheDocument();
169
+ });
170
+ });
171
+ });
172
+ describe('when the value is changed after a successful validation async request', () => {
173
+ it('does not display any messages', async () => {
174
+ const httpClient = vi
175
+ .fn()
176
+ .mockResolvedValue(new Response(JSON.stringify({ message: 'IBAN is valid' })));
177
+ const props = getProps(getInitialStep({ method: 'POST', url: '/validate', param: 'myParameter' }));
178
+ renderWithProviders(_jsx(DynamicFlowWise, Object.assign({}, props, { httpClient: httpClient })));
179
+ const input = screen.getByLabelText('IBAN');
180
+ await user.type(input, '12345678901234567');
181
+ await user.tab();
182
+ await waitFor(() => {
183
+ expect(screen.getByText('IBAN is valid')).toBeInTheDocument();
184
+ });
185
+ await user.type(input, '8');
186
+ await user.tab();
187
+ await waitFor(() => {
188
+ expect(screen.queryByText('IBAN is valid')).not.toBeInTheDocument();
189
+ });
190
+ });
191
+ describe('when the new value is the same as before', () => {
192
+ it('does not trigger another validation async call', async () => {
193
+ const httpClient = vi
194
+ .fn()
195
+ .mockResolvedValue(new Response(JSON.stringify({ message: 'IBAN is valid' })));
196
+ const props = getProps(getInitialStep({ method: 'POST', url: '/validate', param: 'myParameter' }));
197
+ renderWithProviders(_jsx(DynamicFlowWise, Object.assign({}, props, { httpClient: httpClient })));
198
+ const input = screen.getByLabelText('IBAN');
199
+ await user.type(input, '123456789012345678');
200
+ await user.tab();
201
+ await waitFor(() => {
202
+ expect(httpClient).toHaveBeenCalledTimes(1);
203
+ });
204
+ await user.click(input);
205
+ await user.tab();
206
+ await waitFor(() => {
207
+ expect(httpClient).toHaveBeenCalledTimes(1);
208
+ });
209
+ });
210
+ });
211
+ });
212
+ describe('other server responses', () => {
213
+ const otherCases = [
214
+ {
215
+ description: 'when the validation response is successful without a body',
216
+ httpClient: vi.fn(async () => Promise.resolve(new Response(null))),
217
+ // Original:
218
+ // expectedTrackingEvent: 'failure',
219
+ // Modification:
220
+ expectedTrackingEvent: 'Dynamic Flow - ValidationAsync Succeeded',
221
+ doNotExpect: 'Error',
222
+ },
223
+ {
224
+ description: 'when the validation response is successful with a string body',
225
+ httpClient: vi.fn(async () => Promise.resolve(new Response(`Everything is fine`))),
226
+ // Original:
227
+ // expectedTrackingEvent: 'failure',
228
+ // Modification:
229
+ expectedTrackingEvent: 'Dynamic Flow - ValidationAsync Succeeded',
230
+ doNotExpect: 'Everything is fine',
231
+ },
232
+ {
233
+ description: 'when the validation response fails with 500',
234
+ httpClient: vi.fn(async () => Promise.resolve(new Response(`Internal server error`, { status: 500 }))),
235
+ expectedTrackingEvent: 'Dynamic Flow - ValidationAsync Failed',
236
+ doNotExpect: 'Internal server error',
237
+ },
238
+ {
239
+ description: 'when the validation response fails with 403',
240
+ httpClient: vi.fn(async () => Promise.resolve(new Response(`{ "messsage": "Forbidden" }`, { status: 403 }))),
241
+ // Original:
242
+ // expectedTrackingEvent: 'success',
243
+ // Modification:
244
+ expectedTrackingEvent: 'Dynamic Flow - ValidationAsync Failed',
245
+ doNotExpect: 'Forbidden',
246
+ },
247
+ {
248
+ description: 'when the validation response JSON does not parse as an object',
249
+ httpClient: vi.fn(async () => Promise.resolve(new Response(`1234567890`, { status: 422 }))),
250
+ expectedTrackingEvent: 'Dynamic Flow - ValidationAsync Failed',
251
+ doNotExpect: '1234567890',
252
+ },
253
+ {
254
+ description: 'when the validation response does not even parse as JSON',
255
+ httpClient: vi.fn(async () => Promise.resolve(new Response(`non-json-string`, { status: 422 }))),
256
+ expectedTrackingEvent: 'Dynamic Flow - ValidationAsync Failed',
257
+ doNotExpect: 'non-json-string',
258
+ },
259
+ ];
260
+ describe.each(otherCases)('$description', ({ httpClient, expectedTrackingEvent, doNotExpect }) => {
261
+ it('does NOT display a validation message', async () => {
262
+ const props = getProps(getInitialStep({ method: 'POST', url: '/validate', param: 'myParameter' }));
263
+ renderWithProviders(_jsx(DynamicFlowWise, Object.assign({}, props, { httpClient: httpClient })));
264
+ const input = screen.getByLabelText('IBAN');
265
+ await user.type(input, '123456789012345678');
266
+ await user.tab();
267
+ await waitFor(() => {
268
+ expect(screen.queryByText(doNotExpect)).not.toBeInTheDocument();
269
+ });
270
+ });
271
+ it(`triggers analytics event with {status: "${expectedTrackingEvent}"}`, async () => {
272
+ const props = getProps(getInitialStep({ method: 'POST', url: '/validate', param: 'myParameter' }));
273
+ renderWithProviders(_jsx(DynamicFlowWise, Object.assign({}, props, { httpClient: httpClient })));
274
+ const input = screen.getByLabelText('IBAN');
275
+ await user.type(input, '123456789012345678');
276
+ await user.tab();
277
+ await waitFor(() => {
278
+ expect(props.onEvent).toHaveBeenLastCalledWith(expectedTrackingEvent, expect.objectContaining({
279
+ flowId: 'flow-id',
280
+ schema: '#iban-string-schema',
281
+ stepId: 'validation-async-step-id',
282
+ }));
283
+ });
284
+ // Original
285
+ // await waitFor(() => {
286
+ // expect(props.onEvent).toHaveBeenLastCalledWith(
287
+ // 'Dynamic Flow - ValidationAsync',
288
+ // expect.objectContaining({ status: expectedTrackingEvent }),
289
+ // );
290
+ // });
291
+ });
292
+ });
293
+ });
294
+ });
295
+ });
@@ -0,0 +1,158 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { screen, waitFor } from '@testing-library/react';
3
+ import { userEvent } from '@testing-library/user-event';
4
+ import { vi } from 'vitest';
5
+ import { renderWithProviders } from '../../test-utils';
6
+ import DynamicFlowWise from '../../test-utils/DynamicFlowWise';
7
+ const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime });
8
+ describe('Actions', () => {
9
+ // TODO: Add more tests here / copy over to revamp when ready.
10
+ describe('given an action with `exit: true`', () => {
11
+ describe('when the response is OK', () => {
12
+ describe('and the body can be parsed to a JSON object', () => {
13
+ it('should exit the flow with the response body as a result when the action has no result', async () => {
14
+ const onError = vi.fn();
15
+ const onCompletion = vi.fn();
16
+ const httpClient = vi.fn(async () => Promise.resolve(new Response('body', { status: 200 })));
17
+ const step = {
18
+ id: 'step-id',
19
+ title: 'Step Title',
20
+ layout: [{ type: 'button', action: { url: '/submit', exit: true } }],
21
+ schemas: [],
22
+ };
23
+ renderWithProviders(_jsx(DynamicFlowWise, { flowId: "the-flow-id", initialStep: step, httpClient: httpClient, onCompletion: onCompletion, onError: onError }));
24
+ await user.click(await screen.findByRole('button'));
25
+ await waitFor(() => {
26
+ expect(onCompletion).toHaveBeenCalledTimes(1);
27
+ });
28
+ expect(onError).not.toHaveBeenCalled();
29
+ });
30
+ it('should exit the flow with a merged object of the response body and result when the action has a result', async () => {
31
+ const onError = vi.fn();
32
+ const onCompletion = vi.fn();
33
+ const httpClient = vi.fn(async () => Promise.resolve(new Response(JSON.stringify({ key: 'response body value', extra_key: 'value' }), {
34
+ status: 200,
35
+ })));
36
+ const step = {
37
+ id: 'step-id',
38
+ title: 'Step Title',
39
+ layout: [
40
+ {
41
+ type: 'button',
42
+ action: { url: '/submit', exit: true, result: { key: 'action result value' } },
43
+ },
44
+ ],
45
+ schemas: [],
46
+ };
47
+ renderWithProviders(_jsx(DynamicFlowWise, { flowId: "the-flow-id", initialStep: step, httpClient: httpClient, onCompletion: onCompletion, onError: onError }));
48
+ await user.click(await screen.findByRole('button'));
49
+ await waitFor(() => {
50
+ expect(onCompletion).toHaveBeenCalledTimes(1);
51
+ });
52
+ expect(onCompletion).toHaveBeenCalledWith(expect.objectContaining({ key: 'action result value', extra_key: 'value' }));
53
+ expect(onError).not.toHaveBeenCalled();
54
+ });
55
+ });
56
+ describe('and the body cannot be parsed to a JSON object', () => {
57
+ it('should exit the flow with the contents of the action result', async () => {
58
+ const onError = vi.fn();
59
+ const onCompletion = vi.fn();
60
+ const httpClient = vi.fn(async () => Promise.resolve(new Response(']} not valid json {[', { status: 200 })));
61
+ const step = {
62
+ id: 'step-id',
63
+ title: 'Step Title',
64
+ layout: [
65
+ { type: 'button', action: { url: '/submit', exit: true, result: { key: 'value' } } },
66
+ ],
67
+ schemas: [],
68
+ };
69
+ renderWithProviders(_jsx(DynamicFlowWise, { flowId: "the-flow-id", initialStep: step, httpClient: httpClient, onCompletion: onCompletion, onError: onError }));
70
+ await user.click(await screen.findByRole('button'));
71
+ await waitFor(() => {
72
+ expect(onCompletion).toHaveBeenCalledTimes(1);
73
+ });
74
+ expect(onCompletion).toHaveBeenCalledWith(expect.objectContaining({ key: 'value' }));
75
+ expect(onError).not.toHaveBeenCalled();
76
+ });
77
+ });
78
+ });
79
+ describe('when the response is NOT OK', () => {
80
+ it('should not exit the flow, and handle the error response as normal', async () => {
81
+ const onError = vi.fn();
82
+ const onCompletion = vi.fn();
83
+ const httpClient = vi.fn(async () => Promise.resolve(new Response('body', { status: 400 })));
84
+ const step = {
85
+ id: 'step-id',
86
+ title: 'Step Title',
87
+ layout: [{ type: 'button', action: { url: '/submit', exit: true } }],
88
+ schemas: [],
89
+ };
90
+ renderWithProviders(_jsx(DynamicFlowWise, { flowId: "the-flow-id", initialStep: step, httpClient: httpClient, onCompletion: onCompletion, onError: onError }));
91
+ await user.click(await screen.findByRole('button'));
92
+ await waitFor(() => {
93
+ expect(screen.getByText(/something went wrong, please try again/i)).toBeInTheDocument();
94
+ });
95
+ expect(onCompletion).not.toHaveBeenCalled();
96
+ });
97
+ });
98
+ });
99
+ describe('given an non-exit action', () => {
100
+ describe('when the response contains "X-DF-ResponseType: exit" header', () => {
101
+ it('should exit the flow with a merged object of the response body and result when the action has a result', async () => {
102
+ const onError = vi.fn();
103
+ const onCompletion = vi.fn();
104
+ const httpClient = vi.fn(async () => Promise.resolve(new Response(JSON.stringify({ key: 'response body value', extra_key: 'value' }), {
105
+ status: 200,
106
+ headers: { 'X-DF-Response-Type': 'exit' },
107
+ })));
108
+ const step = {
109
+ id: 'step-id',
110
+ title: 'Step Title',
111
+ layout: [
112
+ {
113
+ type: 'button',
114
+ action: { url: '/submit', result: { key: 'action result value' } },
115
+ },
116
+ ],
117
+ schemas: [],
118
+ };
119
+ renderWithProviders(_jsx(DynamicFlowWise, { flowId: "the-flow-id", initialStep: step, httpClient: httpClient, onCompletion: onCompletion, onError: onError }));
120
+ await user.click(await screen.findByRole('button'));
121
+ await waitFor(() => {
122
+ expect(onCompletion).toHaveBeenCalledTimes(1);
123
+ });
124
+ expect(onCompletion).toHaveBeenCalledWith(expect.objectContaining({ key: 'action result value', extra_key: 'value' }));
125
+ expect(onError).not.toHaveBeenCalled();
126
+ expect(httpClient).toHaveBeenCalledTimes(1);
127
+ });
128
+ });
129
+ describe('when the response contains an exiting action', () => {
130
+ it('should exit the flow with the result of the exiting action and not make an additional network request', async () => {
131
+ const onError = vi.fn();
132
+ const onCompletion = vi.fn();
133
+ const httpClient = vi.fn(async () => Promise.resolve(new Response(JSON.stringify({ action: { exit: true, result: { abc: '123' } } }), {
134
+ status: 200,
135
+ })));
136
+ const step = {
137
+ id: 'step-id',
138
+ title: 'Step Title',
139
+ layout: [
140
+ {
141
+ type: 'button',
142
+ action: { url: '/submit', result: { key: 'action result value' } },
143
+ },
144
+ ],
145
+ schemas: [],
146
+ };
147
+ renderWithProviders(_jsx(DynamicFlowWise, { flowId: "the-flow-id", initialStep: step, httpClient: httpClient, onCompletion: onCompletion, onError: onError }));
148
+ await user.click(await screen.findByRole('button'));
149
+ await waitFor(() => {
150
+ expect(onCompletion).toHaveBeenCalledTimes(1);
151
+ });
152
+ expect(onCompletion).toHaveBeenCalledWith(expect.objectContaining({ abc: '123' }));
153
+ expect(onError).not.toHaveBeenCalled();
154
+ expect(httpClient).toHaveBeenCalledTimes(1);
155
+ });
156
+ });
157
+ });
158
+ });
@@ -0,0 +1,114 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { screen } from '@testing-library/react';
3
+ import { userEvent } from '@testing-library/user-event';
4
+ import DynamicFlowWise from '../../test-utils/DynamicFlowWise';
5
+ import { renderWithProviders, respondWith } from '../../test-utils';
6
+ import { vi } from 'vitest';
7
+ const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime });
8
+ const getStepWithBack = (navigation) => ({
9
+ id: 'back-button-step',
10
+ title: 'Basic step',
11
+ navigation,
12
+ schemas: [
13
+ {
14
+ $id: 'schema',
15
+ type: 'object',
16
+ displayOrder: ['name'],
17
+ required: ['name'],
18
+ properties: {
19
+ name: {
20
+ title: 'Full name',
21
+ type: 'string',
22
+ },
23
+ },
24
+ },
25
+ ],
26
+ layout: [
27
+ {
28
+ type: 'form',
29
+ schemaId: 'schema',
30
+ },
31
+ ],
32
+ });
33
+ describe('DynamicFlow / Back Button', () => {
34
+ const onCompletion = vi.fn();
35
+ const onError = vi.fn();
36
+ const httpClient = vi.fn();
37
+ beforeEach(() => {
38
+ vi.clearAllMocks();
39
+ });
40
+ describe('when the step contains a back navigation property', () => {
41
+ it('renders a back button', () => {
42
+ const backLabel = 'Back to payment methods';
43
+ const backAction = {
44
+ method: 'GET',
45
+ url: '/back',
46
+ };
47
+ renderWithProviders(_jsx(DynamicFlowWise, { flowId: "the-flow-id", httpClient: httpClient, initialStep: getStepWithBack({ back: { title: backLabel, action: backAction } }), onCompletion: onCompletion, onError: onError }));
48
+ expect(screen.getByRole('button', { name: backLabel })).toBeInTheDocument();
49
+ });
50
+ });
51
+ describe('when the step contains the deprecated backButton navigation property', () => {
52
+ it('renders a back button', () => {
53
+ const backLabel = 'Back to payment methods';
54
+ const backAction = {
55
+ method: 'GET',
56
+ url: '/back',
57
+ };
58
+ renderWithProviders(_jsx(DynamicFlowWise, { flowId: "the-flow-id", httpClient: httpClient, initialStep: getStepWithBack({ backButton: { title: backLabel, action: backAction } }), onCompletion: onCompletion, onError: onError }));
59
+ expect(screen.getByRole('button', { name: backLabel })).toBeInTheDocument();
60
+ });
61
+ });
62
+ it('performs (GET) action on back', async () => {
63
+ const backLabel = 'Back to payment methods';
64
+ const backAction = {
65
+ method: 'GET',
66
+ url: '/back',
67
+ };
68
+ const mockHttpClient = vi.fn();
69
+ mockHttpClient.mockImplementationOnce(async () => respondWith({
70
+ // once again bad steps in old tests!!
71
+ id: 'next-step',
72
+ title: 'Next step',
73
+ schemas: [],
74
+ layout: [],
75
+ }));
76
+ renderWithProviders(_jsx(DynamicFlowWise, { flowId: "the-flow-id", httpClient: mockHttpClient, initialStep: getStepWithBack({ back: { title: backLabel, action: backAction } }), onCompletion: onCompletion, onError: onError }));
77
+ const backButton = screen.getByRole('button', { name: backLabel });
78
+ await user.click(backButton);
79
+ expect(mockHttpClient).toHaveBeenCalledWith('/back', expect.objectContaining({ method: 'GET' }));
80
+ await expect(screen.findByRole('heading', { name: 'Next step' })).resolves.toBeInTheDocument();
81
+ });
82
+ describe('when the backButton action specified the POST method', () => {
83
+ const backLabel = 'Back to payment methods';
84
+ const backAction = {
85
+ method: 'POST',
86
+ url: '/back',
87
+ };
88
+ const mockHttpClient = vi.fn();
89
+ beforeEach(() => {
90
+ mockHttpClient.mockImplementationOnce(async () => respondWith({
91
+ // added
92
+ id: 'next-step',
93
+ title: 'Next step',
94
+ schemas: [],
95
+ layout: [],
96
+ }));
97
+ });
98
+ const initialStep = getStepWithBack({ back: { title: backLabel, action: backAction } });
99
+ it('performs (POST) action on back', async () => {
100
+ renderWithProviders(_jsx(DynamicFlowWise, { flowId: "the-flow-id", httpClient: mockHttpClient, initialStep: initialStep, onCompletion: onCompletion, onError: onError }));
101
+ const backButton = screen.getByRole('button', { name: backLabel });
102
+ await user.click(backButton);
103
+ expect(mockHttpClient).toHaveBeenCalledWith('/back', expect.objectContaining({ method: 'POST' }));
104
+ await expect(screen.findByRole('heading', { name: 'Next step' })).resolves.toBeInTheDocument();
105
+ });
106
+ it('does not display client-side validation errors', async () => {
107
+ renderWithProviders(_jsx(DynamicFlowWise, { flowId: "the-flow-id", httpClient: mockHttpClient, initialStep: initialStep, onCompletion: onCompletion, onError: onError }));
108
+ const backButton = screen.getByRole('button', { name: backLabel });
109
+ await user.click(backButton);
110
+ expect(screen.queryByText('Please fill out this field.')).not.toBeInTheDocument();
111
+ await expect(screen.findByRole('heading', { name: 'Next step' })).resolves.toBeInTheDocument();
112
+ });
113
+ });
114
+ });