@aws-amplify/ui-react-native 0.0.0-in-app-messaging-20220826014803

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 (242) hide show
  1. package/.eslintrc.js +100 -0
  2. package/.lintstagedrc.js +6 -0
  3. package/.turbo/turbo-build.log +4 -0
  4. package/CHANGELOG.md +11 -0
  5. package/LICENSE +201 -0
  6. package/README.md +25 -0
  7. package/babel.config.js +3 -0
  8. package/dist/InAppMessaging/components/BannerMessage/BannerMessage.d.ts +3 -0
  9. package/dist/InAppMessaging/components/BannerMessage/BannerMessage.js +16 -0
  10. package/dist/InAppMessaging/components/BannerMessage/index.d.ts +2 -0
  11. package/dist/InAppMessaging/components/BannerMessage/index.js +1 -0
  12. package/dist/InAppMessaging/components/BannerMessage/styles.d.ts +7 -0
  13. package/dist/InAppMessaging/components/BannerMessage/styles.js +77 -0
  14. package/dist/InAppMessaging/components/BannerMessage/types.d.ts +12 -0
  15. package/dist/InAppMessaging/components/BannerMessage/types.js +1 -0
  16. package/dist/InAppMessaging/components/CarouselMessage/CarouselMessage.d.ts +3 -0
  17. package/dist/InAppMessaging/components/CarouselMessage/CarouselMessage.js +20 -0
  18. package/dist/InAppMessaging/components/CarouselMessage/CarouselMessageItem.d.ts +3 -0
  19. package/dist/InAppMessaging/components/CarouselMessage/CarouselMessageItem.js +18 -0
  20. package/dist/InAppMessaging/components/CarouselMessage/index.d.ts +2 -0
  21. package/dist/InAppMessaging/components/CarouselMessage/index.js +1 -0
  22. package/dist/InAppMessaging/components/CarouselMessage/styles.d.ts +5 -0
  23. package/dist/InAppMessaging/components/CarouselMessage/styles.js +98 -0
  24. package/dist/InAppMessaging/components/CarouselMessage/types.d.ts +18 -0
  25. package/dist/InAppMessaging/components/CarouselMessage/types.js +1 -0
  26. package/dist/InAppMessaging/components/FullScreenMessage/FullScreenMessage.d.ts +3 -0
  27. package/dist/InAppMessaging/components/FullScreenMessage/FullScreenMessage.js +18 -0
  28. package/dist/InAppMessaging/components/FullScreenMessage/index.d.ts +2 -0
  29. package/dist/InAppMessaging/components/FullScreenMessage/index.js +1 -0
  30. package/dist/InAppMessaging/components/FullScreenMessage/styles.d.ts +3 -0
  31. package/dist/InAppMessaging/components/FullScreenMessage/styles.js +86 -0
  32. package/dist/InAppMessaging/components/FullScreenMessage/types.d.ts +6 -0
  33. package/dist/InAppMessaging/components/FullScreenMessage/types.js +1 -0
  34. package/dist/InAppMessaging/components/InAppMessageDisplay/InAppMessageDisplay.d.ts +10 -0
  35. package/dist/InAppMessaging/components/InAppMessageDisplay/InAppMessageDisplay.js +29 -0
  36. package/dist/InAppMessaging/components/InAppMessageDisplay/handleMessageLinkAction.d.ts +3 -0
  37. package/dist/InAppMessaging/components/InAppMessageDisplay/handleMessageLinkAction.js +24 -0
  38. package/dist/InAppMessaging/components/InAppMessageDisplay/index.d.ts +2 -0
  39. package/dist/InAppMessaging/components/InAppMessageDisplay/index.js +1 -0
  40. package/dist/InAppMessaging/components/InAppMessageDisplay/types.d.ts +24 -0
  41. package/dist/InAppMessaging/components/InAppMessageDisplay/types.js +1 -0
  42. package/dist/InAppMessaging/components/MessageLayout/MessageLayout.d.ts +3 -0
  43. package/dist/InAppMessaging/components/MessageLayout/MessageLayout.js +34 -0
  44. package/dist/InAppMessaging/components/MessageLayout/index.d.ts +1 -0
  45. package/dist/InAppMessaging/components/MessageLayout/index.js +1 -0
  46. package/dist/InAppMessaging/components/MessageLayout/types.d.ts +7 -0
  47. package/dist/InAppMessaging/components/MessageLayout/types.js +1 -0
  48. package/dist/InAppMessaging/components/MessageWrapper/MessageWrapper.d.ts +3 -0
  49. package/dist/InAppMessaging/components/MessageWrapper/MessageWrapper.js +20 -0
  50. package/dist/InAppMessaging/components/MessageWrapper/index.d.ts +2 -0
  51. package/dist/InAppMessaging/components/MessageWrapper/index.js +1 -0
  52. package/dist/InAppMessaging/components/MessageWrapper/styles.d.ts +2 -0
  53. package/dist/InAppMessaging/components/MessageWrapper/styles.js +5 -0
  54. package/dist/InAppMessaging/components/MessageWrapper/types.d.ts +10 -0
  55. package/dist/InAppMessaging/components/MessageWrapper/types.js +1 -0
  56. package/dist/InAppMessaging/components/ModalMessage/ModalMessage.d.ts +3 -0
  57. package/dist/InAppMessaging/components/ModalMessage/ModalMessage.js +18 -0
  58. package/dist/InAppMessaging/components/ModalMessage/index.d.ts +2 -0
  59. package/dist/InAppMessaging/components/ModalMessage/index.js +1 -0
  60. package/dist/InAppMessaging/components/ModalMessage/styles.d.ts +4 -0
  61. package/dist/InAppMessaging/components/ModalMessage/styles.js +99 -0
  62. package/dist/InAppMessaging/components/ModalMessage/types.d.ts +6 -0
  63. package/dist/InAppMessaging/components/ModalMessage/types.js +1 -0
  64. package/dist/InAppMessaging/components/index.d.ts +6 -0
  65. package/dist/InAppMessaging/components/index.js +2 -0
  66. package/dist/InAppMessaging/components/withInAppMessaging/index.d.ts +1 -0
  67. package/dist/InAppMessaging/components/withInAppMessaging/index.js +1 -0
  68. package/dist/InAppMessaging/components/withInAppMessaging/withInAppMessaging.d.ts +5 -0
  69. package/dist/InAppMessaging/components/withInAppMessaging/withInAppMessaging.js +11 -0
  70. package/dist/InAppMessaging/constants.d.ts +31 -0
  71. package/dist/InAppMessaging/constants.js +43 -0
  72. package/dist/InAppMessaging/hooks/index.d.ts +2 -0
  73. package/dist/InAppMessaging/hooks/index.js +2 -0
  74. package/dist/InAppMessaging/hooks/useMessageImage/constants.d.ts +8 -0
  75. package/dist/InAppMessaging/hooks/useMessageImage/constants.js +18 -0
  76. package/dist/InAppMessaging/hooks/useMessageImage/index.d.ts +2 -0
  77. package/dist/InAppMessaging/hooks/useMessageImage/index.js +1 -0
  78. package/dist/InAppMessaging/hooks/useMessageImage/types.d.ts +15 -0
  79. package/dist/InAppMessaging/hooks/useMessageImage/types.js +6 -0
  80. package/dist/InAppMessaging/hooks/useMessageImage/useMessageImage.d.ts +10 -0
  81. package/dist/InAppMessaging/hooks/useMessageImage/useMessageImage.js +50 -0
  82. package/dist/InAppMessaging/hooks/useMessageImage/utils.d.ts +4 -0
  83. package/dist/InAppMessaging/hooks/useMessageImage/utils.js +56 -0
  84. package/dist/InAppMessaging/hooks/useMessageProps/index.d.ts +2 -0
  85. package/dist/InAppMessaging/hooks/useMessageProps/index.js +1 -0
  86. package/dist/InAppMessaging/hooks/useMessageProps/types.d.ts +109 -0
  87. package/dist/InAppMessaging/hooks/useMessageProps/types.js +1 -0
  88. package/dist/InAppMessaging/hooks/useMessageProps/useMessageProps.d.ts +12 -0
  89. package/dist/InAppMessaging/hooks/useMessageProps/useMessageProps.js +49 -0
  90. package/dist/InAppMessaging/hooks/useMessageProps/utils.d.ts +43 -0
  91. package/dist/InAppMessaging/hooks/useMessageProps/utils.js +192 -0
  92. package/dist/InAppMessaging/index.d.ts +2 -0
  93. package/dist/InAppMessaging/index.js +2 -0
  94. package/dist/__mocks__/react-native-safe-area-context.d.ts +3 -0
  95. package/dist/__mocks__/react-native-safe-area-context.js +4 -0
  96. package/dist/assets/close.png +0 -0
  97. package/dist/assets/index.d.ts +5 -0
  98. package/dist/assets/index.js +4 -0
  99. package/dist/assets/index.ts +7 -0
  100. package/dist/hooks/index.d.ts +1 -0
  101. package/dist/hooks/index.js +1 -0
  102. package/dist/hooks/useDeviceOrientation/index.d.ts +1 -0
  103. package/dist/hooks/useDeviceOrientation/index.js +1 -0
  104. package/dist/hooks/useDeviceOrientation/useDeviceOrientation.d.ts +6 -0
  105. package/dist/hooks/useDeviceOrientation/useDeviceOrientation.js +33 -0
  106. package/dist/index.d.ts +1 -0
  107. package/dist/index.js +1 -0
  108. package/dist/primitives/Button/Button.d.ts +3 -0
  109. package/dist/primitives/Button/Button.js +8 -0
  110. package/dist/primitives/Button/index.d.ts +2 -0
  111. package/dist/primitives/Button/index.js +1 -0
  112. package/dist/primitives/Button/styles.d.ts +2 -0
  113. package/dist/primitives/Button/styles.js +4 -0
  114. package/dist/primitives/Button/types.d.ts +7 -0
  115. package/dist/primitives/Button/types.js +1 -0
  116. package/dist/primitives/Carousel/Carousel.d.ts +3 -0
  117. package/dist/primitives/Carousel/Carousel.js +58 -0
  118. package/dist/primitives/Carousel/CarouselPageIndicator.d.ts +3 -0
  119. package/dist/primitives/Carousel/CarouselPageIndicator.js +10 -0
  120. package/dist/primitives/Carousel/constants.d.ts +9 -0
  121. package/dist/primitives/Carousel/constants.js +18 -0
  122. package/dist/primitives/Carousel/index.d.ts +3 -0
  123. package/dist/primitives/Carousel/index.js +2 -0
  124. package/dist/primitives/Carousel/styles.d.ts +2 -0
  125. package/dist/primitives/Carousel/styles.js +11 -0
  126. package/dist/primitives/Carousel/types.d.ts +19 -0
  127. package/dist/primitives/Carousel/types.js +1 -0
  128. package/dist/primitives/IconButton/IconButton.d.ts +3 -0
  129. package/dist/primitives/IconButton/IconButton.js +9 -0
  130. package/dist/primitives/IconButton/index.d.ts +2 -0
  131. package/dist/primitives/IconButton/index.js +1 -0
  132. package/dist/primitives/IconButton/styles.d.ts +2 -0
  133. package/dist/primitives/IconButton/styles.js +9 -0
  134. package/dist/primitives/IconButton/types.d.ts +18 -0
  135. package/dist/primitives/IconButton/types.js +1 -0
  136. package/dist/primitives/index.d.ts +3 -0
  137. package/dist/primitives/index.js +3 -0
  138. package/dist/utils/index.d.ts +1 -0
  139. package/dist/utils/index.js +4 -0
  140. package/jest.config.js +20 -0
  141. package/package.json +55 -0
  142. package/src/InAppMessaging/components/BannerMessage/BannerMessage.tsx +37 -0
  143. package/src/InAppMessaging/components/BannerMessage/__tests__/BannerMessage.spec.tsx +138 -0
  144. package/src/InAppMessaging/components/BannerMessage/__tests__/__snapshots__/BannerMessage.spec.tsx.snap +224 -0
  145. package/src/InAppMessaging/components/BannerMessage/index.ts +2 -0
  146. package/src/InAppMessaging/components/BannerMessage/styles.ts +105 -0
  147. package/src/InAppMessaging/components/BannerMessage/types.ts +15 -0
  148. package/src/InAppMessaging/components/CarouselMessage/CarouselMessage.tsx +42 -0
  149. package/src/InAppMessaging/components/CarouselMessage/CarouselMessageItem.tsx +37 -0
  150. package/src/InAppMessaging/components/CarouselMessage/__tests__/CarouselMessage.spec.tsx +55 -0
  151. package/src/InAppMessaging/components/CarouselMessage/__tests__/CarouselMessageItem.spec.tsx +56 -0
  152. package/src/InAppMessaging/components/CarouselMessage/__tests__/__snapshots__/CarouselMessage.spec.tsx.snap +86 -0
  153. package/src/InAppMessaging/components/CarouselMessage/__tests__/__snapshots__/CarouselMessageItem.spec.tsx.snap +248 -0
  154. package/src/InAppMessaging/components/CarouselMessage/index.ts +2 -0
  155. package/src/InAppMessaging/components/CarouselMessage/styles.ts +125 -0
  156. package/src/InAppMessaging/components/CarouselMessage/types.ts +28 -0
  157. package/src/InAppMessaging/components/FullScreenMessage/FullScreenMessage.tsx +38 -0
  158. package/src/InAppMessaging/components/FullScreenMessage/__tests__/FullScreenMessage.spec.tsx +53 -0
  159. package/src/InAppMessaging/components/FullScreenMessage/__tests__/__snapshots__/FullScreenMessage.spec.tsx.snap +236 -0
  160. package/src/InAppMessaging/components/FullScreenMessage/index.ts +2 -0
  161. package/src/InAppMessaging/components/FullScreenMessage/styles.ts +106 -0
  162. package/src/InAppMessaging/components/FullScreenMessage/types.ts +7 -0
  163. package/src/InAppMessaging/components/InAppMessageDisplay/InAppMessageDisplay.tsx +48 -0
  164. package/src/InAppMessaging/components/InAppMessageDisplay/__tests__/InAppMessageDisplay.spec.tsx +33 -0
  165. package/src/InAppMessaging/components/InAppMessageDisplay/__tests__/__snapshots__/InAppMessageDisplay.spec.tsx.snap +9 -0
  166. package/src/InAppMessaging/components/InAppMessageDisplay/__tests__/handleMessageLinkAction.spec.ts +51 -0
  167. package/src/InAppMessaging/components/InAppMessageDisplay/handleMessageLinkAction.ts +30 -0
  168. package/src/InAppMessaging/components/InAppMessageDisplay/index.ts +2 -0
  169. package/src/InAppMessaging/components/InAppMessageDisplay/types.ts +32 -0
  170. package/src/InAppMessaging/components/MessageLayout/MessageLayout.tsx +102 -0
  171. package/src/InAppMessaging/components/MessageLayout/index.ts +1 -0
  172. package/src/InAppMessaging/components/MessageLayout/types.ts +15 -0
  173. package/src/InAppMessaging/components/MessageWrapper/MessageWrapper.tsx +34 -0
  174. package/src/InAppMessaging/components/MessageWrapper/__tests__/MessageWrapper.spec.tsx +19 -0
  175. package/src/InAppMessaging/components/MessageWrapper/__tests__/__snapshots__/MessageWrapper.spec.tsx.snap +35 -0
  176. package/src/InAppMessaging/components/MessageWrapper/index.ts +2 -0
  177. package/src/InAppMessaging/components/MessageWrapper/styles.ts +7 -0
  178. package/src/InAppMessaging/components/MessageWrapper/types.ts +12 -0
  179. package/src/InAppMessaging/components/ModalMessage/ModalMessage.tsx +37 -0
  180. package/src/InAppMessaging/components/ModalMessage/__tests__/ModalMessage.spec.tsx +155 -0
  181. package/src/InAppMessaging/components/ModalMessage/__tests__/__snapshots__/ModalMessage.spec.tsx.snap +323 -0
  182. package/src/InAppMessaging/components/ModalMessage/index.ts +2 -0
  183. package/src/InAppMessaging/components/ModalMessage/styles.ts +132 -0
  184. package/src/InAppMessaging/components/ModalMessage/types.ts +8 -0
  185. package/src/InAppMessaging/components/index.ts +6 -0
  186. package/src/InAppMessaging/components/withInAppMessaging/__tests__/__snapshots__/withInAppMessaging.spec.tsx.snap +3 -0
  187. package/src/InAppMessaging/components/withInAppMessaging/__tests__/withInAppMessaging.spec.tsx +15 -0
  188. package/src/InAppMessaging/components/withInAppMessaging/index.ts +1 -0
  189. package/src/InAppMessaging/components/withInAppMessaging/withInAppMessaging.tsx +18 -0
  190. package/src/InAppMessaging/constants.ts +56 -0
  191. package/src/InAppMessaging/hooks/index.ts +9 -0
  192. package/src/InAppMessaging/hooks/useMessageImage/__tests__/useMessageImage.spec.ts +141 -0
  193. package/src/InAppMessaging/hooks/useMessageImage/__tests__/utils.spec.ts +107 -0
  194. package/src/InAppMessaging/hooks/useMessageImage/constants.ts +27 -0
  195. package/src/InAppMessaging/hooks/useMessageImage/index.ts +2 -0
  196. package/src/InAppMessaging/hooks/useMessageImage/types.ts +18 -0
  197. package/src/InAppMessaging/hooks/useMessageImage/useMessageImage.ts +74 -0
  198. package/src/InAppMessaging/hooks/useMessageImage/utils.ts +80 -0
  199. package/src/InAppMessaging/hooks/useMessageProps/__tests__/__snapshots__/utils.spec.ts.snap +223 -0
  200. package/src/InAppMessaging/hooks/useMessageProps/__tests__/useMessageProps.spec.ts +162 -0
  201. package/src/InAppMessaging/hooks/useMessageProps/__tests__/utils.spec.ts +354 -0
  202. package/src/InAppMessaging/hooks/useMessageProps/index.ts +8 -0
  203. package/src/InAppMessaging/hooks/useMessageProps/types.ts +131 -0
  204. package/src/InAppMessaging/hooks/useMessageProps/useMessageProps.ts +70 -0
  205. package/src/InAppMessaging/hooks/useMessageProps/utils.ts +274 -0
  206. package/src/InAppMessaging/index.ts +14 -0
  207. package/src/__mocks__/react-native-safe-area-context.ts +6 -0
  208. package/src/__tests__/__snapshots__/index.spec.ts.snap +15 -0
  209. package/src/__tests__/index.spec.ts +8 -0
  210. package/src/assets/close.png +0 -0
  211. package/src/assets/index.ts +7 -0
  212. package/src/hooks/index.ts +4 -0
  213. package/src/hooks/useDeviceOrientation/__tests__/useDeviceOrientation.spec.ts +87 -0
  214. package/src/hooks/useDeviceOrientation/index.ts +4 -0
  215. package/src/hooks/useDeviceOrientation/useDeviceOrientation.ts +47 -0
  216. package/src/index.ts +1 -0
  217. package/src/primitives/Button/Button.tsx +21 -0
  218. package/src/primitives/Button/__tests__/Button.spec.tsx +24 -0
  219. package/src/primitives/Button/__tests__/__snapshots__/Button.spec.tsx.snap +52 -0
  220. package/src/primitives/Button/index.ts +2 -0
  221. package/src/primitives/Button/styles.ts +6 -0
  222. package/src/primitives/Button/types.ts +9 -0
  223. package/src/primitives/Carousel/Carousel.tsx +115 -0
  224. package/src/primitives/Carousel/CarouselPageIndicator.tsx +39 -0
  225. package/src/primitives/Carousel/__tests__/Carousel.spec.tsx +185 -0
  226. package/src/primitives/Carousel/__tests__/CarouselPageIndicator.spec.tsx +71 -0
  227. package/src/primitives/Carousel/__tests__/__snapshots__/Carousel.spec.tsx.snap +216 -0
  228. package/src/primitives/Carousel/__tests__/__snapshots__/CarouselPageIndicator.spec.tsx.snap +191 -0
  229. package/src/primitives/Carousel/constants.ts +25 -0
  230. package/src/primitives/Carousel/index.ts +3 -0
  231. package/src/primitives/Carousel/styles.ts +14 -0
  232. package/src/primitives/Carousel/types.ts +22 -0
  233. package/src/primitives/IconButton/IconButton.tsx +20 -0
  234. package/src/primitives/IconButton/__tests__/IconButton.spec.tsx +13 -0
  235. package/src/primitives/IconButton/__tests__/__snapshots__/IconButton.spec.tsx.snap +34 -0
  236. package/src/primitives/IconButton/index.ts +2 -0
  237. package/src/primitives/IconButton/styles.ts +16 -0
  238. package/src/primitives/IconButton/types.ts +27 -0
  239. package/src/primitives/index.ts +3 -0
  240. package/src/utils/index.ts +6 -0
  241. package/tsconfig.dist.json +4 -0
  242. package/tsconfig.json +21 -0
