stream-chat-react-native-core 4.3.1 → 4.4.0-beta.3

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 (186) hide show
  1. package/README.md +3 -3
  2. package/lib/commonjs/components/Attachment/Card.js +25 -28
  3. package/lib/commonjs/components/Attachment/Card.js.map +1 -1
  4. package/lib/commonjs/components/Attachment/FileAttachment.js +19 -24
  5. package/lib/commonjs/components/Attachment/FileAttachment.js.map +1 -1
  6. package/lib/commonjs/components/Attachment/Giphy.js +27 -25
  7. package/lib/commonjs/components/Attachment/Giphy.js.map +1 -1
  8. package/lib/commonjs/components/Attachment/hooks/useGoToURL.js +42 -0
  9. package/lib/commonjs/components/Attachment/hooks/useGoToURL.js.map +1 -0
  10. package/lib/commonjs/components/AttachmentPicker/AttachmentPicker.js +11 -7
  11. package/lib/commonjs/components/AttachmentPicker/AttachmentPicker.js.map +1 -1
  12. package/lib/commonjs/components/Channel/Channel.js.map +1 -1
  13. package/lib/commonjs/components/Channel/hooks/useCreatePaginatedMessageListContext.js +4 -12
  14. package/lib/commonjs/components/Channel/hooks/useCreatePaginatedMessageListContext.js.map +1 -1
  15. package/lib/commonjs/components/Channel/hooks/useCreateThreadContext.js +4 -12
  16. package/lib/commonjs/components/Channel/hooks/useCreateThreadContext.js.map +1 -1
  17. package/lib/commonjs/components/Chat/Chat.js +8 -4
  18. package/lib/commonjs/components/Chat/Chat.js.map +1 -1
  19. package/lib/commonjs/components/Chat/hooks/useAppSettings.js +80 -0
  20. package/lib/commonjs/components/Chat/hooks/useAppSettings.js.map +1 -0
  21. package/lib/commonjs/components/Chat/hooks/useCreateChatContext.js +3 -1
  22. package/lib/commonjs/components/Chat/hooks/useCreateChatContext.js.map +1 -1
  23. package/lib/commonjs/components/Message/Message.js +27 -22
  24. package/lib/commonjs/components/Message/Message.js.map +1 -1
  25. package/lib/commonjs/components/Message/MessageSimple/utils/renderText.js +28 -14
  26. package/lib/commonjs/components/Message/MessageSimple/utils/renderText.js.map +1 -1
  27. package/lib/commonjs/components/MessageInput/FileUploadPreview.js +108 -40
  28. package/lib/commonjs/components/MessageInput/FileUploadPreview.js.map +1 -1
  29. package/lib/commonjs/components/MessageInput/ImageUploadPreview.js +117 -24
  30. package/lib/commonjs/components/MessageInput/ImageUploadPreview.js.map +1 -1
  31. package/lib/commonjs/components/MessageInput/UploadProgressIndicator.js +52 -20
  32. package/lib/commonjs/components/MessageInput/UploadProgressIndicator.js.map +1 -1
  33. package/lib/commonjs/components/MessageList/ScrollToBottomButton.js +8 -6
  34. package/lib/commonjs/components/MessageList/ScrollToBottomButton.js.map +1 -1
  35. package/lib/commonjs/contexts/chatContext/ChatContext.js +2 -2
  36. package/lib/commonjs/contexts/chatContext/ChatContext.js.map +1 -1
  37. package/lib/commonjs/contexts/messageContext/MessageContext.js +2 -2
  38. package/lib/commonjs/contexts/messageContext/MessageContext.js.map +1 -1
  39. package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js +145 -119
  40. package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js.map +1 -1
  41. package/lib/commonjs/contexts/messageInputContext/hooks/useMessageDetailsForState.js.map +1 -1
  42. package/lib/commonjs/contexts/themeContext/utils/theme.js.map +1 -1
  43. package/lib/commonjs/i18n/en.json +2 -0
  44. package/lib/commonjs/i18n/fr.json +2 -0
  45. package/lib/commonjs/i18n/hi.json +2 -0
  46. package/lib/commonjs/i18n/it.json +2 -0
  47. package/lib/commonjs/i18n/ja.json +3 -1
  48. package/lib/commonjs/i18n/ko.json +3 -1
  49. package/lib/commonjs/i18n/nl.json +2 -0
  50. package/lib/commonjs/i18n/ru.json +2 -0
  51. package/lib/commonjs/i18n/tr.json +2 -0
  52. package/lib/commonjs/icons/Warning.js +38 -0
  53. package/lib/commonjs/icons/Warning.js.map +1 -0
  54. package/lib/commonjs/icons/index.js +13 -0
  55. package/lib/commonjs/icons/index.js.map +1 -1
  56. package/lib/commonjs/utils/utils.js +33 -2
  57. package/lib/commonjs/utils/utils.js.map +1 -1
  58. package/lib/commonjs/version.json +1 -1
  59. package/lib/module/components/Attachment/Card.js +25 -28
  60. package/lib/module/components/Attachment/Card.js.map +1 -1
  61. package/lib/module/components/Attachment/FileAttachment.js +19 -24
  62. package/lib/module/components/Attachment/FileAttachment.js.map +1 -1
  63. package/lib/module/components/Attachment/Giphy.js +27 -25
  64. package/lib/module/components/Attachment/Giphy.js.map +1 -1
  65. package/lib/module/components/Attachment/hooks/useGoToURL.js +42 -0
  66. package/lib/module/components/Attachment/hooks/useGoToURL.js.map +1 -0
  67. package/lib/module/components/AttachmentPicker/AttachmentPicker.js +11 -7
  68. package/lib/module/components/AttachmentPicker/AttachmentPicker.js.map +1 -1
  69. package/lib/module/components/Channel/Channel.js.map +1 -1
  70. package/lib/module/components/Channel/hooks/useCreatePaginatedMessageListContext.js +4 -12
  71. package/lib/module/components/Channel/hooks/useCreatePaginatedMessageListContext.js.map +1 -1
  72. package/lib/module/components/Channel/hooks/useCreateThreadContext.js +4 -12
  73. package/lib/module/components/Channel/hooks/useCreateThreadContext.js.map +1 -1
  74. package/lib/module/components/Chat/Chat.js +8 -4
  75. package/lib/module/components/Chat/Chat.js.map +1 -1
  76. package/lib/module/components/Chat/hooks/useAppSettings.js +80 -0
  77. package/lib/module/components/Chat/hooks/useAppSettings.js.map +1 -0
  78. package/lib/module/components/Chat/hooks/useCreateChatContext.js +3 -1
  79. package/lib/module/components/Chat/hooks/useCreateChatContext.js.map +1 -1
  80. package/lib/module/components/Message/Message.js +27 -22
  81. package/lib/module/components/Message/Message.js.map +1 -1
  82. package/lib/module/components/Message/MessageSimple/utils/renderText.js +28 -14
  83. package/lib/module/components/Message/MessageSimple/utils/renderText.js.map +1 -1
  84. package/lib/module/components/MessageInput/FileUploadPreview.js +108 -40
  85. package/lib/module/components/MessageInput/FileUploadPreview.js.map +1 -1
  86. package/lib/module/components/MessageInput/ImageUploadPreview.js +117 -24
  87. package/lib/module/components/MessageInput/ImageUploadPreview.js.map +1 -1
  88. package/lib/module/components/MessageInput/UploadProgressIndicator.js +52 -20
  89. package/lib/module/components/MessageInput/UploadProgressIndicator.js.map +1 -1
  90. package/lib/module/components/MessageList/ScrollToBottomButton.js +8 -6
  91. package/lib/module/components/MessageList/ScrollToBottomButton.js.map +1 -1
  92. package/lib/module/contexts/chatContext/ChatContext.js +2 -2
  93. package/lib/module/contexts/chatContext/ChatContext.js.map +1 -1
  94. package/lib/module/contexts/messageContext/MessageContext.js +2 -2
  95. package/lib/module/contexts/messageContext/MessageContext.js.map +1 -1
  96. package/lib/module/contexts/messageInputContext/MessageInputContext.js +145 -119
  97. package/lib/module/contexts/messageInputContext/MessageInputContext.js.map +1 -1
  98. package/lib/module/contexts/messageInputContext/hooks/useMessageDetailsForState.js.map +1 -1
  99. package/lib/module/contexts/themeContext/utils/theme.js.map +1 -1
  100. package/lib/module/i18n/en.json +2 -0
  101. package/lib/module/i18n/fr.json +2 -0
  102. package/lib/module/i18n/hi.json +2 -0
  103. package/lib/module/i18n/it.json +2 -0
  104. package/lib/module/i18n/ja.json +3 -1
  105. package/lib/module/i18n/ko.json +3 -1
  106. package/lib/module/i18n/nl.json +2 -0
  107. package/lib/module/i18n/ru.json +2 -0
  108. package/lib/module/i18n/tr.json +2 -0
  109. package/lib/module/icons/Warning.js +38 -0
  110. package/lib/module/icons/Warning.js.map +1 -0
  111. package/lib/module/icons/index.js +13 -0
  112. package/lib/module/icons/index.js.map +1 -1
  113. package/lib/module/utils/utils.js +33 -2
  114. package/lib/module/utils/utils.js.map +1 -1
  115. package/lib/module/version.json +1 -1
  116. package/lib/typescript/components/Attachment/FileAttachment.d.ts +0 -1
  117. package/lib/typescript/components/Attachment/hooks/useGoToURL.d.ts +2 -0
  118. package/lib/typescript/components/Chat/hooks/__tests__/useAppSettings.test.d.ts +1 -0
  119. package/lib/typescript/components/Chat/hooks/useAppSettings.d.ts +3 -0
  120. package/lib/typescript/components/Chat/hooks/useCreateChatContext.d.ts +1 -1
  121. package/lib/typescript/components/Message/Message.d.ts +12 -2
  122. package/lib/typescript/components/MessageInput/UploadProgressIndicator.d.ts +1 -3
  123. package/lib/typescript/contexts/chatContext/ChatContext.d.ts +5 -1
  124. package/lib/typescript/contexts/messageContext/MessageContext.d.ts +4 -4
  125. package/lib/typescript/contexts/messageInputContext/MessageInputContext.d.ts +3 -3
  126. package/lib/typescript/contexts/themeContext/utils/theme.d.ts +1 -0
  127. package/lib/typescript/i18n/en.json +2 -0
  128. package/lib/typescript/i18n/fr.json +2 -0
  129. package/lib/typescript/i18n/hi.json +2 -0
  130. package/lib/typescript/i18n/it.json +2 -0
  131. package/lib/typescript/i18n/ja.json +3 -1
  132. package/lib/typescript/i18n/ko.json +3 -1
  133. package/lib/typescript/i18n/nl.json +2 -0
  134. package/lib/typescript/i18n/ru.json +2 -0
  135. package/lib/typescript/i18n/tr.json +2 -0
  136. package/lib/typescript/icons/Warning.d.ts +3 -0
  137. package/lib/typescript/icons/index.d.ts +1 -0
  138. package/lib/typescript/utils/Streami18n.d.ts +6 -0
  139. package/lib/typescript/utils/utils.d.ts +15 -2
  140. package/package.json +2 -2
  141. package/src/components/Attachment/Card.tsx +5 -13
  142. package/src/components/Attachment/FileAttachment.tsx +5 -13
  143. package/src/components/Attachment/Giphy.tsx +3 -1
  144. package/src/components/Attachment/__tests__/Attachment.test.js +39 -0
  145. package/src/components/Attachment/hooks/useGoToURL.ts +27 -0
  146. package/src/components/AttachmentPicker/AttachmentPicker.tsx +23 -13
  147. package/src/components/Channel/Channel.tsx +1 -1
  148. package/src/components/Channel/hooks/useCreatePaginatedMessageListContext.ts +3 -9
  149. package/src/components/Channel/hooks/useCreateThreadContext.ts +3 -9
  150. package/src/components/ChannelList/hooks/listeners/__tests__/useChannelUpdated.test.tsx +1 -0
  151. package/src/components/Chat/Chat.tsx +4 -0
  152. package/src/components/Chat/hooks/__tests__/useAppSettings.test.tsx +34 -0
  153. package/src/components/Chat/hooks/useAppSettings.ts +39 -0
  154. package/src/components/Chat/hooks/useCreateChatContext.ts +2 -0
  155. package/src/components/Message/Message.tsx +56 -48
  156. package/src/components/Message/MessageSimple/utils/renderText.tsx +17 -2
  157. package/src/components/MessageInput/FileUploadPreview.tsx +60 -14
  158. package/src/components/MessageInput/ImageUploadPreview.tsx +95 -42
  159. package/src/components/MessageInput/UploadProgressIndicator.tsx +49 -22
  160. package/src/components/MessageInput/__tests__/FileUploadPreview.test.js +50 -80
  161. package/src/components/MessageInput/__tests__/ImageUploadPreview.test.js +49 -74
  162. package/src/components/MessageInput/__tests__/UploadProgressIndicator.test.js +36 -13
  163. package/src/components/MessageInput/__tests__/__snapshots__/MessageInput.test.js.snap +2 -2
  164. package/src/components/MessageInput/__tests__/__snapshots__/UploadProgressIndicator.test.js.snap +122 -17
  165. package/src/components/MessageList/ScrollToBottomButton.tsx +2 -1
  166. package/src/components/MessageList/__tests__/__snapshots__/ScrollToBottomButton.test.js.snap +1 -0
  167. package/src/contexts/chatContext/ChatContext.tsx +5 -1
  168. package/src/contexts/messageContext/MessageContext.tsx +7 -4
  169. package/src/contexts/messageInputContext/MessageInputContext.tsx +127 -96
  170. package/src/contexts/messageInputContext/hooks/useMessageDetailsForState.ts +2 -2
  171. package/src/contexts/themeContext/utils/theme.ts +1 -0
  172. package/src/i18n/en.json +2 -0
  173. package/src/i18n/fr.json +2 -0
  174. package/src/i18n/hi.json +2 -0
  175. package/src/i18n/it.json +2 -0
  176. package/src/i18n/ja.json +3 -1
  177. package/src/i18n/ko.json +3 -1
  178. package/src/i18n/nl.json +2 -0
  179. package/src/i18n/ru.json +2 -0
  180. package/src/i18n/tr.json +2 -0
  181. package/src/icons/Warning.tsx +12 -0
  182. package/src/icons/index.ts +1 -0
  183. package/src/utils/utils.ts +53 -1
  184. package/src/version.json +1 -1
  185. package/src/components/MessageInput/__tests__/__snapshots__/FileUploadPreview.test.js.snap +0 -4413
  186. package/src/components/MessageInput/__tests__/__snapshots__/ImageUploadPreview.test.js.snap +0 -2373
