stream-chat-react-native-core 4.9.0-beta.3 → 4.9.0-beta.4

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 (73) hide show
  1. package/lib/commonjs/components/Attachment/Gallery.js +11 -9
  2. package/lib/commonjs/components/Attachment/Gallery.js.map +1 -1
  3. package/lib/commonjs/components/Attachment/VideoThumbnail.js +11 -5
  4. package/lib/commonjs/components/Attachment/VideoThumbnail.js.map +1 -1
  5. package/lib/commonjs/components/Attachment/utils/buildGallery/buildThumbnail.js +1 -0
  6. package/lib/commonjs/components/Attachment/utils/buildGallery/buildThumbnail.js.map +1 -1
  7. package/lib/commonjs/components/Message/Message.js +7 -6
  8. package/lib/commonjs/components/Message/Message.js.map +1 -1
  9. package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js +20 -27
  10. package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js.map +1 -1
  11. package/lib/commonjs/mock-builders/generator/attachment.js +3 -2
  12. package/lib/commonjs/mock-builders/generator/attachment.js.map +1 -1
  13. package/lib/commonjs/utils/getUrlOfImageAttachment.js +1 -1
  14. package/lib/commonjs/utils/getUrlOfImageAttachment.js.map +1 -1
  15. package/lib/commonjs/version.json +1 -1
  16. package/lib/module/components/Attachment/Gallery.js +11 -9
  17. package/lib/module/components/Attachment/Gallery.js.map +1 -1
  18. package/lib/module/components/Attachment/VideoThumbnail.js +11 -5
  19. package/lib/module/components/Attachment/VideoThumbnail.js.map +1 -1
  20. package/lib/module/components/Attachment/utils/buildGallery/buildThumbnail.js +1 -0
  21. package/lib/module/components/Attachment/utils/buildGallery/buildThumbnail.js.map +1 -1
  22. package/lib/module/components/Message/Message.js +7 -6
  23. package/lib/module/components/Message/Message.js.map +1 -1
  24. package/lib/module/contexts/messageInputContext/MessageInputContext.js +20 -27
  25. package/lib/module/contexts/messageInputContext/MessageInputContext.js.map +1 -1
  26. package/lib/module/mock-builders/generator/attachment.js +3 -2
  27. package/lib/module/mock-builders/generator/attachment.js.map +1 -1
  28. package/lib/module/utils/getUrlOfImageAttachment.js +1 -1
  29. package/lib/module/utils/getUrlOfImageAttachment.js.map +1 -1
  30. package/lib/module/version.json +1 -1
  31. package/lib/typescript/components/Attachment/VideoThumbnail.d.ts +3 -1
  32. package/lib/typescript/components/Attachment/utils/buildGallery/types.d.ts +1 -0
  33. package/lib/typescript/contexts/messageInputContext/MessageInputContext.d.ts +1 -0
  34. package/lib/typescript/contexts/messageInputContext/__tests__/MessageInputContext.test.d.ts +1 -0
  35. package/lib/typescript/contexts/messageInputContext/__tests__/isValidMessage.test.d.ts +1 -0
  36. package/lib/typescript/contexts/messageInputContext/__tests__/pickFile.test.d.ts +1 -0
  37. package/lib/typescript/contexts/messageInputContext/__tests__/removeFile.test.d.ts +1 -0
  38. package/lib/typescript/contexts/messageInputContext/__tests__/removeImage.test.d.ts +1 -0
  39. package/lib/typescript/contexts/messageInputContext/__tests__/sendMessage.test.d.ts +1 -0
  40. package/lib/typescript/contexts/messageInputContext/__tests__/sendMessageAsync.test.d.ts +1 -0
  41. package/lib/typescript/contexts/messageInputContext/__tests__/updateMessage.test.d.ts +1 -0
  42. package/lib/typescript/contexts/messageInputContext/__tests__/uploadFile.test.d.ts +1 -0
  43. package/lib/typescript/contexts/messageInputContext/__tests__/uploadImage.test.d.ts +1 -0
  44. package/lib/typescript/contexts/messageInputContext/__tests__/useMessageDetailsForState.test.d.ts +1 -0
  45. package/lib/typescript/mock-builders/generator/attachment.d.ts +10 -0
  46. package/lib/typescript/mock-builders/generator/channel.d.ts +13 -13
  47. package/lib/typescript/mock-builders/generator/message.d.ts +38 -0
  48. package/lib/typescript/mock-builders/generator/user.d.ts +9 -9
  49. package/package.json +5 -4
  50. package/src/components/Attachment/Gallery.tsx +2 -1
  51. package/src/components/Attachment/VideoThumbnail.tsx +12 -5
  52. package/src/components/Attachment/__tests__/Attachment.test.js +12 -0
  53. package/src/components/Attachment/__tests__/Gallery.test.js +23 -1
  54. package/src/components/Attachment/utils/buildGallery/buildThumbnail.ts +1 -0
  55. package/src/components/Attachment/utils/buildGallery/types.ts +1 -0
  56. package/src/components/Message/Message.tsx +5 -1
  57. package/src/contexts/messageInputContext/MessageInputContext.tsx +3 -4
  58. package/src/contexts/messageInputContext/__tests__/MessageInputContext.test.tsx +208 -0
  59. package/src/contexts/messageInputContext/__tests__/__snapshots__/sendMessage.test.tsx.snap +109 -0
  60. package/src/contexts/messageInputContext/__tests__/__snapshots__/sendMessageAsync.test.tsx.snap +33 -0
  61. package/src/contexts/messageInputContext/__tests__/isValidMessage.test.tsx +71 -0
  62. package/src/contexts/messageInputContext/__tests__/pickFile.test.tsx +67 -0
  63. package/src/contexts/messageInputContext/__tests__/removeFile.test.tsx +82 -0
  64. package/src/contexts/messageInputContext/__tests__/removeImage.test.tsx +80 -0
  65. package/src/contexts/messageInputContext/__tests__/sendMessage.test.tsx +286 -0
  66. package/src/contexts/messageInputContext/__tests__/sendMessageAsync.test.tsx +124 -0
  67. package/src/contexts/messageInputContext/__tests__/updateMessage.test.tsx +92 -0
  68. package/src/contexts/messageInputContext/__tests__/uploadFile.test.tsx +76 -0
  69. package/src/contexts/messageInputContext/__tests__/uploadImage.test.tsx +55 -0
  70. package/src/contexts/messageInputContext/__tests__/useMessageDetailsForState.test.tsx +62 -0
  71. package/src/mock-builders/generator/attachment.js +4 -2
  72. package/src/utils/getUrlOfImageAttachment.ts +1 -1
  73. package/src/version.json +1 -1