@@ -0,0 +1,80 @@
1
+ import { Image } from 'react-native';
2
+ import { ConsoleLogger as Logger } from '@aws-amplify/core';
3
+ import { MessageLayout } from '@aws-amplify/ui-react-core';
4
+
5
+ import {
6
+ BANNER_IMAGE_SCREEN_SIZE,
7
+ CAROUSEL_IMAGE_SCREEN_SIZE,
8
+ FULL_SCREEN_IMAGE_SCREEN_SIZE,
9
+ MODAL_IMAGE_SCREEN_SIZE,
10
+ } from './constants';
11
+ import { ImageDimensions, ImageLoadingState } from './types';
12
+
13
+ const logger = new Logger('Notifications.InAppMessaging');
14
+
15
+ const inAppMessageImageSizes: Record<MessageLayout, number> = {
16
+ BOTTOM_BANNER: BANNER_IMAGE_SCREEN_SIZE,
17
+ MIDDLE_BANNER: BANNER_IMAGE_SCREEN_SIZE,
18
+ TOP_BANNER: BANNER_IMAGE_SCREEN_SIZE,
19
+ CAROUSEL: CAROUSEL_IMAGE_SCREEN_SIZE,
20
+ FULL_SCREEN: FULL_SCREEN_IMAGE_SCREEN_SIZE,
21
+ MODAL: MODAL_IMAGE_SCREEN_SIZE,
22
+ };
23
+
24
+ export const prefetchNetworkImage = async (
25
+ url: string
26
+ ): Promise<ImageLoadingState> => {
27
+ try {
28
+ const loaded = await Image.prefetch(url);
29
+ if (loaded) {
30
+ return 'loaded';
31
+ }
32
+
33
+ logger.error(`Image failed to load: ${url}`);
34
+ return 'failed';
35
+ } catch (e) {
36
+ logger.error(`Image.prefetch failed: ${e}`);
37
+ return 'failed';
38
+ }
39
+ };
40
+
41
+ export const getLayoutImageDimensions = (
42
+ imageHeight: number,
43
+ imageWidth: number,
44
+ layout: MessageLayout
45
+ ): ImageDimensions => {
46
+ // determine aspect ratio for scaling rendered image
47
+ const aspectRatio = imageWidth / imageHeight;
48
+ const isSquare = aspectRatio === 1;
49
+ const isPortrait = imageHeight > imageWidth;
50
+ const isLandscape = imageWidth > imageHeight;
51
+
52
+ // an image that has smaller dimensions than the max image dimension (e.g. 10px x 10px)
53
+ // will be scaled up in size to match the size the message component expects.
54
+ // While this could lead to pixelated images, it was ultimately a product decision,
55
+ // ideally the message creator would follow the image guidelines in the pinpoint console
56
+ const maxImageDimension = inAppMessageImageSizes[layout];
57
+
58
+ let height: ImageDimensions['height'] = undefined;
59
+ let width: ImageDimensions['width'] = undefined;
60
+
61
+ // set square image dimensions
62
+ if (isSquare) {
63
+ height = maxImageDimension;
64
+ width = maxImageDimension;
65
+ }
66
+
67
+ // set portrait image dimensions
68
+ if (isPortrait) {
69
+ height = maxImageDimension;
70
+ width = maxImageDimension * aspectRatio;
71
+ }
72
+
73
+ // set landscape image dimensions
74
+ if (isLandscape) {
75
+ height = maxImageDimension / aspectRatio;
76
+ width = maxImageDimension;
77
+ }
78
+
79
+ return { height, width };
80
+ };
@@ -0,0 +1,223 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`getMessageStyles adds a bottom padding for carousel page indicators 1`] = `
4
+ Object {
5
+ "body": Array [
6
+ Object {
7
+ "color": "fuschia",
8
+ },
9
+ undefined,
10
+ undefined,
11
+ ],
12
+ "buttonsContainer": Object {
13
+ "backgroundColor": "teal",
14
+ },
15
+ "container": Array [
16
+ Array [
17
+ Object {
18
+ "borderRadius": 1,
19
+ },
20
+ Object {},
21
+ Object {},
22
+ ],
23
+ Object {
24
+ "paddingBottom": 36,
25
+ },
26
+ ],
27
+ "contentContainer": Object {
28
+ "backgroundColor": "lightblue",
29
+ },
30
+ "header": Array [
31
+ Object {
32
+ "backgroundColor": "purple",
33
+ },
34
+ undefined,
35
+ undefined,
36
+ ],
37
+ "iconButton": Object {
38
+ "container": Array [
39
+ Object {
40
+ "backgroundColor": "blue",
41
+ },
42
+ undefined,
43
+ ],
44
+ "iconColor": undefined,
45
+ },
46
+ "image": Array [
47
+ Object {
48
+ "backgroundColor": "yellow",
49
+ },
50
+ undefined,
51
+ ],
52
+ "imageContainer": Object {
53
+ "backgroundColor": "green",
54
+ },
55
+ "primaryButton": Object {
56
+ "container": [Function],
57
+ "text": Array [
58
+ Object {
59
+ "color": "pink",
60
+ },
61
+ Object {},
62
+ Object {},
63
+ ],
64
+ },
65
+ "secondaryButton": Object {
66
+ "container": [Function],
67
+ "text": Array [
68
+ Object {
69
+ "color": "pink",
70
+ },
71
+ Object {},
72
+ Object {},
73
+ ],
74
+ },
75
+ "textContainer": Object {
76
+ "backgroundColor": "antiquewhite",
77
+ },
78
+ "wrapper": Array [
79
+ Object {
80
+ "backgroundColor": "gray",
81
+ },
82
+ Object {
83
+ "backgroundColor": "red",
84
+ },
85
+ Object {},
86
+ Object {},
87
+ ],
88
+ }
89
+ `;
90
+
91
+ exports[`getMessageStyles returns the expected output in the happy path 1`] = `
92
+ Object {
93
+ "body": Array [
94
+ Object {
95
+ "color": "fuschia",
96
+ },
97
+ Object {
98
+ "textAlign": "left",
99
+ },
100
+ Object {
101
+ "color": "white",
102
+ },
103
+ ],
104
+ "buttonsContainer": Object {
105
+ "backgroundColor": "teal",
106
+ },
107
+ "container": Array [
108
+ Object {
109
+ "borderRadius": 1,
110
+ },
111
+ Object {
112
+ "borderRadius": 2,
113
+ },
114
+ Object {
115
+ "borderRadius": 3,
116
+ },
117
+ ],
118
+ "contentContainer": Object {
119
+ "backgroundColor": "lightblue",
120
+ },
121
+ "header": Array [
122
+ Object {
123
+ "backgroundColor": "purple",
124
+ },
125
+ Object {
126
+ "textAlign": "center",
127
+ },
128
+ Object {
129
+ "backgroundColor": "lightpink",
130
+ },
131
+ ],
132
+ "iconButton": Object {
133
+ "container": Array [
134
+ Object {
135
+ "backgroundColor": "blue",
136
+ },
137
+ Object {
138
+ "backgroundColor": "turquoise",
139
+ },
140
+ ],
141
+ "iconColor": "darkcyan",
142
+ },
143
+ "image": Array [
144
+ Object {
145
+ "backgroundColor": "yellow",
146
+ },
147
+ Object {
148
+ "backgroundColor": "royalblue",
149
+ },
150
+ ],
151
+ "imageContainer": Object {
152
+ "backgroundColor": "green",
153
+ },
154
+ "primaryButton": Object {
155
+ "container": [Function],
156
+ "text": Array [
157
+ Object {
158
+ "color": "pink",
159
+ },
160
+ Object {
161
+ "color": "olive",
162
+ },
163
+ Object {
164
+ "color": "black",
165
+ },
166
+ ],
167
+ },
168
+ "secondaryButton": Object {
169
+ "container": [Function],
170
+ "text": Array [
171
+ Object {
172
+ "color": "pink",
173
+ },
174
+ Object {
175
+ "color": "peru",
176
+ },
177
+ Object {
178
+ "color": "orchid",
179
+ },
180
+ ],
181
+ },
182
+ "textContainer": Object {
183
+ "backgroundColor": "antiquewhite",
184
+ },
185
+ "wrapper": Array [
186
+ Object {
187
+ "backgroundColor": "gray",
188
+ },
189
+ Object {
190
+ "backgroundColor": "red",
191
+ },
192
+ Object {
193
+ "backgroundColor": "lightgray",
194
+ },
195
+ Object {
196
+ "backgroundColor": "lawngreen",
197
+ },
198
+ ],
199
+ }
200
+ `;
201
+
202
+ exports[`getPayloadStyle returns the expected output in the happy path 1`] = `
203
+ Object {
204
+ "body": Object {
205
+ "textAlign": "left",
206
+ },
207
+ "container": Object {
208
+ "backgroundColor": "lightgray",
209
+ "borderRadius": 2,
210
+ },
211
+ "header": Object {
212
+ "textAlign": "center",
213
+ },
214
+ "primaryButton": Object {
215
+ "backgroundColor": "salmon",
216
+ "color": "olive",
217
+ },
218
+ "secondaryButton": Object {
219
+ "backgroundColor": "sand",
220
+ "color": "peru",
221
+ },
222
+ }
223
+ `;
@@ -0,0 +1,162 @@
1
+ import { renderHook } from '@testing-library/react-hooks';
2
+ import {
3
+ MessageButtonProps,
4
+ MessageComponentBaseProps,
5
+ } from '@aws-amplify/ui-react-core';
6
+
7
+ import { useMessageImage } from '../../useMessageImage';
8
+ import { MessageOverrideStyle } from '../types';
9
+ import useMessageProps from '../useMessageProps';
10
+
11
+ jest.mock('../../useMessageImage');
12
+ jest.mock('../../../../hooks/useDeviceOrientation');
13
+
14
+ type TestComponentProps = MessageComponentBaseProps<MessageOverrideStyle>;
15
+
16
+ const mockUseMessageImage = useMessageImage as jest.Mock;
17
+
18
+ const onDisplay = jest.fn();
19
+ const getDefaultStyle = jest.fn();
20
+
21
+ describe('useMessageProps', () => {
22
+ beforeEach(() => {
23
+ mockUseMessageImage.mockReturnValue({
24
+ hasRenderableImage: false,
25
+ imageDimensions: null,
26
+ isImageFetching: false,
27
+ });
28
+ onDisplay.mockClear();
29
+ });
30
+
31
+ it('behaves as expected in the happy path', () => {
32
+ const props: TestComponentProps = {
33
+ layout: 'MIDDLE_BANNER',
34
+ onDisplay,
35
+ };
36
+
37
+ const { result } = renderHook(() =>
38
+ useMessageProps(props, getDefaultStyle)
39
+ );
40
+
41
+ expect(onDisplay).toHaveBeenCalledTimes(1);
42
+ expect(result.current).toEqual({
43
+ hasButtons: false,
44
+ hasPrimaryButton: false,
45
+ hasRenderableImage: false,
46
+ hasSecondaryButton: false,
47
+ shouldRenderMessage: true,
48
+ styles: expect.any(Object) as MessageOverrideStyle,
49
+ });
50
+ });
51
+
52
+ it('behaves as expected when props includes an image', () => {
53
+ mockUseMessageImage.mockReturnValue({
54
+ hasRenderableImage: false,
55
+ imageDimensions: null,
56
+ isImageFetching: true,
57
+ });
58
+
59
+ const props: TestComponentProps = {
60
+ image: { src: 'https://test.png' },
61
+ layout: 'MIDDLE_BANNER',
62
+ onDisplay,
63
+ };
64
+
65
+ const { result, rerender } = renderHook(() =>
66
+ useMessageProps(props, getDefaultStyle)
67
+ );
68
+
69
+ // first render
70
+ expect(onDisplay).not.toHaveBeenCalled();
71
+ expect(result.current).toEqual({
72
+ hasButtons: false,
73
+ hasPrimaryButton: false,
74
+ hasRenderableImage: false,
75
+ hasSecondaryButton: false,
76
+ shouldRenderMessage: false,
77
+ styles: null,
78
+ });
79
+
80
+ mockUseMessageImage.mockReturnValue({
81
+ hasRenderableImage: true,
82
+ imageDimensions: { height: 12, width: 12 },
83
+ isImageFetching: false,
84
+ });
85
+
86
+ rerender();
87
+
88
+ expect(onDisplay).toHaveBeenCalledTimes(1);
89
+ expect(result.current).toEqual({
90
+ hasButtons: false,
91
+ hasPrimaryButton: false,
92
+ hasRenderableImage: true,
93
+ hasSecondaryButton: false,
94
+ shouldRenderMessage: true,
95
+ styles: expect.any(Object) as MessageOverrideStyle,
96
+ });
97
+ });
98
+
99
+ it('returns the expected values when props includes buttons', () => {
100
+ const props: TestComponentProps = {
101
+ layout: 'MIDDLE_BANNER',
102
+
103
+ primaryButton: { title: 'primary', onAction: jest.fn() },
104
+ secondaryButton: { title: 'secondary', onAction: jest.fn() },
105
+ };
106
+
107
+ const { result } = renderHook(() =>
108
+ useMessageProps(props, getDefaultStyle)
109
+ );
110
+
111
+ expect(result.current.hasButtons).toBe(true);
112
+ expect(result.current.hasPrimaryButton).toBe(true);
113
+ expect(result.current.hasSecondaryButton).toBe(true);
114
+ });
115
+
116
+ it('returns the expected values when props includes empty buttons', () => {
117
+ const props: TestComponentProps = {
118
+ layout: 'MIDDLE_BANNER',
119
+
120
+ primaryButton: {} as MessageButtonProps,
121
+ secondaryButton: {} as MessageButtonProps,
122
+ };
123
+
124
+ const { result } = renderHook(() =>
125
+ useMessageProps(props, getDefaultStyle)
126
+ );
127
+
128
+ expect(result.current.hasButtons).toBe(false);
129
+ expect(result.current.hasPrimaryButton).toBe(false);
130
+ expect(result.current.hasSecondaryButton).toBe(false);
131
+ });
132
+
133
+ it('returns the expected values when props includes only a primary button', () => {
134
+ const props: TestComponentProps = {
135
+ layout: 'MIDDLE_BANNER',
136
+ primaryButton: { title: 'primary', onAction: jest.fn() },
137
+ };
138
+
139
+ const { result } = renderHook(() =>
140
+ useMessageProps(props, getDefaultStyle)
141
+ );
142
+
143
+ expect(result.current.hasButtons).toBe(true);
144
+ expect(result.current.hasPrimaryButton).toBe(true);
145
+ expect(result.current.hasSecondaryButton).toBe(false);
146
+ });
147
+
148
+ it('returns the expected values when props includes only a secondary button', () => {
149
+ const props: TestComponentProps = {
150
+ layout: 'MIDDLE_BANNER',
151
+ secondaryButton: { title: 'primary', onAction: jest.fn() },
152
+ };
153
+
154
+ const { result } = renderHook(() =>
155
+ useMessageProps(props, getDefaultStyle)
156
+ );
157
+
158
+ expect(result.current.hasButtons).toBe(true);
159
+ expect(result.current.hasPrimaryButton).toBe(false);
160
+ expect(result.current.hasSecondaryButton).toBe(true);
161
+ });
162
+ });