@aws-amplify/ui-react-native 1.2.0 → 1.2.2
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.
- package/CHANGELOG.md +18 -0
- package/dist/Authenticator/common/DefaultFormFields/DefaultTextFormFields.js +2 -7
- package/dist/Authenticator/common/DefaultFormFields/Field.d.ts +6 -0
- package/dist/Authenticator/common/DefaultFormFields/Field.js +34 -0
- package/dist/Authenticator/common/DefaultFormFields/types.d.ts +3 -0
- package/dist/InAppMessaging/components/CarouselMessage/CarouselMessage.js +2 -1
- package/dist/InAppMessaging/constants.d.ts +1 -0
- package/dist/InAppMessaging/constants.js +1 -0
- package/dist/primitives/Carousel/types.d.ts +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
- package/src/Authenticator/Defaults/ConfirmResetPassword/__tests__/__snapshots__/ConfirmResetPassword.spec.tsx.snap +44 -0
- package/src/Authenticator/Defaults/ForceNewPassword/__tests__/__snapshots__/ForceNewPassword.spec.tsx.snap +33 -0
- package/src/Authenticator/Defaults/SignIn/__tests__/__snapshots__/SignIn.spec.tsx.snap +33 -0
- package/src/Authenticator/Defaults/SignUp/__tests__/__snapshots__/SignUp.spec.tsx.snap +110 -0
- package/src/Authenticator/common/DefaultFormFields/DefaultTextFormFields.tsx +2 -13
- package/src/Authenticator/common/DefaultFormFields/Field.tsx +50 -0
- package/src/Authenticator/common/DefaultFormFields/types.ts +4 -0
- package/src/InAppMessaging/components/BannerMessage/__tests__/BannerMessage.spec.tsx +46 -33
- package/src/InAppMessaging/components/BannerMessage/__tests__/__snapshots__/BannerMessage.spec.tsx.snap +372 -0
- package/src/InAppMessaging/components/CarouselMessage/CarouselMessage.tsx +2 -0
- package/src/InAppMessaging/components/CarouselMessage/__tests__/CarouselMessage.spec.tsx +64 -27
- package/src/InAppMessaging/components/CarouselMessage/__tests__/CarouselMessageItem.spec.tsx +5 -11
- package/src/InAppMessaging/components/CarouselMessage/__tests__/__snapshots__/CarouselMessage.spec.tsx.snap +38 -0
- package/src/InAppMessaging/components/FullScreenMessage/__tests__/FullScreenMessage.spec.tsx +5 -5
- package/src/InAppMessaging/components/InAppMessageDisplay/__tests__/InAppMessageDisplay.spec.tsx +3 -3
- package/src/InAppMessaging/components/MessageWrapper/__tests__/MessageWrapper.spec.tsx +3 -3
- package/src/InAppMessaging/components/ModalMessage/__tests__/ModalMessage.spec.tsx +48 -34
- package/src/InAppMessaging/components/ModalMessage/__tests__/__snapshots__/ModalMessage.spec.tsx.snap +372 -0
- package/src/InAppMessaging/components/withInAppMessaging/__tests__/withInAppMessaging.spec.tsx +3 -3
- package/src/InAppMessaging/constants.ts +1 -0
- package/src/primitives/Carousel/__tests__/Carousel.spec.tsx +53 -64
- package/src/primitives/Carousel/__tests__/CarouselPageIndicator.spec.tsx +46 -44
- package/src/primitives/Carousel/__tests__/__snapshots__/Carousel.spec.tsx.snap +94 -0
- package/src/primitives/Carousel/types.ts +1 -0
- package/src/version.ts +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import { fireEvent, render } from '@testing-library/react-native';
|
|
3
3
|
|
|
4
4
|
import { IN_APP_MESSAGING_TEST_ID } from '../../../constants';
|
|
5
5
|
import { useMessageImage } from '../../../hooks/useMessageImage';
|
|
@@ -27,9 +27,9 @@ describe('BannerMessage', () => {
|
|
|
27
27
|
isImageFetching: false,
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
-
const
|
|
30
|
+
const { toJSON } = render(<BannerMessage {...baseProps} />);
|
|
31
31
|
|
|
32
|
-
expect(
|
|
32
|
+
expect(toJSON()).toMatchSnapshot();
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
it('renders a message as expected with an image', () => {
|
|
@@ -42,16 +42,14 @@ describe('BannerMessage', () => {
|
|
|
42
42
|
const src = 'asset.png';
|
|
43
43
|
const props = { ...baseProps, image: { src } };
|
|
44
44
|
|
|
45
|
-
const
|
|
45
|
+
const { toJSON, getByTestId } = render(<BannerMessage {...props} />);
|
|
46
46
|
|
|
47
|
-
const image =
|
|
48
|
-
testID: IN_APP_MESSAGING_TEST_ID.IMAGE,
|
|
49
|
-
});
|
|
47
|
+
const image = getByTestId(IN_APP_MESSAGING_TEST_ID.IMAGE);
|
|
50
48
|
|
|
51
49
|
expect(image.props).toEqual(
|
|
52
50
|
expect.objectContaining({ source: { uri: src } })
|
|
53
51
|
);
|
|
54
|
-
expect(
|
|
52
|
+
expect(toJSON()).toMatchSnapshot();
|
|
55
53
|
});
|
|
56
54
|
|
|
57
55
|
it('returns null while an image is fetching', () => {
|
|
@@ -61,9 +59,9 @@ describe('BannerMessage', () => {
|
|
|
61
59
|
isImageFetching: true,
|
|
62
60
|
});
|
|
63
61
|
|
|
64
|
-
const
|
|
62
|
+
const { toJSON } = render(<BannerMessage {...baseProps} />);
|
|
65
63
|
|
|
66
|
-
expect(
|
|
64
|
+
expect(toJSON()).toBeNull();
|
|
67
65
|
});
|
|
68
66
|
|
|
69
67
|
it.each([
|
|
@@ -83,12 +81,30 @@ describe('BannerMessage', () => {
|
|
|
83
81
|
expectedProps: { children: 'body content' },
|
|
84
82
|
},
|
|
85
83
|
],
|
|
84
|
+
])(
|
|
85
|
+
'correctly handles a %s prop',
|
|
86
|
+
(key, testID, { testProps, expectedProps }) => {
|
|
87
|
+
mockUseMessageImage.mockReturnValueOnce({
|
|
88
|
+
hasRenderableImage: false,
|
|
89
|
+
imageDimensions: { height: undefined, width: undefined },
|
|
90
|
+
isImageFetching: false,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const props = { ...baseProps, [key]: testProps };
|
|
94
|
+
|
|
95
|
+
const { getByTestId } = render(<BannerMessage {...props} />);
|
|
96
|
+
const testElement = getByTestId(testID);
|
|
97
|
+
|
|
98
|
+
expect(testElement.children).toContain(expectedProps.children);
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
it.each([
|
|
86
103
|
[
|
|
87
104
|
'primaryButton',
|
|
88
105
|
IN_APP_MESSAGING_TEST_ID.PRIMARY_BUTTON,
|
|
89
106
|
{
|
|
90
107
|
testProps: { onAction, title: 'primary button' },
|
|
91
|
-
expectedProps: { children: 'primary button', onPress: onAction },
|
|
92
108
|
},
|
|
93
109
|
],
|
|
94
110
|
[
|
|
@@ -96,26 +112,27 @@ describe('BannerMessage', () => {
|
|
|
96
112
|
IN_APP_MESSAGING_TEST_ID.SECONDARY_BUTTON,
|
|
97
113
|
{
|
|
98
114
|
testProps: { onAction, title: 'secondary button' },
|
|
99
|
-
expectedProps: { children: 'secondary button', onPress: onAction },
|
|
100
115
|
},
|
|
101
116
|
],
|
|
102
|
-
])(
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
isImageFetching: false,
|
|
109
|
-
});
|
|
117
|
+
])('correctly handles a %s button prop', (key, testID, { testProps }) => {
|
|
118
|
+
mockUseMessageImage.mockReturnValueOnce({
|
|
119
|
+
hasRenderableImage: false,
|
|
120
|
+
imageDimensions: { height: undefined, width: undefined },
|
|
121
|
+
isImageFetching: false,
|
|
122
|
+
});
|
|
110
123
|
|
|
111
|
-
|
|
124
|
+
const props = { ...baseProps, [key]: testProps };
|
|
125
|
+
const { toJSON, getByRole, getByTestId, getByText, queryAllByRole } =
|
|
126
|
+
render(<BannerMessage {...props} />);
|
|
112
127
|
|
|
113
|
-
|
|
114
|
-
|
|
128
|
+
expect(toJSON()).toMatchSnapshot();
|
|
129
|
+
expect(queryAllByRole('button')).toHaveLength(2);
|
|
130
|
+
expect(getByTestId(testID)).toBeDefined();
|
|
131
|
+
expect(getByTestId(IN_APP_MESSAGING_TEST_ID.CLOSE_BUTTON)).toBeDefined();
|
|
115
132
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
);
|
|
133
|
+
expect(getByRole('image')).toBeDefined();
|
|
134
|
+
expect(getByText(testProps.title)).toBeDefined();
|
|
135
|
+
});
|
|
119
136
|
|
|
120
137
|
it('calls onClose when the close button is pressed', () => {
|
|
121
138
|
mockUseMessageImage.mockReturnValueOnce({
|
|
@@ -124,14 +141,10 @@ describe('BannerMessage', () => {
|
|
|
124
141
|
isImageFetching: false,
|
|
125
142
|
});
|
|
126
143
|
|
|
127
|
-
const
|
|
128
|
-
const closeButton =
|
|
129
|
-
testID: IN_APP_MESSAGING_TEST_ID.CLOSE_BUTTON,
|
|
130
|
-
});
|
|
144
|
+
const { getByTestId } = render(<BannerMessage {...baseProps} />);
|
|
145
|
+
const closeButton = getByTestId(IN_APP_MESSAGING_TEST_ID.CLOSE_BUTTON);
|
|
131
146
|
|
|
132
|
-
|
|
133
|
-
(closeButton.props as { onPress: () => void }).onPress();
|
|
134
|
-
});
|
|
147
|
+
fireEvent.press(closeButton);
|
|
135
148
|
|
|
136
149
|
expect(onClose).toHaveBeenCalledTimes(1);
|
|
137
150
|
});
|
|
@@ -1,5 +1,377 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
+
exports[`BannerMessage correctly handles a primaryButton button prop 1`] = `
|
|
4
|
+
<MessageWrapper
|
|
5
|
+
style={
|
|
6
|
+
Object {
|
|
7
|
+
"backgroundColor": "transparent",
|
|
8
|
+
"flex": 1,
|
|
9
|
+
"justifyContent": "flex-start",
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
>
|
|
13
|
+
<View
|
|
14
|
+
style={
|
|
15
|
+
Array [
|
|
16
|
+
Object {
|
|
17
|
+
"backgroundColor": "#fff",
|
|
18
|
+
"elevation": 3,
|
|
19
|
+
"margin": 16,
|
|
20
|
+
"shadowColor": "#000",
|
|
21
|
+
"shadowOffset": Object {
|
|
22
|
+
"height": 2,
|
|
23
|
+
"width": 2,
|
|
24
|
+
},
|
|
25
|
+
"shadowOpacity": 0.1,
|
|
26
|
+
"shadowRadius": 2,
|
|
27
|
+
},
|
|
28
|
+
Object {},
|
|
29
|
+
Object {},
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
>
|
|
33
|
+
<View
|
|
34
|
+
style={
|
|
35
|
+
Object {
|
|
36
|
+
"flexDirection": "row",
|
|
37
|
+
"padding": 12,
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
>
|
|
41
|
+
<View
|
|
42
|
+
style={
|
|
43
|
+
Object {
|
|
44
|
+
"flex": 1,
|
|
45
|
+
"paddingHorizontal": 8,
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/>
|
|
49
|
+
<View
|
|
50
|
+
accessibilityRole="button"
|
|
51
|
+
accessible={true}
|
|
52
|
+
collapsable={false}
|
|
53
|
+
focusable={true}
|
|
54
|
+
hitSlop={
|
|
55
|
+
Object {
|
|
56
|
+
"bottom": 10,
|
|
57
|
+
"left": 10,
|
|
58
|
+
"right": 10,
|
|
59
|
+
"top": 10,
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
onBlur={[Function]}
|
|
63
|
+
onClick={[Function]}
|
|
64
|
+
onFocus={[Function]}
|
|
65
|
+
onResponderGrant={[Function]}
|
|
66
|
+
onResponderMove={[Function]}
|
|
67
|
+
onResponderRelease={[Function]}
|
|
68
|
+
onResponderTerminate={[Function]}
|
|
69
|
+
onResponderTerminationRequest={[Function]}
|
|
70
|
+
onStartShouldSetResponder={[Function]}
|
|
71
|
+
style={
|
|
72
|
+
Array [
|
|
73
|
+
Object {},
|
|
74
|
+
undefined,
|
|
75
|
+
Array [
|
|
76
|
+
Object {
|
|
77
|
+
"alignSelf": "flex-start",
|
|
78
|
+
"marginLeft": "auto",
|
|
79
|
+
},
|
|
80
|
+
undefined,
|
|
81
|
+
],
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
testID="in-app-messaging--close-button"
|
|
85
|
+
>
|
|
86
|
+
<Image
|
|
87
|
+
accessibilityRole="image"
|
|
88
|
+
source={
|
|
89
|
+
Object {
|
|
90
|
+
"testUri": "../../../src/assets/icons/close.png",
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
style={
|
|
94
|
+
Array [
|
|
95
|
+
Object {
|
|
96
|
+
"height": 20,
|
|
97
|
+
"resizeMode": "contain",
|
|
98
|
+
"tintColor": undefined,
|
|
99
|
+
"width": 20,
|
|
100
|
+
},
|
|
101
|
+
undefined,
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
/>
|
|
105
|
+
</View>
|
|
106
|
+
</View>
|
|
107
|
+
<View
|
|
108
|
+
style={
|
|
109
|
+
Object {
|
|
110
|
+
"flexDirection": "row",
|
|
111
|
+
"justifyContent": "center",
|
|
112
|
+
"padding": 4,
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
>
|
|
116
|
+
<View
|
|
117
|
+
accessibilityRole="button"
|
|
118
|
+
accessible={true}
|
|
119
|
+
collapsable={false}
|
|
120
|
+
focusable={true}
|
|
121
|
+
onBlur={[Function]}
|
|
122
|
+
onClick={[Function]}
|
|
123
|
+
onFocus={[Function]}
|
|
124
|
+
onResponderGrant={[Function]}
|
|
125
|
+
onResponderMove={[Function]}
|
|
126
|
+
onResponderRelease={[Function]}
|
|
127
|
+
onResponderTerminate={[Function]}
|
|
128
|
+
onResponderTerminationRequest={[Function]}
|
|
129
|
+
onStartShouldSetResponder={[Function]}
|
|
130
|
+
style={
|
|
131
|
+
Array [
|
|
132
|
+
Object {
|
|
133
|
+
"alignItems": "center",
|
|
134
|
+
"backgroundColor": "transparent",
|
|
135
|
+
"borderColor": "hsl(210, 10%, 58%)",
|
|
136
|
+
"borderRadius": 4,
|
|
137
|
+
"borderWidth": 1,
|
|
138
|
+
"justifyContent": "center",
|
|
139
|
+
"paddingHorizontal": 16,
|
|
140
|
+
"paddingVertical": 12,
|
|
141
|
+
},
|
|
142
|
+
undefined,
|
|
143
|
+
Array [
|
|
144
|
+
Object {},
|
|
145
|
+
Object {
|
|
146
|
+
"backgroundColor": "#e8e8e8",
|
|
147
|
+
"borderRadius": 4,
|
|
148
|
+
"flex": 1,
|
|
149
|
+
"margin": 8,
|
|
150
|
+
"padding": 12,
|
|
151
|
+
},
|
|
152
|
+
Object {},
|
|
153
|
+
Object {},
|
|
154
|
+
],
|
|
155
|
+
]
|
|
156
|
+
}
|
|
157
|
+
testID="in-app-messaging--primary-button"
|
|
158
|
+
>
|
|
159
|
+
<Text
|
|
160
|
+
style={
|
|
161
|
+
Array [
|
|
162
|
+
Object {
|
|
163
|
+
"color": "hsl(210, 50%, 10%)",
|
|
164
|
+
"fontSize": 16,
|
|
165
|
+
"fontWeight": "700",
|
|
166
|
+
"textAlign": "center",
|
|
167
|
+
},
|
|
168
|
+
Array [
|
|
169
|
+
Object {
|
|
170
|
+
"fontSize": 16,
|
|
171
|
+
"fontWeight": "400",
|
|
172
|
+
"lineHeight": 24,
|
|
173
|
+
"textAlign": "center",
|
|
174
|
+
},
|
|
175
|
+
Object {},
|
|
176
|
+
Object {},
|
|
177
|
+
],
|
|
178
|
+
]
|
|
179
|
+
}
|
|
180
|
+
>
|
|
181
|
+
primary button
|
|
182
|
+
</Text>
|
|
183
|
+
</View>
|
|
184
|
+
</View>
|
|
185
|
+
</View>
|
|
186
|
+
</MessageWrapper>
|
|
187
|
+
`;
|
|
188
|
+
|
|
189
|
+
exports[`BannerMessage correctly handles a secondaryButton button prop 1`] = `
|
|
190
|
+
<MessageWrapper
|
|
191
|
+
style={
|
|
192
|
+
Object {
|
|
193
|
+
"backgroundColor": "transparent",
|
|
194
|
+
"flex": 1,
|
|
195
|
+
"justifyContent": "flex-start",
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
>
|
|
199
|
+
<View
|
|
200
|
+
style={
|
|
201
|
+
Array [
|
|
202
|
+
Object {
|
|
203
|
+
"backgroundColor": "#fff",
|
|
204
|
+
"elevation": 3,
|
|
205
|
+
"margin": 16,
|
|
206
|
+
"shadowColor": "#000",
|
|
207
|
+
"shadowOffset": Object {
|
|
208
|
+
"height": 2,
|
|
209
|
+
"width": 2,
|
|
210
|
+
},
|
|
211
|
+
"shadowOpacity": 0.1,
|
|
212
|
+
"shadowRadius": 2,
|
|
213
|
+
},
|
|
214
|
+
Object {},
|
|
215
|
+
Object {},
|
|
216
|
+
]
|
|
217
|
+
}
|
|
218
|
+
>
|
|
219
|
+
<View
|
|
220
|
+
style={
|
|
221
|
+
Object {
|
|
222
|
+
"flexDirection": "row",
|
|
223
|
+
"padding": 12,
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
>
|
|
227
|
+
<View
|
|
228
|
+
style={
|
|
229
|
+
Object {
|
|
230
|
+
"flex": 1,
|
|
231
|
+
"paddingHorizontal": 8,
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/>
|
|
235
|
+
<View
|
|
236
|
+
accessibilityRole="button"
|
|
237
|
+
accessible={true}
|
|
238
|
+
collapsable={false}
|
|
239
|
+
focusable={true}
|
|
240
|
+
hitSlop={
|
|
241
|
+
Object {
|
|
242
|
+
"bottom": 10,
|
|
243
|
+
"left": 10,
|
|
244
|
+
"right": 10,
|
|
245
|
+
"top": 10,
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
onBlur={[Function]}
|
|
249
|
+
onClick={[Function]}
|
|
250
|
+
onFocus={[Function]}
|
|
251
|
+
onResponderGrant={[Function]}
|
|
252
|
+
onResponderMove={[Function]}
|
|
253
|
+
onResponderRelease={[Function]}
|
|
254
|
+
onResponderTerminate={[Function]}
|
|
255
|
+
onResponderTerminationRequest={[Function]}
|
|
256
|
+
onStartShouldSetResponder={[Function]}
|
|
257
|
+
style={
|
|
258
|
+
Array [
|
|
259
|
+
Object {},
|
|
260
|
+
undefined,
|
|
261
|
+
Array [
|
|
262
|
+
Object {
|
|
263
|
+
"alignSelf": "flex-start",
|
|
264
|
+
"marginLeft": "auto",
|
|
265
|
+
},
|
|
266
|
+
undefined,
|
|
267
|
+
],
|
|
268
|
+
]
|
|
269
|
+
}
|
|
270
|
+
testID="in-app-messaging--close-button"
|
|
271
|
+
>
|
|
272
|
+
<Image
|
|
273
|
+
accessibilityRole="image"
|
|
274
|
+
source={
|
|
275
|
+
Object {
|
|
276
|
+
"testUri": "../../../src/assets/icons/close.png",
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
style={
|
|
280
|
+
Array [
|
|
281
|
+
Object {
|
|
282
|
+
"height": 20,
|
|
283
|
+
"resizeMode": "contain",
|
|
284
|
+
"tintColor": undefined,
|
|
285
|
+
"width": 20,
|
|
286
|
+
},
|
|
287
|
+
undefined,
|
|
288
|
+
]
|
|
289
|
+
}
|
|
290
|
+
/>
|
|
291
|
+
</View>
|
|
292
|
+
</View>
|
|
293
|
+
<View
|
|
294
|
+
style={
|
|
295
|
+
Object {
|
|
296
|
+
"flexDirection": "row",
|
|
297
|
+
"justifyContent": "center",
|
|
298
|
+
"padding": 4,
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
>
|
|
302
|
+
<View
|
|
303
|
+
accessibilityRole="button"
|
|
304
|
+
accessible={true}
|
|
305
|
+
collapsable={false}
|
|
306
|
+
focusable={true}
|
|
307
|
+
onBlur={[Function]}
|
|
308
|
+
onClick={[Function]}
|
|
309
|
+
onFocus={[Function]}
|
|
310
|
+
onResponderGrant={[Function]}
|
|
311
|
+
onResponderMove={[Function]}
|
|
312
|
+
onResponderRelease={[Function]}
|
|
313
|
+
onResponderTerminate={[Function]}
|
|
314
|
+
onResponderTerminationRequest={[Function]}
|
|
315
|
+
onStartShouldSetResponder={[Function]}
|
|
316
|
+
style={
|
|
317
|
+
Array [
|
|
318
|
+
Object {
|
|
319
|
+
"alignItems": "center",
|
|
320
|
+
"backgroundColor": "transparent",
|
|
321
|
+
"borderColor": "hsl(210, 10%, 58%)",
|
|
322
|
+
"borderRadius": 4,
|
|
323
|
+
"borderWidth": 1,
|
|
324
|
+
"justifyContent": "center",
|
|
325
|
+
"paddingHorizontal": 16,
|
|
326
|
+
"paddingVertical": 12,
|
|
327
|
+
},
|
|
328
|
+
undefined,
|
|
329
|
+
Array [
|
|
330
|
+
Object {},
|
|
331
|
+
Object {
|
|
332
|
+
"backgroundColor": "#e8e8e8",
|
|
333
|
+
"borderRadius": 4,
|
|
334
|
+
"flex": 1,
|
|
335
|
+
"margin": 8,
|
|
336
|
+
"padding": 12,
|
|
337
|
+
},
|
|
338
|
+
Object {},
|
|
339
|
+
Object {},
|
|
340
|
+
],
|
|
341
|
+
]
|
|
342
|
+
}
|
|
343
|
+
testID="in-app-messaging--secondary-button"
|
|
344
|
+
>
|
|
345
|
+
<Text
|
|
346
|
+
style={
|
|
347
|
+
Array [
|
|
348
|
+
Object {
|
|
349
|
+
"color": "hsl(210, 50%, 10%)",
|
|
350
|
+
"fontSize": 16,
|
|
351
|
+
"fontWeight": "700",
|
|
352
|
+
"textAlign": "center",
|
|
353
|
+
},
|
|
354
|
+
Array [
|
|
355
|
+
Object {
|
|
356
|
+
"fontSize": 16,
|
|
357
|
+
"fontWeight": "400",
|
|
358
|
+
"lineHeight": 24,
|
|
359
|
+
"textAlign": "center",
|
|
360
|
+
},
|
|
361
|
+
Object {},
|
|
362
|
+
Object {},
|
|
363
|
+
],
|
|
364
|
+
]
|
|
365
|
+
}
|
|
366
|
+
>
|
|
367
|
+
secondary button
|
|
368
|
+
</Text>
|
|
369
|
+
</View>
|
|
370
|
+
</View>
|
|
371
|
+
</View>
|
|
372
|
+
</MessageWrapper>
|
|
373
|
+
`;
|
|
374
|
+
|
|
3
375
|
exports[`BannerMessage renders a message as expected with an image 1`] = `
|
|
4
376
|
<MessageWrapper
|
|
5
377
|
style={
|
|
@@ -2,6 +2,7 @@ import React, { useMemo } from 'react';
|
|
|
2
2
|
import { MessageContentProps } from '@aws-amplify/ui-react-core';
|
|
3
3
|
|
|
4
4
|
import { Carousel } from '../../../primitives';
|
|
5
|
+
import { IN_APP_MESSAGING_TEST_ID } from '../../constants';
|
|
5
6
|
|
|
6
7
|
import { MessageWrapper } from '../MessageWrapper';
|
|
7
8
|
import CarouselMessageItem from './CarouselMessageItem';
|
|
@@ -36,6 +37,7 @@ export default function CarouselMessage(
|
|
|
36
37
|
renderItem={renderItem}
|
|
37
38
|
indicatorActiveStyle={indicatorStyle.active}
|
|
38
39
|
indicatorInactiveStyle={indicatorStyle.inactive}
|
|
40
|
+
testID={IN_APP_MESSAGING_TEST_ID.CAROUSEL}
|
|
39
41
|
/>
|
|
40
42
|
</MessageWrapper>
|
|
41
43
|
);
|
|
@@ -1,25 +1,53 @@
|
|
|
1
1
|
import React, { ReactElement } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { render } from '@testing-library/react-native';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { IN_APP_MESSAGING_TEST_ID } from '../../../constants';
|
|
5
5
|
import CarouselMessage from '../CarouselMessage';
|
|
6
|
+
import { defaultStyle } from '../styles';
|
|
7
|
+
import { ReactTestRendererJSON } from 'react-test-renderer';
|
|
6
8
|
|
|
7
9
|
jest.mock('../../../../primitives', () => ({ Carousel: 'Carousel' }));
|
|
8
10
|
jest.mock('../../MessageWrapper', () => ({ MessageWrapper: 'MessageWrapper' }));
|
|
9
11
|
jest.mock('../CarouselMessageItem', () => 'CarouselMessageItem');
|
|
10
12
|
|
|
11
|
-
const baseProps = {
|
|
13
|
+
const baseProps = {
|
|
14
|
+
layout: 'CAROUSEL' as const,
|
|
15
|
+
data: [],
|
|
16
|
+
};
|
|
12
17
|
|
|
13
18
|
describe('CarouselMessage', () => {
|
|
14
|
-
let carouselMessage: ReactTestRenderer;
|
|
15
|
-
let itemRenderer: ReactTestRenderer;
|
|
16
|
-
|
|
17
19
|
it('renders as expected', () => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
const { toJSON, getByTestId } = render(<CarouselMessage {...baseProps} />);
|
|
21
|
+
|
|
22
|
+
expect(toJSON()).toMatchSnapshot();
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
const carousel = getByTestId(IN_APP_MESSAGING_TEST_ID.CAROUSEL);
|
|
25
|
+
expect(carousel).toBeDefined();
|
|
26
|
+
expect(carousel.props.data).toStrictEqual(baseProps.data);
|
|
27
|
+
expect(carousel.props.indicatorActiveStyle).toContain(
|
|
28
|
+
defaultStyle.pageIndicatorActive
|
|
29
|
+
);
|
|
30
|
+
expect(carousel.props.indicatorInactiveStyle).toContain(
|
|
31
|
+
defaultStyle.pageIndicatorInactive
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('renders as expected with minimal props', () => {
|
|
36
|
+
const { toJSON, getByTestId } = render(
|
|
37
|
+
<CarouselMessage layout={baseProps.layout} />
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
expect(toJSON()).toMatchSnapshot();
|
|
41
|
+
|
|
42
|
+
const carousel = getByTestId(IN_APP_MESSAGING_TEST_ID.CAROUSEL);
|
|
43
|
+
expect(carousel).toBeDefined();
|
|
44
|
+
expect(carousel.props.data).toEqual([]);
|
|
45
|
+
expect(carousel.props.indicatorActiveStyle).toContain(
|
|
46
|
+
defaultStyle.pageIndicatorActive
|
|
47
|
+
);
|
|
48
|
+
expect(carousel.props.indicatorInactiveStyle).toContain(
|
|
49
|
+
defaultStyle.pageIndicatorInactive
|
|
50
|
+
);
|
|
23
51
|
});
|
|
24
52
|
|
|
25
53
|
it('allows style overrides', () => {
|
|
@@ -27,29 +55,38 @@ describe('CarouselMessage', () => {
|
|
|
27
55
|
pageIndicatorActive: { backgroundColor: 'red' },
|
|
28
56
|
pageIndicatorInactive: { backgroundColor: 'blue' },
|
|
29
57
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
58
|
+
const { toJSON, getByTestId } = render(
|
|
59
|
+
<CarouselMessage {...baseProps} style={overrides} />
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
expect(toJSON()).toMatchSnapshot();
|
|
35
63
|
|
|
36
|
-
|
|
64
|
+
const carousel = getByTestId(IN_APP_MESSAGING_TEST_ID.CAROUSEL);
|
|
65
|
+
expect(carousel.props.indicatorActiveStyle).toContain(
|
|
66
|
+
overrides.pageIndicatorActive
|
|
67
|
+
);
|
|
68
|
+
expect(carousel.props.indicatorInactiveStyle).toContain(
|
|
69
|
+
overrides.pageIndicatorInactive
|
|
70
|
+
);
|
|
37
71
|
});
|
|
38
72
|
|
|
39
73
|
it('renders items', () => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
74
|
+
const { getByTestId } = render(<CarouselMessage {...baseProps} />);
|
|
75
|
+
|
|
76
|
+
const carousel = getByTestId(IN_APP_MESSAGING_TEST_ID.CAROUSEL);
|
|
77
|
+
const image = { src: 'image-src' };
|
|
44
78
|
const Item = () =>
|
|
45
|
-
(
|
|
46
|
-
|
|
79
|
+
(
|
|
80
|
+
carousel.props as { renderItem: (data: any) => ReactElement }
|
|
81
|
+
).renderItem({
|
|
82
|
+
item: { image },
|
|
47
83
|
});
|
|
84
|
+
const { toJSON } = render(<Item />);
|
|
85
|
+
const carouselMessageItem = toJSON();
|
|
86
|
+
expect(carouselMessageItem).toMatchSnapshot();
|
|
48
87
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
expect(itemRenderer.toJSON()).toMatchSnapshot();
|
|
88
|
+
const { props } = toJSON() as ReactTestRendererJSON;
|
|
89
|
+
expect(props.layout).toEqual(baseProps.layout);
|
|
90
|
+
expect(props.image).toEqual({ src: 'image-src' });
|
|
54
91
|
});
|
|
55
92
|
});
|
package/src/InAppMessaging/components/CarouselMessage/__tests__/CarouselMessageItem.spec.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { render } from '@testing-library/react-native';
|
|
3
3
|
|
|
4
4
|
import { useDeviceOrientation } from '../../../../hooks';
|
|
5
5
|
import { useMessageImage } from '../../../hooks/useMessageImage';
|
|
@@ -14,8 +14,6 @@ jest.mock('../../MessageWrapper', () => ({ MessageWrapper: 'MessageWrapper' }));
|
|
|
14
14
|
const baseProps = { layout: 'CAROUSEL' as const };
|
|
15
15
|
|
|
16
16
|
describe('CarouselMessageItem', () => {
|
|
17
|
-
let carouselMessageItem: ReactTestRenderer;
|
|
18
|
-
|
|
19
17
|
beforeEach(() => {
|
|
20
18
|
jest.clearAllMocks();
|
|
21
19
|
});
|
|
@@ -34,11 +32,9 @@ describe('CarouselMessageItem', () => {
|
|
|
34
32
|
isImageFetching: false,
|
|
35
33
|
});
|
|
36
34
|
|
|
37
|
-
|
|
38
|
-
carouselMessageItem = create(<CarouselMessageItem {...baseProps} />);
|
|
39
|
-
});
|
|
35
|
+
const { toJSON } = render(<CarouselMessageItem {...baseProps} />);
|
|
40
36
|
|
|
41
|
-
expect(
|
|
37
|
+
expect(toJSON()).toMatchSnapshot();
|
|
42
38
|
});
|
|
43
39
|
|
|
44
40
|
it('returns null if message is not ready for rendering', () => {
|
|
@@ -47,10 +43,8 @@ describe('CarouselMessageItem', () => {
|
|
|
47
43
|
imageDimensions: { height: null, width: null },
|
|
48
44
|
isImageFetching: true,
|
|
49
45
|
});
|
|
50
|
-
|
|
51
|
-
carouselMessageItem = create(<CarouselMessageItem {...baseProps} />);
|
|
52
|
-
});
|
|
46
|
+
const { toJSON } = render(<CarouselMessageItem {...baseProps} />);
|
|
53
47
|
|
|
54
|
-
expect(
|
|
48
|
+
expect(toJSON()).toBeNull();
|
|
55
49
|
});
|
|
56
50
|
});
|