@planningcenter/chat-react-native 4.5.1-qa-1036.0 → 4.5.1-qa-staging.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 (124) hide show
  1. package/build/components/conversation/message_list.d.ts.map +1 -1
  2. package/build/components/conversation/message_list.js +155 -123
  3. package/build/components/conversation/message_list.js.map +1 -1
  4. package/build/components/conversations/conversations.d.ts.map +1 -1
  5. package/build/components/conversations/conversations.js +1 -0
  6. package/build/components/conversations/conversations.js.map +1 -1
  7. package/build/components/display/keyboard_scroll_view.d.ts.map +1 -1
  8. package/build/components/display/keyboard_scroll_view.js +1 -0
  9. package/build/components/display/keyboard_scroll_view.js.map +1 -1
  10. package/build/components/page/page_error_boundary.d.ts +9 -1
  11. package/build/components/page/page_error_boundary.d.ts.map +1 -1
  12. package/build/components/page/page_error_boundary.js +56 -31
  13. package/build/components/page/page_error_boundary.js.map +1 -1
  14. package/build/contexts/api_provider.d.ts +1 -0
  15. package/build/contexts/api_provider.d.ts.map +1 -1
  16. package/build/contexts/api_provider.js +11 -5
  17. package/build/contexts/api_provider.js.map +1 -1
  18. package/build/hooks/index.d.ts +1 -0
  19. package/build/hooks/index.d.ts.map +1 -1
  20. package/build/hooks/index.js +1 -0
  21. package/build/hooks/index.js.map +1 -1
  22. package/build/hooks/use_system_message_people.d.ts +14 -0
  23. package/build/hooks/use_system_message_people.d.ts.map +1 -0
  24. package/build/hooks/use_system_message_people.js +101 -0
  25. package/build/hooks/use_system_message_people.js.map +1 -0
  26. package/build/navigation/index.d.ts.map +1 -1
  27. package/build/navigation/index.js +12 -3
  28. package/build/navigation/index.js.map +1 -1
  29. package/build/navigation/page_error_fallbacks.d.ts +7 -0
  30. package/build/navigation/page_error_fallbacks.d.ts.map +1 -0
  31. package/build/navigation/page_error_fallbacks.js +7 -0
  32. package/build/navigation/page_error_fallbacks.js.map +1 -0
  33. package/build/navigation/screenLayout.d.ts.map +1 -1
  34. package/build/navigation/screenLayout.js +10 -6
  35. package/build/navigation/screenLayout.js.map +1 -1
  36. package/build/screens/age_check/age_check_required_screen.d.ts.map +1 -1
  37. package/build/screens/age_check/age_check_required_screen.js +1 -0
  38. package/build/screens/age_check/age_check_required_screen.js.map +1 -1
  39. package/build/screens/conversation_details_screen.d.ts.map +1 -1
  40. package/build/screens/conversation_details_screen.js +1 -0
  41. package/build/screens/conversation_details_screen.js.map +1 -1
  42. package/build/screens/conversation_new/components/groups_form.js +25 -18
  43. package/build/screens/conversation_new/components/groups_form.js.map +1 -1
  44. package/build/screens/conversation_new/components/services_form.js +51 -40
  45. package/build/screens/conversation_new/components/services_form.js.map +1 -1
  46. package/build/screens/conversation_select_recipients/conversation_new_entry_screen.d.ts.map +1 -1
  47. package/build/screens/conversation_select_recipients/conversation_new_entry_screen.js +1 -0
  48. package/build/screens/conversation_select_recipients/conversation_new_entry_screen.js.map +1 -1
  49. package/build/screens/conversation_select_recipients/conversation_select_direct_message_recipients_screen.d.ts.map +1 -1
  50. package/build/screens/conversation_select_recipients/conversation_select_direct_message_recipients_screen.js +332 -291
  51. package/build/screens/conversation_select_recipients/conversation_select_direct_message_recipients_screen.js.map +1 -1
  52. package/build/screens/conversation_select_recipients/conversation_select_group_recipients_screen.d.ts.map +1 -1
  53. package/build/screens/conversation_select_recipients/conversation_select_group_recipients_screen.js +1 -0
  54. package/build/screens/conversation_select_recipients/conversation_select_group_recipients_screen.js.map +1 -1
  55. package/build/screens/conversation_select_recipients/conversation_select_teams_i_lead_recipients_screen.d.ts.map +1 -1
  56. package/build/screens/conversation_select_recipients/conversation_select_teams_i_lead_recipients_screen.js +1 -0
  57. package/build/screens/conversation_select_recipients/conversation_select_teams_i_lead_recipients_screen.js.map +1 -1
  58. package/build/screens/get_help_screen.js +56 -62
  59. package/build/screens/get_help_screen.js.map +1 -1
  60. package/build/screens/group_notification_settings_screen.js +3 -2
  61. package/build/screens/group_notification_settings_screen.js.map +1 -1
  62. package/build/screens/notification_settings_screen.d.ts.map +1 -1
  63. package/build/screens/notification_settings_screen.js +1 -0
  64. package/build/screens/notification_settings_screen.js.map +1 -1
  65. package/build/screens/preferred_app_selection_screen.js +45 -39
  66. package/build/screens/preferred_app_selection_screen.js.map +1 -1
  67. package/build/screens/search/components/search_results_list.d.ts +4 -1
  68. package/build/screens/search/components/search_results_list.d.ts.map +1 -1
  69. package/build/screens/search/components/search_results_list.js +136 -110
  70. package/build/screens/search/components/search_results_list.js.map +1 -1
  71. package/build/screens/search/search_screen.d.ts.map +1 -1
  72. package/build/screens/search/search_screen.js +21 -28
  73. package/build/screens/search/search_screen.js.map +1 -1
  74. package/build/screens/settings_screen.d.ts.map +1 -1
  75. package/build/screens/settings_screen.js +7 -6
  76. package/build/screens/settings_screen.js.map +1 -1
  77. package/build/screens/system_message_people_screen.d.ts.map +1 -1
  78. package/build/screens/system_message_people_screen.js +33 -96
  79. package/build/screens/system_message_people_screen.js.map +1 -1
  80. package/build/utils/index.d.ts +1 -0
  81. package/build/utils/index.d.ts.map +1 -1
  82. package/build/utils/index.js +1 -0
  83. package/build/utils/index.js.map +1 -1
  84. package/build/utils/membership_sync_info_text.d.ts +2 -0
  85. package/build/utils/membership_sync_info_text.d.ts.map +1 -0
  86. package/build/utils/membership_sync_info_text.js +4 -0
  87. package/build/utils/membership_sync_info_text.js.map +1 -0
  88. package/package.json +3 -3
  89. package/src/components/conversation/__tests__/message_list.test.tsx +4 -0
  90. package/src/components/conversation/message_list.tsx +6 -0
  91. package/src/components/conversations/conversations.tsx +1 -0
  92. package/src/components/display/keyboard_scroll_view.tsx +1 -0
  93. package/src/components/page/__tests__/page_error_boundary.test.tsx +33 -0
  94. package/src/components/page/page_error_boundary.tsx +43 -12
  95. package/src/contexts/__tests__/configured_retry.test.ts +39 -0
  96. package/src/contexts/api_provider.tsx +12 -5
  97. package/src/hooks/__tests__/use_system_message_people.test.tsx +79 -0
  98. package/src/hooks/index.ts +1 -0
  99. package/src/hooks/use_system_message_people.ts +55 -0
  100. package/src/navigation/index.tsx +12 -2
  101. package/src/navigation/page_error_fallbacks.ts +14 -0
  102. package/src/navigation/screenLayout.tsx +3 -1
  103. package/src/screens/age_check/age_check_required_screen.tsx +5 -1
  104. package/src/screens/conversation_details_screen.tsx +1 -0
  105. package/src/screens/conversation_new/components/groups_form.tsx +2 -2
  106. package/src/screens/conversation_new/components/services_form.tsx +2 -2
  107. package/src/screens/conversation_select_recipients/__tests__/conversation_select_direct_message_recipients_screen.test.tsx +100 -0
  108. package/src/screens/conversation_select_recipients/conversation_new_entry_screen.tsx +4 -1
  109. package/src/screens/conversation_select_recipients/conversation_select_direct_message_recipients_screen.tsx +78 -68
  110. package/src/screens/conversation_select_recipients/conversation_select_group_recipients_screen.tsx +1 -0
  111. package/src/screens/conversation_select_recipients/conversation_select_teams_i_lead_recipients_screen.tsx +1 -0
  112. package/src/screens/get_help_screen.tsx +4 -4
  113. package/src/screens/group_notification_settings_screen.tsx +3 -3
  114. package/src/screens/notification_settings_screen.tsx +1 -0
  115. package/src/screens/preferred_app_selection_screen.tsx +4 -4
  116. package/src/screens/search/__tests__/search_screen.test.tsx +5 -7
  117. package/src/screens/search/components/__tests__/search_results_list.test.tsx +6 -2
  118. package/src/screens/search/components/search_results_list.tsx +34 -13
  119. package/src/screens/search/search_screen.tsx +8 -18
  120. package/src/screens/settings_screen.tsx +25 -25
  121. package/src/screens/system_message_people_screen.tsx +6 -20
  122. package/src/utils/__tests__/membership_sync_info_text.test.ts +15 -0
  123. package/src/utils/index.ts +1 -0
  124. package/src/utils/membership_sync_info_text.ts +3 -0
