@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.
Files changed (37) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/Authenticator/common/DefaultFormFields/DefaultTextFormFields.js +2 -7
  3. package/dist/Authenticator/common/DefaultFormFields/Field.d.ts +6 -0
  4. package/dist/Authenticator/common/DefaultFormFields/Field.js +34 -0
  5. package/dist/Authenticator/common/DefaultFormFields/types.d.ts +3 -0
  6. package/dist/InAppMessaging/components/CarouselMessage/CarouselMessage.js +2 -1
  7. package/dist/InAppMessaging/constants.d.ts +1 -0
  8. package/dist/InAppMessaging/constants.js +1 -0
  9. package/dist/primitives/Carousel/types.d.ts +1 -0
  10. package/dist/version.d.ts +1 -1
  11. package/dist/version.js +1 -1
  12. package/package.json +3 -3
  13. package/src/Authenticator/Defaults/ConfirmResetPassword/__tests__/__snapshots__/ConfirmResetPassword.spec.tsx.snap +44 -0
  14. package/src/Authenticator/Defaults/ForceNewPassword/__tests__/__snapshots__/ForceNewPassword.spec.tsx.snap +33 -0
  15. package/src/Authenticator/Defaults/SignIn/__tests__/__snapshots__/SignIn.spec.tsx.snap +33 -0
  16. package/src/Authenticator/Defaults/SignUp/__tests__/__snapshots__/SignUp.spec.tsx.snap +110 -0
  17. package/src/Authenticator/common/DefaultFormFields/DefaultTextFormFields.tsx +2 -13
  18. package/src/Authenticator/common/DefaultFormFields/Field.tsx +50 -0
  19. package/src/Authenticator/common/DefaultFormFields/types.ts +4 -0
  20. package/src/InAppMessaging/components/BannerMessage/__tests__/BannerMessage.spec.tsx +46 -33
  21. package/src/InAppMessaging/components/BannerMessage/__tests__/__snapshots__/BannerMessage.spec.tsx.snap +372 -0
  22. package/src/InAppMessaging/components/CarouselMessage/CarouselMessage.tsx +2 -0
  23. package/src/InAppMessaging/components/CarouselMessage/__tests__/CarouselMessage.spec.tsx +64 -27
  24. package/src/InAppMessaging/components/CarouselMessage/__tests__/CarouselMessageItem.spec.tsx +5 -11
  25. package/src/InAppMessaging/components/CarouselMessage/__tests__/__snapshots__/CarouselMessage.spec.tsx.snap +38 -0
  26. package/src/InAppMessaging/components/FullScreenMessage/__tests__/FullScreenMessage.spec.tsx +5 -5
  27. package/src/InAppMessaging/components/InAppMessageDisplay/__tests__/InAppMessageDisplay.spec.tsx +3 -3
  28. package/src/InAppMessaging/components/MessageWrapper/__tests__/MessageWrapper.spec.tsx +3 -3
  29. package/src/InAppMessaging/components/ModalMessage/__tests__/ModalMessage.spec.tsx +48 -34
  30. package/src/InAppMessaging/components/ModalMessage/__tests__/__snapshots__/ModalMessage.spec.tsx.snap +372 -0
  31. package/src/InAppMessaging/components/withInAppMessaging/__tests__/withInAppMessaging.spec.tsx +3 -3
  32. package/src/InAppMessaging/constants.ts +1 -0
  33. package/src/primitives/Carousel/__tests__/Carousel.spec.tsx +53 -64
  34. package/src/primitives/Carousel/__tests__/CarouselPageIndicator.spec.tsx +46 -44
  35. package/src/primitives/Carousel/__tests__/__snapshots__/Carousel.spec.tsx.snap +94 -0
  36. package/src/primitives/Carousel/types.ts +1 -0
  37. package/src/version.ts +1 -1
@@ -7,10 +7,10 @@ import {
7
7
  Text,
8
8
  ViewToken,
9
9
  } from 'react-native';
10
- import { act, create, ReactTestRenderer } from 'react-test-renderer';
10
+ import { act, render } from '@testing-library/react-native';
11
11
 
12
12
  import Carousel from '../Carousel';
