@blaze-cms/react-page-builder 0.139.0-project-admin-customisations.0 → 0.139.1-core-styles.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 (252) hide show
  1. package/CHANGELOG.md +77 -3
  2. package/README.md +9 -0
  3. package/lib/components/Banner/BannerRender.js +2 -2
  4. package/lib/components/Banner/BannerRender.js.map +1 -1
  5. package/lib/components/Banner/helpers.js +2 -2
  6. package/lib/components/Banner/helpers.js.map +1 -1
  7. package/lib/components/BlazeLink.js +2 -2
  8. package/lib/components/BlazeLink.js.map +1 -1
  9. package/lib/components/Button.js +2 -2
  10. package/lib/components/Button.js.map +1 -1
  11. package/lib/components/Card/Card.js +5 -3
  12. package/lib/components/Card/Card.js.map +1 -1
  13. package/lib/components/Card/CardsContainer.js +3 -6
  14. package/lib/components/Card/CardsContainer.js.map +1 -1
  15. package/lib/components/Card/CardsRender.js +3 -4
  16. package/lib/components/Card/CardsRender.js.map +1 -1
  17. package/lib/components/Card/helpers/filter-query-setup.js +2 -2
  18. package/lib/components/Card/helpers/filter-query-setup.js.map +1 -1
  19. package/lib/components/Carousel/Carousel.js +26 -17
  20. package/lib/components/Carousel/Carousel.js.map +1 -1
  21. package/lib/components/Carousel/CarouselRender/CarouselRender.js +34 -60
  22. package/lib/components/Carousel/CarouselRender/CarouselRender.js.map +1 -1
  23. package/lib/components/Carousel/hooks/useCarouselNavigation.js +56 -0
  24. package/lib/components/Carousel/hooks/useCarouselNavigation.js.map +1 -0
  25. package/lib/components/ClickWrapper.js +2 -2
  26. package/lib/components/ClickWrapper.js.map +1 -1
  27. package/lib/components/Code/Code.js +2 -2
  28. package/lib/components/Code/Code.js.map +1 -1
  29. package/lib/components/Image/Image.js +2 -2
  30. package/lib/components/Image/Image.js.map +1 -1
  31. package/lib/components/Image/ImageFactory.js +20 -8
  32. package/lib/components/Image/ImageFactory.js.map +1 -1
  33. package/lib/components/Image/ImageRender.js +8 -2
  34. package/lib/components/Image/ImageRender.js.map +1 -1
  35. package/lib/components/Layout/Layout.js +9 -5
  36. package/lib/components/Layout/Layout.js.map +1 -1
  37. package/lib/components/List/ListBuilder.js +2 -2
  38. package/lib/components/List/ListBuilder.js.map +1 -1
  39. package/lib/components/List/ListFactory.js +2 -2
  40. package/lib/components/List/ListFactory.js.map +1 -1
  41. package/lib/components/List/components/Cards/CardsRender.js +2 -2
  42. package/lib/components/List/components/Cards/CardsRender.js.map +1 -1
  43. package/lib/components/List/components/Full/FullRender.js +9 -5
  44. package/lib/components/List/components/Full/FullRender.js.map +1 -1
  45. package/lib/components/List/components/Full/FullRenderItem.js +2 -2
  46. package/lib/components/List/components/Full/FullRenderItem.js.map +1 -1
  47. package/lib/components/List/components/Pagination/ListPagination.js +2 -2
  48. package/lib/components/List/components/Pagination/ListPagination.js.map +1 -1
  49. package/lib/components/List/helpers/build-az-url.js +2 -2
  50. package/lib/components/List/helpers/build-az-url.js.map +1 -1
  51. package/lib/components/List/helpers/build-pagination-url.js +2 -2
  52. package/lib/components/List/helpers/build-pagination-url.js.map +1 -1
  53. package/lib/components/SearchContent/SearchContent.js +55 -52
  54. package/lib/components/SearchContent/SearchContent.js.map +1 -1
  55. package/lib/components/SearchContent/SearchContentResults.js +16 -17
  56. package/lib/components/SearchContent/SearchContentResults.js.map +1 -1
  57. package/lib/components/SearchContent/SearchContentToggleIcon.js +8 -16
  58. package/lib/components/SearchContent/SearchContentToggleIcon.js.map +1 -1
  59. package/lib/components/SearchContent/constants.js +12 -0
  60. package/lib/components/SearchContent/constants.js.map +1 -0
  61. package/lib/components/SearchFilter/components/Range.js +2 -2
  62. package/lib/components/SearchFilter/components/Range.js.map +1 -1
  63. package/lib/components/SearchFilter/searchFilterReducer.js +2 -2
  64. package/lib/components/SearchFilterSort/helpers/update-sort.js +2 -2
  65. package/lib/components/SearchFilterSort/helpers/update-sort.js.map +1 -1
  66. package/lib/components/TextBlock/index.js +2 -2
  67. package/lib/components/TextBlock/index.js.map +1 -1
  68. package/lib/components/Video/Video.js +2 -2
  69. package/lib/components/Video/Video.js.map +1 -1
  70. package/lib/components/Video/providers/JWPlayer/JWPlayerProvider.js +2 -2
  71. package/lib/components/Video/providers/JWPlayer/JWPlayerProvider.js.map +1 -1
  72. package/lib/helpers/append-images.js +2 -2
  73. package/lib/helpers/build-raw-query-base.js +2 -2
  74. package/lib/helpers/build-raw-query-base.js.map +1 -1
  75. package/lib/helpers/build-raw-query.js +2 -2
  76. package/lib/helpers/build-raw-query.js.map +1 -1
  77. package/lib/helpers/get-banner-data.js +2 -2
  78. package/lib/helpers/get-click-wrapper-options.js +2 -2
  79. package/lib/helpers/get-click-wrapper-options.js.map +1 -1
  80. package/lib/helpers/get-entities-with-banner.js +2 -2
  81. package/lib/helpers/get-entities-with-banner.js.map +1 -1
  82. package/lib/helpers/get-generic-props.js +2 -2
  83. package/lib/helpers/get-generic-props.js.map +1 -1
  84. package/lib/helpers/get-generic-render-variables.js +2 -2
  85. package/lib/helpers/get-generic-render-variables.js.map +1 -1
  86. package/lib/helpers/inject-multiple-banners/get-banners-for-nodes/get-banners-for-nodes.js +2 -2
  87. package/lib/helpers/inject-multiple-banners/get-banners-for-nodes/get-banners-for-nodes.js.map +1 -1
  88. package/lib/helpers/process-data-summary-value.js +2 -2
  89. package/lib/helpers/process-data-summary-value.js.map +1 -1
  90. package/lib/helpers/remove-unwanted-characters.js +2 -2
  91. package/lib/helpers/render-children.js +2 -2
  92. package/lib/helpers/render-children.js.map +1 -1
  93. package/lib/helpers/split-children.js +2 -2
  94. package/lib/helpers/update-childrens-parent.js +2 -2
  95. package/lib/hooks/helpers/RenderComponent.js +9 -2
  96. package/lib/hooks/helpers/RenderComponent.js.map +1 -1
  97. package/lib/hooks/helpers/append-gtm-classname.js +2 -2
  98. package/lib/hooks/helpers/append-gtm-classname.js.map +1 -1
  99. package/lib/hooks/helpers/buildPBComponents.js +2 -2
  100. package/lib/hooks/helpers/buildPBComponents.js.map +1 -1
  101. package/lib/hooks/helpers/get-lightbox-images.js +2 -2
  102. package/lib/hooks/helpers/get-lightbox-images.js.map +1 -1
  103. package/lib/hooks/helpers/getVariant.js +18 -0
  104. package/lib/hooks/helpers/getVariant.js.map +1 -0
  105. package/lib/hooks/helpers/inject-element-banners.js +2 -2
  106. package/lib/hooks/helpers/inject-element-banners.js.map +1 -1
  107. package/lib/hooks/helpers/inject-textblock-banners.js +2 -2
  108. package/lib/hooks/helpers/inject-textblock-banners.js.map +1 -1
  109. package/lib/hooks/use-get-image-id-from-relation.js +2 -2
  110. package/lib/hooks/use-get-image-id-from-relation.js.map +1 -1
  111. package/lib/hooks/use-get-images.js +4 -3
  112. package/lib/hooks/use-get-images.js.map +1 -1
  113. package/lib/index.js +13 -0
  114. package/lib/index.js.map +1 -1
  115. package/lib/utils/component-map.js +4 -4
  116. package/lib/utils/component-map.js.map +1 -1
  117. package/lib/utils/get-class-modifiers.js +2 -2
  118. package/lib/utils/get-class-modifiers.js.map +1 -1
  119. package/lib/utils/index.js +7 -0
  120. package/lib/utils/index.js.map +1 -1
  121. package/lib/utils/variant-handler.js +40 -0
  122. package/lib/utils/variant-handler.js.map +1 -0
  123. package/lib/variants/index.js +10 -0
  124. package/lib/variants/index.js.map +1 -0
  125. package/lib-es/components/Banner/BannerRender.js +2 -2
  126. package/lib-es/components/Banner/helpers.js +2 -2
  127. package/lib-es/components/BlazeLink.js +2 -2
  128. package/lib-es/components/Button.js +2 -2
  129. package/lib-es/components/Card/Card.js +5 -3
  130. package/lib-es/components/Card/Card.js.map +1 -1
  131. package/lib-es/components/Card/CardsContainer.js +4 -7
  132. package/lib-es/components/Card/CardsContainer.js.map +1 -1
  133. package/lib-es/components/Card/CardsRender.js +3 -4
  134. package/lib-es/components/Card/CardsRender.js.map +1 -1
  135. package/lib-es/components/Card/helpers/filter-query-setup.js +2 -2
  136. package/lib-es/components/Carousel/Carousel.js +27 -17
  137. package/lib-es/components/Carousel/Carousel.js.map +1 -1
  138. package/lib-es/components/Carousel/CarouselRender/CarouselRender.js +33 -53
  139. package/lib-es/components/Carousel/CarouselRender/CarouselRender.js.map +1 -1
  140. package/lib-es/components/Carousel/hooks/useCarouselNavigation.js +49 -0
  141. package/lib-es/components/Carousel/hooks/useCarouselNavigation.js.map +1 -0
  142. package/lib-es/components/ClickWrapper.js +2 -2
  143. package/lib-es/components/Code/Code.js +2 -2
  144. package/lib-es/components/Image/Image.js +2 -2
  145. package/lib-es/components/Image/ImageFactory.js +18 -8
  146. package/lib-es/components/Image/ImageFactory.js.map +1 -1
  147. package/lib-es/components/Image/ImageRender.js +9 -3
  148. package/lib-es/components/Image/ImageRender.js.map +1 -1
  149. package/lib-es/components/Layout/Layout.js +10 -6
  150. package/lib-es/components/Layout/Layout.js.map +1 -1
  151. package/lib-es/components/List/ListBuilder.js +2 -2
  152. package/lib-es/components/List/ListFactory.js +2 -2
  153. package/lib-es/components/List/components/Cards/CardsRender.js +2 -2
  154. package/lib-es/components/List/components/Full/FullRender.js +11 -7
  155. package/lib-es/components/List/components/Full/FullRender.js.map +1 -1
  156. package/lib-es/components/List/components/Full/FullRenderItem.js +2 -2
  157. package/lib-es/components/List/components/Pagination/ListPagination.js +2 -2
  158. package/lib-es/components/List/helpers/build-az-url.js +2 -2
  159. package/lib-es/components/List/helpers/build-pagination-url.js +2 -2
  160. package/lib-es/components/SearchContent/SearchContent.js +53 -49
  161. package/lib-es/components/SearchContent/SearchContent.js.map +1 -1
  162. package/lib-es/components/SearchContent/SearchContentResults.js +16 -17
  163. package/lib-es/components/SearchContent/SearchContentResults.js.map +1 -1
  164. package/lib-es/components/SearchContent/SearchContentToggleIcon.js +13 -23
  165. package/lib-es/components/SearchContent/SearchContentToggleIcon.js.map +1 -1
  166. package/lib-es/components/SearchContent/constants.js +4 -0
  167. package/lib-es/components/SearchContent/constants.js.map +1 -0
  168. package/lib-es/components/SearchFilter/components/Range.js +2 -2
  169. package/lib-es/components/SearchFilter/searchFilterReducer.js +2 -2
  170. package/lib-es/components/SearchFilterSort/helpers/update-sort.js +2 -2
  171. package/lib-es/components/TextBlock/index.js +2 -2
  172. package/lib-es/components/Video/Video.js +2 -2
  173. package/lib-es/components/Video/providers/JWPlayer/JWPlayerProvider.js +2 -2
  174. package/lib-es/helpers/append-images.js +2 -2
  175. package/lib-es/helpers/build-raw-query-base.js +2 -2
  176. package/lib-es/helpers/build-raw-query.js +2 -2
  177. package/lib-es/helpers/get-banner-data.js +2 -2
  178. package/lib-es/helpers/get-click-wrapper-options.js +2 -2
  179. package/lib-es/helpers/get-entities-with-banner.js +2 -2
  180. package/lib-es/helpers/get-generic-props.js +2 -2
  181. package/lib-es/helpers/get-generic-render-variables.js +2 -2
  182. package/lib-es/helpers/inject-multiple-banners/get-banners-for-nodes/get-banners-for-nodes.js +2 -2
  183. package/lib-es/helpers/process-data-summary-value.js +2 -2
  184. package/lib-es/helpers/remove-unwanted-characters.js +2 -2
  185. package/lib-es/helpers/render-children.js +2 -2
  186. package/lib-es/helpers/split-children.js +2 -2
  187. package/lib-es/helpers/update-childrens-parent.js +2 -2
  188. package/lib-es/hooks/helpers/RenderComponent.js +5 -2
  189. package/lib-es/hooks/helpers/RenderComponent.js.map +1 -1
  190. package/lib-es/hooks/helpers/append-gtm-classname.js +2 -2
  191. package/lib-es/hooks/helpers/buildPBComponents.js +2 -2
  192. package/lib-es/hooks/helpers/get-lightbox-images.js +2 -2
  193. package/lib-es/hooks/helpers/getVariant.js +14 -0
  194. package/lib-es/hooks/helpers/getVariant.js.map +1 -0
  195. package/lib-es/hooks/helpers/inject-element-banners.js +2 -2
  196. package/lib-es/hooks/helpers/inject-textblock-banners.js +2 -2
  197. package/lib-es/hooks/use-get-image-id-from-relation.js +2 -2
  198. package/lib-es/hooks/use-get-image-id-from-relation.js.map +1 -1
  199. package/lib-es/hooks/use-get-images.js +4 -4
  200. package/lib-es/hooks/use-get-images.js.map +1 -1
  201. package/lib-es/index.js +2 -1
  202. package/lib-es/index.js.map +1 -1
  203. package/lib-es/utils/component-map.js +4 -4
  204. package/lib-es/utils/component-map.js.map +1 -1
  205. package/lib-es/utils/get-class-modifiers.js +2 -2
  206. package/lib-es/utils/index.js +2 -1
  207. package/lib-es/utils/index.js.map +1 -1
  208. package/lib-es/utils/variant-handler.js +26 -0
  209. package/lib-es/utils/variant-handler.js.map +1 -0
  210. package/lib-es/variants/index.js +2 -0
  211. package/lib-es/variants/index.js.map +1 -0
  212. package/package.json +11 -11
  213. package/src/components/Card/Card.js +1 -2
  214. package/src/components/Card/CardsContainer.js +0 -3
  215. package/src/components/Card/CardsRender.js +0 -1
  216. package/src/components/Carousel/Carousel.js +28 -12
  217. package/src/components/Carousel/CarouselRender/CarouselRender.js +36 -56
  218. package/src/components/Carousel/hooks/useCarouselNavigation.js +50 -0
  219. package/src/components/Image/ImageFactory.js +20 -5
  220. package/src/components/Image/ImageRender.js +14 -8
  221. package/src/components/Layout/Layout.js +8 -5
  222. package/src/components/List/components/Full/FullRender.js +11 -3
  223. package/src/components/SearchContent/SearchContent.js +66 -52
  224. package/src/components/SearchContent/SearchContentResults.js +17 -17
  225. package/src/components/SearchContent/SearchContentToggleIcon.js +10 -23
  226. package/src/components/SearchContent/constants.js +6 -0
  227. package/src/hooks/helpers/RenderComponent.js +4 -0
  228. package/src/hooks/helpers/getVariant.js +11 -0
  229. package/src/hooks/use-get-image-id-from-relation.js +13 -2
  230. package/src/hooks/use-get-images.js +4 -4
  231. package/src/index.js +2 -1
  232. package/src/utils/component-map.js +4 -5
  233. package/src/utils/index.js +9 -1
  234. package/src/utils/variant-handler.js +33 -0
  235. package/src/variants/index.js +1 -0
  236. package/tests/unit/src/components/Carousel/Carousel.test.js +23 -0
  237. package/tests/unit/src/components/Carousel/CarouselRender/CarouselRender.test.js +14 -22
  238. package/tests/unit/src/components/Carousel/__snapshots__/Carousel.test.js.snap +10 -0
  239. package/tests/unit/src/components/Image/ImageFactory.test.js +20 -3
  240. package/tests/unit/src/components/Image/ImageRender.test.js +12 -0
  241. package/tests/unit/src/components/Image/__snapshots__/ImageFactory.test.js.snap +24 -0
  242. package/tests/unit/src/components/Image/__snapshots__/ImageRender.test.js.snap +9 -0
  243. package/tests/unit/src/components/Image/mocks.js +49 -1
  244. package/tests/unit/src/components/Layout/Layout.test.js +11 -0
  245. package/tests/unit/src/components/List/components/Full/FullRender.test.js +14 -1
  246. package/tests/unit/src/components/List/components/Full/__snapshots__/FullRender.test.js.snap +24 -6
  247. package/tests/unit/src/components/List/components/mocks.js +9 -3
  248. package/tests/unit/src/components/Menu/__snapshots__/Menu.test.js.snap +1 -1
  249. package/tests/unit/src/components/PlaceholderIcon/__snapshots__/index.test.js.snap +4 -6
  250. package/tests/unit/src/components/SearchContent/SearchContent.test.js +32 -7
  251. package/tests/unit/src/components/SearchContent/__snapshots__/SearchContent.test.js.snap +66 -2
  252. package/tests/unit/src/utils/variant-handler.test.js +41 -0
