@aws-amplify/ui-react-native 1.1.4 → 1.2.1
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 +24 -0
- package/dist/Authenticator/Authenticator.js +8 -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 -0
- package/dist/version.js +1 -0
- package/package.json +3 -3
- package/src/Authenticator/Authenticator.tsx +10 -0
- 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 -0
|
@@ -7,10 +7,10 @@ import {
|
|
|
7
7
|
Text,
|
|
8
8
|
ViewToken,
|
|
9
9
|
} from 'react-native';
|
|
10
|
-
import { act,
|
|
10
|
+
import { act, render } from '@testing-library/react-native';
|
|
11
11
|
|
|
12
12
|
import Carousel from '../Carousel';
|
|
13
|
-
import
|
|
13
|
+
import { ReactTestInstance } from 'react-test-renderer';
|
|
14
14
|
|
|
15
15
|
jest.mock('../CarouselPageIndicator', () => 'CarouselPageIndicator');
|
|
16
16
|
|
|
@@ -22,8 +22,6 @@ const renderItem: ListRenderItem<ItemProps> = ({ item }) => (
|
|
|
22
22
|
);
|
|
23
23
|
|
|
24
24
|
describe('Carousel', () => {
|
|
25
|
-
let carousel: ReactTestRenderer;
|
|
26
|
-
|
|
27
25
|
beforeEach(() => {
|
|
28
26
|
jest.clearAllMocks();
|
|
29
27
|
});
|
|
@@ -42,50 +40,49 @@ describe('Carousel', () => {
|
|
|
42
40
|
{ key: 1, str: 'foo' },
|
|
43
41
|
{ key: 2, str: 'bar' },
|
|
44
42
|
];
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
});
|
|
48
|
-
const instance = carousel.root;
|
|
49
|
-
|
|
50
|
-
expect(carousel.toJSON()).toMatchSnapshot();
|
|
51
|
-
expect(instance.findAllByType(Text)).toHaveLength(2);
|
|
52
|
-
expect(instance.findByType(CarouselPageIndicator).props.numberOfItems).toBe(
|
|
53
|
-
2
|
|
43
|
+
const { container, getByText, toJSON } = render(
|
|
44
|
+
<Carousel data={data} renderItem={renderItem} />
|
|
54
45
|
);
|
|
46
|
+
|
|
47
|
+
expect(toJSON()).toMatchSnapshot();
|
|
48
|
+
expect(getByText(data[0].str)).toBeDefined();
|
|
49
|
+
expect(getByText(data[1].str)).toBeDefined();
|
|
50
|
+
|
|
51
|
+
const carouselPageIndicator = container.children[1] as ReactTestInstance;
|
|
52
|
+
expect(carouselPageIndicator.type).toBe('CarouselPageIndicator');
|
|
53
|
+
expect(carouselPageIndicator.props.numberOfItems).toBe(2);
|
|
55
54
|
});
|
|
56
55
|
|
|
57
56
|
it('renders with just one item in the data', () => {
|
|
58
57
|
const data = [{ key: 1, str: 'qux' }];
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
});
|
|
62
|
-
const instance = carousel.root;
|
|
63
|
-
|
|
64
|
-
expect(carousel.toJSON()).toMatchSnapshot();
|
|
65
|
-
expect(instance.findAllByType(Text)).toHaveLength(1);
|
|
66
|
-
expect(instance.findByType(CarouselPageIndicator).props.numberOfItems).toBe(
|
|
67
|
-
1
|
|
58
|
+
const { container, toJSON, getByText } = render(
|
|
59
|
+
<Carousel data={data} renderItem={renderItem} />
|
|
68
60
|
);
|
|
61
|
+
|
|
62
|
+
expect(toJSON()).toMatchSnapshot();
|
|
63
|
+
expect(getByText(data[0].str)).toBeDefined();
|
|
64
|
+
const flatList = container.children[0] as ReactTestInstance;
|
|
65
|
+
expect(flatList.props.data).toStrictEqual(data);
|
|
66
|
+
|
|
67
|
+
const carouselPageIndicator = container.children[1] as ReactTestInstance;
|
|
68
|
+
expect(carouselPageIndicator.type).toBe('CarouselPageIndicator');
|
|
69
|
+
expect(carouselPageIndicator.props.numberOfItems).toBe(1);
|
|
69
70
|
});
|
|
70
71
|
|
|
71
72
|
it('returns null if data is null', () => {
|
|
72
73
|
// Ideally, this should not happen but, if it does, we should be able to handle gracefully
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
);
|
|
77
|
-
});
|
|
74
|
+
const { toJSON } = render(
|
|
75
|
+
<Carousel data={null as any} renderItem={renderItem} />
|
|
76
|
+
);
|
|
78
77
|
|
|
79
|
-
expect(
|
|
78
|
+
expect(toJSON()).toBeNull();
|
|
80
79
|
});
|
|
81
80
|
|
|
82
81
|
it('returns null if there are no items in the data', () => {
|
|
83
82
|
// Ideally, this should not happen but, if it does, we should be able to handle gracefully
|
|
84
|
-
|
|
85
|
-
carousel = create(<Carousel data={[]} renderItem={renderItem} />);
|
|
86
|
-
});
|
|
83
|
+
const { toJSON } = render(<Carousel data={[]} renderItem={renderItem} />);
|
|
87
84
|
|
|
88
|
-
expect(
|
|
85
|
+
expect(toJSON()).toBeNull();
|
|
89
86
|
});
|
|
90
87
|
|
|
91
88
|
it('calls the orientation handler on orientation change', () => {
|
|
@@ -97,23 +94,21 @@ describe('Carousel', () => {
|
|
|
97
94
|
addEventListenerSpy.mockImplementation(((_, handler) => {
|
|
98
95
|
orientationHandler = handler;
|
|
99
96
|
}) as Dimensions['addEventListener']);
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const instance = carousel.root;
|
|
97
|
+
const { container, toJSON } = render(
|
|
98
|
+
<Carousel data={data} renderItem={renderItem} />
|
|
99
|
+
);
|
|
104
100
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
).not.toStrictEqual(window);
|
|
101
|
+
const flatList = container.children[0] as ReactTestInstance;
|
|
102
|
+
expect(flatList.props.snapToInterval).not.toBe(window.width);
|
|
108
103
|
|
|
109
104
|
// Call the orientation handler with an arbitrary `ScaledSize`
|
|
110
105
|
act(() => {
|
|
111
106
|
orientationHandler({ window });
|
|
112
107
|
});
|
|
113
108
|
|
|
114
|
-
expect(
|
|
115
|
-
|
|
116
|
-
);
|
|
109
|
+
expect(flatList.props.snapToInterval).toBe(window.width);
|
|
110
|
+
|
|
111
|
+
expect(toJSON()).toMatchSnapshot();
|
|
117
112
|
});
|
|
118
113
|
|
|
119
114
|
it('cleans up the orientation change listener (React Native < v0.65)', () => {
|
|
@@ -124,11 +119,10 @@ describe('Carousel', () => {
|
|
|
124
119
|
|
|
125
120
|
const removeEventListener = jest.spyOn(Dimensions, 'removeEventListener');
|
|
126
121
|
|
|
122
|
+
const { unmount } = render(<Carousel data={[]} renderItem={renderItem} />);
|
|
123
|
+
|
|
127
124
|
act(() => {
|
|
128
|
-
|
|
129
|
-
});
|
|
130
|
-
act(() => {
|
|
131
|
-
carousel.unmount();
|
|
125
|
+
unmount();
|
|
132
126
|
});
|
|
133
127
|
|
|
134
128
|
expect(removeEventListener).toBeCalled();
|
|
@@ -138,11 +132,10 @@ describe('Carousel', () => {
|
|
|
138
132
|
const mockSubscription = { remove: jest.fn() };
|
|
139
133
|
const addEventListenerSpy = jest.spyOn(Dimensions, 'addEventListener');
|
|
140
134
|
(addEventListenerSpy as jest.Mock).mockReturnValue(mockSubscription);
|
|
135
|
+
const { unmount } = render(<Carousel data={[]} renderItem={renderItem} />);
|
|
136
|
+
|
|
141
137
|
act(() => {
|
|
142
|
-
|
|
143
|
-
});
|
|
144
|
-
act(() => {
|
|
145
|
-
carousel.unmount();
|
|
138
|
+
unmount();
|
|
146
139
|
});
|
|
147
140
|
expect(mockSubscription.remove).toBeCalled();
|
|
148
141
|
});
|
|
@@ -152,25 +145,23 @@ describe('Carousel', () => {
|
|
|
152
145
|
{ key: 1, str: 'foo' },
|
|
153
146
|
{ key: 2, str: 'bar' },
|
|
154
147
|
];
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const flatList =
|
|
148
|
+
const { container } = render(
|
|
149
|
+
<Carousel data={data} renderItem={renderItem} />
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
const flatList = container.children[0] as ReactTestInstance;
|
|
153
|
+
const carouselPageIndicator = container.children[1] as ReactTestInstance;
|
|
154
|
+
|
|
160
155
|
const { onViewableItemsChanged } = flatList.props as FlatList['props'];
|
|
161
156
|
|
|
162
|
-
expect(
|
|
163
|
-
0
|
|
164
|
-
);
|
|
157
|
+
expect(carouselPageIndicator.props.currentIndex).toBe(0);
|
|
165
158
|
|
|
166
159
|
act(() => {
|
|
167
160
|
const info = { viewableItems: [{ index: 1 } as ViewToken], changed: [] };
|
|
168
161
|
onViewableItemsChanged!(info);
|
|
169
162
|
});
|
|
170
163
|
|
|
171
|
-
expect(
|
|
172
|
-
1
|
|
173
|
-
);
|
|
164
|
+
expect(carouselPageIndicator.props.currentIndex).toBe(1);
|
|
174
165
|
|
|
175
166
|
// should not update the index if `viewableItems` is empty
|
|
176
167
|
act(() => {
|
|
@@ -178,8 +169,6 @@ describe('Carousel', () => {
|
|
|
178
169
|
onViewableItemsChanged!(info);
|
|
179
170
|
});
|
|
180
171
|
|
|
181
|
-
expect(
|
|
182
|
-
1
|
|
183
|
-
);
|
|
172
|
+
expect(carouselPageIndicator.props.currentIndex).toBe(1);
|
|
184
173
|
});
|
|
185
174
|
});
|
|
@@ -1,71 +1,73 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import { act, create, ReactTestRenderer } from 'react-test-renderer';
|
|
2
|
+
import { render } from '@testing-library/react-native';
|
|
4
3
|
|
|
5
4
|
import CarouselPageIndicator from '../CarouselPageIndicator';
|
|
5
|
+
import { ReactTestRendererJSON } from 'react-test-renderer';
|
|
6
|
+
import {
|
|
7
|
+
DEFAULT_CAROUSEL_INDICATOR_ACTIVE_STYLE,
|
|
8
|
+
DEFAULT_CAROUSEL_INDICATOR_INACTIVE_STYLE,
|
|
9
|
+
} from '../constants';
|
|
6
10
|
|
|
7
11
|
describe('CarouselPageIndicator', () => {
|
|
8
|
-
let carouselPageIndicator: ReactTestRenderer;
|
|
9
|
-
|
|
10
12
|
it('renders with multiple items', () => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const instance = carouselPageIndicator.root;
|
|
13
|
+
const { toJSON } = render(
|
|
14
|
+
<CarouselPageIndicator currentIndex={0} numberOfItems={3} />
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
expect(toJSON()).toMatchSnapshot();
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
expect(
|
|
19
|
+
const { children } = toJSON() as ReactTestRendererJSON;
|
|
20
|
+
expect(children).toHaveLength(3);
|
|
20
21
|
});
|
|
21
22
|
|
|
22
23
|
it('renders with just one item', () => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
);
|
|
27
|
-
});
|
|
28
|
-
const instance = carouselPageIndicator.root;
|
|
24
|
+
const { toJSON } = render(
|
|
25
|
+
<CarouselPageIndicator currentIndex={0} numberOfItems={1} />
|
|
26
|
+
);
|
|
29
27
|
|
|
30
|
-
expect(
|
|
31
|
-
|
|
28
|
+
expect(toJSON()).toMatchSnapshot();
|
|
29
|
+
const { children } = toJSON() as ReactTestRendererJSON;
|
|
30
|
+
expect(children).toHaveLength(1);
|
|
32
31
|
});
|
|
33
32
|
|
|
34
33
|
it('handles null numberOfItems value', () => {
|
|
35
34
|
// Ideally, this should not happen but, if it does, we should be able to handle gracefully
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
);
|
|
40
|
-
});
|
|
35
|
+
const { toJSON } = render(
|
|
36
|
+
<CarouselPageIndicator currentIndex={0} numberOfItems={null as any} />
|
|
37
|
+
);
|
|
41
38
|
|
|
42
|
-
expect(
|
|
39
|
+
expect(toJSON()).toMatchSnapshot();
|
|
43
40
|
});
|
|
44
41
|
|
|
45
42
|
it('renders indicator styles based on current index', () => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const activeIndicator = indicators[1];
|
|
43
|
+
const { toJSON } = render(
|
|
44
|
+
<CarouselPageIndicator currentIndex={1} numberOfItems={3} />
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const { children } = toJSON() as ReactTestRendererJSON;
|
|
48
|
+
|
|
49
|
+
expect(toJSON()).toMatchSnapshot();
|
|
54
50
|
|
|
55
|
-
expect(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
51
|
+
expect((children?.[0] as ReactTestRendererJSON).props.style).toStrictEqual([
|
|
52
|
+
DEFAULT_CAROUSEL_INDICATOR_INACTIVE_STYLE,
|
|
53
|
+
undefined,
|
|
54
|
+
]);
|
|
55
|
+
expect((children?.[1] as ReactTestRendererJSON).props.style).toStrictEqual([
|
|
56
|
+
DEFAULT_CAROUSEL_INDICATOR_ACTIVE_STYLE,
|
|
57
|
+
undefined,
|
|
58
|
+
]);
|
|
59
|
+
expect((children?.[2] as ReactTestRendererJSON).props.style).toStrictEqual([
|
|
60
|
+
DEFAULT_CAROUSEL_INDICATOR_INACTIVE_STYLE,
|
|
61
|
+
undefined,
|
|
62
|
+
]);
|
|
59
63
|
});
|
|
60
64
|
|
|
61
65
|
it('handles null index value', () => {
|
|
62
66
|
// Ideally, this should not happen but, if it does, we should be able to handle gracefully
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
);
|
|
67
|
-
});
|
|
67
|
+
const { toJSON } = render(
|
|
68
|
+
<CarouselPageIndicator currentIndex={null} numberOfItems={5} />
|
|
69
|
+
);
|
|
68
70
|
|
|
69
|
-
expect(
|
|
71
|
+
expect(toJSON()).toMatchSnapshot();
|
|
70
72
|
});
|
|
71
73
|
});
|
|
@@ -1,5 +1,99 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
+
exports[`Carousel calls the orientation handler on orientation change 1`] = `
|
|
4
|
+
Array [
|
|
5
|
+
<RCTScrollView
|
|
6
|
+
bounces={false}
|
|
7
|
+
data={
|
|
8
|
+
Array [
|
|
9
|
+
Object {
|
|
10
|
+
"key": 1,
|
|
11
|
+
"str": "qux",
|
|
12
|
+
},
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
decelerationRate="fast"
|
|
16
|
+
disableIntervalMomentum={true}
|
|
17
|
+
getItem={[Function]}
|
|
18
|
+
getItemCount={[Function]}
|
|
19
|
+
horizontal={true}
|
|
20
|
+
keyExtractor={[Function]}
|
|
21
|
+
onContentSizeChange={[Function]}
|
|
22
|
+
onLayout={[Function]}
|
|
23
|
+
onMomentumScrollBegin={[Function]}
|
|
24
|
+
onMomentumScrollEnd={[Function]}
|
|
25
|
+
onScroll={[Function]}
|
|
26
|
+
onScrollBeginDrag={[Function]}
|
|
27
|
+
onScrollEndDrag={[Function]}
|
|
28
|
+
onViewableItemsChanged={[Function]}
|
|
29
|
+
removeClippedSubviews={false}
|
|
30
|
+
renderItem={[Function]}
|
|
31
|
+
renderToHardwareTextureAndroid={true}
|
|
32
|
+
scrollEventThrottle={50}
|
|
33
|
+
showsHorizontalScrollIndicator={false}
|
|
34
|
+
showsVerticalScrollIndicator={false}
|
|
35
|
+
snapToAlignment="start"
|
|
36
|
+
snapToInterval={350}
|
|
37
|
+
stickyHeaderIndices={Array []}
|
|
38
|
+
viewabilityConfig={
|
|
39
|
+
Object {
|
|
40
|
+
"itemVisiblePercentThreshold": 60,
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
viewabilityConfigCallbackPairs={
|
|
44
|
+
Array [
|
|
45
|
+
Object {
|
|
46
|
+
"onViewableItemsChanged": [Function],
|
|
47
|
+
"viewabilityConfig": Object {
|
|
48
|
+
"itemVisiblePercentThreshold": 60,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
>
|
|
54
|
+
<View>
|
|
55
|
+
<View
|
|
56
|
+
onLayout={[Function]}
|
|
57
|
+
style={
|
|
58
|
+
Array [
|
|
59
|
+
Object {
|
|
60
|
+
"flexDirection": "row",
|
|
61
|
+
},
|
|
62
|
+
null,
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
>
|
|
66
|
+
<View
|
|
67
|
+
style={
|
|
68
|
+
Object {
|
|
69
|
+
"width": 350,
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
>
|
|
73
|
+
<Text>
|
|
74
|
+
qux
|
|
75
|
+
</Text>
|
|
76
|
+
</View>
|
|
77
|
+
</View>
|
|
78
|
+
</View>
|
|
79
|
+
</RCTScrollView>,
|
|
80
|
+
<CarouselPageIndicator
|
|
81
|
+
currentIndex={0}
|
|
82
|
+
numberOfItems={1}
|
|
83
|
+
style={
|
|
84
|
+
Object {
|
|
85
|
+
"bottom": 0,
|
|
86
|
+
"flexDirection": "row",
|
|
87
|
+
"justifyContent": "center",
|
|
88
|
+
"left": 0,
|
|
89
|
+
"position": "absolute",
|
|
90
|
+
"right": 0,
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/>,
|
|
94
|
+
]
|
|
95
|
+
`;
|
|
96
|
+
|
|
3
97
|
exports[`Carousel renders with just one item in the data 1`] = `
|
|
4
98
|
Array [
|
|
5
99
|
<RCTScrollView
|
package/src/version.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const VERSION = '1.2.1';
|