@@ -14,7 +14,7 @@ import { featuresQueryOptions } from '../hooks/use_features'
14
14
  import { useJoltForegroundPing } from '../hooks/use_jolt'
15
15
  import { RequestQueryKey } from '../hooks/use_suspense_api'
16
16
  import { emitAuthRefresh } from '../utils/auth_events'
17
- import { ResponseError } from '../utils/response_error'
17
+ import { isResponseLike, ResponseError } from '../utils/response_error'
18
18
  import { ChatContext, ChatContextValue } from './chat_context'
19
19
 
20
20
  let apiClient: ApiClient | undefined
@@ -29,14 +29,21 @@ const defaultQueryFn = ({ queryKey }: { queryKey: QueryKey }) => {
29
29
  return apiClient[app].get({ url, data, headers })
30
30
  }
31
31
 
32
- const configuredRetry = (failureCount: number, error: any) => {
33
- if (is429Error(error)) return false
32
+ export const configuredRetry = (failureCount: number, error: unknown) => {
33
+ if (isClientError(error)) return false
34
34
 
35
35
  return failureCount < 3
36
36
  }
37
37
 
38
- const is429Error = (error: any): boolean => {
39
- return error instanceof ResponseError && error.status === 429
38
+ const isClientError = (error: unknown): boolean => {
39
+ const status = errorStatus(error)
40
+ return status !== undefined && status >= 400 && status < 500
41
+ }
42
+
43
+ const errorStatus = (error: unknown): number | undefined => {
44
+ if (error instanceof ResponseError) return error.status
45
+ if (isResponseLike(error)) return error.status
46
+ return undefined
40
47
  }
41
48
 
42
49
  export const chatQueryClient = new QueryClient({
@@ -0,0 +1,79 @@
1
+ import { notifyManager, QueryClient, QueryClientProvider } from '@tanstack/react-query'
2
+ import { act, renderHook, waitFor } from '@testing-library/react-native'
3
+ import React, { Suspense } from 'react'
4
+ import { MEMBERS_PER_REQUEST, useSystemMessagePeople } from '../use_system_message_people'
5
+
6
+ const mockGet = jest.fn()
7
+ jest.mock('../use_api_client', () => ({
8
+ useApiClient: () => ({ chat: { get: mockGet } }),
9
+ }))
10
+
11
+ notifyManager.setNotifyFunction(fn => act(fn))
12
+
13
+ const conversationId = 7
14
+
15
+ const member = (id: number) => ({ type: 'Member', id, name: `Person ${id}`, avatar: '' })
16
+
17
+ const membersPage = (ids: number[]) => ({
18
+ data: ids.map(member),
19
+ links: {},
20
+ meta: { count: ids.length, totalCount: ids.length },
21
+ })
22
+
23
+ const requestedIds = () => mockGet.mock.calls.map(([request]) => request.data.where.id as number[])
24
+
25
+ const render = (personIds: number[]) => {
26
+ const queryClient = new QueryClient({
27
+ defaultOptions: { queries: { retry: false, gcTime: 0 } },
28
+ })
29
+ const wrapper = ({ children }: { children: React.ReactNode }) => (
30
+ <QueryClientProvider client={queryClient}>
31
+ <Suspense fallback={null}>{children}</Suspense>
32
+ </QueryClientProvider>
33
+ )
34
+
35
+ return renderHook(() => useSystemMessagePeople({ conversationId, personIds }), { wrapper })
36
+ }
37
+
38
+ beforeEach(() => {
39
+ mockGet.mockReset()
40
+ mockGet.mockImplementation(({ data }) =>
41
+ Promise.resolve(membersPage([...(data.where.id as number[])].reverse()))
42
+ )
43
+ })
44
+
45
+ describe('useSystemMessagePeople', () => {
46
+ it('requests members in batches no larger than a page', async () => {
47
+ const personIds = Array.from({ length: 250 }, (_, i) => i + 1)
48
+
49
+ render(personIds)
50
+
51
+ await waitFor(() => expect(mockGet).toHaveBeenCalledTimes(3))
52
+
53
+ expect(requestedIds().map(ids => ids.length)).toEqual([100, 100, 50])
54
+ expect(requestedIds().flat()).toEqual(personIds)
55
+ mockGet.mock.calls.forEach(([request]) => {
56
+ expect(request.url).toEqual(`/me/conversations/${conversationId}/members`)
57
+ expect(request.data.perPage).toEqual(MEMBERS_PER_REQUEST)
58
+ })
59
+ })
60
+
61
+ it('returns everyone in the order of the system message', async () => {
62
+ const personIds = Array.from({ length: 150 }, (_, i) => 1000 - i)
63
+
64
+ const { result } = render(personIds)
65
+
66
+ await waitFor(() => expect(result.current?.data).toHaveLength(150))
67
+
68
+ expect(result.current.data.map(({ id }) => id)).toEqual(personIds)
69
+ })
70
+
71
+ it('makes a single request for a small list', async () => {
72
+ const { result } = render([3, 1, 2])
73
+
74
+ await waitFor(() => expect(result.current?.data).toHaveLength(3))
75
+
76
+ expect(mockGet).toHaveBeenCalledTimes(1)
77
+ expect(result.current.data.map(({ id }) => id)).toEqual([3, 1, 2])
78
+ })
79
+ })
@@ -29,4 +29,5 @@ export * from './use_reduce_motion'
29
29
  export * from './use_scalable_number_of_lines'
30
30
  export * from './use_submit_age_check'
31
31
  export * from './use_suspense_api'
32
+ export * from './use_system_message_people'
32
33
  export * from './use_theme'
@@ -0,0 +1,55 @@
1
+ import { useSuspenseQueries } from '@tanstack/react-query'
2
+ import { chunk, sortBy } from 'lodash'
3
+ import { ApiCollection, MemberResource } from '../types'
4
+ import { GetRequest } from '../utils/client'
5
+ import { throwResponseError } from '../utils/response_error'
6
+ import { useApiClient } from './use_api_client'
7
+ import { getRequestQueryKey } from './use_suspense_api'
8
+
9
+ export const MEMBERS_PER_REQUEST = 100
10
+
11
+ type SystemMessagePeopleArgs = {
12
+ conversationId: number
13
+ personIds: number[]
14
+ }
15
+
16
+ export type SystemMessagePerson = Pick<MemberResource, 'type' | 'id' | 'name' | 'avatar'>
17
+
18
+ export const systemMessagePeopleRequest = (
19
+ conversationId: number,
20
+ personIds: number[]
21
+ ): GetRequest => ({
22
+ url: `/me/conversations/${conversationId}/members`,
23
+ data: {
24
+ fields: {
25
+ Member: ['id', 'name', 'avatar'],
26
+ },
27
+ where: {
28
+ id: personIds,
29
+ },
30
+ perPage: MEMBERS_PER_REQUEST,
31
+ },
32
+ })
33
+
34
+ export const useSystemMessagePeople = ({ conversationId, personIds }: SystemMessagePeopleArgs) => {
35
+ const apiClient = useApiClient()
36
+ const requests = chunk(personIds, MEMBERS_PER_REQUEST).map(ids =>
37
+ systemMessagePeopleRequest(conversationId, ids)
38
+ )
39
+
40
+ const queries = useSuspenseQueries({
41
+ queries: requests.map(request => ({
42
+ queryKey: getRequestQueryKey(request),
43
+ queryFn: (): Promise<ApiCollection<SystemMessagePerson>> =>
44
+ apiClient.chat.get<ApiCollection<SystemMessagePerson>>(request).catch(throwResponseError),
45
+ })),
46
+ })
47
+
48
+ const orderById = Object.fromEntries(personIds.map((id, index) => [id, index]))
49
+ const people = sortBy(
50
+ queries.flatMap(query => query.data.data),
51
+ person => orderById[person.id] ?? personIds.length
52
+ )
53
+
54
+ return { data: people }
55
+ }
@@ -83,9 +83,12 @@ import { TeamConversationScreen } from '../screens/team_conversation_screen'
83
83
  import { isLiquidGlassEnabled } from '../utils/liquid_glass'
84
84
  import { ScreenLayoutWithChatAccessGate } from './screenLayout'
85
85
 
86
+ const conversationGlassHeader = (): NativeStackNavigationOptions =>
87
+ isLiquidGlassEnabled() ? { headerBlurEffect: 'systemChromeMaterial' } : {}
88
+
86
89
  const globalScreenOptions: () => NativeStackNavigationOptions = () => ({
87
90
  headerBackButtonDisplayMode: 'minimal',
88
- ...(isLiquidGlassEnabled() ? { headerShadowVisible: false } : {}),
91
+ ...(isLiquidGlassEnabled() ? { headerShadowVisible: false, headerTransparent: true } : {}),
89
92
  })
90
93
 
91
94
  export const NewConversationStack = createNativeStackNavigator({
@@ -151,6 +154,7 @@ export const NewConversationStack = createNativeStackNavigator({
151
154
  {
152
155
  title: 'New conversation',
153
156
  headerLeft: () => null,
157
+ headerTransparent: false,
154
158
  },
155
159
  withRightClose({
156
160
  onPress: () => {
@@ -196,6 +200,7 @@ export const ChatStack = createNativeStackNavigator({
196
200
  options: ({ route, navigation }) =>
197
201
  composeOptions(
198
202
  {
203
+ ...conversationGlassHeader(),
199
204
  headerTitle: (props: NativeStackHeaderRightProps) => {
200
205
  const { conversation_id, title, badge, deleted, muted } =
201
206
  route.params as ConversationRouteProps
@@ -232,7 +237,10 @@ export const ChatStack = createNativeStackNavigator({
232
237
  screen: ConversationScreen,
233
238
  options: ({ route, navigation }) =>
234
239
  composeOptions(
235
- { title: (route.params as ConversationRouteProps)?.title ?? 'Reply' },
240
+ {
241
+ ...conversationGlassHeader(),
242
+ title: (route.params as ConversationRouteProps)?.title ?? 'Reply',
243
+ },
236
244
  withMinimalBack({ onPress: navigation.goBack })
237
245
  ),
238
246
  },
@@ -250,6 +258,7 @@ export const ChatStack = createNativeStackNavigator({
250
258
  options: ({ navigation }) =>
251
259
  composeOptions(
252
260
  {
261
+ ...conversationGlassHeader(),
253
262
  presentation: 'modal',
254
263
  title: 'Conversation details',
255
264
  },
@@ -325,6 +334,7 @@ export const ChatStack = createNativeStackNavigator({
325
334
  {
326
335
  title: 'New conversation',
327
336
  headerLeft: () => null,
337
+ headerTransparent: false,
328
338
  },
329
339
  withRightClose({ onPress: () => navigation.getParent()?.goBack() })
330
340
  ),
@@ -0,0 +1,14 @@
1
+ import type { StaticParamList } from '@react-navigation/native'
2
+ import type { PageErrorFallback } from '../components/page/page_error_boundary'
3
+ import type { NewConversationStack } from './index'
4
+
5
+ type RouteName =
6
+ | keyof ReactNavigation.RootParamList
7
+ | keyof StaticParamList<typeof NewConversationStack>
8
+
9
+ export const PAGE_ERROR_FALLBACKS: Partial<Record<RouteName, PageErrorFallback>> = {
10
+ ConversationSelectDirectMessageRecipients: {
11
+ heading: "Couldn't load people right now",
12
+ body: 'Try again.',
13
+ },
14
+ }
@@ -6,14 +6,16 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context'
6
6
  import { DefaultLoading } from '../components/page/loading'
7
7
  import { PageErrorBoundary } from '../components/page/page_error_boundary'
8
8
  import { ChatAccessGate } from './chat_access_gate'
9
+ import { PAGE_ERROR_FALLBACKS } from './page_error_fallbacks'
9
10
 
10
11
  export function ScreenLayout({ children }: { children: React.ReactElement }) {
11
12
  const route = useRoute()
12
13
  const styles = useStyles()
13
14
  const { fontScale } = useWindowDimensions()
15
+ const genericFallback = PAGE_ERROR_FALLBACKS[route.name as keyof typeof PAGE_ERROR_FALLBACKS]
14
16
 
15
17
  return (
16
- <PageErrorBoundary screenName={route.name}>
18
+ <PageErrorBoundary screenName={route.name} genericFallback={genericFallback}>
17
19
  <View key={fontScale} style={styles.screen}>
18
20
  <Suspense fallback={<DefaultLoading />}>{children}</Suspense>
19
21
  </View>
@@ -58,7 +58,11 @@ export function AgeCheckRequiredScreen() {
58
58
 
59
59
  return (
60
60
  <>
61
- <ScrollView style={styles.scrollView} contentContainerStyle={styles.container}>
61
+ <ScrollView
62
+ contentInsetAdjustmentBehavior="automatic"
63
+ style={styles.scrollView}
64
+ contentContainerStyle={styles.container}
65
+ >
62
66
  <View style={styles.header}>
63
67
  <View style={styles.heading}>
64
68
  <Icon name="general.exclamationTriangle" size={20} style={styles.warningIcon} />
@@ -427,6 +427,7 @@ export function ConversationDetailsScreen({ route }: ConversationDetailsScreenPr
427
427
  return (
428
428
  <View style={styles.listContainer}>
429
429
  <FlatList
430
+ contentInsetAdjustmentBehavior="automatic"
430
431
  data={listData as SectionListData}
431
432
  contentContainerStyle={styles.contentContainer}
432
433
  renderItem={({ item, index }) => {
@@ -22,7 +22,7 @@ import { useMyGender } from '../../../hooks/use_my_gender'
22
22
  import { useUploadClient } from '../../../hooks/use_upload_client'
23
23
  import { GroupsGroupResource } from '../../../types'
24
24
  import { GraphId } from '../../../types/resources/group_resource'
25
- import { pluralize } from '../../../utils'
25
+ import { membershipSyncInfoText, pluralize } from '../../../utils'
26
26
  import { genderDisplayLabel } from '../../../utils/gender_display_label'
27
27
  import { Haptic } from '../../../utils/native_adapters'
28
28
  import { AvatarSelectionRow } from './avatar_selection_row'
@@ -147,7 +147,7 @@ export const GroupsForm = ({ groupId, chat_group_graph_id, avatarSelection }: Gr
147
147
  disabled={!title || isPending || validationPending || warnings.length > 0}
148
148
  title="Start Conversation"
149
149
  onPress={() => handleSave()}
150
- infoText="Conversation will be automatically updated if any members are added or removed from this group."
150
+ infoText={membershipSyncInfoText('the group')}
151
151
  warnings={warnings}
152
152
  />
153
153
  </KeyboardView>
@@ -17,7 +17,7 @@ import { useConversationValidate } from '../../../hooks/use_conversation_validat
17
17
  import { availableFeatures, useFeatures } from '../../../hooks/use_features'
18
18
  import { useUploadClient } from '../../../hooks/use_upload_client'
19
19
  import { MemberResource } from '../../../types'
20
- import { pluralize } from '../../../utils'
20
+ import { membershipSyncInfoText, pluralize } from '../../../utils'
21
21
  import { Haptic } from '../../../utils/native_adapters'
22
22
  import { tokens } from '../../../vendor/tapestry/tokens'
23
23
  import { TeamFilterTypes } from '../../conversation_filter_recipients/types'
@@ -139,7 +139,7 @@ export const ServicesForm = ({
139
139
  }
140
140
  title={selectionHasConversation ? 'Open conversation' : 'Start conversation'}
141
141
  onPress={createConversation}
142
- infoText="Conversation will be automatically updated if any members are added or removed from included teams."
142
+ infoText={membershipSyncInfoText(selectedTeamIds.length === 1 ? 'the team' : 'the teams')}
143
143
  loading={isLoadingConversationCheck}
144
144
  warnings={warnings}
145
145
  />
@@ -0,0 +1,100 @@
1
+ import { fireEvent, render } from '@testing-library/react-native'
2
+ import React from 'react'
3
+ import { SafeAreaProvider } from 'react-native-safe-area-context'
4
+ import { ScreenLayout } from '../../../navigation/screenLayout'
5
+ import { Log } from '../../../utils/native_adapters/configuration'
6
+ import { ResponseError } from '../../../utils/response_error'
7
+ import { ConversationSelectDirectMessageRecipientsScreen } from '../conversation_select_direct_message_recipients_screen'
8
+
9
+ jest.mock('@react-navigation/native', () => ({
10
+ ...jest.requireActual('@react-navigation/native'),
11
+ useNavigation: () => ({ getParent: jest.fn(), goBack: jest.fn(), navigate: jest.fn() }),
12
+ useRoute: () => ({ name: 'ConversationSelectDirectMessageRecipients' }),
13
+ }))
14
+ jest.mock('../../../hooks/use_features', () => ({
15
+ ...jest.requireActual('../../../hooks/use_features'),
16
+ useFeatures: () => ({ featureEnabled: () => false }),
17
+ }))
18
+ jest.mock('../../../hooks/use_debounced_search_term', () => ({
19
+ useDebouncedSearchTerm: (term: string) => term,
20
+ }))
21
+ jest.mock('../../../hooks/direct_messages/use_direct_message_conversation_validate', () => ({
22
+ useDirectMessageConversationValidate: () => ({ warnings: [], validationPending: false }),
23
+ }))
24
+ jest.mock('../../../hooks/direct_messages/use_find_or_create_direct_message_conversation', () => ({
25
+ useFindOrCreateDirectMessageConversation: () => ({
26
+ findOrCreateConversation: jest.fn(),
27
+ directMessageExists: false,
28
+ isFinding: false,
29
+ isError: false,
30
+ }),
31
+ }))
32
+ jest.mock('../../../hooks/direct_messages/use_direct_message_affiliations', () => ({
33
+ useDirectMessageAffiliations: () => ({
34
+ groups: new Map(),
35
+ teams: new Map(),
36
+ resultsDescription: null,
37
+ }),
38
+ }))
39
+ let mockSearchFailure: Error = new TypeError('Network request failed')
40
+ jest.mock('../../../hooks/direct_messages/use_direct_message_candidates', () => ({
41
+ useDirectMessageCandidates: (term: string) => {
42
+ if (term) throw mockSearchFailure
43
+ return { data: undefined, isFetching: false }
44
+ },
45
+ }))
46
+ jest.mock('../../../components/display/action_button', () => ({ ActionButton: () => null }))
47
+ jest.mock('../../../components/display/keyboard_view', () => ({
48
+ ...jest.requireActual('../../../components/display/keyboard_view'),
49
+ KeyboardView: ({ children }: { children: React.ReactNode }) => children,
50
+ }))
51
+
52
+ const renderScreen = () =>
53
+ render(
54
+ <SafeAreaProvider
55
+ initialMetrics={{
56
+ frame: { x: 0, y: 0, width: 390, height: 844 },
57
+ insets: { top: 0, left: 0, right: 0, bottom: 0 },
58
+ }}
59
+ >
60
+ <ScreenLayout>
61
+ <ConversationSelectDirectMessageRecipientsScreen route={{ params: {} } as never} />
62
+ </ScreenLayout>
63
+ </SafeAreaProvider>
64
+ )
65
+
66
+ describe('ConversationSelectDirectMessageRecipientsScreen', () => {
67
+ let reportError: jest.SpyInstance
68
+ let consoleError: jest.SpyInstance
69
+
70
+ beforeEach(() => {
71
+ reportError = jest.spyOn(Log, 'reportError').mockImplementation(() => {})
72
+ consoleError = jest.spyOn(console, 'error').mockImplementation(() => {})
73
+ })
74
+
75
+ afterEach(() => {
76
+ reportError.mockRestore()
77
+ consoleError.mockRestore()
78
+ })
79
+
80
+ it('hands a failed search to the page error view', () => {
81
+ mockSearchFailure = new TypeError('Network request failed')
82
+ const view = renderScreen()
83
+
84
+ fireEvent.changeText(view.getByPlaceholderText('Search'), 'pi')
85
+
86
+ expect(view.getByText('Problem connecting!')).toBeTruthy()
87
+ expect(view.queryByPlaceholderText('Search')).toBeNull()
88
+ expect(reportError).toHaveBeenCalledTimes(1)
89
+ })
90
+
91
+ it("uses the screen's own wording when the search fails for no known reason", () => {
92
+ mockSearchFailure = new ResponseError({ status: 500, statusText: 'x', errors: [] } as never)
93
+ const view = renderScreen()
94
+
95
+ fireEvent.changeText(view.getByPlaceholderText('Search'), 'pi')
96
+
97
+ expect(view.getByText("Couldn't load people right now")).toBeTruthy()
98
+ expect(view.queryByText('Oops!')).toBeNull()
99
+ })
100
+ })
@@ -59,7 +59,10 @@ export const ConversationNewEntryScreen = ({ route }: ConversationSelectRecipien
59
59
  }
60
60
 
61
61
  return (
62
- <ScrollView contentContainerStyle={styles.contentContainer}>
62
+ <ScrollView
63
+ contentInsetAdjustmentBehavior="automatic"
64
+ contentContainerStyle={styles.contentContainer}
65
+ >
63
66
  <View style={styles.header}>
64
67
  <Heading variant="h2">Start a conversation by</Heading>
65
68
  </View>