@@ -0,0 +1,11 @@
1
+ import { variantHandler } from '../../utils';
2
+
3
+ export default function getVariant(settings) {
4
+ const { variant } = settings;
5
+ if (!variant) return [null, {}];
6
+ const { VariantComponent, getSettings } = variantHandler.get(variant) || {};
7
+ const variantSettings =
8
+ !!getSettings && typeof getSettings === 'function' ? getSettings(settings) : settings;
9
+
10
+ return [VariantComponent, variantSettings];
11
+ }
@@ -1,9 +1,20 @@
1
1
  import { useQuery } from '@apollo/client';
2
2
  import { generateSingleItemQuery } from '../application/query';
3
3
 
4
- function useGetImageIdFromRelation(id, imageRelation, actions, isUsingRelationImage, isPreview) {
4
+ function useGetImageIdFromRelation(
5
+ id,
6
+ imageRelation,
7
+ actions,
8
+ isUsingRelationImage,
9
+ isPreview,
10
+ hasImgSrc
11
+ ) {
5
12
  const skip =
6
- !id || typeof id !== 'string' || !isUsingRelationImage || !Object.keys(actions).length;
13
+ !id ||
14
+ hasImgSrc ||
15
+ typeof id !== 'string' ||
16
+ !isUsingRelationImage ||
17
+ !Object.keys(actions).length;
7
18
 
8
19
  const [imageRelationData = ''] = imageRelation;
9
20
  const [relationName = '', relationProp = ''] = imageRelationData.split('.');
@@ -1,7 +1,7 @@
1
1
  import { useQuery } from '@apollo/client';
2
2
  import { getFiles, getFileById } from '../application/query';
3
3
 
4
- function shouldSkip(id) {
4
+ function checkShouldSkip(id) {
5
5
  return !id || (Array.isArray(id) && !id.length);
6
6
  }
7
7
 
@@ -10,11 +10,11 @@ const getWhereQuery = id => {
10
10
  return { where: { id: { _in: inClause } } };
11
11
  };
12
12
 
13
- const useGetImages = (id, hasMultipleIds = false) => {
14
- const skip = shouldSkip(id);
13
+ const useGetImages = (id, hasMultipleIds = false, skip = false) => {
14
+ const shouldSkip = skip || checkShouldSkip(id);
15
15
  const variables = hasMultipleIds ? getWhereQuery(id) : { id };
16
16
  const currentQuery = hasMultipleIds ? getFiles : getFileById;
17
- const { data = {}, loading, error } = useQuery(currentQuery, { variables, skip });
17
+ const { data = {}, loading, error } = useQuery(currentQuery, { variables, skip: shouldSkip });
18
18
 
19
19
  return { data, loading, error };
20
20
  };
package/src/index.js CHANGED
@@ -1,8 +1,9 @@
1
1
  export { default as buildPBComponents } from './hooks/helpers/buildPBComponents';
2
2
  export { default as getLightboxImages } from './hooks/helpers/get-lightbox-images';
3
3
  export { default as getComponent } from './hooks/helpers/getComponent';
4
- export { componentMap, getClassModifiers } from './utils';
4
+ export { componentMap, variantHandler, getClassModifiers } from './utils';
5
5
  export { default as components } from './components';
6
+ export { default as variants } from './variants';
6
7
  export {
7
8
  getAction,
8
9
  generateSingleItemQuery,
@@ -1,8 +1,7 @@
1
1
  import { BlazeError } from '@blaze-cms/core-errors';
2
2
 
3
- function componentMap() {
3
+ function componentMapHandler() {
4
4
  const components = new Map();
5
-
6
5
  function get(key) {
7
6
  return components.get(key);
8
7
  }
@@ -18,7 +17,7 @@ function componentMap() {
18
17
 
19
18
  function validate(key, component) {
20
19
  if (!key || !component) throw new BlazeError('Component requires key and component');
21
- if (components.has(key) && key !== 'array') throw new BlazeError(`Component already exist`);
20
+ if (components.has(key) && key !== 'array') throw new BlazeError(`Component already exists`);
22
21
  }
23
22
 
24
23
  return {
@@ -29,6 +28,6 @@ function componentMap() {
29
28
  };
30
29
  }
31
30
 
32
- const test = componentMap();
31
+ const componentMap = componentMapHandler();
33
32
 
34
- export default test;
33
+ export default componentMap;
@@ -1,7 +1,15 @@
1
1
  import getClassModifiers from './get-class-modifiers';
2
2
  import componentMap from './component-map';
3
+ import variantHandler from './variant-handler';
3
4
  import isObjectEmpty from './is-object-empty';
4
5
  import getImageData from './get-image-data';
5
6
  import getPropsToDisplayModifiers from './get-props-to-display-modifiers';
6
7
 
7
- export { getClassModifiers, componentMap, isObjectEmpty, getImageData, getPropsToDisplayModifiers };
8
+ export {
9
+ componentMap,
10
+ variantHandler,
11
+ getClassModifiers,
12
+ isObjectEmpty,
13
+ getImageData,
14
+ getPropsToDisplayModifiers
15
+ };
@@ -0,0 +1,33 @@
1
+ import { BlazeError } from '@blaze-cms/core-errors';
2
+
3
+ function variantMapHandler() {
4
+ const variants = new Map();
5
+
6
+ function get(key) {
7
+ return variants.get(key);
8
+ }
9
+
10
+ function getAll() {
11
+ return Array.from(variants.entries());
12
+ }
13
+
14
+ function add(key, variant) {
15
+ validate(key, variant);
16
+ variants.set(key, variant);
17
+ }
18
+
19
+ function validate(key, variant) {
20
+ if (!key || !variant) throw new BlazeError('Variant requires key and component');
21
+ if (variants.has(key) && key !== 'array') throw new BlazeError(`Variant already exists`);
22
+ }
23
+
24
+ return {
25
+ add,
26
+ get,
27
+ getAll
28
+ };
29
+ }
30
+
31
+ const variantHandler = variantMapHandler();
32
+
33
+ export default variantHandler;
@@ -0,0 +1 @@
1
+ export default {};
@@ -15,8 +15,10 @@ const getMockedProps = overrides => ({
15
15
  imageId,
16
16
  toggleModal: jest.fn(),
17
17
  handleSelectedImage: jest.fn(),
18
+ displayCount: true,
18
19
  ...overrides
19
20
  });
21
+
20
22
  const mock = [
21
23
  {
22
24
  request: {
@@ -40,6 +42,8 @@ const mock = [
40
42
  }
41
43
  ];
42
44
 
45
+ const MockedVariantComponent = () => <div>Variation component</div>;
46
+
43
47
  const setup = props => {
44
48
  const mockComponent = (
45
49
  <MockedProvider mocks={mock}>
@@ -88,4 +92,23 @@ describe('Carousel component', () => {
88
92
  setup(mockedProps);
89
93
  expect(screen.getByText(caption)).toBeInTheDocument();
90
94
  });
95
+
96
+ it('should render VariantComponent if it is set', () => {
97
+ const mockedProps = getMockedProps({ VariantComponent: MockedVariantComponent });
98
+ const { container } = setup(mockedProps);
99
+
100
+ expect(container.innerHTML).toBe('<div>Variation component</div>');
101
+ });
102
+
103
+ it('should display image count if displayCount is true', () => {
104
+ const mockedProps = getMockedProps({ imageIds: ['id1', 'id2', 'id3'] });
105
+ setup(mockedProps);
106
+ expect(screen.getByTestId('count')).toHaveTextContent('3 images');
107
+ });
108
+
109
+ it('should not display image count if displayCount is false', () => {
110
+ const mockedProps = getMockedProps({ displayCount: false });
111
+ setup(mockedProps);
112
+ expect(screen.queryByTestId('count')).toBeNull();
113
+ });
91
114
  });
@@ -11,17 +11,22 @@ jest.mock('@blaze-cms/utils-handlebars', () => ({
11
11
  useStringTemplate: jest.fn((parent, [title]) => ({ loadig: false, data: [title] }))
12
12
  }));
13
13
 
14
- const getMockedProps = overrides => ({
14
+ const mockedProps = {
15
15
  imageIds: ['test-id', 'test-altText', 'test-caption'],
16
16
  displayCount: true,
17
17
  enableLightbox: true,
18
18
  toggleModal: jest.fn(),
19
19
  handleSelectedImage: jest.fn(),
20
- ...overrides
21
- });
20
+ shouldDisplayCount: true,
21
+ shouldDisplayCaption: true,
22
+ direction: {
23
+ next: true,
24
+ back: false
25
+ },
26
+ handleNavigation: jest.fn()
27
+ };
22
28
 
23
29
  describe('CarouselRender component', () => {
24
- const mockedProps = getMockedProps();
25
30
  let wrapper;
26
31
 
27
32
  beforeAll(() => {
@@ -42,24 +47,12 @@ describe('CarouselRender component', () => {
42
47
  expect(wrapper.find('p').length).toEqual(1);
43
48
  });
44
49
 
45
- it('should render one image button if there is one image to display', () => {
46
- const overrides = { imageIds: ['test1'] };
47
- const wrapperTwoImages = shallow(
48
- <CarouselRender.WrappedComponent {...mockedProps} {...overrides} />
49
- );
50
- expect(wrapperTwoImages.find('p').text()).toEqual('1 image');
51
- });
52
-
53
- it('should render n images button if there is more than one image to display', () => {
54
- expect(wrapper.find('p').text()).toEqual('3 images');
55
- });
56
-
57
50
  it('should render the right amount of images to display', () => {
58
51
  expect(wrapper.find(CarouselImage).length).toEqual(3);
59
52
  });
60
53
 
61
54
  it('should not render number count if display count is disabled', () => {
62
- const overrides = { displayCount: false };
55
+ const overrides = { shouldDisplayCount: false };
63
56
  const wrapperCountDisabled = shallow(
64
57
  <CarouselRender.WrappedComponent {...mockedProps} {...overrides} />
65
58
  );
@@ -67,15 +60,14 @@ describe('CarouselRender component', () => {
67
60
  });
68
61
 
69
62
  it('should not display number count after clicking previous image', () => {
70
- expect(wrapper.find('p').length).toEqual(1);
71
- wrapper.find('div.carousel__button--previous').simulate('click');
72
- expect(wrapper.find('p').length).toEqual(0);
63
+ const wrapperPrevClick = shallow(<CarouselRender.WrappedComponent {...mockedProps} />);
64
+ wrapperPrevClick.find('div.carousel__button--previous').simulate('click');
65
+ expect(mockedProps.handleNavigation).toHaveBeenCalledWith(mockedProps.direction.back);
73
66
  });
74
67
 
75
68
  it('should not display number count after clicking next image', () => {
76
69
  const wrapperNextClick = shallow(<CarouselRender.WrappedComponent {...mockedProps} />);
77
- expect(wrapperNextClick.find('p').length).toEqual(1);
78
70
  wrapperNextClick.find('div.carousel__button--next').simulate('click');
79
- expect(wrapperNextClick.find('p').length).toEqual(0);
71
+ expect(mockedProps.handleNavigation).toHaveBeenCalledWith(mockedProps.direction.next);
80
72
  });
81
73
  });
@@ -27,6 +27,11 @@ exports[`Carousel component should render carousel and match snapshot 1`] = `
27
27
  class="carousel__button carousel__button--next"
28
28
  role="button"
29
29
  >
30
+ <p
31
+ data-testid="count"
32
+ >
33
+ 1 image
34
+ </p>
30
35
  <div
31
36
  class="arrow arrow--right"
32
37
  />
@@ -69,6 +74,11 @@ exports[`Carousel component should render priority images and match snapshot 1`]
69
74
  class="carousel__button carousel__button--next"
70
75
  role="button"
71
76
  >
77
+ <p
78
+ data-testid="count"
79
+ >
80
+ 1 image
81
+ </p>
72
82
  <div
73
83
  class="arrow arrow--right"
74
84
  />
@@ -6,7 +6,13 @@ import '@testing-library/jest-dom/extend-expect';
6
6
  import { render, act, waitFor } from '@testing-library/react';
7
7
  import { MockedRoot } from '@blaze-cms/tools/test-helpers/test-functions';
8
8
  import ImageFactory from '../../../../../src/components/Image/ImageFactory';
9
- import { MOCK_BASIC, MOCK_NO_URL, MOCK_WITH_ERR, MOCK_RELATION } from './mocks';
9
+ import {
10
+ MOCK_BASIC,
11
+ MOCK_HANDLEBAR_IMG_SRC,
12
+ MOCK_NO_URL,
13
+ MOCK_WITH_ERR,
14
+ MOCK_RELATION
15
+ } from './mocks';
10
16
 
11
17
  jest.mock('@blaze-react/utils/lib/customHooks', () => ({
12
18
  useInView: jest.fn(() => [true, null])
@@ -34,7 +40,8 @@ const setupTest = async (props = {}, mocks = {}) => {
34
40
  const mockProps = {
35
41
  parent: {
36
42
  itemId: 'parentId',
37
- getAction: 'getPublishedPage'
43
+ getAction: 'getPublishedPage',
44
+ itemEntity: 'page'
38
45
  },
39
46
  imageId: 'test-id',
40
47
  url: 'www.url-test-prop.com',
@@ -55,7 +62,7 @@ const setupTest = async (props = {}, mocks = {}) => {
55
62
 
56
63
  const options = {
57
64
  interval: 500,
58
- timeout: 5000
65
+ timeout: 8000
59
66
  };
60
67
 
61
68
  describe('ImageFactory component', () => {
@@ -72,6 +79,16 @@ describe('ImageFactory component', () => {
72
79
  expect(asFragment()).toMatchSnapshot();
73
80
  });
74
81
 
82
+ it('should render image with handlebar compiled value if imgSrc is present and returns a value', async () => {
83
+ const { asFragment } = await setupTest(
84
+ { imgSrc: '{{currentParent.image.url}}' },
85
+ MOCK_HANDLEBAR_IMG_SRC
86
+ );
87
+
88
+ await waitFor(() => expect(asFragment()).toBeDefined(), options);
89
+ expect(asFragment()).toMatchSnapshot();
90
+ });
91
+
75
92
  it('should render image fetching data from relation', async () => {
76
93
  const entity = 'page';
77
94
  const { asFragment, container } = await setupTest(
@@ -39,4 +39,16 @@ describe('Image Render component', () => {
39
39
  expect(container.childNodes[0]).toHaveStyle({ cursor: 'pointer' });
40
40
  expect(asFragment()).toMatchSnapshot();
41
41
  });
42
+
43
+ it('should render plain img tag if imgSrc is present', () => {
44
+ const { asFragment } = render(
45
+ <ImageRender
46
+ {...mockedProps}
47
+ shouldRenderImgTag
48
+ imageUrl="some-external-image-url"
49
+ alt="image-alt"
50
+ />
51
+ );
52
+ expect(asFragment()).toMatchSnapshot();
53
+ });
42
54
  });
@@ -63,3 +63,27 @@ exports[`ImageFactory component should render image fetching data from relation
63
63
  </div>
64
64
  </DocumentFragment>
65
65
  `;
66
+
67
+ exports[`ImageFactory component should render image with handlebar compiled value if imgSrc is present and returns a value 1`] = `
68
+ <DocumentFragment>
69
+ <div
70
+ class="image "
71
+ entity=""
72
+ imagerelation="publishedPage.otherImageIds"
73
+ imgsrc="{{currentParent.image.url}}"
74
+ parent="[object Object]"
75
+ >
76
+ <a
77
+ class="image__wrapper"
78
+ href="http://www.url-test-prop.com"
79
+ rel="noopener nofollow"
80
+ target="_blank"
81
+ >
82
+ <img
83
+ alt=""
84
+ src="parent-image-url"
85
+ />
86
+ </a>
87
+ </div>
88
+ </DocumentFragment>
89
+ `;
@@ -21,6 +21,15 @@ exports[`Image Render component should render image and lightbox 1`] = `
21
21
  </DocumentFragment>
22
22
  `;
23
23
 
24
+ exports[`Image Render component should render plain img tag if imgSrc is present 1`] = `
25
+ <DocumentFragment>
26
+ <img
27
+ alt="image-alt"
28
+ src="some-external-image-url"
29
+ />
30
+ </DocumentFragment>
31
+ `;
32
+
24
33
  exports[`Image Render component should set cursor style when lightbox enabled 1`] = `
25
34
  <DocumentFragment>
26
35
  <img
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  getFiles,
3
3
  getFileById,
4
+ getSingleEntitySchema,
4
5
  generateSingleItemQuery
5
6
  } from '../../../../../src/application/query';
6
7
  import { DATA_SUMMARY_MOCK } from '../../../../helpers/mocks';
@@ -26,6 +27,53 @@ const MOCK_BASIC = [
26
27
  }
27
28
  ];
28
29
 
30
+ const MOCK_HANDLEBAR_IMG_SRC = [
31
+ {
32
+ request: {
33
+ query: getSingleEntitySchema,
34
+ variables: { id: 'page' }
35
+ },
36
+ result: {
37
+ loading: false,
38
+ data: {
39
+ getEntitySchema: {
40
+ actions: {
41
+ getPublished: 'getPublishedPage',
42
+ get: 'getPage'
43
+ },
44
+ id: 'page',
45
+ identifier: 'page',
46
+ properties: {},
47
+ dynamicProperties: {},
48
+ interfaces: [],
49
+ relations: [],
50
+ __typename: 'page'
51
+ }
52
+ }
53
+ }
54
+ },
55
+ {
56
+ request: {
57
+ query: generateSingleItemQuery('getPublishedPage', 'image { url }'),
58
+ variables: {
59
+ id: 'parentId'
60
+ }
61
+ },
62
+ result: {
63
+ loading: false,
64
+ data: {
65
+ entityData: {
66
+ id: 'parentId',
67
+ image: {
68
+ url: 'parent-image-url'
69
+ },
70
+ __typename: 'PublishedPage'
71
+ }
72
+ }
73
+ }
74
+ }
75
+ ];
76
+
29
77
  const MOCK_RELATION = [
30
78
  ...DATA_SUMMARY_MOCK,
31
79
  {
@@ -204,4 +252,4 @@ const MOCKS = [
204
252
  ]
205
253
  ];
206
254
 
207
- export { MOCKS, MOCK_BASIC, MOCK_WITH_ERR, MOCK_NO_URL, MOCK_RELATION };
255
+ export { MOCKS, MOCK_BASIC, MOCK_HANDLEBAR_IMG_SRC, MOCK_WITH_ERR, MOCK_NO_URL, MOCK_RELATION };
@@ -11,6 +11,7 @@ import useGetImages from '../../../../../src/hooks/use-get-images';
11
11
  jest.mock('../../../../../src/hooks/use-get-images', () => jest.fn(() => ({ data: {} })));
12
12
 
13
13
  const testId = 'child-test-id';
14
+ const MockedVariantComponent = () => <div>Variation component</div>;
14
15
 
15
16
  describe('Layout component', () => {
16
17
  const simpleComponent = <div data-testid="child-test-id" />;
@@ -20,6 +21,16 @@ describe('Layout component', () => {
20
21
  expect(Layout).toBeDefined();
21
22
  });
22
23
 
24
+ it('should render VariantComponent insted of wrapper', () => {
25
+ const { getByText } = render(Layout, {
26
+ type: COLUMN,
27
+ children: simpleChildren,
28
+ VariantComponent: MockedVariantComponent
29
+ });
30
+ const titleTag = getByText('Variation component');
31
+ expect(titleTag).toBeDefined();
32
+ });
33
+
23
34
  it('should render empty if its a column with no children', () => {
24
35
  const { container } = render(Layout, { type: COLUMN, children: [] });
25
36
  expect(container).toBeEmptyDOMElement();
@@ -8,7 +8,11 @@ import FullRender from '../../../../../../../src/components/List/components/Full
8
8
  import { MOCKED_LIST_OPTIONS } from '../mocks';
9
9
 
10
10
  jest.mock('../../../../../../../src/components/List/components/Full/FullRenderItem', () =>
11
- jest.fn().mockImplementation(({ itemId }) => <div>{itemId}</div>)
11
+ jest.fn().mockImplementation(({ itemId, entity }) => (
12
+ <div>
13
+ {itemId}:{entity}
14
+ </div>
15
+ ))
12
16
  );
13
17
 
14
18
  describe('FullRender component', () => {
@@ -17,6 +21,15 @@ describe('FullRender component', () => {
17
21
  expect(asFragment()).toMatchSnapshot();
18
22
  });
19
23
 
24
+ it('should backward compatibility check', async () => {
25
+ const { asFragment } = await render(FullRender, {
26
+ ...MOCKED_LIST_OPTIONS,
27
+ entity: 'page',
28
+ entities: undefined
29
+ });
30
+ expect(asFragment()).toMatchSnapshot();
31
+ });
32
+
20
33
  it('should render without wrapper, when requested', async () => {
21
34
  const { asFragment } = await render(FullRender, { ...MOCKED_LIST_OPTIONS, omitWrappers: true });
22
35
  expect(asFragment()).toMatchSnapshot();
@@ -1,18 +1,36 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
+ exports[`FullRender component should backward compatibility check 1`] = `
4
+ <DocumentFragment>
5
+ <div
6
+ class="list list--full "
7
+ >
8
+ <div>
9
+ item1:page
10
+ </div>
11
+ <div>
12
+ item2:article
13
+ </div>
14
+ <div>
15
+ item3:article
16
+ </div>
17
+ </div>
18
+ </DocumentFragment>
19
+ `;
20
+
3
21
  exports[`FullRender component should render if orderedListData is received 1`] = `
4
22
  <DocumentFragment>
5
23
  <div
6
24
  class="list list--full "
7
25
  >
8
26
  <div>
9
- item1
27
+ item1:page
10
28
  </div>
11
29
  <div>
12
- item2
30
+ item2:article
13
31
  </div>
14
32
  <div>
15
- item3
33
+ item3:article
16
34
  </div>
17
35
  </div>
18
36
  </DocumentFragment>
@@ -21,13 +39,13 @@ exports[`FullRender component should render if orderedListData is received 1`] =
21
39
  exports[`FullRender component should render without wrapper, when requested 1`] = `
22
40
  <DocumentFragment>
23
41
  <div>
24
- item1
42
+ item1:page
25
43
  </div>
26
44
  <div>
27
- item2
45
+ item2:article
28
46
  </div>
29
47
  <div>
30
- item3
48
+ item3:article
31
49
  </div>
32
50
  </DocumentFragment>
33
51
  `;
@@ -22,12 +22,17 @@ const MOCKED_LIST_OPTIONS = {
22
22
  infiniteTotal: 10,
23
23
  gridModifier: 'grid grid--three',
24
24
  currentListLength: 3,
25
- orderedListData: [{ id: 'item1' }, { id: 'item2' }, { id: 'item3' }],
25
+ orderedListData: [
26
+ { id: 'item1', __typename: 'PublishedPage' },
27
+ { id: 'item2', __typename: 'PublishedArticle' },
28
+ { id: 'item3', __typename: 'PublishedArticle' }
29
+ ],
26
30
  isInfinite: false,
27
31
  pageBuilderComponents: [{ id: '1' }, { id: '2' }],
28
32
  entityProps: {},
29
33
  propsToDisplay: [],
30
- entity: 'page',
34
+ // entity: 'page', // old prop
35
+ entities: ['page', 'article'],
31
36
  itemId: '123',
32
37
  listTotal: 10,
33
38
  initialOffset: 0,
@@ -43,7 +48,8 @@ const MOCKED_LIST_OPTIONS = {
43
48
  displayThumbnail: true,
44
49
  displayTitle: true,
45
50
  graphqlEntityMap: {
46
- PublishedPage: 'page'
51
+ PublishedPage: 'page',
52
+ PublishedArticle: 'article'
47
53
  }
48
54
  };
49
55
 
@@ -9,7 +9,7 @@ exports[`Menu component should render without throwing an error and match snapsh
9
9
  class="menu--desktop-wrapper"
10
10
  >
11
11
  <ul
12
- class=" menu-mod"
12
+ class="menu-mod"
13
13
  >
14
14
  <div
15
15
  class="child_1"
@@ -7,10 +7,8 @@ exports[`Placeholder component should render PlaceholderIcon 1`] = `
7
7
  data-testid="placeholder-icon"
8
8
  >
9
9
  <svg
10
- height="25px"
11
10
  version="1.1"
12
11
  viewBox="0 0 20 20"
13
- width="25px"
14
12
  xmlns="http://www.w3.org/2000/svg"
15
13
  xmlns:xlink="http://www.w3.org/1999/xlink"
16
14
  >
@@ -44,13 +42,13 @@ exports[`Placeholder component should render PlaceholderIcon 1`] = `
44
42
  />
45
43
  <path
46
44
  d="M5.00003877,4.07973585 C5.00003879,3.4834142 5.50109477,3 6.11917864,3 C6.73726251,3 7.2383185,3.4834142 7.2383185,4.07973585 C7.2383185,4.6760575 6.73726252,5.15947172 6.11917864,5.15947172 C5.82268209,5.15728623 5.53857972,5.04442179 5.32645457,4.84454876 C5.11586241,4.64208328 4.99827309,4.36656405 5.00003877,4.07973585 Z"
47
- fill="red"
45
+ fill="#899BBC"
48
46
  fill-rule="nonzero"
49
47
  id="Path"
50
48
  />
51
49
  <path
52
50
  d="M3.375,14.625 C3.375,14.3143398 3.62683983,14.0625 3.9375,14.0625 L14.0625,14.0625 C14.3731602,14.0625 14.625,14.3143398 14.625,14.625 C14.625,14.9356602 14.3731602,15.1875 14.0625,15.1875 L3.9375,15.1875 C3.62683983,15.1875 3.375,14.9356602 3.375,14.625 Z"
53
- fill="red"
51
+ fill="#899BBC"
54
52
  fill-rule="nonzero"
55
53
  id="Shape"
56
54
  />
@@ -58,7 +56,7 @@ exports[`Placeholder component should render PlaceholderIcon 1`] = `
58
56
  height="16.7"
59
57
  id="Rectangle"
60
58
  rx="2"
61
- stroke="red"
59
+ stroke="#899BBC"
62
60
  stroke-width="1.3"
63
61
  width="16.7"
64
62
  x="0.65"
@@ -66,7 +64,7 @@ exports[`Placeholder component should render PlaceholderIcon 1`] = `
66
64
  />
67
65
  <line
68
66
  id="Line-2"
69
- stroke="red"
67
+ stroke="#899BBC"
70
68
  stroke-linecap="square"
71
69
  stroke-width="1.3"
72
70
  x1="1"