@@ -0,0 +1,109 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`MessageInputContext's sendMessage exit sendMessage when edit message is not boolean image upload status is uploaded successfully 1`] = `
4
+ Object {
5
+ "attachments": Array [
6
+ Object {
7
+ "fallback": undefined,
8
+ "image_url": undefined,
9
+ "original_height": undefined,
10
+ "original_width": undefined,
11
+ "type": "image",
12
+ },
13
+ ],
14
+ "created_at": "Sat Jul 02 2022 23:55:13 GMT+0530 (India Standard Time)",
15
+ "html": "<p>regular</p>",
16
+ "id": "7a85f744-cc89-4f82-a1d4-5456432cc8bf",
17
+ "mentioned_users": Array [
18
+ "dummy1",
19
+ "dummy2",
20
+ ],
21
+ "quoted_message": undefined,
22
+ "text": "",
23
+ "type": "regular",
24
+ "updated_at": "Sat Jul 02 2022 23:55:13 GMT+0530 (India Standard Time)",
25
+ "user": Object {
26
+ "banned": false,
27
+ "created_at": "2020-04-27T13:39:49.331742Z",
28
+ "id": "5d6f6322-567e-4e1e-af90-97ef1ed5cc23",
29
+ "image": "fc86ddcb-bac4-400c-9afd-b0c0a1c0cd33",
30
+ "name": "50cbdd0e-ca7e-4478-9e2c-be0f1ac6a995",
31
+ "online": false,
32
+ "role": "user",
33
+ "updated_at": "2020-04-27T13:39:49.332087Z",
34
+ },
35
+ }
36
+ `;
37
+
38
+ exports[`MessageInputContext's sendMessage exit sendMessage when file upload status is uploaded successfully 1`] = `
39
+ Object {
40
+ "attachments": Array [
41
+ Object {
42
+ "asset_url": undefined,
43
+ "file_size": undefined,
44
+ "mime_type": "file",
45
+ "title": "dummy.pdf",
46
+ "type": "file",
47
+ },
48
+ Object {
49
+ "asset_url": undefined,
50
+ "duration": undefined,
51
+ "file_size": undefined,
52
+ "mime_type": "video/mp4",
53
+ "thumb_url": undefined,
54
+ "title": "dummy.pdf",
55
+ "type": "video",
56
+ },
57
+ Object {
58
+ "asset_url": undefined,
59
+ "duration": undefined,
60
+ "file_size": undefined,
61
+ "mime_type": "audio/mp3",
62
+ "title": "dummy.pdf",
63
+ "type": "audio",
64
+ },
65
+ Object {
66
+ "fallback": "dummy.pdf",
67
+ "image_url": undefined,
68
+ "type": "image",
69
+ },
70
+ ],
71
+ "mentioned_users": Array [
72
+ "dummy1",
73
+ "dummy2",
74
+ ],
75
+ "parent_id": undefined,
76
+ "quoted_message_id": undefined,
77
+ "show_in_channel": undefined,
78
+ "text": "",
79
+ }
80
+ `;
81
+
82
+ exports[`MessageInputContext's sendMessage exit sendMessage when image upload status is uploaded successfully 1`] = `
83
+ Object {
84
+ "attachments": Array [
85
+ Object {
86
+ "fallback": undefined,
87
+ "image_url": undefined,
88
+ "original_height": undefined,
89
+ "original_width": undefined,
90
+ "type": "image",
91
+ },
92
+ Object {
93
+ "fallback": undefined,
94
+ "image_url": undefined,
95
+ "original_height": undefined,
96
+ "original_width": undefined,
97
+ "type": "image",
98
+ },
99
+ ],
100
+ "mentioned_users": Array [
101
+ "dummy1",
102
+ "dummy2",
103
+ ],
104
+ "parent_id": undefined,
105
+ "quoted_message_id": undefined,
106
+ "show_in_channel": undefined,
107
+ "text": "",
108
+ }
109
+ `;
@@ -0,0 +1,33 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`MessageInputContext's sendMessageAsync sendImageAsync is been called with finished file upload state and checked for snapshot) 1`] = `
4
+ Object {
5
+ "attachments": Array [
6
+ Object {
7
+ "image_url": "https://www.test.com",
8
+ "type": "image",
9
+ },
10
+ ],
11
+ "mentioned_users": Array [],
12
+ "parent_id": undefined,
13
+ "quoted_message_id": undefined,
14
+ "show_in_channel": undefined,
15
+ "text": "",
16
+ }
17
+ `;
18
+
19
+ exports[`MessageInputContext's sendMessageAsync sendImageAsync is been called with uploaded file upload state and checked for snapshot) 1`] = `
20
+ Object {
21
+ "attachments": Array [
22
+ Object {
23
+ "image_url": "https://www.test.com",
24
+ "type": "image",
25
+ },
26
+ ],
27
+ "mentioned_users": Array [],
28
+ "parent_id": undefined,
29
+ "quoted_message_id": undefined,
30
+ "show_in_channel": undefined,
31
+ "text": "",
32
+ }
33
+ `;
@@ -0,0 +1,71 @@
1
+ import React, { PropsWithChildren } from 'react';
2
+ import { act } from 'react-test-renderer';
3
+
4
+ import { renderHook } from '@testing-library/react-hooks';
5
+
6
+ import {
7
+ generateFileUploadPreview,
8
+ generateImageUploadPreview,
9
+ } from '../../../mock-builders/generator/attachment';
10
+ import type { DefaultStreamChatGenerics } from '../../../types/types';
11
+ import { FileState } from '../../../utils/utils';
12
+ import {
13
+ InputMessageInputContextValue,
14
+ MessageInputContextValue,
15
+ MessageInputProvider,
16
+ useMessageInputContext,
17
+ } from '../MessageInputContext';
18
+
19
+ type WrapperType<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> =
20
+ Partial<InputMessageInputContextValue<StreamChatGenerics>>;
21
+
22
+ const Wrapper = <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>({
23
+ children,
24
+ ...rest
25
+ }: PropsWithChildren<WrapperType<StreamChatGenerics>>) => (
26
+ <MessageInputProvider
27
+ value={
28
+ {
29
+ ...rest,
30
+ } as MessageInputContextValue<StreamChatGenerics>
31
+ }
32
+ >
33
+ {children}
34
+ </MessageInputProvider>
35
+ );
36
+
37
+ describe("MessageInputContext's isValidMessage", () => {
38
+ const initialProps = {
39
+ editing: true,
40
+ hasImagePicker: true,
41
+ };
42
+
43
+ it.each([
44
+ [[], [], [], 0, '', false],
45
+ [[], [], [], 0, 'Dummy Text', true],
46
+ [[generateFileUploadPreview()], [], [], 0, '', true],
47
+ [[], [generateImageUploadPreview()], [], 0, '', true],
48
+ [[], [generateImageUploadPreview({ state: FileState.UPLOAD_FAILED })], [], 0, '', false],
49
+ [[generateFileUploadPreview({ state: FileState.UPLOAD_FAILED })], [], [], 0, '', false],
50
+ [[generateFileUploadPreview({ state: FileState.UPLOADING })], [], [], 0, '', false],
51
+ [[], [generateImageUploadPreview({ state: FileState.UPLOADING })], [], 0, '', false],
52
+ ])(
53
+ 'isValidMessage with fileUploads %p, imageUploads %p, mentionedUsers %p, numberOfUploads %d, text %s gives %p',
54
+ (fileUploads, imageUploads, mentionedUsers, numberOfUploads, text, isValidMessageStatus) => {
55
+ const { result } = renderHook(() => useMessageInputContext(), {
56
+ initialProps,
57
+ wrapper: Wrapper,
58
+ });
59
+
60
+ act(() => {
61
+ result.current.setFileUploads(fileUploads);
62
+ result.current.setImageUploads(imageUploads);
63
+ result.current.setMentionedUsers(mentionedUsers);
64
+ result.current.setNumberOfUploads(numberOfUploads);
65
+ result.current.setText(text);
66
+ });
67
+
68
+ expect(result.current.isValidMessage()).toBe(isValidMessageStatus);
69
+ },
70
+ );
71
+ });
@@ -0,0 +1,67 @@
1
+ import React, { PropsWithChildren } from 'react';
2
+ import { Alert } from 'react-native';
3
+ import { act } from 'react-test-renderer';
4
+
5
+ import { renderHook } from '@testing-library/react-hooks';
6
+
7
+ import type { DefaultStreamChatGenerics } from '../../../types/types';
8
+ import {
9
+ InputMessageInputContextValue,
10
+ MessageInputContextValue,
11
+ MessageInputProvider,
12
+ useMessageInputContext,
13
+ } from '../MessageInputContext';
14
+
15
+ type WrapperType<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> =
16
+ Partial<InputMessageInputContextValue<StreamChatGenerics>>;
17
+
18
+ const Wrapper = <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>({
19
+ children,
20
+ ...rest
21
+ }: PropsWithChildren<WrapperType<StreamChatGenerics>>) => (
22
+ <MessageInputProvider
23
+ value={
24
+ {
25
+ ...rest,
26
+ } as MessageInputContextValue<StreamChatGenerics>
27
+ }
28
+ >
29
+ {children}
30
+ </MessageInputProvider>
31
+ );
32
+
33
+ afterEach(jest.clearAllMocks);
34
+
35
+ describe("MessageInputContext's pickFile", () => {
36
+ jest.spyOn(Alert, 'alert');
37
+
38
+ const initialProps = {
39
+ editing: true,
40
+ maxNumberOfFiles: 2,
41
+ };
42
+
43
+ it.each([
44
+ [3, 1],
45
+ [1, 0],
46
+ ])(
47
+ 'run pickFile when numberOfUploads is %d and alert is triggered %d number of times',
48
+ (numberOfUploads, numberOfTimesCalled) => {
49
+ const { rerender, result } = renderHook(() => useMessageInputContext(), {
50
+ initialProps,
51
+ wrapper: Wrapper,
52
+ });
53
+
54
+ act(() => {
55
+ result.current.setNumberOfUploads(numberOfUploads);
56
+ });
57
+
58
+ rerender({ editing: false, maxNumberOfFiles: 2 });
59
+
60
+ act(() => {
61
+ result.current.pickFile();
62
+ });
63
+
64
+ expect(Alert.alert).toHaveBeenCalledTimes(numberOfTimesCalled);
65
+ },
66
+ );
67
+ });
@@ -0,0 +1,82 @@
1
+ import React, { PropsWithChildren } from 'react';
2
+ import { act } from 'react-test-renderer';
3
+
4
+ import { renderHook } from '@testing-library/react-hooks';
5
+
6
+ import { waitFor } from '@testing-library/react-native';
7
+
8
+ import { generateFileUploadPreview } from '../../../mock-builders/generator/attachment';
9
+ import type { DefaultStreamChatGenerics } from '../../../types/types';
10
+ import {
11
+ InputMessageInputContextValue,
12
+ MessageInputContextValue,
13
+ MessageInputProvider,
14
+ useMessageInputContext,
15
+ } from '../MessageInputContext';
16
+
17
+ type WrapperType<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> =
18
+ Partial<InputMessageInputContextValue<StreamChatGenerics>>;
19
+
20
+ const Wrapper = <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>({
21
+ children,
22
+ ...rest
23
+ }: PropsWithChildren<WrapperType<StreamChatGenerics>>) => (
24
+ <MessageInputProvider
25
+ value={
26
+ {
27
+ ...rest,
28
+ } as MessageInputContextValue<StreamChatGenerics>
29
+ }
30
+ >
31
+ {children}
32
+ </MessageInputProvider>
33
+ );
34
+
35
+ describe("MessageInputContext's removeFile", () => {
36
+ const initialProps = {
37
+ editing: true,
38
+ };
39
+
40
+ const file = generateFileUploadPreview({
41
+ file: {
42
+ id: 'test',
43
+ name: 'Test Image',
44
+ uri: 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg',
45
+ },
46
+ });
47
+
48
+ it.each([
49
+ [file.id, 0, 0],
50
+ ['dummy', 1, 1],
51
+ ])(
52
+ 'removeFile is been called with %s and checked for expectedFileUploadsLength %i, and expectedNumberOfUploadsLength %i)',
53
+ async (fileId, expectedFileUploadsLength, expectedNumberOfUploadsLength) => {
54
+ const { rerender, result } = renderHook(() => useMessageInputContext(), {
55
+ initialProps,
56
+ wrapper: Wrapper,
57
+ });
58
+
59
+ act(() => {
60
+ result.current.setFileUploads([file]);
61
+ result.current.setNumberOfUploads(1);
62
+ });
63
+
64
+ rerender({ editing: false });
65
+
66
+ await waitFor(() => {
67
+ expect(result.current.fileUploads.length).toBe(1);
68
+ });
69
+
70
+ act(() => {
71
+ result.current.removeFile(fileId);
72
+ });
73
+
74
+ rerender({ editing: true });
75
+
76
+ await waitFor(() => {
77
+ expect(result.current.fileUploads.length).toBe(expectedFileUploadsLength);
78
+ expect(result.current.numberOfUploads).toBe(expectedNumberOfUploadsLength);
79
+ });
80
+ },
81
+ );
82
+ });
@@ -0,0 +1,80 @@
1
+ import React, { PropsWithChildren } from 'react';
2
+ import { act } from 'react-test-renderer';
3
+
4
+ import { renderHook } from '@testing-library/react-hooks';
5
+
6
+ import { waitFor } from '@testing-library/react-native';
7
+
8
+ import { generateImageUploadPreview } from '../../../mock-builders/generator/attachment';
9
+ import type { DefaultStreamChatGenerics } from '../../../types/types';
10
+ import {
11
+ InputMessageInputContextValue,
12
+ MessageInputContextValue,
13
+ MessageInputProvider,
14
+ useMessageInputContext,
15
+ } from '../MessageInputContext';
16
+
17
+ type WrapperType<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> =
18
+ Partial<InputMessageInputContextValue<StreamChatGenerics>>;
19
+
20
+ const Wrapper = <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>({
21
+ children,
22
+ ...rest
23
+ }: PropsWithChildren<WrapperType<StreamChatGenerics>>) => (
24
+ <MessageInputProvider
25
+ value={
26
+ {
27
+ ...rest,
28
+ } as MessageInputContextValue<StreamChatGenerics>
29
+ }
30
+ >
31
+ {children}
32
+ </MessageInputProvider>
33
+ );
34
+
35
+ describe("MessageInputContext's removeImage", () => {
36
+ const initialProps = {
37
+ editing: true,
38
+ };
39
+ const image = generateImageUploadPreview({
40
+ file: {
41
+ id: 'test',
42
+ name: 'Test Image',
43
+ uri: 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg',
44
+ },
45
+ });
46
+ it.each([
47
+ [image.id, 0, 0],
48
+ ['dummy', 1, 1],
49
+ ])(
50
+ 'removeImage is been called with %s and checked for expectedImageUploadsLength %i, and expectedNumberOfUploadsLength %i)',
51
+ async (imageId, expectedImageUploadsLength, expectedNumberOfUploadsLength) => {
52
+ const { rerender, result } = renderHook(() => useMessageInputContext(), {
53
+ initialProps,
54
+ wrapper: Wrapper,
55
+ });
56
+
57
+ act(() => {
58
+ result.current.setImageUploads([image]);
59
+ result.current.setNumberOfUploads(1);
60
+ });
61
+
62
+ rerender({ editing: false });
63
+
64
+ await waitFor(() => {
65
+ expect(result.current.imageUploads.length).toBe(1);
66
+ });
67
+
68
+ act(() => {
69
+ result.current.removeImage(imageId);
70
+ });
71
+
72
+ rerender({ editing: true });
73
+
74
+ await waitFor(() => {
75
+ expect(result.current.imageUploads.length).toBe(expectedImageUploadsLength);
76
+ expect(result.current.numberOfUploads).toBe(expectedNumberOfUploadsLength);
77
+ });
78
+ },
79
+ );
80
+ });