@jetshop/ui 5.13.0 → 5.13.10-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 (558) hide show
  1. package/Accordion/Accordion.d.ts +33 -33
  2. package/Accordion/Accordion.js +58 -58
  3. package/Accordion/Accordion.test.js +73 -73
  4. package/Accordion/__doc_utils__/AccordionHeader.js +12 -12
  5. package/Auth/FormFields/CountriesInput.d.ts +14 -14
  6. package/Auth/FormFields/CountriesInput.js +27 -27
  7. package/Auth/LogInBehavior.d.ts +22 -22
  8. package/Auth/LogInBehavior.js +23 -23
  9. package/Auth/LogInFormProvider.d.ts +7 -7
  10. package/Auth/LogInFormProvider.js +70 -70
  11. package/Auth/LogOut.d.ts +10 -10
  12. package/Auth/LogOut.js +23 -23
  13. package/Auth/logInValidator.d.ts +8 -8
  14. package/Auth/logInValidator.js +15 -15
  15. package/Breadcrumbs/Breadcrumbs.d.ts +14 -14
  16. package/Breadcrumbs/Breadcrumbs.js +83 -83
  17. package/Breadcrumbs/getParentsOrCanonicalRoute.d.ts +3 -3
  18. package/Breadcrumbs/getParentsOrCanonicalRoute.js +13 -13
  19. package/Breadcrumbs/index.d.ts +1 -1
  20. package/Breadcrumbs/index.js +1 -1
  21. package/Breakpoints.d.ts +12 -12
  22. package/Breakpoints.js +35 -35
  23. package/Button/Button.d.ts +14 -14
  24. package/Button/Button.js +59 -59
  25. package/Button/OutlineButton.d.ts +4 -4
  26. package/Button/OutlineButton.js +9 -9
  27. package/Button/SecondaryButton.d.ts +3 -3
  28. package/Button/SecondaryButton.js +8 -8
  29. package/Button/TrendButton.d.ts +3 -3
  30. package/Button/TrendButton.js +7 -7
  31. package/Button/index.d.ts +4 -4
  32. package/Button/index.js +4 -4
  33. package/CategoryLink.d.ts +9 -9
  34. package/CategoryLink.js +42 -42
  35. package/ChannelSelector/ChannelListItem.d.ts +10 -10
  36. package/ChannelSelector/ChannelListItem.js +50 -50
  37. package/ChannelSelector/ChannelListItem.test.js +85 -85
  38. package/ChannelSelector/ChannelSelector.d.ts +63 -63
  39. package/ChannelSelector/ChannelSelector.js +79 -79
  40. package/ChannelSelector/ChannelSelector.test.js +167 -167
  41. package/ChannelSelector/ChannelSelectorButtons.d.ts +3 -3
  42. package/ChannelSelector/ChannelSelectorButtons.js +19 -19
  43. package/ChannelSelector/Channels.d.ts +17 -17
  44. package/ChannelSelector/Channels.js +11 -11
  45. package/ChannelSelector/Channels.test.js +90 -90
  46. package/ChannelSelector/LargeSelector.d.ts +3 -3
  47. package/ChannelSelector/LargeSelector.js +66 -66
  48. package/ChannelSelector/MiniSelector.d.ts +4 -4
  49. package/ChannelSelector/MiniSelector.js +57 -57
  50. package/ChannelSelector/Region.d.ts +28 -28
  51. package/ChannelSelector/Region.js +20 -20
  52. package/ChannelSelector/Region.test.js +37 -37
  53. package/ChannelSelector/exampleChannels.js +577 -577
  54. package/ChannelSelector/groupBy.d.ts +7 -7
  55. package/ChannelSelector/groupBy.js +15 -15
  56. package/ChannelSelector/groupBy.test.js +42 -42
  57. package/Checkbox/Checkbox.d.ts +10 -10
  58. package/Checkbox/Checkbox.js +68 -68
  59. package/Checkbox/Checkbox.js.map +1 -1
  60. package/Checkbox/CheckboxGroup.d.ts +23 -23
  61. package/Checkbox/CheckboxGroup.js +21 -21
  62. package/Checkbox/index.d.ts +2 -2
  63. package/Checkbox/index.js +2 -2
  64. package/ContentPageLink.d.ts +9 -9
  65. package/ContentPageLink.js +36 -36
  66. package/ContentRenderer.d.ts +9 -9
  67. package/ContentRenderer.js +35 -35
  68. package/DropdownMenu/Button.d.ts +7 -7
  69. package/DropdownMenu/Button.js +31 -31
  70. package/DropdownMenu/DropdownMenu.d.ts +21 -21
  71. package/DropdownMenu/DropdownMenu.js +71 -71
  72. package/DropdownMenu/Item.d.ts +13 -13
  73. package/DropdownMenu/Item.js +47 -47
  74. package/DropdownMenu/Items.d.ts +16 -16
  75. package/DropdownMenu/Items.js +52 -52
  76. package/DropdownMenu/index.d.ts +4 -4
  77. package/DropdownMenu/index.js +4 -4
  78. package/ErrorBoundary/Generic.d.ts +17 -17
  79. package/ErrorBoundary/Generic.js +68 -68
  80. package/ErrorBoundary/PassThrough.d.ts +3 -3
  81. package/ErrorBoundary/PassThrough.js +6 -6
  82. package/Gallery/Gallery.d.ts +39 -39
  83. package/Gallery/Gallery.js +121 -121
  84. package/Gallery/constructGallery.d.ts +15 -15
  85. package/Gallery/constructGallery.js +40 -40
  86. package/Image/B2BImage.d.ts +50 -50
  87. package/Image/B2BImage.js +52 -52
  88. package/Image/BaseImage.d.ts +39 -39
  89. package/Image/BaseImage.js +191 -191
  90. package/Image/Fallback.d.ts +5 -5
  91. package/Image/Fallback.js +3 -3
  92. package/Image/FlightImage.d.ts +52 -52
  93. package/Image/FlightImage.js +57 -57
  94. package/Image/FlightImage.test.js +277 -277
  95. package/Image/Image.d.ts +2 -2
  96. package/Image/Image.js +2 -2
  97. package/Image/index.d.ts +1 -1
  98. package/Image/index.js +1 -1
  99. package/Image/useConstructImage.d.ts +46 -46
  100. package/Image/useConstructImage.js +96 -96
  101. package/Image/utils/aspectRatioToFraction.d.ts +2 -2
  102. package/Image/utils/aspectRatioToFraction.js +10 -10
  103. package/Image/utils/getFullUrl.d.ts +6 -6
  104. package/Image/utils/getFullUrl.js +17 -17
  105. package/Image/utils/getImageWidth.d.ts +1 -1
  106. package/Image/utils/getImageWidth.js +11 -11
  107. package/Image/utils/getImageWidths.d.ts +2 -2
  108. package/Image/utils/getImageWidths.js +13 -13
  109. package/Image/utils/getLQIP.d.ts +8 -8
  110. package/Image/utils/getLQIP.js +19 -19
  111. package/Image/utils/getLargestSize.d.ts +7 -7
  112. package/Image/utils/getLargestSize.js +16 -16
  113. package/Image/utils/getSizeForBreakpoint.d.ts +2 -2
  114. package/Image/utils/getSizeForBreakpoint.js +15 -15
  115. package/Image/utils/getSizesMap.d.ts +2 -2
  116. package/Image/utils/getSizesMap.js +21 -21
  117. package/Image/utils/getSmallestSize.d.ts +2 -2
  118. package/Image/utils/getSmallestSize.js +11 -11
  119. package/Image/utils/getSrcSetFromWidths.d.ts +10 -10
  120. package/Image/utils/getSrcSetFromWidths.js +8 -8
  121. package/Image/utils/getSrcWithParams.d.ts +3 -3
  122. package/Image/utils/getSrcWithParams.js +28 -28
  123. package/Image/utils/paddingForAspectRatio.d.ts +1 -1
  124. package/Image/utils/paddingForAspectRatio.js +5 -5
  125. package/Image/utils/remToPx.d.ts +1 -1
  126. package/Image/utils/remToPx.js +1 -1
  127. package/Image/utils/sizeToNumber.d.ts +2 -2
  128. package/Image/utils/sizeToNumber.js +26 -26
  129. package/Input/Input.d.ts +6 -6
  130. package/Input/Input.js +44 -44
  131. package/Input/index.d.ts +3 -3
  132. package/Input/index.js +3 -3
  133. package/JetshopText.d.ts +3 -3
  134. package/JetshopText.js +11 -11
  135. package/JetshopText.js.map +1 -1
  136. package/Loading/LoadingBar.d.ts +8 -8
  137. package/Loading/LoadingBar.js +57 -57
  138. package/Loading/LoadingLine.d.ts +31 -31
  139. package/Loading/LoadingLine.js +25 -25
  140. package/Loading/LoadingLine.test.js +18 -18
  141. package/Loading/NetworkStatusNotifier.d.ts +2 -2
  142. package/Loading/NetworkStatusNotifier.js +3 -3
  143. package/Menu/GetMoreSubcategoriesQuery.gql +25 -25
  144. package/Menu/MenuContainer.d.ts +28 -28
  145. package/Menu/MenuContainer.js +45 -45
  146. package/Menu/MenuContainer.test.js +245 -245
  147. package/Menu/RecursiveTree.d.ts +28 -28
  148. package/Menu/RecursiveTree.js +90 -90
  149. package/Menu/RecursiveTree.test.js +416 -416
  150. package/Modal/Drawer/Drawer.d.ts +11 -11
  151. package/Modal/Drawer/Drawer.js +30 -30
  152. package/Modal/Drawer/DrawerTarget.d.ts +6 -6
  153. package/Modal/Drawer/DrawerTarget.js +11 -11
  154. package/Modal/Drawer/DrawerTarget.test.js +92 -92
  155. package/Modal/Drawer/DrawerTrigger.d.ts +11 -11
  156. package/Modal/Drawer/DrawerTrigger.js +15 -15
  157. package/Modal/Drawer/DrawerTrigger.test.js +51 -51
  158. package/Modal/Drawer/index.d.ts +3 -3
  159. package/Modal/Drawer/index.js +3 -3
  160. package/Modal/Flyout/FlyoutTarget.d.ts +10 -10
  161. package/Modal/Flyout/FlyoutTarget.js +14 -14
  162. package/Modal/Flyout/FlyoutTarget.test.js +84 -84
  163. package/Modal/Flyout/FlyoutTrigger.d.ts +15 -15
  164. package/Modal/Flyout/FlyoutTrigger.js +17 -17
  165. package/Modal/Flyout/FlyoutTrigger.test.js +72 -72
  166. package/Modal/Flyout/index.d.ts +2 -2
  167. package/Modal/Flyout/index.js +2 -2
  168. package/Modal/ModalContext.d.ts +26 -26
  169. package/Modal/ModalContext.js +8 -8
  170. package/Modal/ModalProvider.d.ts +5 -5
  171. package/Modal/ModalProvider.js +82 -82
  172. package/Modal/ModalProvider.test.js +26 -26
  173. package/Modal/ModalRoot.d.ts +3 -3
  174. package/Modal/ModalRoot.js +43 -43
  175. package/Modal/ModalRoot.test.js +80 -80
  176. package/Modal/ModalTrigger.d.ts +9 -9
  177. package/Modal/ModalTrigger.js +8 -8
  178. package/Modal/__test_utils__/getComponentWithModalContext.js +29 -29
  179. package/Pagination/Pagination.d.ts +7 -7
  180. package/Pagination/Pagination.js +22 -22
  181. package/Pagination/PaginationBehaviour.d.ts +52 -52
  182. package/Pagination/PaginationBehaviour.js +67 -67
  183. package/Pagination/index.d.ts +2 -2
  184. package/Pagination/index.js +2 -2
  185. package/Pagination/usePagination.d.ts +15 -15
  186. package/Pagination/usePagination.js +45 -45
  187. package/PreOrderDateSelector/PreOrderDateSelector.d.ts +20 -20
  188. package/PreOrderDateSelector/PreOrderDateSelector.js +73 -73
  189. package/PreOrderDateSelector/index.d.ts +2 -2
  190. package/PreOrderDateSelector/index.js +2 -2
  191. package/Price/Currency.d.ts +9 -9
  192. package/Price/Currency.js +10 -10
  193. package/Price/Currency.js.map +1 -1
  194. package/Price/Price.d.ts +28 -28
  195. package/Price/Price.js +34 -34
  196. package/Price/index.d.ts +1 -1
  197. package/Price/index.js +1 -1
  198. package/ProductLink.d.ts +21 -21
  199. package/ProductLink.js +81 -81
  200. package/ProductList/Badges.d.ts +6 -6
  201. package/ProductList/Badges.js +55 -55
  202. package/ProductList/GridProduct.d.ts +24 -24
  203. package/ProductList/GridProduct.js +57 -57
  204. package/ProductList/ProductGrid.d.ts +16 -16
  205. package/ProductList/ProductGrid.js +29 -29
  206. package/ProductList/ProductImage.d.ts +12 -12
  207. package/ProductList/ProductImage.js +20 -20
  208. package/ProductSpecifications/ProductSpecifications.d.ts +8 -8
  209. package/ProductSpecifications/ProductSpecifications.js +77 -77
  210. package/ScrollRestorationHandler/ScrollRestorationHandler.d.ts +8 -8
  211. package/ScrollRestorationHandler/ScrollRestorationHandler.js +16 -16
  212. package/ScrollRestorationHandler/ScrollRestorationHandler.test.js +75 -75
  213. package/ScrollRestorationHandler/index.d.ts +1 -1
  214. package/ScrollRestorationHandler/index.js +1 -1
  215. package/ScrollRestorationHandler/isInIgnoredRouteTypes.d.ts +6 -6
  216. package/ScrollRestorationHandler/isInIgnoredRouteTypes.js +7 -7
  217. package/ScrollRestorationHandler/useScrollRestore.d.ts +7 -7
  218. package/ScrollRestorationHandler/useScrollRestore.js +19 -19
  219. package/Search/AutocompleteQuery.gql +10 -10
  220. package/Search/SearchAutoCompleteContainer.d.ts +45 -45
  221. package/Search/SearchAutoCompleteContainer.js +171 -171
  222. package/Search/SearchAutoCompleteContainer.test.js +460 -460
  223. package/Search/SearchField.d.ts +15 -15
  224. package/Search/SearchField.js +96 -96
  225. package/Search/SearchPage/PageOf.d.ts +5 -5
  226. package/Search/SearchPage/PageOf.js +6 -6
  227. package/Search/SearchPage/SearchMeta.d.ts +16 -16
  228. package/Search/SearchPage/SearchMeta.js +19 -19
  229. package/Search/SearchPage/SearchPageBehaviour.d.ts +19 -19
  230. package/Search/SearchPage/SearchPageBehaviour.js +66 -66
  231. package/Search/SuggestedTerm.d.ts +16 -16
  232. package/Search/SuggestedTerm.js +34 -34
  233. package/Search/index.d.ts +1 -1
  234. package/Search/index.js +1 -1
  235. package/Select/Components.d.ts +28 -28
  236. package/Select/Components.js +90 -90
  237. package/Select/SelectComponents/Quantity.d.ts +5 -5
  238. package/Select/SelectComponents/Quantity.js +7 -7
  239. package/Select/index.d.ts +5 -5
  240. package/Select/index.js +1 -1
  241. package/SortOrder/SortOrder.d.ts +16 -16
  242. package/SortOrder/SortOrder.js +31 -31
  243. package/SortOrder/SortOrderDropdown.d.ts +9 -9
  244. package/SortOrder/SortOrderDropdown.js +24 -24
  245. package/SortOrder/SortOrderList.d.ts +7 -7
  246. package/SortOrder/SortOrderList.js +16 -16
  247. package/StartPageRenderer/StartPageRenderer.d.ts +17 -17
  248. package/StartPageRenderer/StartPageRenderer.js +51 -51
  249. package/StartPageRenderer/index.d.ts +1 -1
  250. package/StartPageRenderer/index.js +1 -1
  251. package/Stock/StockStatusContainer.d.ts +16 -16
  252. package/Stock/StockStatusContainer.js +39 -39
  253. package/Stock/__tests__/StockStatusContainer.test.js +65 -65
  254. package/Text/Text.d.ts +11 -11
  255. package/Text/Text.js +21 -21
  256. package/Text/index.d.ts +3 -3
  257. package/Text/index.js +3 -3
  258. package/Theme/createTheme.d.ts +16 -16
  259. package/Theme/createTheme.js +4 -4
  260. package/Theme/cssReset.d.ts +1 -1
  261. package/Theme/cssReset.js +159 -159
  262. package/Theme/normalizeCss.d.ts +1 -1
  263. package/Theme/normalizeCss.js +356 -356
  264. package/Theme/sanitizeCss.d.ts +1 -1
  265. package/Theme/sanitizeCss.js +571 -571
  266. package/WindowGrid/WindowGrid.d.ts +11 -11
  267. package/WindowGrid/WindowGrid.js +57 -57
  268. package/WindowGrid/index.d.ts +1 -1
  269. package/WindowGrid/index.js +1 -1
  270. package/WindowGrid/useResizeObserver.d.ts +8 -8
  271. package/WindowGrid/useResizeObserver.js +13 -13
  272. package/WindowGrid/useScrollWithWindow.d.ts +12 -12
  273. package/WindowGrid/useScrollWithWindow.js +38 -38
  274. package/dependencies.d.ts +98 -98
  275. package/fuzzySearch/fuzzySearch.d.ts +8 -8
  276. package/fuzzySearch/fuzzySearch.js +42 -42
  277. package/fuzzySearch/index.d.ts +1 -1
  278. package/fuzzySearch/index.js +1 -1
  279. package/global.d.ts +1 -1
  280. package/hooks/index.d.ts +2 -2
  281. package/hooks/index.js +2 -2
  282. package/hooks/useOnClickOutside.d.ts +6 -6
  283. package/hooks/useOnClickOutside.js +16 -16
  284. package/hooks/useOnEsc.d.ts +4 -4
  285. package/hooks/useOnEsc.js +16 -16
  286. package/package.json +1 -1
  287. package/setupTests.js +2 -2
  288. package/svg/flags/ad.svg +150 -150
  289. package/svg/flags/ae.svg +6 -6
  290. package/svg/flags/af.svg +81 -81
  291. package/svg/flags/ag.svg +14 -14
  292. package/svg/flags/ai.svg +767 -767
  293. package/svg/flags/al.svg +5 -5
  294. package/svg/flags/am.svg +5 -5
  295. package/svg/flags/ao.svg +13 -13
  296. package/svg/flags/aq.svg +6 -6
  297. package/svg/flags/ar.svg +31 -31
  298. package/svg/flags/as.svg +33 -33
  299. package/svg/flags/at.svg +6 -6
  300. package/svg/flags/au.svg +9 -9
  301. package/svg/flags/aw.svg +186 -186
  302. package/svg/flags/ax.svg +18 -18
  303. package/svg/flags/az.svg +8 -8
  304. package/svg/flags/ba.svg +12 -12
  305. package/svg/flags/bb.svg +6 -6
  306. package/svg/flags/bd.svg +4 -4
  307. package/svg/flags/be.svg +7 -7
  308. package/svg/flags/bf.svg +7 -7
  309. package/svg/flags/bg.svg +7 -7
  310. package/svg/flags/bh.svg +11 -11
  311. package/svg/flags/bi.svg +15 -15
  312. package/svg/flags/bj.svg +14 -14
  313. package/svg/flags/bl.svg +7 -7
  314. package/svg/flags/bm.svg +98 -98
  315. package/svg/flags/bn.svg +36 -36
  316. package/svg/flags/bo.svg +676 -676
  317. package/svg/flags/bq.svg +5 -5
  318. package/svg/flags/br.svg +45 -45
  319. package/svg/flags/bs.svg +13 -13
  320. package/svg/flags/bt.svg +89 -89
  321. package/svg/flags/bv.svg +13 -13
  322. package/svg/flags/bw.svg +7 -7
  323. package/svg/flags/by.svg +20 -20
  324. package/svg/flags/bz.svg +145 -145
  325. package/svg/flags/ca.svg +4 -4
  326. package/svg/flags/cc.svg +19 -19
  327. package/svg/flags/cd.svg +5 -5
  328. package/svg/flags/cf.svg +15 -15
  329. package/svg/flags/cg.svg +12 -12
  330. package/svg/flags/ch.svg +9 -9
  331. package/svg/flags/ci.svg +7 -7
  332. package/svg/flags/ck.svg +9 -9
  333. package/svg/flags/cl.svg +13 -13
  334. package/svg/flags/cm.svg +15 -15
  335. package/svg/flags/cn.svg +11 -11
  336. package/svg/flags/co.svg +7 -7
  337. package/svg/flags/cr.svg +7 -7
  338. package/svg/flags/cu.svg +13 -13
  339. package/svg/flags/cv.svg +13 -13
  340. package/svg/flags/cw.svg +14 -14
  341. package/svg/flags/cx.svg +15 -15
  342. package/svg/flags/cy.svg +6 -6
  343. package/svg/flags/cz.svg +12 -12
  344. package/svg/flags/de.svg +5 -5
  345. package/svg/flags/dj.svg +13 -13
  346. package/svg/flags/dk.svg +5 -5
  347. package/svg/flags/dm.svg +152 -152
  348. package/svg/flags/do.svg +6745 -6745
  349. package/svg/flags/dz.svg +5 -5
  350. package/svg/flags/ec.svg +138 -138
  351. package/svg/flags/ee.svg +7 -7
  352. package/svg/flags/eg.svg +38 -38
  353. package/svg/flags/eh.svg +15 -15
  354. package/svg/flags/er.svg +8 -8
  355. package/svg/flags/es-ct.svg +4 -4
  356. package/svg/flags/es.svg +544 -544
  357. package/svg/flags/et.svg +14 -14
  358. package/svg/flags/eu.svg +28 -28
  359. package/svg/flags/fi.svg +5 -5
  360. package/svg/flags/fj.svg +120 -120
  361. package/svg/flags/fk.svg +89 -89
  362. package/svg/flags/fm.svg +11 -11
  363. package/svg/flags/fo.svg +12 -12
  364. package/svg/flags/fr.svg +7 -7
  365. package/svg/flags/ga.svg +7 -7
  366. package/svg/flags/gb-eng.svg +5 -5
  367. package/svg/flags/gb-nir.svg +131 -131
  368. package/svg/flags/gb-sct.svg +4 -4
  369. package/svg/flags/gb-wls.svg +9 -9
  370. package/svg/flags/gb.svg +15 -15
  371. package/svg/flags/gd.svg +27 -27
  372. package/svg/flags/ge.svg +6 -6
  373. package/svg/flags/gf.svg +5 -5
  374. package/svg/flags/gg.svg +9 -9
  375. package/svg/flags/gh.svg +6 -6
  376. package/svg/flags/gi.svg +32 -32
  377. package/svg/flags/gl.svg +4 -4
  378. package/svg/flags/gm.svg +14 -14
  379. package/svg/flags/gn.svg +7 -7
  380. package/svg/flags/gp.svg +7 -7
  381. package/svg/flags/gq.svg +23 -23
  382. package/svg/flags/gr.svg +22 -22
  383. package/svg/flags/gs.svg +201 -201
  384. package/svg/flags/gt.svg +204 -204
  385. package/svg/flags/gu.svg +39 -39
  386. package/svg/flags/gw.svg +13 -13
  387. package/svg/flags/gy.svg +9 -9
  388. package/svg/flags/hk.svg +30 -30
  389. package/svg/flags/hm.svg +9 -9
  390. package/svg/flags/hn.svg +18 -18
  391. package/svg/flags/hr.svg +58 -58
  392. package/svg/flags/ht.svg +116 -116
  393. package/svg/flags/hu.svg +7 -7
  394. package/svg/flags/id.svg +6 -6
  395. package/svg/flags/ie.svg +7 -7
  396. package/svg/flags/il.svg +14 -14
  397. package/svg/flags/im.svg +36 -36
  398. package/svg/flags/in.svg +25 -25
  399. package/svg/flags/io.svg +138 -138
  400. package/svg/flags/iq.svg +10 -10
  401. package/svg/flags/ir.svg +219 -219
  402. package/svg/flags/is.svg +12 -12
  403. package/svg/flags/it.svg +7 -7
  404. package/svg/flags/je.svg +31 -31
  405. package/svg/flags/jm.svg +8 -8
  406. package/svg/flags/jo.svg +16 -16
  407. package/svg/flags/jp.svg +11 -11
  408. package/svg/flags/ke.svg +23 -23
  409. package/svg/flags/kg.svg +15 -15
  410. package/svg/flags/kh.svg +61 -61
  411. package/svg/flags/ki.svg +36 -36
  412. package/svg/flags/km.svg +16 -16
  413. package/svg/flags/kn.svg +14 -14
  414. package/svg/flags/kp.svg +15 -15
  415. package/svg/flags/kr.svg +24 -24
  416. package/svg/flags/kw.svg +13 -13
  417. package/svg/flags/ky.svg +63 -63
  418. package/svg/flags/kz.svg +23 -23
  419. package/svg/flags/la.svg +12 -12
  420. package/svg/flags/lb.svg +15 -15
  421. package/svg/flags/lc.svg +8 -8
  422. package/svg/flags/li.svg +43 -43
  423. package/svg/flags/lk.svg +22 -22
  424. package/svg/flags/lr.svg +14 -14
  425. package/svg/flags/ls.svg +8 -8
  426. package/svg/flags/lt.svg +7 -7
  427. package/svg/flags/lu.svg +5 -5
  428. package/svg/flags/lv.svg +6 -6
  429. package/svg/flags/ly.svg +13 -13
  430. package/svg/flags/ma.svg +4 -4
  431. package/svg/flags/mc.svg +6 -6
  432. package/svg/flags/md.svg +70 -70
  433. package/svg/flags/me.svg +116 -116
  434. package/svg/flags/mf.svg +7 -7
  435. package/svg/flags/mg.svg +7 -7
  436. package/svg/flags/mh.svg +7 -7
  437. package/svg/flags/mk.svg +5 -5
  438. package/svg/flags/ml.svg +7 -7
  439. package/svg/flags/mm.svg +16 -16
  440. package/svg/flags/mn.svg +13 -13
  441. package/svg/flags/mo.svg +9 -9
  442. package/svg/flags/mp.svg +86 -86
  443. package/svg/flags/mq.svg +7 -7
  444. package/svg/flags/mr.svg +6 -6
  445. package/svg/flags/ms.svg +39 -39
  446. package/svg/flags/mt.svg +49 -49
  447. package/svg/flags/mu.svg +8 -8
  448. package/svg/flags/mv.svg +6 -6
  449. package/svg/flags/mw.svg +10 -10
  450. package/svg/flags/mx.svg +382 -382
  451. package/svg/flags/my.svg +15 -15
  452. package/svg/flags/mz.svg +21 -21
  453. package/svg/flags/na.svg +16 -16
  454. package/svg/flags/nc.svg +7 -7
  455. package/svg/flags/ne.svg +6 -6
  456. package/svg/flags/nf.svg +9 -9
  457. package/svg/flags/ng.svg +6 -6
  458. package/svg/flags/ni.svg +129 -129
  459. package/svg/flags/nl.svg +7 -7
  460. package/svg/flags/no.svg +7 -7
  461. package/svg/flags/np.svg +14 -14
  462. package/svg/flags/nr.svg +12 -12
  463. package/svg/flags/nu.svg +26 -26
  464. package/svg/flags/nz.svg +41 -41
  465. package/svg/flags/om.svg +115 -115
  466. package/svg/flags/pa.svg +14 -14
  467. package/svg/flags/pe.svg +244 -244
  468. package/svg/flags/pf.svg +19 -19
  469. package/svg/flags/pg.svg +9 -9
  470. package/svg/flags/ph.svg +13 -13
  471. package/svg/flags/pk.svg +15 -15
  472. package/svg/flags/pl.svg +6 -6
  473. package/svg/flags/pm.svg +7 -7
  474. package/svg/flags/pn.svg +62 -62
  475. package/svg/flags/pr.svg +13 -13
  476. package/svg/flags/ps.svg +15 -15
  477. package/svg/flags/pt.svg +57 -57
  478. package/svg/flags/pw.svg +11 -11
  479. package/svg/flags/py.svg +157 -157
  480. package/svg/flags/qa.svg +4 -4
  481. package/svg/flags/re.svg +7 -7
  482. package/svg/flags/ro.svg +7 -7
  483. package/svg/flags/rs.svg +292 -292
  484. package/svg/flags/ru.svg +7 -7
  485. package/svg/flags/rw.svg +13 -13
  486. package/svg/flags/sa.svg +26 -26
  487. package/svg/flags/sb.svg +13 -13
  488. package/svg/flags/sc.svg +14 -14
  489. package/svg/flags/sd.svg +13 -13
  490. package/svg/flags/se.svg +16 -16
  491. package/svg/flags/sg.svg +13 -13
  492. package/svg/flags/sh.svg +74 -74
  493. package/svg/flags/si.svg +18 -18
  494. package/svg/flags/sj.svg +7 -7
  495. package/svg/flags/sk.svg +9 -9
  496. package/svg/flags/sl.svg +7 -7
  497. package/svg/flags/sm.svg +91 -91
  498. package/svg/flags/sn.svg +8 -8
  499. package/svg/flags/so.svg +11 -11
  500. package/svg/flags/sr.svg +6 -6
  501. package/svg/flags/ss.svg +8 -8
  502. package/svg/flags/st.svg +16 -16
  503. package/svg/flags/sv.svg +606 -606
  504. package/svg/flags/sx.svg +56 -56
  505. package/svg/flags/sy.svg +6 -6
  506. package/svg/flags/sz.svg +45 -45
  507. package/svg/flags/tc.svg +67 -67
  508. package/svg/flags/td.svg +7 -7
  509. package/svg/flags/tf.svg +15 -15
  510. package/svg/flags/tg.svg +14 -14
  511. package/svg/flags/th.svg +7 -7
  512. package/svg/flags/tj.svg +22 -22
  513. package/svg/flags/tk.svg +5 -5
  514. package/svg/flags/tl.svg +13 -13
  515. package/svg/flags/tm.svg +206 -206
  516. package/svg/flags/tn.svg +13 -13
  517. package/svg/flags/to.svg +10 -10
  518. package/svg/flags/tr.svg +8 -8
  519. package/svg/flags/tt.svg +5 -5
  520. package/svg/flags/tv.svg +27 -27
  521. package/svg/flags/tw.svg +14 -14
  522. package/svg/flags/tz.svg +13 -13
  523. package/svg/flags/ua.svg +6 -6
  524. package/svg/flags/ug.svg +30 -30
  525. package/svg/flags/um.svg +15 -15
  526. package/svg/flags/un.svg +16 -16
  527. package/svg/flags/us.svg +10 -10
  528. package/svg/flags/uy.svg +28 -28
  529. package/svg/flags/uz.svg +30 -30
  530. package/svg/flags/va.svg +479 -479
  531. package/svg/flags/vc.svg +8 -8
  532. package/svg/flags/ve.svg +26 -26
  533. package/svg/flags/vg.svg +127 -127
  534. package/svg/flags/vi.svg +28 -28
  535. package/svg/flags/vn.svg +11 -11
  536. package/svg/flags/vu.svg +18 -18
  537. package/svg/flags/wf.svg +7 -7
  538. package/svg/flags/ws.svg +7 -7
  539. package/svg/flags/ye.svg +7 -7
  540. package/svg/flags/yt.svg +7 -7
  541. package/svg/flags/za.svg +17 -17
  542. package/svg/flags/zm.svg +27 -27
  543. package/svg/flags/zw.svg +21 -21
  544. package/test-utils/mock-response/product-status.js +44 -44
  545. package/utils/breakpoints.d.ts +23 -23
  546. package/utils/breakpoints.js +89 -89
  547. package/utils/callAllEventHandlers.d.ts +5 -5
  548. package/utils/callAllEventHandlers.js +8 -8
  549. package/utils/text.d.ts +1 -1
  550. package/utils/text.js +22 -22
  551. package/utils/theme.d.ts +3 -3
  552. package/utils/theme.js +4 -4
  553. package/utils/useHoverIntent.d.ts +10 -10
  554. package/utils/useHoverIntent.js +77 -77
  555. package/utils/usePropsOfType.d.ts +11 -11
  556. package/utils/usePropsOfType.js +17 -17
  557. package/withFlightUI.d.ts +17 -17
  558. package/withFlightUI.js +19 -19