13
- import CarouselPageIndicator from '../CarouselPageIndicator';
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
- act(() => {
46
- carousel = create(<Carousel data={data} renderItem={renderItem} />);
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
- act(() => {
60
- carousel = create(<Carousel data={data} renderItem={renderItem} />);
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
- act(() => {
74
- carousel = create(
75
- <Carousel data={null as any} renderItem={renderItem} />
76
- );
77
- });
74
+ const { toJSON } = render(
75
+ <Carousel data={null as any} renderItem={renderItem} />
76
+ );
78
77
 
79
- expect(carousel.toJSON()).toBeNull();
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
- act(() => {
85
- carousel = create(<Carousel data={[]} renderItem={renderItem} />);
86
- });
83
+ const { toJSON } = render(<Carousel data={[]} renderItem={renderItem} />);
87
84
 
88
- expect(carousel.toJSON()).toBeNull();
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
- act(() => {
101
- carousel = create(<Carousel data={data} renderItem={renderItem} />);
102
- });
103
- const instance = carousel.root;
97
+ const { container, toJSON } = render(
98
+ <Carousel data={data} renderItem={renderItem} />
99
+ );
104
100
 
105
- expect(
106
- instance.findByType(Text).parent!.parent!.props.style
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(instance.findByType(Text).parent!.parent!.props.style).toStrictEqual(
115
- window
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
- carousel = create(<Carousel data={[]} renderItem={renderItem} />);
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
- carousel = create(<Carousel data={[]} renderItem={renderItem} />);
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
- act(() => {
156
- carousel = create(<Carousel data={data} renderItem={renderItem} />);
157
- });
158
- const instance = carousel.root;
159
- const flatList = instance.findByType(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(instance.findByType(CarouselPageIndicator).props.currentIndex).toBe(
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(instance.findByType(CarouselPageIndicator).props.currentIndex).toBe(
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(instance.findByType(CarouselPageIndicator).props.currentIndex).toBe(
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 { View } from 'react-native';
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
- act(() => {
12
- carouselPageIndicator = create(
13
- <CarouselPageIndicator currentIndex={0} numberOfItems={3} />
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
- expect(carouselPageIndicator.toJSON()).toMatchSnapshot();
19
- expect(instance.findAllByType(View)).toHaveLength(3);
19
+ const { children } = toJSON() as ReactTestRendererJSON;
20
+ expect(children).toHaveLength(3);
20
21
  });
21
22
 
22
23
  it('renders with just one item', () => {
23
- act(() => {
24
- carouselPageIndicator = create(
25
- <CarouselPageIndicator currentIndex={0} numberOfItems={1} />
26
- );
27
- });
28
- const instance = carouselPageIndicator.root;
24
+ const { toJSON } = render(
25
+ <CarouselPageIndicator currentIndex={0} numberOfItems={1} />
26
+ );
29
27
 
30
- expect(carouselPageIndicator.toJSON()).toMatchSnapshot();
31
- expect(instance.findAllByType(View)).toHaveLength(1);
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
- act(() => {
37
- carouselPageIndicator = create(
38
- <CarouselPageIndicator currentIndex={0} numberOfItems={null as any} />
39
- );
40
- });
35
+ const { toJSON } = render(
36
+ <CarouselPageIndicator currentIndex={0} numberOfItems={null as any} />
37
+ );
41
38
 
42
- expect(carouselPageIndicator.toJSON()).toMatchSnapshot();
39
+ expect(toJSON()).toMatchSnapshot();
43
40
  });
44
41
 
45
42
  it('renders indicator styles based on current index', () => {
46
- act(() => {
47
- carouselPageIndicator = create(
48
- <CarouselPageIndicator currentIndex={1} numberOfItems={3} />
49
- );
50
- });
51
- const instance = carouselPageIndicator.root;
52
- const indicators = instance.findAllByType(View);
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(carouselPageIndicator.toJSON()).toMatchSnapshot();
56
- expect(indicators[0].props).toStrictEqual(indicators[2].props);
57
- expect(indicators[0].props).not.toStrictEqual(activeIndicator.props);
58
- expect(indicators[2].props).not.toStrictEqual(activeIndicator.props);
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
- act(() => {
64
- carouselPageIndicator = create(
65
- <CarouselPageIndicator currentIndex={null} numberOfItems={5} />
66
- );
67
- });
67
+ const { toJSON } = render(
68
+ <CarouselPageIndicator currentIndex={null} numberOfItems={5} />
69
+ );
68
70
 
69
- expect(carouselPageIndicator.toJSON()).toMatchSnapshot();
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
@@ -7,6 +7,7 @@ export interface CarouselProps<T> {
7
7
  onClose?: () => void;
8
8
  renderItem: ListRenderItem<T>;
9
9
  style?: StyleProp<ViewStyle>;
10
+ testID?: string;
10
11
  }
11
12
 
12
13
  export interface CarouselPageIndicatorProps {
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '1.2.0';
1
+ export const VERSION = '1.2.2';