@planningcenter/chat-react-native 4.5.1-rc.0 → 4.6.0-qa-1063.0
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/assets/powered_by_giphy.png +0 -0
- package/assets/powered_by_giphy_dark.png +0 -0
- package/build/components/conversation/attachments/giphy_attachment.d.ts.map +1 -1
- package/build/components/conversation/attachments/giphy_attachment.js +2 -2
- package/build/components/conversation/attachments/giphy_attachment.js.map +1 -1
- package/build/components/conversation/attachments/image_attachment.d.ts.map +1 -1
- package/build/components/conversation/attachments/image_attachment.js +5 -3
- package/build/components/conversation/attachments/image_attachment.js.map +1 -1
- package/build/components/conversation/message_form.d.ts.map +1 -1
- package/build/components/conversation/message_form.js +2 -2
- package/build/components/conversation/message_form.js.map +1 -1
- package/build/components/conversation/message_list.d.ts.map +1 -1
- package/build/components/conversation/message_list.js +155 -123
- package/build/components/conversation/message_list.js.map +1 -1
- package/build/components/conversations/conversations.d.ts.map +1 -1
- package/build/components/conversations/conversations.js +1 -0
- package/build/components/conversations/conversations.js.map +1 -1
- package/build/components/display/conversation_avatar.d.ts +3 -1
- package/build/components/display/conversation_avatar.d.ts.map +1 -1
- package/build/components/display/conversation_avatar.js +77 -66
- package/build/components/display/conversation_avatar.js.map +1 -1
- package/build/components/display/keyboard_scroll_view.d.ts.map +1 -1
- package/build/components/display/keyboard_scroll_view.js +1 -0
- package/build/components/display/keyboard_scroll_view.js.map +1 -1
- package/build/components/page/page_error_boundary.d.ts +9 -1
- package/build/components/page/page_error_boundary.d.ts.map +1 -1
- package/build/components/page/page_error_boundary.js +56 -31
- package/build/components/page/page_error_boundary.js.map +1 -1
- package/build/hooks/use_conversation_avatar_update.d.ts +4 -3
- package/build/hooks/use_conversation_avatar_update.d.ts.map +1 -1
- package/build/hooks/use_conversation_avatar_update.js +146 -48
- package/build/hooks/use_conversation_avatar_update.js.map +1 -1
- package/build/navigation/index.d.ts.map +1 -1
- package/build/navigation/index.js +3 -1
- package/build/navigation/index.js.map +1 -1
- package/build/navigation/page_error_fallbacks.d.ts +7 -0
- package/build/navigation/page_error_fallbacks.d.ts.map +1 -0
- package/build/navigation/page_error_fallbacks.js +7 -0
- package/build/navigation/page_error_fallbacks.js.map +1 -0
- package/build/navigation/screenLayout.d.ts.map +1 -1
- package/build/navigation/screenLayout.js +10 -6
- package/build/navigation/screenLayout.js.map +1 -1
- package/build/screens/age_check/age_check_required_screen.d.ts.map +1 -1
- package/build/screens/age_check/age_check_required_screen.js +1 -0
- package/build/screens/age_check/age_check_required_screen.js.map +1 -1
- package/build/screens/age_check/age_check_underage_screen.d.ts.map +1 -1
- package/build/screens/age_check/age_check_underage_screen.js +2 -1
- package/build/screens/age_check/age_check_underage_screen.js.map +1 -1
- package/build/screens/attachment_actions/attachment_actions_screen.d.ts.map +1 -1
- package/build/screens/attachment_actions/attachment_actions_screen.js +5 -2
- package/build/screens/attachment_actions/attachment_actions_screen.js.map +1 -1
- package/build/screens/avatar_picker/avatar_picker_screen.d.ts.map +1 -1
- package/build/screens/avatar_picker/avatar_picker_screen.js +76 -66
- package/build/screens/avatar_picker/avatar_picker_screen.js.map +1 -1
- package/build/screens/bug_report_screen.d.ts.map +1 -1
- package/build/screens/bug_report_screen.js +3 -3
- package/build/screens/bug_report_screen.js.map +1 -1
- package/build/screens/conversation_details_screen.d.ts.map +1 -1
- package/build/screens/conversation_details_screen.js +1 -0
- package/build/screens/conversation_details_screen.js.map +1 -1
- package/build/screens/conversation_new/components/form_list.d.ts.map +1 -1
- package/build/screens/conversation_new/components/form_list.js +1 -0
- package/build/screens/conversation_new/components/form_list.js.map +1 -1
- package/build/screens/conversation_new/components/groups_form.js +25 -18
- package/build/screens/conversation_new/components/groups_form.js.map +1 -1
- package/build/screens/conversation_new/components/services_form.js +51 -40
- package/build/screens/conversation_new/components/services_form.js.map +1 -1
- package/build/screens/conversation_select_recipients/conversation_new_entry_screen.d.ts.map +1 -1
- package/build/screens/conversation_select_recipients/conversation_new_entry_screen.js +1 -0
- package/build/screens/conversation_select_recipients/conversation_new_entry_screen.js.map +1 -1
- package/build/screens/conversation_select_recipients/conversation_select_direct_message_recipients_screen.d.ts.map +1 -1
- package/build/screens/conversation_select_recipients/conversation_select_direct_message_recipients_screen.js +332 -291
- package/build/screens/conversation_select_recipients/conversation_select_direct_message_recipients_screen.js.map +1 -1
- package/build/screens/conversation_select_recipients/conversation_select_group_recipients_screen.d.ts.map +1 -1
- package/build/screens/conversation_select_recipients/conversation_select_group_recipients_screen.js +2 -1
- package/build/screens/conversation_select_recipients/conversation_select_group_recipients_screen.js.map +1 -1
- package/build/screens/conversation_select_recipients/conversation_select_teams_i_lead_recipients_screen.d.ts.map +1 -1
- package/build/screens/conversation_select_recipients/conversation_select_teams_i_lead_recipients_screen.js +1 -0
- package/build/screens/conversation_select_recipients/conversation_select_teams_i_lead_recipients_screen.js.map +1 -1
- package/build/screens/get_help_screen.js +57 -63
- package/build/screens/get_help_screen.js.map +1 -1
- package/build/screens/group_notification_settings_screen.js +3 -2
- package/build/screens/group_notification_settings_screen.js.map +1 -1
- package/build/screens/notification_settings_screen.d.ts.map +1 -1
- package/build/screens/notification_settings_screen.js +1 -0
- package/build/screens/notification_settings_screen.js.map +1 -1
- package/build/screens/preferred_app_selection_screen.js +45 -39
- package/build/screens/preferred_app_selection_screen.js.map +1 -1
- package/build/screens/search/components/search_results_list.d.ts +4 -1
- package/build/screens/search/components/search_results_list.d.ts.map +1 -1
- package/build/screens/search/components/search_results_list.js +136 -110
- package/build/screens/search/components/search_results_list.js.map +1 -1
- package/build/screens/search/search_screen.d.ts.map +1 -1
- package/build/screens/search/search_screen.js +21 -28
- package/build/screens/search/search_screen.js.map +1 -1
- package/build/screens/send_giphy_screen.d.ts.map +1 -1
- package/build/screens/send_giphy_screen.js +93 -136
- package/build/screens/send_giphy_screen.js.map +1 -1
- package/build/screens/settings_screen.d.ts.map +1 -1
- package/build/screens/settings_screen.js +7 -6
- package/build/screens/settings_screen.js.map +1 -1
- package/build/utils/index.d.ts +1 -0
- package/build/utils/index.d.ts.map +1 -1
- package/build/utils/index.js +1 -0
- package/build/utils/index.js.map +1 -1
- package/build/utils/membership_sync_info_text.d.ts +2 -0
- package/build/utils/membership_sync_info_text.d.ts.map +1 -0
- package/build/utils/membership_sync_info_text.js +4 -0
- package/build/utils/membership_sync_info_text.js.map +1 -0
- package/build/utils/native_adapters/linking.d.ts +11 -3
- package/build/utils/native_adapters/linking.d.ts.map +1 -1
- package/build/utils/native_adapters/linking.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/components/conversation/attachments/giphy_attachment.test.tsx +76 -0
- package/src/__tests__/screens/get_help_screen.test.ts +36 -0
- package/src/__utils__/render_with_query_client.tsx +13 -0
- package/src/components/conversation/__tests__/message_list.test.tsx +4 -0
- package/src/components/conversation/attachments/giphy_attachment.tsx +2 -3
- package/src/components/conversation/attachments/image_attachment.tsx +2 -3
- package/src/components/conversation/message_form.tsx +1 -1
- package/src/components/conversation/message_list.tsx +6 -0
- package/src/components/conversations/__tests__/conversation_preview.test.tsx +2 -2
- package/src/components/conversations/conversations.tsx +1 -0
- package/src/components/display/__tests__/conversation_avatar.test.tsx +94 -0
- package/src/components/display/conversation_avatar.tsx +9 -2
- package/src/components/display/keyboard_scroll_view.tsx +1 -0
- package/src/components/page/__tests__/page_error_boundary.test.tsx +33 -0
- package/src/components/page/page_error_boundary.tsx +43 -12
- package/src/hooks/__tests__/use_conversation_avatar_update.test.tsx +40 -0
- package/src/hooks/use_conversation_avatar_update.ts +67 -11
- package/src/navigation/index.tsx +6 -2
- package/src/navigation/page_error_fallbacks.ts +14 -0
- package/src/navigation/screenLayout.tsx +3 -1
- package/src/screens/age_check/age_check_required_screen.tsx +5 -1
- package/src/screens/age_check/age_check_underage_screen.tsx +2 -1
- package/src/screens/attachment_actions/__tests__/attachment_actions_screen.test.tsx +37 -1
- package/src/screens/attachment_actions/attachment_actions_screen.tsx +3 -2
- package/src/screens/avatar_picker/__tests__/avatar_picker_screen.test.tsx +67 -0
- package/src/screens/avatar_picker/avatar_picker_screen.tsx +7 -1
- package/src/screens/bug_report_screen.tsx +3 -11
- package/src/screens/conversation_details_screen.tsx +1 -0
- package/src/screens/conversation_new/components/form_list.tsx +1 -0
- package/src/screens/conversation_new/components/groups_form.tsx +2 -2
- package/src/screens/conversation_new/components/services_form.tsx +2 -2
- package/src/screens/conversation_select_recipients/__tests__/conversation_select_direct_message_recipients_screen.test.tsx +100 -0
- package/src/screens/conversation_select_recipients/conversation_new_entry_screen.tsx +4 -1
- package/src/screens/conversation_select_recipients/conversation_select_direct_message_recipients_screen.tsx +78 -68
- package/src/screens/conversation_select_recipients/conversation_select_group_recipients_screen.tsx +2 -1
- package/src/screens/conversation_select_recipients/conversation_select_teams_i_lead_recipients_screen.tsx +1 -0
- package/src/screens/get_help_screen.tsx +5 -5
- package/src/screens/group_notification_settings_screen.tsx +3 -3
- package/src/screens/notification_settings_screen.tsx +1 -0
- package/src/screens/preferred_app_selection_screen.tsx +4 -4
- package/src/screens/search/__tests__/search_screen.test.tsx +11 -12
- package/src/screens/search/components/__tests__/conversation_results.test.tsx +14 -5
- package/src/screens/search/components/__tests__/message_result_row.test.tsx +5 -4
- package/src/screens/search/components/__tests__/search_results_list.test.tsx +10 -5
- package/src/screens/search/components/search_results_list.tsx +34 -13
- package/src/screens/search/search_screen.tsx +8 -18
- package/src/screens/send_giphy_screen.tsx +13 -44
- package/src/screens/settings_screen.tsx +25 -25
- package/src/utils/__tests__/membership_sync_info_text.test.ts +15 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/membership_sync_info_text.ts +3 -0
- package/src/utils/native_adapters/__tests__/linking.test.ts +12 -0
- package/src/utils/native_adapters/linking.ts +12 -3
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { Linking } from 'react-native';
|
|
2
|
-
export
|
|
3
|
-
|
|
2
|
+
export type LinkingOpenURLOptions = {
|
|
3
|
+
forceOpenInBrowser?: boolean;
|
|
4
|
+
};
|
|
5
|
+
type LinkingMethods = {
|
|
6
|
+
openURL: (url: string, options?: LinkingOpenURLOptions) => Promise<unknown>;
|
|
4
7
|
canOpenURL: Linking['canOpenURL'];
|
|
5
|
-
|
|
8
|
+
};
|
|
9
|
+
export declare class LinkingAdapter {
|
|
10
|
+
openURL: LinkingMethods['openURL'];
|
|
11
|
+
canOpenURL: LinkingMethods['canOpenURL'];
|
|
12
|
+
constructor(methods: LinkingMethods);
|
|
6
13
|
}
|
|
14
|
+
export {};
|
|
7
15
|
//# sourceMappingURL=linking.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linking.d.ts","sourceRoot":"","sources":["../../../src/utils/native_adapters/linking.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,
|
|
1
|
+
{"version":3,"file":"linking.d.ts","sourceRoot":"","sources":["../../../src/utils/native_adapters/linking.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,MAAM,MAAM,qBAAqB,GAAG;IAClC,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B,CAAA;AAED,KAAK,cAAc,GAAG;IACpB,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAC3E,UAAU,EAAE,OAAO,CAAC,YAAY,CAAC,CAAA;CAClC,CAAA;AAED,qBAAa,cAAc;IACzB,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,CAAA;IAClC,UAAU,EAAE,cAAc,CAAC,YAAY,CAAC,CAAA;gBAE5B,OAAO,EAAE,cAAc;CAIpC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linking.js","names":["Linking","LinkingAdapter","constructor","methods","openURL","bind","canOpenURL"],"sources":["../../../src/utils/native_adapters/linking.ts"],"sourcesContent":["import { Linking } from 'react-native'\n\nexport class LinkingAdapter {\n openURL:
|
|
1
|
+
{"version":3,"file":"linking.js","names":["Linking","LinkingAdapter","constructor","methods","openURL","bind","canOpenURL"],"sources":["../../../src/utils/native_adapters/linking.ts"],"sourcesContent":["import { Linking } from 'react-native'\n\nexport type LinkingOpenURLOptions = {\n forceOpenInBrowser?: boolean\n}\n\ntype LinkingMethods = {\n openURL: (url: string, options?: LinkingOpenURLOptions) => Promise<unknown>\n canOpenURL: Linking['canOpenURL']\n}\n\nexport class LinkingAdapter {\n openURL: LinkingMethods['openURL']\n canOpenURL: LinkingMethods['canOpenURL']\n\n constructor(methods: LinkingMethods) {\n this.openURL = methods.openURL.bind(Linking)\n this.canOpenURL = methods.canOpenURL.bind(Linking)\n }\n}\n"],"mappings":"AAAA,SAASA,OAAO,QAAQ,cAAc;AAWtC,OAAO,MAAMC,cAAc,CAAC;EAI1BC,WAAWA,CAACC,OAAuB,EAAE;IACnC,IAAI,CAACC,OAAO,GAAGD,OAAO,CAACC,OAAO,CAACC,IAAI,CAACL,OAAO,CAAC;IAC5C,IAAI,CAACM,UAAU,GAAGH,OAAO,CAACG,UAAU,CAACD,IAAI,CAACL,OAAO,CAAC;EACpD;AACF","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planningcenter/chat-react-native",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0-qa-1063.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@fortawesome/fontawesome-svg-core": "^7.2.0",
|
|
35
35
|
"@fortawesome/react-native-fontawesome": "^0.3.2",
|
|
36
|
-
"@planningcenter/emoji-keyboard": "4.
|
|
36
|
+
"@planningcenter/emoji-keyboard": "4.6.0-qa-1063.0",
|
|
37
37
|
"lodash-inflection": "^1.5.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
"sf-symbols-typescript": "^2.2.0",
|
|
85
85
|
"typescript": "~6.0.3"
|
|
86
86
|
},
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "ac6b3de382d402052835a23dcad56dc43bbc42a8"
|
|
88
88
|
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { DefaultTheme, ThemeProvider } from '@react-navigation/native'
|
|
2
|
+
import { fireEvent, render } from '@testing-library/react-native'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import { Linking as RNLinking } from 'react-native'
|
|
5
|
+
import { GiphyAttachment } from '../../../../components/conversation/attachments/giphy_attachment'
|
|
6
|
+
import {
|
|
7
|
+
DenormalizedGiphyAttachmentResource,
|
|
8
|
+
GiphyAttachmentVariant,
|
|
9
|
+
} from '../../../../types/resources/denormalized_attachment_resource'
|
|
10
|
+
import {
|
|
11
|
+
AudioAdapter,
|
|
12
|
+
ChatAdapters,
|
|
13
|
+
ClipboardAdapter,
|
|
14
|
+
ImagePickerAdapter,
|
|
15
|
+
LinkingAdapter,
|
|
16
|
+
VideoAdapter,
|
|
17
|
+
} from '../../../../utils/native_adapters'
|
|
18
|
+
|
|
19
|
+
const variant: GiphyAttachmentVariant = {
|
|
20
|
+
url: 'https://media.giphy.com/cat.gif',
|
|
21
|
+
width: '200',
|
|
22
|
+
height: '100',
|
|
23
|
+
size: '1',
|
|
24
|
+
frames: '1',
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const attachment: DenormalizedGiphyAttachmentResource = {
|
|
28
|
+
type: 'giphy',
|
|
29
|
+
id: '1',
|
|
30
|
+
title: 'cat',
|
|
31
|
+
titleLink: 'https://giphy.com/gifs/cat',
|
|
32
|
+
thumbUrl: variant.url,
|
|
33
|
+
giphy: {
|
|
34
|
+
original: variant,
|
|
35
|
+
fixedHeight: variant,
|
|
36
|
+
fixedHeightStill: variant,
|
|
37
|
+
fixedHeightDownsampled: variant,
|
|
38
|
+
fixedWidth: variant,
|
|
39
|
+
fixedWidthStill: variant,
|
|
40
|
+
fixedWidthDownsampled: variant,
|
|
41
|
+
},
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const hostOpenURL = jest.fn(async (_: string) => {})
|
|
45
|
+
|
|
46
|
+
describe('GiphyAttachment', () => {
|
|
47
|
+
beforeAll(() => {
|
|
48
|
+
ChatAdapters.configure({
|
|
49
|
+
clipboard: new ClipboardAdapter({
|
|
50
|
+
getStringAsync: async () => '',
|
|
51
|
+
setStringAsync: async () => {},
|
|
52
|
+
}),
|
|
53
|
+
audio: new AudioAdapter({ useAudio: () => ({}) as any }),
|
|
54
|
+
video: new VideoAdapter({ Player: React.forwardRef(() => null) }),
|
|
55
|
+
imagePicker: new ImagePickerAdapter({
|
|
56
|
+
openCameraAsync: async () => ({ canceled: true, assets: null }),
|
|
57
|
+
openImageLibraryAsync: async () => ({ canceled: true, assets: null }),
|
|
58
|
+
}),
|
|
59
|
+
linking: new LinkingAdapter({ openURL: hostOpenURL, canOpenURL: async () => true }),
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it("opens the Giphy link through the host app's linking adapter", () => {
|
|
64
|
+
const rnOpenURL = jest.spyOn(RNLinking, 'openURL')
|
|
65
|
+
const { getByText } = render(
|
|
66
|
+
<ThemeProvider value={DefaultTheme}>
|
|
67
|
+
<GiphyAttachment attachment={attachment} onMessageLongPress={jest.fn()} />
|
|
68
|
+
</ThemeProvider>
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
fireEvent.press(getByText('/giphy'))
|
|
72
|
+
|
|
73
|
+
expect(hostOpenURL).toHaveBeenCalledWith('https://giphy.com/gifs/cat')
|
|
74
|
+
expect(rnOpenURL).not.toHaveBeenCalled()
|
|
75
|
+
})
|
|
76
|
+
})
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { sendEmail } from '../../screens/get_help_screen'
|
|
3
|
+
import {
|
|
4
|
+
AudioAdapter,
|
|
5
|
+
ChatAdapters,
|
|
6
|
+
ClipboardAdapter,
|
|
7
|
+
ImagePickerAdapter,
|
|
8
|
+
LinkingAdapter,
|
|
9
|
+
VideoAdapter,
|
|
10
|
+
} from '../../utils/native_adapters'
|
|
11
|
+
|
|
12
|
+
const hostOpenURL = jest.fn(async (_: string) => {})
|
|
13
|
+
|
|
14
|
+
describe('sendEmail', () => {
|
|
15
|
+
beforeAll(() => {
|
|
16
|
+
ChatAdapters.configure({
|
|
17
|
+
clipboard: new ClipboardAdapter({
|
|
18
|
+
getStringAsync: async () => '',
|
|
19
|
+
setStringAsync: async () => {},
|
|
20
|
+
}),
|
|
21
|
+
audio: new AudioAdapter({ useAudio: () => ({}) as any }),
|
|
22
|
+
video: new VideoAdapter({ Player: React.forwardRef(() => null) }),
|
|
23
|
+
imagePicker: new ImagePickerAdapter({
|
|
24
|
+
openCameraAsync: async () => ({ canceled: true, assets: null }),
|
|
25
|
+
openImageLibraryAsync: async () => ({ canceled: true, assets: null }),
|
|
26
|
+
}),
|
|
27
|
+
linking: new LinkingAdapter({ openURL: hostOpenURL, canOpenURL: async () => true }),
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it("opens mailto through the host app's linking adapter", () => {
|
|
32
|
+
sendEmail('help@example.com')
|
|
33
|
+
|
|
34
|
+
expect(hostOpenURL).toHaveBeenCalledWith('mailto:help@example.com')
|
|
35
|
+
})
|
|
36
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { QueryClientProvider } from '@tanstack/react-query'
|
|
2
|
+
import { render, type RenderOptions } from '@testing-library/react-native'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import { buildTestQueryClient } from './query_client'
|
|
5
|
+
|
|
6
|
+
export const renderWithQueryClient = (ui: React.ReactElement, options: RenderOptions = {}) => {
|
|
7
|
+
const queryClient = buildTestQueryClient()
|
|
8
|
+
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
9
|
+
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
return render(ui, { wrapper, ...options })
|
|
13
|
+
}
|
|
@@ -27,6 +27,10 @@ import { addRecordInPagesData, deleteRecordInPagesData } from '../../../utils/ca
|
|
|
27
27
|
import { getMessagesQueryKey } from '../../../utils/request/get_messages'
|
|
28
28
|
import { MessageList } from '../message_list'
|
|
29
29
|
|
|
30
|
+
jest.mock('@react-navigation/elements', () => ({
|
|
31
|
+
...jest.requireActual('@react-navigation/elements'),
|
|
32
|
+
useHeaderHeight: () => 0,
|
|
33
|
+
}))
|
|
30
34
|
jest.mock('../../../hooks/use_api_client')
|
|
31
35
|
const mockFlash = jest.fn()
|
|
32
36
|
jest.mock('../../../hooks/use_animated_message_background_color', () => ({
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { PlatformPressable } from '@react-navigation/elements'
|
|
2
2
|
import React from 'react'
|
|
3
|
-
import { Text, StyleSheet
|
|
3
|
+
import { Text, StyleSheet } from 'react-native'
|
|
4
4
|
import { useTheme } from '../../../hooks'
|
|
5
5
|
import { DenormalizedGiphyAttachmentResource } from '../../../types/resources/denormalized_attachment_resource'
|
|
6
|
-
import { assertKeysAreNumbers } from '../../../utils'
|
|
6
|
+
import { assertKeysAreNumbers, Linking } from '../../../utils'
|
|
7
7
|
import { tokens } from '../../../vendor/tapestry/tokens'
|
|
8
8
|
import { Image } from '../../display'
|
|
9
9
|
|
|
@@ -22,7 +22,6 @@ export function GiphyAttachment({
|
|
|
22
22
|
|
|
23
23
|
function handlePress() {
|
|
24
24
|
if (titleLink) {
|
|
25
|
-
// Open Giphy link in the default web browser
|
|
26
25
|
Linking.openURL(titleLink)
|
|
27
26
|
}
|
|
28
27
|
}
|
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
StyleSheet,
|
|
7
7
|
Modal,
|
|
8
8
|
View,
|
|
9
|
-
Linking,
|
|
10
9
|
Dimensions,
|
|
11
10
|
NativeSyntheticEvent,
|
|
12
11
|
NativeScrollEvent,
|
|
@@ -30,7 +29,7 @@ import Animated, {
|
|
|
30
29
|
import { useSafeAreaInsets, SafeAreaProvider } from 'react-native-safe-area-context'
|
|
31
30
|
import { useTheme } from '../../../hooks'
|
|
32
31
|
import { DenormalizedMessageAttachmentResource } from '../../../types/resources/denormalized_attachment_resource'
|
|
33
|
-
import { Haptic, platformFontWeightMedium } from '../../../utils'
|
|
32
|
+
import { Haptic, Linking, platformFontWeightMedium } from '../../../utils'
|
|
34
33
|
import { formatDatePreview } from '../../../utils/date'
|
|
35
34
|
import { tokens } from '../../../vendor/tapestry/tokens'
|
|
36
35
|
import { IconButton, Image, Heading, Text } from '../../display'
|
|
@@ -212,7 +211,7 @@ const LightboxGallery = ({
|
|
|
212
211
|
HANDLERS
|
|
213
212
|
============================ */
|
|
214
213
|
const handleOpenInBrowser = useCallback(() => {
|
|
215
|
-
Linking.openURL(urlMedium || url)
|
|
214
|
+
Linking.openURL(urlMedium || url, { forceOpenInBrowser: true })
|
|
216
215
|
}, [urlMedium, url])
|
|
217
216
|
|
|
218
217
|
// Helper to enable or disable FlatList scroll state after gestures have ended
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useNavigation, useTheme as useNavigationTheme, useRoute } from '@react-navigation/native'
|
|
2
2
|
import React, { useCallback, useContext, useEffect, useRef, useState } from 'react'
|
|
3
3
|
import {
|
|
4
|
-
Linking,
|
|
5
4
|
Platform,
|
|
6
5
|
Pressable,
|
|
7
6
|
ScrollView,
|
|
@@ -34,6 +33,7 @@ import {
|
|
|
34
33
|
FileAttachment,
|
|
35
34
|
} from '../../types/resources/denormalized_attachment_resource_for_create'
|
|
36
35
|
import {
|
|
36
|
+
Linking,
|
|
37
37
|
Log,
|
|
38
38
|
MAX_FONT_SIZE_MULTIPLIER_LANDMARK,
|
|
39
39
|
platformFontWeightMedium,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { date as formatDate } from '@planningcenter/datetime-fmt'
|
|
2
|
+
import { useHeaderHeight } from '@react-navigation/elements'
|
|
2
3
|
import { noop } from 'lodash'
|
|
3
4
|
import React, { RefObject, useCallback, useEffect, useRef, useState } from 'react'
|
|
4
5
|
import { FlatList, FlatListProps, StyleSheet, View } from 'react-native'
|
|
@@ -7,6 +8,7 @@ import { ConversationResource } from '../../types/resources/conversation'
|
|
|
7
8
|
import { MessageResource } from '../../types/resources/message'
|
|
8
9
|
import { getRelativeDateStatus } from '../../utils/date'
|
|
9
10
|
import { groupMessages, type DateSeparator, type EnrichedMessage } from '../../utils/group_messages'
|
|
11
|
+
import { isLiquidGlassEnabled } from '../../utils/liquid_glass'
|
|
10
12
|
import { CONVERSATION_MESSAGE_LIST_PADDING_HORIZONTAL } from '../../utils/styles'
|
|
11
13
|
import { isSystemMessage } from '../../utils/system_messages'
|
|
12
14
|
import { Text } from '../display'
|
|
@@ -69,6 +71,8 @@ export function MessageList({
|
|
|
69
71
|
onMomentumScrollEnd,
|
|
70
72
|
}: MessageListProps) {
|
|
71
73
|
const styles = useStyles()
|
|
74
|
+
const headerHeight = useHeaderHeight()
|
|
75
|
+
const glassHeaderInset = isLiquidGlassEnabled() ? headerHeight : 0
|
|
72
76
|
const inReplyScreen = !!replyRootId
|
|
73
77
|
const canDeleteNonAuthoredMessages =
|
|
74
78
|
conversation.memberAbility?.canDeleteNonAuthoredMessages ?? false
|
|
@@ -155,6 +159,8 @@ export function MessageList({
|
|
|
155
159
|
inverted
|
|
156
160
|
ref={listRef}
|
|
157
161
|
contentContainerStyle={styles.listContainer}
|
|
162
|
+
contentInset={{ bottom: glassHeaderInset }}
|
|
163
|
+
scrollIndicatorInsets={{ bottom: glassHeaderInset }}
|
|
158
164
|
data={messagesWithSeparators}
|
|
159
165
|
keyExtractor={item => item.id}
|
|
160
166
|
onScroll={onScroll}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { render } from '@testing-library/react-native'
|
|
2
1
|
import React from 'react'
|
|
2
|
+
import { renderWithQueryClient } from '../../../__utils__/render_with_query_client'
|
|
3
3
|
import type { ConversationPreviewData, ConversationResource } from '../../../types'
|
|
4
4
|
import { formatDatePreview } from '../../../utils/date'
|
|
5
5
|
import { ConversationPreview } from '../conversation_preview'
|
|
@@ -49,7 +49,7 @@ const renderPreview = (
|
|
|
49
49
|
preview: ConversationPreviewData,
|
|
50
50
|
overrides: Partial<ConversationResource> = {}
|
|
51
51
|
) =>
|
|
52
|
-
|
|
52
|
+
renderWithQueryClient(
|
|
53
53
|
<ConversationPreview conversation={conversation(preview, overrides)} onPress={jest.fn()} />
|
|
54
54
|
)
|
|
55
55
|
|
|
@@ -79,6 +79,7 @@ export const Conversations = ({ ListHeaderComponent }: ConversationsProps) => {
|
|
|
79
79
|
data={data}
|
|
80
80
|
keyExtractor={item => item.id.toString()}
|
|
81
81
|
contentContainerStyle={styles.contentContainer}
|
|
82
|
+
contentInsetAdjustmentBehavior="automatic"
|
|
82
83
|
onRefresh={refetch}
|
|
83
84
|
refreshing={!isFetched && isRefetching}
|
|
84
85
|
ListHeaderComponent={ListHeaderComponent}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
2
|
+
import { render, waitFor } from '@testing-library/react-native'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import { Image } from 'react-native'
|
|
5
|
+
import { buildTestQueryClient } from '../../../__utils__/query_client'
|
|
6
|
+
import type { AvatarUpdatePayload } from '../../../hooks/use_conversation_avatar_update'
|
|
7
|
+
import { ConversationAvatar } from '../conversation_avatar'
|
|
8
|
+
|
|
9
|
+
const conversation = {
|
|
10
|
+
id: 7,
|
|
11
|
+
customAvatarType: 'emoji' as const,
|
|
12
|
+
customAvatarKey: '🎉',
|
|
13
|
+
customAvatarColor: 'cosmic',
|
|
14
|
+
customAvatarImageUrl: null,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const imagePayload: AvatarUpdatePayload = {
|
|
18
|
+
kind: 'image',
|
|
19
|
+
color: 'cosmic',
|
|
20
|
+
imageAsset: { uri: 'file:///photo.jpg', width: 100, height: 100 },
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let queryClient: QueryClient
|
|
24
|
+
let inFlight: { settle: () => void; done: Promise<unknown> }[]
|
|
25
|
+
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
queryClient = buildTestQueryClient({ defaultOptions: { mutations: { gcTime: Infinity } } })
|
|
28
|
+
inFlight = []
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
afterEach(async () => {
|
|
32
|
+
inFlight.forEach(({ settle }) => settle())
|
|
33
|
+
await Promise.all(inFlight.map(({ done }) => done))
|
|
34
|
+
queryClient.clear()
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
function startAvatarUpdate(conversationId: number) {
|
|
38
|
+
let settle = () => {}
|
|
39
|
+
const upload = new Promise<void>(resolve => (settle = resolve))
|
|
40
|
+
const mutation = queryClient.getMutationCache().build(queryClient, {
|
|
41
|
+
mutationKey: ['updateConversationAvatar', conversationId],
|
|
42
|
+
mutationFn: () => upload,
|
|
43
|
+
networkMode: 'always',
|
|
44
|
+
})
|
|
45
|
+
const done = mutation.execute(imagePayload)
|
|
46
|
+
inFlight.push({ settle, done })
|
|
47
|
+
return settle
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function renderAvatar() {
|
|
51
|
+
return render(
|
|
52
|
+
<QueryClientProvider client={queryClient}>
|
|
53
|
+
<ConversationAvatar conversation={conversation} />
|
|
54
|
+
</QueryClientProvider>
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
describe('ConversationAvatar', () => {
|
|
59
|
+
it('renders the pending avatar update over the cached conversation data', () => {
|
|
60
|
+
startAvatarUpdate(conversation.id)
|
|
61
|
+
|
|
62
|
+
const view = renderAvatar()
|
|
63
|
+
|
|
64
|
+
expect(view.UNSAFE_getByType(Image).props.source).toEqual({ uri: 'file:///photo.jpg' })
|
|
65
|
+
expect(view.queryByText('🎉')).toBeNull()
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('ignores pending avatar updates for other conversations', () => {
|
|
69
|
+
startAvatarUpdate(conversation.id + 1)
|
|
70
|
+
|
|
71
|
+
const view = renderAvatar()
|
|
72
|
+
|
|
73
|
+
expect(view.getByText('🎉')).toBeTruthy()
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it('returns to the cached conversation data once the update settles', async () => {
|
|
77
|
+
const settle = startAvatarUpdate(conversation.id)
|
|
78
|
+
const view = renderAvatar()
|
|
79
|
+
|
|
80
|
+
settle()
|
|
81
|
+
|
|
82
|
+
await waitFor(() => expect(view.getByText('🎉')).toBeTruthy())
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('ignores an older pending update once a newer one has settled', async () => {
|
|
86
|
+
startAvatarUpdate(conversation.id)
|
|
87
|
+
const settleNewer = startAvatarUpdate(conversation.id)
|
|
88
|
+
const view = renderAvatar()
|
|
89
|
+
|
|
90
|
+
settleNewer()
|
|
91
|
+
|
|
92
|
+
await waitFor(() => expect(view.getByText('🎉')).toBeTruthy())
|
|
93
|
+
})
|
|
94
|
+
})
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import type { ViewStyle } from 'react-native'
|
|
3
|
+
import {
|
|
4
|
+
applyAvatarUpdate,
|
|
5
|
+
usePendingConversationAvatarUpdate,
|
|
6
|
+
} from '../../hooks/use_conversation_avatar_update'
|
|
3
7
|
import type { ConversationAvatarData } from '../../types'
|
|
4
8
|
import AvatarPrimitive, { type AvatarRootProps } from '../primitive/avatar_primitive'
|
|
5
9
|
import { AvatarGroup } from './avatar_group'
|
|
@@ -38,7 +42,7 @@ function resolveAvatar(conversation: ConversationAvatarData): ResolvedAvatar {
|
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
interface ConversationAvatarProps {
|
|
41
|
-
conversation: ConversationAvatarData
|
|
45
|
+
conversation: ConversationAvatarData & { id?: number }
|
|
42
46
|
size?: AvatarRootProps['size']
|
|
43
47
|
showFallback?: boolean
|
|
44
48
|
fallbackIconName?: IconString
|
|
@@ -54,7 +58,10 @@ export function ConversationAvatar({
|
|
|
54
58
|
style,
|
|
55
59
|
maxFontSizeMultiplier,
|
|
56
60
|
}: ConversationAvatarProps) {
|
|
57
|
-
const
|
|
61
|
+
const pendingUpdate = usePendingConversationAvatarUpdate(conversation.id)
|
|
62
|
+
const avatar = resolveAvatar(
|
|
63
|
+
pendingUpdate ? applyAvatarUpdate(conversation, pendingUpdate) : conversation
|
|
64
|
+
)
|
|
58
65
|
const sizeProps = { size, maxFontSizeMultiplier, style }
|
|
59
66
|
|
|
60
67
|
switch (avatar.kind) {
|
|
@@ -43,6 +43,7 @@ export function KeyboardScrollView({ children, contentContainerStyle }: Keyboard
|
|
|
43
43
|
<KeyboardView>
|
|
44
44
|
<ScrollView
|
|
45
45
|
ref={scrollViewRef}
|
|
46
|
+
contentInsetAdjustmentBehavior="automatic"
|
|
46
47
|
contentContainerStyle={contentContainerStyle}
|
|
47
48
|
onLayout={scrollFocusedInputIntoView}
|
|
48
49
|
onContentSizeChange={scrollFocusedInputIntoView}
|
|
@@ -4,6 +4,7 @@ import { render } from '@testing-library/react-native'
|
|
|
4
4
|
import React from 'react'
|
|
5
5
|
import { buildTestQueryClient } from '../../../__utils__/query_client'
|
|
6
6
|
import { Log } from '../../../utils/native_adapters/configuration'
|
|
7
|
+
import { ResponseError } from '../../../utils/response_error'
|
|
7
8
|
import { PageErrorBoundary } from '../page_error_boundary'
|
|
8
9
|
|
|
9
10
|
jest.mock('../../primitive/blank_state_primitive', () => {
|
|
@@ -74,4 +75,36 @@ describe('PageErrorBoundary', () => {
|
|
|
74
75
|
expect(getByText('Oops!')).toBeTruthy()
|
|
75
76
|
expect(getByText('Something unexpected happened.')).toBeTruthy()
|
|
76
77
|
})
|
|
78
|
+
|
|
79
|
+
describe('with a generic fallback override', () => {
|
|
80
|
+
const genericFallback = { heading: 'Nothing here', body: 'Come back later.' }
|
|
81
|
+
const responseError = (status: number) =>
|
|
82
|
+
new ResponseError({ status, statusText: 'x', errors: [] } as never)
|
|
83
|
+
|
|
84
|
+
it.each([
|
|
85
|
+
['a plain error', new Error('boom')],
|
|
86
|
+
['an unhandled status', responseError(500)],
|
|
87
|
+
])('replaces the Oops copy for %s', (_label, thrown) => {
|
|
88
|
+
const { getByText, queryByText } = renderWithProviders(
|
|
89
|
+
<PageErrorBoundary genericFallback={genericFallback}>
|
|
90
|
+
<Boom thrown={thrown} />
|
|
91
|
+
</PageErrorBoundary>
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
expect(getByText('Nothing here')).toBeTruthy()
|
|
95
|
+
expect(getByText('Come back later.')).toBeTruthy()
|
|
96
|
+
expect(queryByText('Oops!')).toBeNull()
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
it('leaves a known status alone', () => {
|
|
100
|
+
const { getByText, queryByText } = renderWithProviders(
|
|
101
|
+
<PageErrorBoundary genericFallback={genericFallback}>
|
|
102
|
+
<Boom thrown={responseError(403)} />
|
|
103
|
+
</PageErrorBoundary>
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
expect(getByText('Permission required')).toBeTruthy()
|
|
107
|
+
expect(queryByText('Nothing here')).toBeNull()
|
|
108
|
+
})
|
|
109
|
+
})
|
|
77
110
|
})
|
|
@@ -6,11 +6,26 @@ import { ResponseError } from '../../utils/response_error'
|
|
|
6
6
|
import BlankState from '../primitive/blank_state_primitive'
|
|
7
7
|
import { ErrorBoundary, ErrorBoundaryFallback, ErrorBoundaryProps } from './error_boundary'
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
export type PageErrorFallback = { heading: string; body: string }
|
|
10
|
+
|
|
11
|
+
const GENERIC_FALLBACK: PageErrorFallback = {
|
|
12
|
+
heading: 'Oops!',
|
|
13
|
+
body: 'Something unexpected happened.',
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type PageErrorBoundaryProps = PropsWithChildren<
|
|
17
|
+
ErrorBoundaryProps & { genericFallback?: PageErrorFallback }
|
|
18
|
+
>
|
|
19
|
+
|
|
20
|
+
export function PageErrorBoundary({
|
|
21
|
+
children,
|
|
22
|
+
genericFallback = GENERIC_FALLBACK,
|
|
23
|
+
...props
|
|
24
|
+
}: PageErrorBoundaryProps) {
|
|
25
|
+
const renderPageFallback: ErrorBoundaryFallback = (error, reset) => (
|
|
26
|
+
<ErrorView error={error} reset={reset} generic={genericFallback} />
|
|
27
|
+
)
|
|
12
28
|
|
|
13
|
-
export function PageErrorBoundary({ children, ...props }: PropsWithChildren<ErrorBoundaryProps>) {
|
|
14
29
|
return (
|
|
15
30
|
<ErrorBoundary scope="screen" fallback={renderPageFallback} {...props}>
|
|
16
31
|
{children}
|
|
@@ -18,7 +33,15 @@ export function PageErrorBoundary({ children, ...props }: PropsWithChildren<Erro
|
|
|
18
33
|
)
|
|
19
34
|
}
|
|
20
35
|
|
|
21
|
-
function ErrorView({
|
|
36
|
+
function ErrorView({
|
|
37
|
+
error,
|
|
38
|
+
reset,
|
|
39
|
+
generic,
|
|
40
|
+
}: {
|
|
41
|
+
error: Error
|
|
42
|
+
reset: () => void
|
|
43
|
+
generic: PageErrorFallback
|
|
44
|
+
}) {
|
|
22
45
|
const { reset: resetQueries } = useQueryErrorResetBoundary()
|
|
23
46
|
|
|
24
47
|
const handleReset = useCallback(() => {
|
|
@@ -29,7 +52,7 @@ function ErrorView({ error, reset }: { error: Error; reset: () => void }) {
|
|
|
29
52
|
useEffect(() => handleReset, [handleReset])
|
|
30
53
|
|
|
31
54
|
if (error instanceof ResponseError) {
|
|
32
|
-
return <ResponseErrorView response={error.response} onReset={handleReset} />
|
|
55
|
+
return <ResponseErrorView response={error.response} onReset={handleReset} generic={generic} />
|
|
33
56
|
}
|
|
34
57
|
|
|
35
58
|
if (isNetworkError(error)) {
|
|
@@ -41,7 +64,7 @@ function ErrorView({ error, reset }: { error: Error; reset: () => void }) {
|
|
|
41
64
|
)
|
|
42
65
|
}
|
|
43
66
|
|
|
44
|
-
return <ErrorContent heading={
|
|
67
|
+
return <ErrorContent heading={generic.heading} body={generic.body} />
|
|
45
68
|
}
|
|
46
69
|
|
|
47
70
|
function isNetworkError(error: Error) {
|
|
@@ -54,7 +77,15 @@ function isNetworkError(error: Error) {
|
|
|
54
77
|
return new RegExp(networkFailedMessages.join('|'), 'i').test(error.message)
|
|
55
78
|
}
|
|
56
79
|
|
|
57
|
-
function ResponseErrorView({
|
|
80
|
+
function ResponseErrorView({
|
|
81
|
+
response,
|
|
82
|
+
onReset,
|
|
83
|
+
generic,
|
|
84
|
+
}: {
|
|
85
|
+
response: Response
|
|
86
|
+
onReset: () => void
|
|
87
|
+
generic: PageErrorFallback
|
|
88
|
+
}) {
|
|
58
89
|
const { status } = response
|
|
59
90
|
|
|
60
91
|
const heading = useMemo(() => {
|
|
@@ -64,9 +95,9 @@ function ResponseErrorView({ response, onReset }: { response: Response; onReset:
|
|
|
64
95
|
case 404:
|
|
65
96
|
return 'Content not found'
|
|
66
97
|
default:
|
|
67
|
-
return
|
|
98
|
+
return generic.heading
|
|
68
99
|
}
|
|
69
|
-
}, [status])
|
|
100
|
+
}, [status, generic.heading])
|
|
70
101
|
|
|
71
102
|
const body = useMemo(() => {
|
|
72
103
|
switch (status) {
|
|
@@ -75,9 +106,9 @@ function ResponseErrorView({ response, onReset }: { response: Response; onReset:
|
|
|
75
106
|
case 404:
|
|
76
107
|
return 'If you believe something should be here, please reach out to your administrator.'
|
|
77
108
|
default:
|
|
78
|
-
return
|
|
109
|
+
return generic.body
|
|
79
110
|
}
|
|
80
|
-
}, [status])
|
|
111
|
+
}, [status, generic.body])
|
|
81
112
|
|
|
82
113
|
useEffect(() => {
|
|
83
114
|
if (status !== 401) return
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { QueryClientProvider } from '@tanstack/react-query'
|
|
2
|
+
import { act, renderHook } from '@testing-library/react-native'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import { buildTestQueryClient } from '../../__utils__/query_client'
|
|
5
|
+
import { useConversationAvatarUpdate } from '../use_conversation_avatar_update'
|
|
6
|
+
|
|
7
|
+
const mockPatch = jest.fn().mockResolvedValue({ data: { id: 7 } })
|
|
8
|
+
let finishUpload = () => {}
|
|
9
|
+
jest.mock('../use_api_client', () => ({ useApiClient: () => ({ chat: { patch: mockPatch } }) }))
|
|
10
|
+
jest.mock('../use_upload_client', () => ({
|
|
11
|
+
useUploadClient: () => ({
|
|
12
|
+
uploadFile: () => new Promise(resolve => (finishUpload = () => resolve({ id: 'upload-1' }))),
|
|
13
|
+
}),
|
|
14
|
+
}))
|
|
15
|
+
|
|
16
|
+
describe('useConversationAvatarUpdate', () => {
|
|
17
|
+
it('saves only the newest pick when an icon is chosen during a photo upload', async () => {
|
|
18
|
+
const queryClient = buildTestQueryClient({
|
|
19
|
+
defaultOptions: { mutations: { gcTime: Infinity } },
|
|
20
|
+
})
|
|
21
|
+
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
22
|
+
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
23
|
+
)
|
|
24
|
+
const { result } = renderHook(() => useConversationAvatarUpdate({ conversationId: 7 }), {
|
|
25
|
+
wrapper,
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const photoSave = result.current.mutateAsync({
|
|
29
|
+
kind: 'image',
|
|
30
|
+
color: 'cosmic',
|
|
31
|
+
imageAsset: { uri: 'file:///photo.jpg', width: 100, height: 100 },
|
|
32
|
+
})
|
|
33
|
+
await act(() => result.current.mutateAsync({ kind: 'icon', key: 'star', color: 'cosmic' }))
|
|
34
|
+
finishUpload()
|
|
35
|
+
await act(() => photoSave)
|
|
36
|
+
|
|
37
|
+
expect(mockPatch).toHaveBeenCalledTimes(1)
|
|
38
|
+
expect(mockPatch.mock.calls[0][0].data.data.attributes.custom_avatar_type).toBe('icon')
|
|
39
|
+
})
|
|
40
|
+
})
|