@@ -1,460 +1,460 @@
1
- import renderWithRouter from '@jetshop/core/test-utils/renderWithRouter';
2
- import React from 'react';
3
- import { MockedProvider } from '@apollo/react-testing';
4
- import { Route, Switch } from 'react-router';
5
- import {
6
- cleanup,
7
- fireEvent,
8
- wait,
9
- waitForElement
10
- } from '@testing-library/react';
11
- import SearchAutoCompleteContainer from './SearchAutoCompleteContainer';
12
- import AutocompleteQuery from './AutocompleteQuery.gql';
13
- import { ShopConfigContext } from '@jetshop/core/components/ConfigProvider';
14
-
15
- describe('SearchFieldBehaviour', () => {
16
- it('renders child as fn with args', () => {
17
- const { renderArg } = setup();
18
- expect(renderArg).toMatchSnapshot();
19
- });
20
-
21
- it('allows an initialValue to be set via props', async () => {
22
- const { renderArg } = setup({ initialValue: 'howdy neighbour' });
23
-
24
- expect(renderArg.term).toBe('howdy neighbour');
25
- });
26
-
27
- it('updates term param to match the input field value', () => {
28
- const { input, renderArg } = setup();
29
-
30
- fireEvent.change(input, { target: { value: 'boots' } });
31
-
32
- expect(renderArg.term).toBe('boots');
33
- });
34
-
35
- it('updates the debouncedTerm after a delay', async () => {
36
- // This also tests that the state isn't updated after the component unmounts
37
- // — we'd receive a warning from React
38
- const { input, renderArg } = setup();
39
-
40
- fireEvent.change(input, { target: { value: 'cats' } });
41
-
42
- await wait(() => expect(renderArg.debouncedTerm).toEqual('cats'));
43
- });
44
-
45
- it('executes search and returns results after debouncedTerm is set', async () => {
46
- const { input, childrenSpy, renderArg } = setup();
47
-
48
- fireEvent.change(input, { target: { value: 'autoc' } });
49
-
50
- await wait(() => expect(renderArg.debouncedTerm).toEqual('autoc'));
51
-
52
- // The child fn should have been called with loading set to true at some
53
- // point after the query was made
54
- await wait(() =>
55
- expect(childrenSpy).toHaveBeenCalledWith(
56
- expect.objectContaining({
57
- loading: true
58
- })
59
- )
60
- );
61
-
62
- // Wait for loading to finish
63
- await wait(() =>
64
- expect(childrenSpy).toHaveBeenLastCalledWith(
65
- expect.objectContaining({
66
- loading: false
67
- })
68
- )
69
- );
70
-
71
- // and then it should be called again with the actual results
72
- expect(childrenSpy).lastCalledWith(
73
- expect.objectContaining({
74
- loading: false,
75
- result: {
76
- products: {
77
- result: expect.arrayContaining([
78
- expect.objectContaining({
79
- id: 123
80
- }),
81
- expect.objectContaining({
82
- id: 321
83
- })
84
- ])
85
- }
86
- }
87
- })
88
- );
89
-
90
- fireEvent.change(input, { target: { value: 'autocomplet' } });
91
-
92
- await wait(() => expect(renderArg.debouncedTerm).toEqual('autocomplet'));
93
-
94
- expect(childrenSpy).toHaveBeenLastCalledWith(
95
- expect.objectContaining({
96
- result: {
97
- products: {
98
- result: expect.arrayContaining([
99
- expect.objectContaining({
100
- id: 123
101
- }),
102
- expect.not.objectContaining({
103
- id: 321
104
- })
105
- ])
106
- }
107
- }
108
- })
109
- );
110
- });
111
-
112
- it('updates the isDirty param when the input is dirty', async () => {
113
- const { childrenSpy, input, renderArg } = setup();
114
-
115
- expect(childrenSpy).toHaveBeenCalledTimes(1);
116
-
117
- expect(renderArg.isDirty).toBe(false);
118
- fireEvent.change(input, { target: { value: 'mock' } });
119
- expect(childrenSpy).toHaveBeenCalledTimes(2);
120
- expect(renderArg.isDirty).toBe(true);
121
-
122
- fireEvent.change(input, { target: { value: '' } });
123
- expect(renderArg.isDirty).toBe(false);
124
- });
125
-
126
- it('correctly sets isDirty if the initialValue prop is used', () => {
127
- const { input, renderArg } = setup({ initialValue: 'howdy' });
128
-
129
- expect(renderArg.isDirty).toBe(false);
130
- fireEvent.change(input, { target: { value: 'boots' } });
131
- expect(renderArg.isDirty).toBe(true);
132
- // An empty string is 'dirty' if initialValue is not an empty string…
133
- fireEvent.change(input, { target: { value: '' } });
134
- expect(renderArg.isDirty).toBe(true);
135
- fireEvent.change(input, { target: { value: 'howdy' } });
136
- expect(renderArg.isDirty).toBe(false);
137
- });
138
-
139
- it('automatically focuses the input on mount if `focusOnLoad` is set', () => {
140
- const { input } = setup();
141
- expect(input).not.toHaveFocus();
142
-
143
- cleanup();
144
-
145
- const { input: focusedInput } = setup({ focusOnLoad: true });
146
- expect(focusedInput).toHaveFocus();
147
- });
148
-
149
- it('accepts a custom onBlur event on getInputProps', async () => {
150
- const mockBlurFn = jest.fn();
151
- const { input } = setup({}, null, {
152
- getInputPropsOptions: { onBlur: mockBlurFn }
153
- });
154
-
155
- fireEvent.focus(input);
156
- await wait();
157
- fireEvent.blur(input);
158
-
159
- expect(mockBlurFn).toHaveBeenCalledTimes(1);
160
- });
161
-
162
- it('accepts a custom onFocus event on getInputProps', () => {
163
- const mockFocusFn = jest.fn();
164
- const { input } = setup({}, null, {
165
- getInputPropsOptions: { onFocus: mockFocusFn }
166
- });
167
-
168
- fireEvent.focus(input);
169
-
170
- expect(mockFocusFn).toHaveBeenCalledTimes(1);
171
- });
172
-
173
- it('provides the inputs ref via render props ', () => {
174
- const { input, renderArg } = setup();
175
-
176
- expect(renderArg.inputRef).toEqual(
177
- expect.objectContaining({
178
- current: input
179
- })
180
- );
181
- });
182
-
183
- it('allows focus to be controlled via render prop `updateFocus`', () => {
184
- const { input, renderArg } = setup();
185
-
186
- fireEvent.focus(input);
187
- renderArg.updateFocus('blur');
188
- expect(input).not.toHaveFocus();
189
- renderArg.updateFocus('focus');
190
- expect(input).toHaveFocus();
191
- });
192
-
193
- describe('`isOpen` render prop fn', () => {
194
- test('is true when the search field has focus', () => {
195
- const { input, renderArg } = setup();
196
-
197
- fireEvent.focus(input);
198
-
199
- expect(renderArg.isOpen).toBe(true);
200
- });
201
-
202
- test('is true when the search field has focus', () => {
203
- const { input, renderArg } = setup();
204
-
205
- fireEvent.focus(input);
206
-
207
- expect(renderArg.isOpen).toBe(true);
208
- });
209
-
210
- test('is false when the search field does not have focus', () => {
211
- const { input, renderArg } = setup();
212
-
213
- expect(renderArg.isOpen).toBe(false);
214
-
215
- fireEvent.focus(input);
216
- fireEvent.blur(input);
217
- expect(renderArg.isOpen).toBe(false);
218
- });
219
-
220
- test('is true when the search field loses focus and the `term` has changed', async () => {
221
- const { input, renderArg } = setup();
222
-
223
- fireEvent.focus(input);
224
- fireEvent.change(input, { target: { value: 'bootsandcats' } });
225
- fireEvent.blur(input);
226
- await wait();
227
- expect(renderArg.isOpen).toBe(true);
228
- });
229
- });
230
-
231
- describe('registers cancel button behaviour on the element using `getCancelProps()`', () => {
232
- test('that clears the input value when clicked', () => {
233
- const { input, cancel, renderArg } = setup();
234
-
235
- fireEvent.change(input, { target: { value: 'boots' } });
236
- expect(renderArg.term).toBe('boots');
237
-
238
- fireEvent.click(cancel);
239
-
240
- expect(renderArg.term).toBe('');
241
- });
242
-
243
- test('that accepts onClick handlers passed in to it', () => {
244
- const mockClickFn = jest.fn();
245
- const { cancel } = setup({}, null, {
246
- getCancelPropsOptions: { onClick: mockClickFn }
247
- });
248
-
249
- fireEvent.click(cancel);
250
-
251
- expect(mockClickFn).toHaveBeenCalledTimes(1);
252
- });
253
- });
254
-
255
- describe('triggers a full search', () => {
256
- test('when pressing enter key', async () => {
257
- const { input, getByText } = setup();
258
- fireEvent.focus(input);
259
- fireEvent.change(input, { target: { value: 'boots' } });
260
-
261
- fireEvent.keyDown(input, { key: 'Enter' });
262
-
263
- await waitForElement(() => getByText('you searched for ?term=boots'));
264
- });
265
- test('when clicking button with `triggerSearch` bound', async () => {
266
- const { input, submit, getByText } = setup();
267
- fireEvent.focus(input);
268
- fireEvent.change(input, { target: { value: 'boots' } });
269
-
270
- fireEvent.click(submit);
271
-
272
- await waitForElement(() => getByText('you searched for ?term=boots'));
273
- });
274
- test('with the value passed to `triggerSearch` if one is given', async () => {
275
- const { input, submit, getByText } = setup({}, null, {
276
- getSubmitOpts: 'search this!'
277
- });
278
- fireEvent.focus(input);
279
- fireEvent.change(input, { target: { value: 'boots' } });
280
-
281
- fireEvent.click(submit);
282
-
283
- await waitForElement(() => getByText(/search this!/i));
284
- });
285
- test('sets `isOpen` to false when triggering a full search', async () => {
286
- const { input, renderArg } = setup();
287
- fireEvent.change(input, { target: { value: 'boots' } });
288
- fireEvent.focus(input);
289
- expect(renderArg.isOpen).toBe(true);
290
- fireEvent.keyDown(input, { key: 'Enter' });
291
- expect(renderArg.isOpen).toBe(false);
292
- });
293
- });
294
-
295
- it('calls passed onCancel cb when search is cancelled', () => {
296
- const mockCancelCb = jest.fn();
297
- const { input, cancel } = setup({ onCancel: mockCancelCb });
298
-
299
- fireEvent.change(input, { target: { value: 'hello' } });
300
- fireEvent.click(cancel);
301
-
302
- expect(mockCancelCb).toHaveBeenCalledTimes(1);
303
- });
304
-
305
- it('calls passed onSubmit cb when search is submitted', () => {
306
- const mockSubmitFn = jest.fn();
307
- const { input, submit } = setup({ onSubmit: mockSubmitFn });
308
-
309
- fireEvent.change(input, { target: { value: 'hello' } });
310
- fireEvent.click(submit);
311
-
312
- expect(mockSubmitFn).toHaveBeenCalledTimes(1);
313
-
314
- fireEvent.change(input, { target: { value: 'wow' } });
315
- fireEvent.focus(input);
316
- fireEvent.keyDown(input, { key: 'Enter' });
317
-
318
- expect(mockSubmitFn).toHaveBeenCalledTimes(2);
319
- });
320
- });
321
-
322
- const mocks = [
323
- {
324
- request: {
325
- query: AutocompleteQuery,
326
- variables: {
327
- term: 'autoc'
328
- }
329
- },
330
- result: {
331
- data: {
332
- searchAutoComplete: {
333
- products: {
334
- result: [
335
- {
336
- name: 'autocomplete',
337
- id: 123,
338
- articleNumber: 123,
339
- primaryRoute: {
340
- id: 4353,
341
- slug: 'autocompleted-product',
342
- path: '/product/autocompleted-product'
343
- }
344
- },
345
- {
346
- name: 'autocomputed',
347
- id: 321,
348
- articleNumber: 321,
349
- primaryRoute: {
350
- id: 2737,
351
- slug: 'autocomputed-product',
352
- path: '/product/autocomputed-product'
353
- }
354
- }
355
- ]
356
- }
357
- }
358
- }
359
- }
360
- },
361
- {
362
- request: {
363
- query: AutocompleteQuery,
364
- variables: {
365
- term: 'autocomplet'
366
- }
367
- },
368
- result: {
369
- data: {
370
- searchAutoComplete: {
371
- products: {
372
- result: [
373
- {
374
- name: 'autocomplete',
375
- id: 123,
376
- articleNumber: 123,
377
- primaryRoute: {
378
- id: 345343,
379
- slug: 'autocompleted-product',
380
- path: '/product/autocompleted-product'
381
- }
382
- }
383
- ]
384
- }
385
- }
386
- }
387
- }
388
- }
389
- ];
390
-
391
- function setup(
392
- containerProps = {},
393
- renderFn,
394
- {
395
- getInputPropsOptions = {},
396
- getCancelPropsOptions = {},
397
- getSubmitOpts = undefined
398
- } = {}
399
- ) {
400
- const renderArg = {};
401
-
402
- const childrenSpy = jest.fn(controllerArg => {
403
- Object.assign(renderArg, controllerArg);
404
-
405
- if (typeof renderFn === 'function') return renderFn(controllerArg);
406
-
407
- return (
408
- <>
409
- <input
410
- data-testid="default-input-field"
411
- {...controllerArg.getInputProps(getInputPropsOptions)}
412
- />
413
- <button
414
- data-testid="cancel-button"
415
- {...controllerArg.getCancelProps(getCancelPropsOptions)}
416
- >
417
- Cancel
418
- </button>
419
- <button
420
- data-testid="submit-button"
421
- onClick={() => renderArg.triggerSearch(getSubmitOpts)}
422
- >
423
- Submit
424
- </button>
425
- <Switch>
426
- <Route
427
- path="/search"
428
- component={props => {
429
- return <div>you searched for {props.location.search}</div>;
430
- }}
431
- />
432
- </Switch>
433
- </>
434
- );
435
- });
436
-
437
- const utils = renderWithRouter(
438
- <ShopConfigContext.Provider
439
- value={{ routes: { search: { path: '/search' } } }}
440
- >
441
- <MockedProvider mocks={mocks} addTypename={false}>
442
- <SearchAutoCompleteContainer
443
- autocompleteQuery={AutocompleteQuery}
444
- {...containerProps}
445
- >
446
- {childrenSpy}
447
- </SearchAutoCompleteContainer>
448
- </MockedProvider>
449
- </ShopConfigContext.Provider>
450
- );
451
-
452
- return {
453
- ...utils,
454
- input: utils.queryByTestId('default-input-field'),
455
- cancel: utils.queryByTestId('cancel-button'),
456
- submit: utils.queryByTestId('submit-button'),
457
- childrenSpy,
458
- renderArg
459
- };
460
- }
1
+ import renderWithRouter from '@jetshop/core/test-utils/renderWithRouter';
2
+ import React from 'react';
3
+ import { MockedProvider } from '@apollo/react-testing';
4
+ import { Route, Switch } from 'react-router';
5
+ import {
6
+ cleanup,
7
+ fireEvent,
8
+ wait,
9
+ waitForElement
10
+ } from '@testing-library/react';
11
+ import SearchAutoCompleteContainer from './SearchAutoCompleteContainer';
12
+ import AutocompleteQuery from './AutocompleteQuery.gql';
13
+ import { ShopConfigContext } from '@jetshop/core/components/ConfigProvider';
14
+
15
+ describe('SearchFieldBehaviour', () => {
16
+ it('renders child as fn with args', () => {
17
+ const { renderArg } = setup();
18
+ expect(renderArg).toMatchSnapshot();
19
+ });
20
+
21
+ it('allows an initialValue to be set via props', async () => {
22
+ const { renderArg } = setup({ initialValue: 'howdy neighbour' });
23
+
24
+ expect(renderArg.term).toBe('howdy neighbour');
25
+ });
26
+
27
+ it('updates term param to match the input field value', () => {
28
+ const { input, renderArg } = setup();
29
+
30
+ fireEvent.change(input, { target: { value: 'boots' } });
31
+
32
+ expect(renderArg.term).toBe('boots');
33
+ });
34
+
35
+ it('updates the debouncedTerm after a delay', async () => {
36
+ // This also tests that the state isn't updated after the component unmounts
37
+ // — we'd receive a warning from React
38
+ const { input, renderArg } = setup();
39
+
40
+ fireEvent.change(input, { target: { value: 'cats' } });
41
+
42
+ await wait(() => expect(renderArg.debouncedTerm).toEqual('cats'));
43
+ });
44
+
45
+ it('executes search and returns results after debouncedTerm is set', async () => {
46
+ const { input, childrenSpy, renderArg } = setup();
47
+
48
+ fireEvent.change(input, { target: { value: 'autoc' } });
49
+
50
+ await wait(() => expect(renderArg.debouncedTerm).toEqual('autoc'));
51
+
52
+ // The child fn should have been called with loading set to true at some
53
+ // point after the query was made
54
+ await wait(() =>
55
+ expect(childrenSpy).toHaveBeenCalledWith(
56
+ expect.objectContaining({
57
+ loading: true
58
+ })
59
+ )
60
+ );
61
+
62
+ // Wait for loading to finish
63
+ await wait(() =>
64
+ expect(childrenSpy).toHaveBeenLastCalledWith(
65
+ expect.objectContaining({
66
+ loading: false
67
+ })
68
+ )
69
+ );
70
+
71
+ // and then it should be called again with the actual results
72
+ expect(childrenSpy).lastCalledWith(
73
+ expect.objectContaining({
74
+ loading: false,
75
+ result: {
76
+ products: {
77
+ result: expect.arrayContaining([
78
+ expect.objectContaining({
79
+ id: 123
80
+ }),
81
+ expect.objectContaining({
82
+ id: 321
83
+ })
84
+ ])
85
+ }
86
+ }
87
+ })
88
+ );
89
+
90
+ fireEvent.change(input, { target: { value: 'autocomplet' } });
91
+
92
+ await wait(() => expect(renderArg.debouncedTerm).toEqual('autocomplet'));
93
+
94
+ expect(childrenSpy).toHaveBeenLastCalledWith(
95
+ expect.objectContaining({
96
+ result: {
97
+ products: {
98
+ result: expect.arrayContaining([
99
+ expect.objectContaining({
100
+ id: 123
101
+ }),
102
+ expect.not.objectContaining({
103
+ id: 321
104
+ })
105
+ ])
106
+ }
107
+ }
108
+ })
109
+ );
110
+ });
111
+
112
+ it('updates the isDirty param when the input is dirty', async () => {
113
+ const { childrenSpy, input, renderArg } = setup();
114
+
115
+ expect(childrenSpy).toHaveBeenCalledTimes(1);
116
+
117
+ expect(renderArg.isDirty).toBe(false);
118
+ fireEvent.change(input, { target: { value: 'mock' } });
119
+ expect(childrenSpy).toHaveBeenCalledTimes(2);
120
+ expect(renderArg.isDirty).toBe(true);
121
+
122
+ fireEvent.change(input, { target: { value: '' } });
123
+ expect(renderArg.isDirty).toBe(false);
124
+ });
125
+
126
+ it('correctly sets isDirty if the initialValue prop is used', () => {
127
+ const { input, renderArg } = setup({ initialValue: 'howdy' });
128
+
129
+ expect(renderArg.isDirty).toBe(false);
130
+ fireEvent.change(input, { target: { value: 'boots' } });
131
+ expect(renderArg.isDirty).toBe(true);
132
+ // An empty string is 'dirty' if initialValue is not an empty string…
133
+ fireEvent.change(input, { target: { value: '' } });
134
+ expect(renderArg.isDirty).toBe(true);
135
+ fireEvent.change(input, { target: { value: 'howdy' } });
136
+ expect(renderArg.isDirty).toBe(false);
137
+ });
138
+
139
+ it('automatically focuses the input on mount if `focusOnLoad` is set', () => {
140
+ const { input } = setup();
141
+ expect(input).not.toHaveFocus();
142
+
143
+ cleanup();
144
+
145
+ const { input: focusedInput } = setup({ focusOnLoad: true });
146
+ expect(focusedInput).toHaveFocus();
147
+ });
148
+
149
+ it('accepts a custom onBlur event on getInputProps', async () => {
150
+ const mockBlurFn = jest.fn();
151
+ const { input } = setup({}, null, {
152
+ getInputPropsOptions: { onBlur: mockBlurFn }
153
+ });
154
+
155
+ fireEvent.focus(input);
156
+ await wait();
157
+ fireEvent.blur(input);
158
+
159
+ expect(mockBlurFn).toHaveBeenCalledTimes(1);
160
+ });
161
+
162
+ it('accepts a custom onFocus event on getInputProps', () => {
163
+ const mockFocusFn = jest.fn();
164
+ const { input } = setup({}, null, {
165
+ getInputPropsOptions: { onFocus: mockFocusFn }
166
+ });
167
+
168
+ fireEvent.focus(input);
169
+
170
+ expect(mockFocusFn).toHaveBeenCalledTimes(1);
171
+ });
172
+
173
+ it('provides the inputs ref via render props ', () => {
174
+ const { input, renderArg } = setup();
175
+
176
+ expect(renderArg.inputRef).toEqual(
177
+ expect.objectContaining({
178
+ current: input
179
+ })
180
+ );
181
+ });
182
+
183
+ it('allows focus to be controlled via render prop `updateFocus`', () => {
184
+ const { input, renderArg } = setup();
185
+
186
+ fireEvent.focus(input);
187
+ renderArg.updateFocus('blur');
188
+ expect(input).not.toHaveFocus();
189
+ renderArg.updateFocus('focus');
190
+ expect(input).toHaveFocus();
191
+ });
192
+
193
+ describe('`isOpen` render prop fn', () => {
194
+ test('is true when the search field has focus', () => {
195
+ const { input, renderArg } = setup();
196
+
197
+ fireEvent.focus(input);
198
+
199
+ expect(renderArg.isOpen).toBe(true);
200
+ });
201
+
202
+ test('is true when the search field has focus', () => {
203
+ const { input, renderArg } = setup();
204
+
205
+ fireEvent.focus(input);
206
+
207
+ expect(renderArg.isOpen).toBe(true);
208
+ });
209
+
210
+ test('is false when the search field does not have focus', () => {
211
+ const { input, renderArg } = setup();
212
+
213
+ expect(renderArg.isOpen).toBe(false);
214
+
215
+ fireEvent.focus(input);
216
+ fireEvent.blur(input);
217
+ expect(renderArg.isOpen).toBe(false);
218
+ });
219
+
220
+ test('is true when the search field loses focus and the `term` has changed', async () => {
221
+ const { input, renderArg } = setup();
222
+
223
+ fireEvent.focus(input);
224
+ fireEvent.change(input, { target: { value: 'bootsandcats' } });
225
+ fireEvent.blur(input);
226
+ await wait();
227
+ expect(renderArg.isOpen).toBe(true);
228
+ });
229
+ });
230
+
231
+ describe('registers cancel button behaviour on the element using `getCancelProps()`', () => {
232
+ test('that clears the input value when clicked', () => {
233
+ const { input, cancel, renderArg } = setup();
234
+
235
+ fireEvent.change(input, { target: { value: 'boots' } });
236
+ expect(renderArg.term).toBe('boots');
237
+
238
+ fireEvent.click(cancel);
239
+
240
+ expect(renderArg.term).toBe('');
241
+ });
242
+
243
+ test('that accepts onClick handlers passed in to it', () => {
244
+ const mockClickFn = jest.fn();
245
+ const { cancel } = setup({}, null, {
246
+ getCancelPropsOptions: { onClick: mockClickFn }
247
+ });
248
+
249
+ fireEvent.click(cancel);
250
+
251
+ expect(mockClickFn).toHaveBeenCalledTimes(1);
252
+ });
253
+ });
254
+
255
+ describe('triggers a full search', () => {
256
+ test('when pressing enter key', async () => {
257
+ const { input, getByText } = setup();
258
+ fireEvent.focus(input);
259
+ fireEvent.change(input, { target: { value: 'boots' } });
260
+
261
+ fireEvent.keyDown(input, { key: 'Enter' });
262
+
263
+ await waitForElement(() => getByText('you searched for ?term=boots'));
264
+ });
265
+ test('when clicking button with `triggerSearch` bound', async () => {
266
+ const { input, submit, getByText } = setup();
267
+ fireEvent.focus(input);
268
+ fireEvent.change(input, { target: { value: 'boots' } });
269
+
270
+ fireEvent.click(submit);
271
+
272
+ await waitForElement(() => getByText('you searched for ?term=boots'));
273
+ });
274
+ test('with the value passed to `triggerSearch` if one is given', async () => {
275
+ const { input, submit, getByText } = setup({}, null, {
276
+ getSubmitOpts: 'search this!'
277
+ });
278
+ fireEvent.focus(input);
279
+ fireEvent.change(input, { target: { value: 'boots' } });
280
+
281
+ fireEvent.click(submit);
282
+
283
+ await waitForElement(() => getByText(/search this!/i));
284
+ });
285
+ test('sets `isOpen` to false when triggering a full search', async () => {
286
+ const { input, renderArg } = setup();
287
+ fireEvent.change(input, { target: { value: 'boots' } });
288
+ fireEvent.focus(input);
289
+ expect(renderArg.isOpen).toBe(true);
290
+ fireEvent.keyDown(input, { key: 'Enter' });
291
+ expect(renderArg.isOpen).toBe(false);
292
+ });
293
+ });
294
+
295
+ it('calls passed onCancel cb when search is cancelled', () => {
296
+ const mockCancelCb = jest.fn();
297
+ const { input, cancel } = setup({ onCancel: mockCancelCb });
298
+
299
+ fireEvent.change(input, { target: { value: 'hello' } });
300
+ fireEvent.click(cancel);
301
+
302
+ expect(mockCancelCb).toHaveBeenCalledTimes(1);
303
+ });
304
+
305
+ it('calls passed onSubmit cb when search is submitted', () => {
306
+ const mockSubmitFn = jest.fn();
307
+ const { input, submit } = setup({ onSubmit: mockSubmitFn });
308
+
309
+ fireEvent.change(input, { target: { value: 'hello' } });
310
+ fireEvent.click(submit);
311
+
312
+ expect(mockSubmitFn).toHaveBeenCalledTimes(1);
313
+
314
+ fireEvent.change(input, { target: { value: 'wow' } });
315
+ fireEvent.focus(input);
316
+ fireEvent.keyDown(input, { key: 'Enter' });
317
+
318
+ expect(mockSubmitFn).toHaveBeenCalledTimes(2);
319
+ });
320
+ });
321
+
322
+ const mocks = [
323
+ {
324
+ request: {
325
+ query: AutocompleteQuery,
326
+ variables: {
327
+ term: 'autoc'
328
+ }
329
+ },
330
+ result: {
331
+ data: {
332
+ searchAutoComplete: {
333
+ products: {
334
+ result: [
335
+ {
336
+ name: 'autocomplete',
337
+ id: 123,
338
+ articleNumber: 123,
339
+ primaryRoute: {
340
+ id: 4353,
341
+ slug: 'autocompleted-product',
342
+ path: '/product/autocompleted-product'
343
+ }
344
+ },
345
+ {
346
+ name: 'autocomputed',
347
+ id: 321,
348
+ articleNumber: 321,
349
+ primaryRoute: {
350
+ id: 2737,
351
+ slug: 'autocomputed-product',
352
+ path: '/product/autocomputed-product'
353
+ }
354
+ }
355
+ ]
356
+ }
357
+ }
358
+ }
359
+ }
360
+ },
361
+ {
362
+ request: {
363
+ query: AutocompleteQuery,
364
+ variables: {
365
+ term: 'autocomplet'
366
+ }
367
+ },
368
+ result: {
369
+ data: {
370
+ searchAutoComplete: {
371
+ products: {
372
+ result: [
373
+ {
374
+ name: 'autocomplete',
375
+ id: 123,
376
+ articleNumber: 123,
377
+ primaryRoute: {
378
+ id: 345343,
379
+ slug: 'autocompleted-product',
380
+ path: '/product/autocompleted-product'
381
+ }
382
+ }
383
+ ]
384
+ }
385
+ }
386
+ }
387
+ }
388
+ }
389
+ ];
390
+
391
+ function setup(
392
+ containerProps = {},
393
+ renderFn,
394
+ {
395
+ getInputPropsOptions = {},
396
+ getCancelPropsOptions = {},
397
+ getSubmitOpts = undefined
398
+ } = {}
399
+ ) {
400
+ const renderArg = {};
401
+
402
+ const childrenSpy = jest.fn(controllerArg => {
403
+ Object.assign(renderArg, controllerArg);
404
+
405
+ if (typeof renderFn === 'function') return renderFn(controllerArg);
406
+
407
+ return (
408
+ <>
409
+ <input
410
+ data-testid="default-input-field"
411
+ {...controllerArg.getInputProps(getInputPropsOptions)}
412
+ />
413
+ <button
414
+ data-testid="cancel-button"
415
+ {...controllerArg.getCancelProps(getCancelPropsOptions)}
416
+ >
417
+ Cancel
418
+ </button>
419
+ <button
420
+ data-testid="submit-button"
421
+ onClick={() => renderArg.triggerSearch(getSubmitOpts)}
422
+ >
423
+ Submit
424
+ </button>
425
+ <Switch>
426
+ <Route
427
+ path="/search"
428
+ component={props => {
429
+ return <div>you searched for {props.location.search}</div>;
430
+ }}
431
+ />
432
+ </Switch>
433
+ </>
434
+ );
435
+ });
436
+
437
+ const utils = renderWithRouter(
438
+ <ShopConfigContext.Provider
439
+ value={{ routes: { search: { path: '/search' } } }}
440
+ >
441
+ <MockedProvider mocks={mocks} addTypename={false}>
442
+ <SearchAutoCompleteContainer
443
+ autocompleteQuery={AutocompleteQuery}
444
+ {...containerProps}
445
+ >
446
+ {childrenSpy}
447
+ </SearchAutoCompleteContainer>
448
+ </MockedProvider>
449
+ </ShopConfigContext.Provider>
450
+ );
451
+
452
+ return {
453
+ ...utils,
454
+ input: utils.queryByTestId('default-input-field'),
455
+ cancel: utils.queryByTestId('cancel-button'),
456
+ submit: utils.queryByTestId('submit-button'),
457
+ childrenSpy,
458
+ renderArg
459
+ };
460
+ }