@@ -13,6 +13,8 @@ import { useTheme } from '../../contexts/themeContext/ThemeContext';
13
13
  import { Refresh } from '../../icons';
14
14
  import { ProgressIndicatorTypes } from '../../utils/utils';
15
15
 
16
+ const REFRESH_ICON_SIZE = 18;
17
+
16
18
  const styles = StyleSheet.create({
17
19
  activityIndicatorContainer: {
18
20
  alignItems: 'center',
@@ -55,27 +57,25 @@ const styles = StyleSheet.create({
55
57
  export type UploadProgressIndicatorProps = {
56
58
  /** Action triggered when clicked indicator */
57
59
  action?: (event: GestureResponderEvent) => void;
58
- /** Boolean status of upload progress */
59
- active?: boolean;
60
60
  /** style */
61
61
  style?: StyleProp<ViewStyle>;
62
62
  /** Type of active indicator */
63
- type?: 'in_progress' | 'retry';
63
+ type?: 'in_progress' | 'retry' | 'not_supported' | 'inactive' | null;
64
64
  };
65
65
 
66
66
  export const UploadProgressIndicator: React.FC<UploadProgressIndicatorProps> = (props) => {
67
- const { action, active, children, style, type } = props;
67
+ const { action, children, style, type } = props;
68
68
 
69
69
  const {
70
70
  theme: {
71
- colors: { overlay: overlayColor, white_smoke },
71
+ colors: { overlay: overlayColor },
72
72
  messageInput: {
73
73
  uploadProgressIndicator: { container, overlay },
74
74
  },
75
75
  },
76
76
  } = useTheme();
77
77
 
78
- return !active ? (
78
+ return type === ProgressIndicatorTypes.INACTIVE ? (
79
79
  <View style={[styles.overflowHidden, style]} testID='inactive-upload-progress-indicator'>
80
80
  {children}
81
81
  </View>
@@ -83,26 +83,53 @@ export const UploadProgressIndicator: React.FC<UploadProgressIndicatorProps> = (
83
83
  <View style={[styles.overflowHidden, style]} testID='active-upload-progress-indicator'>
84
84
  {children}
85
85
  <View style={[styles.overlay, { backgroundColor: overlayColor }, overlay]} />
86
- <View style={[styles.container, { backgroundColor: overlayColor }, container]}>
87
- {type === ProgressIndicatorTypes.IN_PROGRESS && (
88
- <View style={styles.activityIndicatorContainer}>
89
- <ActivityIndicator color={white_smoke} testID='upload-progress-indicator' />
90
- </View>
91
- )}
92
- {type === ProgressIndicatorTypes.RETRY && (
93
- <TouchableOpacity onPress={action} style={styles.retryButtonContainer}>
94
- <Refresh
95
- height={18}
96
- pathFill={white_smoke}
97
- testID='retry-upload-progress-indicator'
98
- width={18}
99
- />
100
- </TouchableOpacity>
101
- )}
86
+ <View
87
+ style={[
88
+ type === ProgressIndicatorTypes.NOT_SUPPORTED ? styles.overflowHidden : styles.container,
89
+ { backgroundColor: overlayColor },
90
+ container,
91
+ ]}
92
+ testID='not-supported-upload-progress-indicator'
93
+ >
94
+ {type === ProgressIndicatorTypes.IN_PROGRESS && <InProgressIndicator />}
95
+ {type === ProgressIndicatorTypes.RETRY && <RetryIndicator action={action} />}
102
96
  </View>
103
97
  </View>
104
98
  );
105
99
  };
106
100
 
101
+ const InProgressIndicator = () => {
102
+ const {
103
+ theme: {
104
+ colors: { white_smoke },
105
+ },
106
+ } = useTheme();
107
+
108
+ return (
109
+ <View style={styles.activityIndicatorContainer}>
110
+ <ActivityIndicator color={white_smoke} testID='upload-progress-indicator' />
111
+ </View>
112
+ );
113
+ };
114
+
115
+ const RetryIndicator = ({ action }: Pick<UploadProgressIndicatorProps, 'action'>) => {
116
+ const {
117
+ theme: {
118
+ colors: { white_smoke },
119
+ },
120
+ } = useTheme();
121
+
122
+ return (
123
+ <TouchableOpacity onPress={action} style={styles.retryButtonContainer}>
124
+ <Refresh
125
+ height={REFRESH_ICON_SIZE}
126
+ pathFill={white_smoke}
127
+ testID='retry-upload-progress-indicator'
128
+ width={REFRESH_ICON_SIZE}
129
+ />
130
+ </TouchableOpacity>
131
+ );
132
+ };
133
+
107
134
  UploadProgressIndicator.displayName =
108
135
  'UploadProgressIndicator{messageInput{uploadProgressIndicator}}';
@@ -31,6 +31,7 @@ describe('FileUploadPreview', () => {
31
31
  generateFileUploadPreview({ id: 'file-upload-id-1', state: FileState.UPLOADING }),
32
32
  generateFileUploadPreview({ id: 'file-upload-id-2', state: FileState.UPLOADING }),
33
33
  generateFileUploadPreview({ id: 'file-upload-id-3', state: FileState.UPLOADING }),
34
+ generateFileUploadPreview({ id: 'file-upload-id-4', state: FileState.UPLOADING }),
34
35
  ];
35
36
  const removeFile = jest.fn();
36
37
  const uploadFile = jest.fn();
@@ -47,7 +48,7 @@ describe('FileUploadPreview', () => {
47
48
  const channel = chatClient.channel('messaging', mockedChannel.id);
48
49
  await channel.query();
49
50
 
50
- const { getAllByTestId, queryAllByTestId, rerender, toJSON } = render(
51
+ const { getAllByTestId, queryAllByTestId, queryAllByText } = render(
51
52
  <OverlayProvider>
52
53
  <Chat client={chatClient}>
53
54
  <Channel channel={channel} FlatList={MockedFlatList}>
@@ -66,6 +67,7 @@ describe('FileUploadPreview', () => {
66
67
  expect(queryAllByTestId('inactive-upload-progress-indicator')).toHaveLength(0);
67
68
  expect(queryAllByTestId('upload-progress-indicator')).toHaveLength(fileUploads.length);
68
69
  expect(queryAllByTestId('retry-upload-progress-indicator')).toHaveLength(0);
70
+ expect(queryAllByText('File type not supported')).toHaveLength(0);
69
71
  expect(removeFile).toHaveBeenCalledTimes(0);
70
72
  expect(uploadFile).toHaveBeenCalledTimes(0);
71
73
  });
@@ -76,29 +78,6 @@ describe('FileUploadPreview', () => {
76
78
  expect(removeFile).toHaveBeenCalledTimes(1);
77
79
  expect(uploadFile).toHaveBeenCalledTimes(0);
78
80
  });
79
-
80
- rerender(
81
- <OverlayProvider>
82
- <Chat client={chatClient}>
83
- <Channel channel={channel} FlatList={MockedFlatList}>
84
- <FileUploadPreview
85
- fileUploads={fileUploads.map((file, index) => ({
86
- ...file,
87
- id: `${index}`,
88
- }))}
89
- removeFile={removeFile}
90
- uploadFile={uploadFile}
91
- />
92
- </Channel>
93
- </Chat>
94
- </OverlayProvider>,
95
- );
96
-
97
- const snapshot = toJSON();
98
-
99
- await waitFor(() => {
100
- expect(snapshot).toMatchSnapshot();
101
- });
102
81
  });
103
82
 
104
83
  it('should render FileUploadPreview with all uploaded files', async () => {
@@ -106,6 +85,7 @@ describe('FileUploadPreview', () => {
106
85
  generateFileUploadPreview({ id: 'file-upload-id-1', state: FileState.UPLOADED }),
107
86
  generateFileUploadPreview({ id: 'file-upload-id-2', state: FileState.UPLOADED }),
108
87
  generateFileUploadPreview({ id: 'file-upload-id-3', state: FileState.UPLOADED }),
88
+ generateFileUploadPreview({ id: 'file-upload-id-4', state: FileState.UPLOADED }),
109
89
  ];
110
90
  const removeFile = jest.fn();
111
91
  const uploadFile = jest.fn();
@@ -122,7 +102,7 @@ describe('FileUploadPreview', () => {
122
102
  const channel = chatClient.channel('messaging', mockedChannel.id);
123
103
  await channel.query();
124
104
 
125
- const { getAllByTestId, queryAllByTestId, rerender, toJSON } = render(
105
+ const { getAllByTestId, queryAllByTestId, queryAllByText } = render(
126
106
  <OverlayProvider>
127
107
  <Chat client={chatClient}>
128
108
  <Channel channel={channel} FlatList={MockedFlatList}>
@@ -143,6 +123,7 @@ describe('FileUploadPreview', () => {
143
123
  );
144
124
  expect(queryAllByTestId('upload-progress-indicator')).toHaveLength(0);
145
125
  expect(queryAllByTestId('retry-upload-progress-indicator')).toHaveLength(0);
126
+ expect(queryAllByText('File type not supported')).toHaveLength(0);
146
127
  expect(removeFile).toHaveBeenCalledTimes(0);
147
128
  expect(uploadFile).toHaveBeenCalledTimes(0);
148
129
  });
@@ -153,29 +134,6 @@ describe('FileUploadPreview', () => {
153
134
  expect(removeFile).toHaveBeenCalledTimes(1);
154
135
  expect(uploadFile).toHaveBeenCalledTimes(0);
155
136
  });
156
-
157
- rerender(
158
- <OverlayProvider>
159
- <Chat client={chatClient}>
160
- <Channel channel={channel} FlatList={MockedFlatList}>
161
- <FileUploadPreview
162
- fileUploads={fileUploads.map((file, index) => ({
163
- ...file,
164
- id: `${index}`,
165
- }))}
166
- removeFile={removeFile}
167
- uploadFile={uploadFile}
168
- />
169
- </Channel>
170
- </Chat>
171
- </OverlayProvider>,
172
- );
173
-
174
- const snapshot = toJSON();
175
-
176
- await waitFor(() => {
177
- expect(snapshot).toMatchSnapshot();
178
- });
179
137
  });
180
138
 
181
139
  it('should render FileUploadPreview with all failed files', async () => {
@@ -183,6 +141,7 @@ describe('FileUploadPreview', () => {
183
141
  generateFileUploadPreview({ id: 'file-upload-id-1', state: FileState.UPLOAD_FAILED }),
184
142
  generateFileUploadPreview({ id: 'file-upload-id-2', state: FileState.UPLOAD_FAILED }),
185
143
  generateFileUploadPreview({ id: 'file-upload-id-3', state: FileState.UPLOAD_FAILED }),
144
+ generateFileUploadPreview({ id: 'file-upload-id-4', state: FileState.UPLOAD_FAILED }),
186
145
  ];
187
146
  const removeFile = jest.fn();
188
147
  const uploadFile = jest.fn();
@@ -199,7 +158,7 @@ describe('FileUploadPreview', () => {
199
158
  const channel = chatClient.channel('messaging', mockedChannel.id);
200
159
  await channel.query();
201
160
 
202
- const { getAllByTestId, queryAllByTestId, rerender, toJSON } = render(
161
+ const { getAllByTestId, queryAllByTestId, queryAllByText } = render(
203
162
  <OverlayProvider>
204
163
  <Chat client={chatClient}>
205
164
  <Channel channel={channel} FlatList={MockedFlatList}>
@@ -218,6 +177,7 @@ describe('FileUploadPreview', () => {
218
177
  expect(queryAllByTestId('inactive-upload-progress-indicator')).toHaveLength(0);
219
178
  expect(queryAllByTestId('upload-progress-indicator')).toHaveLength(0);
220
179
  expect(queryAllByTestId('retry-upload-progress-indicator')).toHaveLength(fileUploads.length);
180
+ expect(queryAllByText('File type not supported')).toHaveLength(0);
221
181
  expect(removeFile).toHaveBeenCalledTimes(0);
222
182
  expect(uploadFile).toHaveBeenCalledTimes(0);
223
183
  });
@@ -235,16 +195,36 @@ describe('FileUploadPreview', () => {
235
195
  expect(removeFile).toHaveBeenCalledTimes(1);
236
196
  expect(uploadFile).toHaveBeenCalledTimes(1);
237
197
  });
198
+ });
199
+
200
+ it('should render FileUploadPreview with all unsupported files', async () => {
201
+ const fileUploads = [
202
+ generateFileUploadPreview({ id: 'file-upload-id-1', state: FileState.NOT_SUPPORTED }),
203
+ generateFileUploadPreview({ id: 'file-upload-id-2', state: FileState.NOT_SUPPORTED }),
204
+ generateFileUploadPreview({ id: 'file-upload-id-3', state: FileState.NOT_SUPPORTED }),
205
+ generateFileUploadPreview({ id: 'file-upload-id-4', state: FileState.NOT_SUPPORTED }),
206
+ ];
207
+ const removeFile = jest.fn();
208
+ const uploadFile = jest.fn();
209
+
210
+ const user1 = generateUser();
238
211
 
239
- rerender(
212
+ const mockedChannel = generateChannelResponse({
213
+ members: [generateMember({ user: user1 })],
214
+ messages: [generateMessage({ user: user1 }), generateMessage({ user: user1 })],
215
+ });
216
+
217
+ const chatClient = await getTestClientWithUser({ id: 'testID' });
218
+ useMockedApis(chatClient, [getOrCreateChannelApi(mockedChannel)]);
219
+ const channel = chatClient.channel('messaging', mockedChannel.id);
220
+ await channel.query();
221
+
222
+ const { getAllByTestId, queryAllByTestId, queryAllByText } = render(
240
223
  <OverlayProvider>
241
224
  <Chat client={chatClient}>
242
225
  <Channel channel={channel} FlatList={MockedFlatList}>
243
226
  <FileUploadPreview
244
- fileUploads={fileUploads.map((file, index) => ({
245
- ...file,
246
- id: `${index}`,
247
- }))}
227
+ fileUploads={fileUploads}
248
228
  removeFile={removeFile}
249
229
  uploadFile={uploadFile}
250
230
  />
@@ -253,10 +233,21 @@ describe('FileUploadPreview', () => {
253
233
  </OverlayProvider>,
254
234
  );
255
235
 
256
- const snapshot = toJSON();
236
+ await waitFor(() => {
237
+ expect(queryAllByTestId('active-upload-progress-indicator')).toHaveLength(fileUploads.length);
238
+ expect(queryAllByTestId('inactive-upload-progress-indicator')).toHaveLength(0);
239
+ expect(queryAllByTestId('upload-progress-indicator')).toHaveLength(0);
240
+ expect(queryAllByTestId('retry-upload-progress-indicator')).toHaveLength(0);
241
+ expect(queryAllByText('File type not supported')).toHaveLength(fileUploads.length);
242
+ expect(removeFile).toHaveBeenCalledTimes(0);
243
+ expect(uploadFile).toHaveBeenCalledTimes(0);
244
+ });
245
+
246
+ fireEvent.press(getAllByTestId('remove-file-upload-preview')[0]);
257
247
 
258
248
  await waitFor(() => {
259
- expect(snapshot).toMatchSnapshot();
249
+ expect(removeFile).toHaveBeenCalledTimes(1);
250
+ expect(uploadFile).toHaveBeenCalledTimes(0);
260
251
  });
261
252
  });
262
253
 
@@ -265,6 +256,7 @@ describe('FileUploadPreview', () => {
265
256
  generateFileUploadPreview({ id: 'file-upload-id-1', state: FileState.UPLOADING }),
266
257
  generateFileUploadPreview({ id: 'file-upload-id-2', state: FileState.UPLOADED }),
267
258
  generateFileUploadPreview({ id: 'file-upload-id-3', state: FileState.UPLOAD_FAILED }),
259
+ generateFileUploadPreview({ id: 'file-upload-id-3', state: FileState.NOT_SUPPORTED }),
268
260
  ];
269
261
  const removeFile = jest.fn();
270
262
  const uploadFile = jest.fn();
@@ -281,7 +273,7 @@ describe('FileUploadPreview', () => {
281
273
  const channel = chatClient.channel('messaging', mockedChannel.id);
282
274
  await channel.query();
283
275
 
284
- const { queryAllByTestId, rerender, toJSON } = render(
276
+ const { queryAllByTestId, queryAllByText } = render(
285
277
  <OverlayProvider>
286
278
  <Chat client={chatClient}>
287
279
  <Channel channel={channel} FlatList={MockedFlatList}>
@@ -301,31 +293,9 @@ describe('FileUploadPreview', () => {
301
293
  expect(queryAllByTestId('inactive-upload-progress-indicator')).toHaveLength(1);
302
294
  expect(queryAllByTestId('upload-progress-indicator')).toHaveLength(1);
303
295
  expect(queryAllByTestId('retry-upload-progress-indicator')).toHaveLength(1);
296
+ expect(queryAllByText('File type not supported')).toHaveLength(1);
304
297
  expect(removeFile).toHaveBeenCalledTimes(0);
305
298
  expect(uploadFile).toHaveBeenCalledTimes(0);
306
299
  });
307
-
308
- rerender(
309
- <OverlayProvider>
310
- <Chat client={chatClient}>
311
- <Channel channel={channel} FlatList={MockedFlatList}>
312
- <FileUploadPreview
313
- fileUploads={fileUploads.map((file, index) => ({
314
- ...file,
315
- id: `${index}`,
316
- }))}
317
- removeFile={removeFile}
318
- uploadFile={uploadFile}
319
- />
320
- </Channel>
321
- </Chat>
322
- </OverlayProvider>,
323
- );
324
-
325
- const snapshot = toJSON();
326
-
327
- await waitFor(() => {
328
- expect(snapshot).toMatchSnapshot();
329
- });
330
300
  });
331
301
  });
@@ -14,11 +14,12 @@ describe('ImageUploadPreview', () => {
14
14
  generateImageUploadPreview({ id: 'image-upload-preview-1', state: FileState.UPLOADING }),
15
15
  generateImageUploadPreview({ id: 'image-upload-preview-2', state: FileState.UPLOADING }),
16
16
  generateImageUploadPreview({ id: 'image-upload-preview-3', state: FileState.UPLOADING }),
17
+ generateImageUploadPreview({ id: 'image-upload-preview-4', state: FileState.UPLOADING }),
17
18
  ];
18
19
  const removeImage = jest.fn();
19
20
  const uploadImage = jest.fn();
20
21
 
21
- const { getAllByTestId, queryAllByTestId, rerender, toJSON } = render(
22
+ const { getAllByTestId, queryAllByTestId, queryAllByText } = render(
22
23
  <ThemeProvider>
23
24
  <ImageUploadPreview
24
25
  imageUploads={imageUploads}
@@ -35,6 +36,7 @@ describe('ImageUploadPreview', () => {
35
36
  expect(queryAllByTestId('inactive-upload-progress-indicator')).toHaveLength(0);
36
37
  expect(queryAllByTestId('upload-progress-indicator')).toHaveLength(imageUploads.length);
37
38
  expect(queryAllByTestId('retry-upload-progress-indicator')).toHaveLength(0);
39
+ expect(queryAllByText('Not supported')).toHaveLength(0);
38
40
  expect(removeImage).toHaveBeenCalledTimes(0);
39
41
  expect(uploadImage).toHaveBeenCalledTimes(0);
40
42
  });
@@ -45,25 +47,6 @@ describe('ImageUploadPreview', () => {
45
47
  expect(removeImage).toHaveBeenCalledTimes(1);
46
48
  expect(uploadImage).toHaveBeenCalledTimes(0);
47
49
  });
48
-
49
- rerender(
50
- <ThemeProvider>
51
- <ImageUploadPreview
52
- imageUploads={imageUploads.map((image, index) => ({
53
- ...image,
54
- id: `${index}`,
55
- }))}
56
- removeImage={removeImage}
57
- uploadImage={uploadImage}
58
- />
59
- </ThemeProvider>,
60
- );
61
-
62
- const snapshot = toJSON();
63
-
64
- await waitFor(() => {
65
- expect(snapshot).toMatchSnapshot();
66
- });
67
50
  });
68
51
 
69
52
  it('should render ImageUploadPreview with all uploaded images', async () => {
@@ -71,11 +54,12 @@ describe('ImageUploadPreview', () => {
71
54
  generateImageUploadPreview({ id: 'image-upload-preview-1', state: FileState.UPLOADED }),
72
55
  generateImageUploadPreview({ id: 'image-upload-preview-2', state: FileState.UPLOADED }),
73
56
  generateImageUploadPreview({ id: 'image-upload-preview-3', state: FileState.UPLOADED }),
57
+ generateImageUploadPreview({ id: 'image-upload-preview-4', state: FileState.UPLOADED }),
74
58
  ];
75
59
  const removeImage = jest.fn();
76
60
  const uploadImage = jest.fn();
77
61
 
78
- const { getAllByTestId, queryAllByTestId, rerender, toJSON } = render(
62
+ const { getAllByTestId, queryAllByTestId, queryAllByText } = render(
79
63
  <ThemeProvider>
80
64
  <ImageUploadPreview
81
65
  imageUploads={imageUploads}
@@ -92,6 +76,7 @@ describe('ImageUploadPreview', () => {
92
76
  );
93
77
  expect(queryAllByTestId('upload-progress-indicator')).toHaveLength(0);
94
78
  expect(queryAllByTestId('retry-upload-progress-indicator')).toHaveLength(0);
79
+ expect(queryAllByText('Not supported')).toHaveLength(0);
95
80
  expect(removeImage).toHaveBeenCalledTimes(0);
96
81
  expect(uploadImage).toHaveBeenCalledTimes(0);
97
82
  });
@@ -102,25 +87,6 @@ describe('ImageUploadPreview', () => {
102
87
  expect(removeImage).toHaveBeenCalledTimes(1);
103
88
  expect(uploadImage).toHaveBeenCalledTimes(0);
104
89
  });
105
-
106
- rerender(
107
- <ThemeProvider>
108
- <ImageUploadPreview
109
- imageUploads={imageUploads.map((image, index) => ({
110
- ...image,
111
- id: `${index}`,
112
- }))}
113
- removeImage={removeImage}
114
- uploadImage={uploadImage}
115
- />
116
- </ThemeProvider>,
117
- );
118
-
119
- const snapshot = toJSON();
120
-
121
- await waitFor(() => {
122
- expect(snapshot).toMatchSnapshot();
123
- });
124
90
  });
125
91
 
126
92
  it('should render ImageUploadPreview with all failed images', async () => {
@@ -128,11 +94,12 @@ describe('ImageUploadPreview', () => {
128
94
  generateImageUploadPreview({ id: 'image-upload-preview-1', state: FileState.UPLOAD_FAILED }),
129
95
  generateImageUploadPreview({ id: 'image-upload-preview-2', state: FileState.UPLOAD_FAILED }),
130
96
  generateImageUploadPreview({ id: 'image-upload-preview-3', state: FileState.UPLOAD_FAILED }),
97
+ generateImageUploadPreview({ id: 'image-upload-preview-4', state: FileState.UPLOAD_FAILED }),
131
98
  ];
132
99
  const removeImage = jest.fn();
133
100
  const uploadImage = jest.fn();
134
101
 
135
- const { getAllByTestId, queryAllByTestId, rerender, toJSON } = render(
102
+ const { getAllByTestId, queryAllByTestId, queryAllByText } = render(
136
103
  <ThemeProvider>
137
104
  <ImageUploadPreview
138
105
  imageUploads={imageUploads}
@@ -149,6 +116,7 @@ describe('ImageUploadPreview', () => {
149
116
  expect(queryAllByTestId('inactive-upload-progress-indicator')).toHaveLength(0);
150
117
  expect(queryAllByTestId('upload-progress-indicator')).toHaveLength(0);
151
118
  expect(queryAllByTestId('retry-upload-progress-indicator')).toHaveLength(imageUploads.length);
119
+ expect(queryAllByText('Not supported')).toHaveLength(0);
152
120
  expect(removeImage).toHaveBeenCalledTimes(0);
153
121
  expect(uploadImage).toHaveBeenCalledTimes(0);
154
122
  });
@@ -166,37 +134,65 @@ describe('ImageUploadPreview', () => {
166
134
  expect(removeImage).toHaveBeenCalledTimes(1);
167
135
  expect(uploadImage).toHaveBeenCalledTimes(1);
168
136
  });
137
+ });
169
138
 
170
- rerender(
139
+ it('should render ImageUploadPreview with all unsupported', async () => {
140
+ const imageUploads = [
141
+ generateImageUploadPreview({
142
+ id: 'image-upload-preview-1',
143
+ state: FileState.NOT_SUPPORTED,
144
+ }),
145
+ generateImageUploadPreview({
146
+ id: 'image-upload-preview-2',
147
+ state: FileState.NOT_SUPPORTED,
148
+ }),
149
+ generateImageUploadPreview({
150
+ id: 'image-upload-preview-3',
151
+ state: FileState.NOT_SUPPORTED,
152
+ }),
153
+ generateImageUploadPreview({
154
+ id: 'image-upload-preview-4',
155
+ state: FileState.NOT_SUPPORTED,
156
+ }),
157
+ ];
158
+ const removeImage = jest.fn();
159
+ const uploadImage = jest.fn();
160
+
161
+ const { queryAllByTestId, queryAllByText } = render(
171
162
  <ThemeProvider>
172
163
  <ImageUploadPreview
173
- imageUploads={imageUploads.map((image, index) => ({
174
- ...image,
175
- id: `${index}`,
176
- }))}
164
+ imageUploads={imageUploads}
177
165
  removeImage={removeImage}
178
166
  uploadImage={uploadImage}
179
167
  />
180
168
  </ThemeProvider>,
181
169
  );
182
170
 
183
- const snapshot = toJSON();
184
-
185
171
  await waitFor(() => {
186
- expect(snapshot).toMatchSnapshot();
172
+ expect(queryAllByTestId('active-upload-progress-indicator')).toHaveLength(
173
+ imageUploads.length,
174
+ );
175
+ expect(queryAllByTestId('upload-progress-indicator')).toHaveLength(0);
176
+ expect(queryAllByTestId('inactive-upload-progress-indicator')).toHaveLength(0);
177
+ expect(queryAllByText('Not supported')).toHaveLength(imageUploads.length);
178
+ expect(queryAllByTestId('retry-upload-progress-indicator')).toHaveLength(0);
179
+
180
+ expect(removeImage).toHaveBeenCalledTimes(0);
181
+ expect(uploadImage).toHaveBeenCalledTimes(0);
187
182
  });
188
183
  });
189
184
 
190
- it('should render ImageUploadPreview with 1 uploading, 1 uploaded, and 1 failed image', async () => {
185
+ it('should render ImageUploadPreview with 1 uploading, 1 uploaded, and 1 failed image, and 1 unsupported', async () => {
191
186
  const imageUploads = [
192
187
  generateImageUploadPreview({ id: 'image-upload-preview-1', state: FileState.UPLOADING }),
193
188
  generateImageUploadPreview({ id: 'image-upload-preview-2', state: FileState.UPLOADED }),
194
189
  generateImageUploadPreview({ id: 'image-upload-preview-3', state: FileState.UPLOAD_FAILED }),
190
+ generateImageUploadPreview({ id: 'image-upload-preview-4', state: FileState.NOT_SUPPORTED }),
195
191
  ];
196
192
  const removeImage = jest.fn();
197
193
  const uploadImage = jest.fn();
198
194
 
199
- const { queryAllByTestId, rerender, toJSON } = render(
195
+ const { queryAllByTestId, queryAllByText } = render(
200
196
  <ThemeProvider>
201
197
  <ImageUploadPreview
202
198
  imageUploads={imageUploads}
@@ -207,33 +203,12 @@ describe('ImageUploadPreview', () => {
207
203
  );
208
204
 
209
205
  await waitFor(() => {
210
- expect(queryAllByTestId('active-upload-progress-indicator')).toHaveLength(
211
- imageUploads.length - 1,
212
- );
213
- expect(queryAllByTestId('inactive-upload-progress-indicator')).toHaveLength(1);
214
206
  expect(queryAllByTestId('upload-progress-indicator')).toHaveLength(1);
207
+ expect(queryAllByTestId('inactive-upload-progress-indicator')).toHaveLength(1);
215
208
  expect(queryAllByTestId('retry-upload-progress-indicator')).toHaveLength(1);
209
+ expect(queryAllByText('Not supported')).toHaveLength(1);
216
210
  expect(removeImage).toHaveBeenCalledTimes(0);
217
211
  expect(uploadImage).toHaveBeenCalledTimes(0);
218
212
  });
219
-
220
- rerender(
221
- <ThemeProvider>
222
- <ImageUploadPreview
223
- imageUploads={imageUploads.map((image, index) => ({
224
- ...image,
225
- id: `${index}`,
226
- }))}
227
- removeImage={removeImage}
228
- uploadImage={uploadImage}
229
- />
230
- </ThemeProvider>,
231
- );
232
-
233
- const snapshot = toJSON();
234
-
235
- await waitFor(() => {
236
- expect(snapshot).toMatchSnapshot();
237
- });
238
213
  });
239
214
  });