@planningcenter/chat-react-native 4.2.2 → 4.2.3-qa-staging.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/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/message_form.d.ts +2 -1
- package/build/components/conversation/message_form.d.ts.map +1 -1
- package/build/components/conversation/message_form.js +168 -371
- package/build/components/conversation/message_form.js.map +1 -1
- package/build/components/conversation/message_list.d.ts +5 -2
- package/build/components/conversation/message_list.d.ts.map +1 -1
- package/build/components/conversation/message_list.js +187 -67
- package/build/components/conversation/message_list.js.map +1 -1
- package/build/components/conversation/missing_message.d.ts +2 -0
- package/build/components/conversation/missing_message.d.ts.map +1 -0
- package/build/components/conversation/missing_message.js +139 -0
- package/build/components/conversation/missing_message.js.map +1 -0
- package/build/components/conversation/system_message.js +3 -3
- package/build/components/conversation/system_message.js.map +1 -1
- package/build/components/display/conversation_avatar.d.ts +1 -2
- package/build/components/display/conversation_avatar.d.ts.map +1 -1
- package/build/components/display/conversation_avatar.js.map +1 -1
- package/build/hooks/groups/use_group_members_for_new_conversation.d.ts +4 -3
- package/build/hooks/groups/use_group_members_for_new_conversation.d.ts.map +1 -1
- package/build/hooks/index.d.ts +1 -0
- package/build/hooks/index.d.ts.map +1 -1
- package/build/hooks/index.js +1 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/use_conversation_messages.d.ts +14 -5
- package/build/hooks/use_conversation_messages.d.ts.map +1 -1
- package/build/hooks/use_conversation_messages.js +218 -42
- package/build/hooks/use_conversation_messages.js.map +1 -1
- package/build/hooks/use_conversation_messages_jolt_events.d.ts.map +1 -1
- package/build/hooks/use_conversation_messages_jolt_events.js +58 -42
- package/build/hooks/use_conversation_messages_jolt_events.js.map +1 -1
- package/build/hooks/use_debounced_search_term.d.ts +2 -0
- package/build/hooks/use_debounced_search_term.d.ts.map +1 -0
- package/build/hooks/use_debounced_search_term.js +40 -0
- package/build/hooks/use_debounced_search_term.js.map +1 -0
- package/build/hooks/use_direct_message_eligibility.d.ts +14 -0
- package/build/hooks/use_direct_message_eligibility.d.ts.map +1 -0
- package/build/hooks/use_direct_message_eligibility.js +87 -0
- package/build/hooks/use_direct_message_eligibility.js.map +1 -0
- package/build/hooks/use_features.d.ts +2 -1
- package/build/hooks/use_features.d.ts.map +1 -1
- package/build/hooks/use_features.js +2 -1
- package/build/hooks/use_features.js.map +1 -1
- package/build/hooks/use_mark_latest_message_read.d.ts +2 -1
- package/build/hooks/use_mark_latest_message_read.d.ts.map +1 -1
- package/build/hooks/use_mark_latest_message_read.js +4 -3
- package/build/hooks/use_mark_latest_message_read.js.map +1 -1
- package/build/hooks/use_read_receipts.d.ts +4 -3
- package/build/hooks/use_read_receipts.d.ts.map +1 -1
- package/build/hooks/use_search_results.d.ts +19 -0
- package/build/hooks/use_search_results.d.ts.map +1 -0
- package/build/hooks/use_search_results.js +153 -0
- package/build/hooks/use_search_results.js.map +1 -0
- package/build/hooks/use_suspense_api.d.ts +10 -6
- package/build/hooks/use_suspense_api.d.ts.map +1 -1
- package/build/hooks/use_suspense_api.js +83 -63
- package/build/hooks/use_suspense_api.js.map +1 -1
- package/build/navigation/index.d.ts +5 -0
- package/build/navigation/index.d.ts.map +1 -1
- package/build/navigation/index.js +5 -0
- package/build/navigation/index.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 +3 -2
- package/build/screens/age_check/age_check_underage_screen.js.map +1 -1
- package/build/screens/bug_report_screen.d.ts.map +1 -1
- package/build/screens/bug_report_screen.js +2 -2
- package/build/screens/bug_report_screen.js.map +1 -1
- package/build/screens/conversation_new/components/services_form.js +9 -8
- package/build/screens/conversation_new/components/services_form.js.map +1 -1
- package/build/screens/conversation_screen.d.ts +1 -0
- package/build/screens/conversation_screen.d.ts.map +1 -1
- package/build/screens/conversation_screen.js +305 -203
- package/build/screens/conversation_screen.js.map +1 -1
- package/build/screens/conversation_select_recipients/components/view_more_link_row.d.ts +2 -1
- package/build/screens/conversation_select_recipients/components/view_more_link_row.d.ts.map +1 -1
- package/build/screens/conversation_select_recipients/components/view_more_link_row.js +39 -24
- package/build/screens/conversation_select_recipients/components/view_more_link_row.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 +142 -158
- package/build/screens/conversation_select_recipients/conversation_select_direct_message_recipients_screen.js.map +1 -1
- package/build/screens/conversations/components/search_list_header_component.d.ts.map +1 -1
- package/build/screens/conversations/components/search_list_header_component.js +159 -133
- package/build/screens/conversations/components/search_list_header_component.js.map +1 -1
- package/build/screens/get_help_screen.js +4 -4
- package/build/screens/get_help_screen.js.map +1 -1
- package/build/screens/message_actions_screen.d.ts.map +1 -1
- package/build/screens/message_actions_screen.js +109 -94
- package/build/screens/message_actions_screen.js.map +1 -1
- package/build/screens/notification_settings/hooks/groups.d.ts +4 -3
- package/build/screens/notification_settings/hooks/groups.d.ts.map +1 -1
- package/build/screens/search/components/conversation_result_row.d.ts +8 -0
- package/build/screens/search/components/conversation_result_row.d.ts.map +1 -0
- package/build/screens/search/components/conversation_result_row.js +80 -0
- package/build/screens/search/components/conversation_result_row.js.map +1 -0
- package/build/screens/search/components/conversation_results.d.ts +8 -0
- package/build/screens/search/components/conversation_results.d.ts.map +1 -0
- package/build/screens/search/components/conversation_results.js +77 -0
- package/build/screens/search/components/conversation_results.js.map +1 -0
- package/build/screens/search/components/message_result_row.d.ts +8 -0
- package/build/screens/search/components/message_result_row.d.ts.map +1 -0
- package/build/screens/search/components/message_result_row.js +152 -0
- package/build/screens/search/components/message_result_row.js.map +1 -0
- package/build/screens/search/components/result_row.d.ts +10 -0
- package/build/screens/search/components/result_row.d.ts.map +1 -0
- package/build/screens/search/components/result_row.js +102 -0
- package/build/screens/search/components/result_row.js.map +1 -0
- package/build/screens/search/components/results_section.d.ts +9 -0
- package/build/screens/search/components/results_section.d.ts.map +1 -0
- package/build/screens/search/components/results_section.js +51 -0
- package/build/screens/search/components/results_section.js.map +1 -0
- package/build/screens/search/components/search_blank_states.d.ts +7 -0
- package/build/screens/search/components/search_blank_states.d.ts.map +1 -0
- package/build/screens/search/components/search_blank_states.js +72 -0
- package/build/screens/search/components/search_blank_states.js.map +1 -0
- package/build/screens/search/components/search_field.d.ts +7 -0
- package/build/screens/search/components/search_field.d.ts.map +1 -0
- package/build/screens/search/components/search_field.js +152 -0
- package/build/screens/search/components/search_field.js.map +1 -0
- package/build/screens/search/components/search_results_list.d.ts +8 -0
- package/build/screens/search/components/search_results_list.d.ts.map +1 -0
- package/build/screens/search/components/search_results_list.js +314 -0
- package/build/screens/search/components/search_results_list.js.map +1 -0
- package/build/screens/search/components/snippet.d.ts +8 -0
- package/build/screens/search/components/snippet.d.ts.map +1 -0
- package/build/screens/search/components/snippet.js +68 -0
- package/build/screens/search/components/snippet.js.map +1 -0
- package/build/screens/search/search_screen.d.ts +5 -0
- package/build/screens/search/search_screen.d.ts.map +1 -0
- package/build/screens/search/search_screen.js +68 -0
- package/build/screens/search/search_screen.js.map +1 -0
- package/build/types/api_primitives.d.ts +1 -0
- package/build/types/api_primitives.d.ts.map +1 -1
- package/build/types/api_primitives.js.map +1 -1
- package/build/types/resources/conversation.d.ts +1 -0
- package/build/types/resources/conversation.d.ts.map +1 -1
- package/build/types/resources/conversation.js.map +1 -1
- package/build/types/resources/index.d.ts +1 -0
- package/build/types/resources/index.d.ts.map +1 -1
- package/build/types/resources/index.js +1 -0
- package/build/types/resources/index.js.map +1 -1
- package/build/types/resources/member.d.ts +1 -0
- package/build/types/resources/member.d.ts.map +1 -1
- package/build/types/resources/member.js.map +1 -1
- package/build/types/resources/search_result.d.ts +29 -0
- package/build/types/resources/search_result.d.ts.map +1 -0
- package/build/types/resources/search_result.js +2 -0
- package/build/types/resources/search_result.js.map +1 -0
- package/build/utils/cache/messages_cache.d.ts +1 -0
- package/build/utils/cache/messages_cache.d.ts.map +1 -1
- package/build/utils/cache/messages_cache.js +37 -1
- package/build/utils/cache/messages_cache.js.map +1 -1
- package/build/utils/cache/messages_window.d.ts +11 -0
- package/build/utils/cache/messages_window.d.ts.map +1 -0
- package/build/utils/cache/messages_window.js +51 -0
- package/build/utils/cache/messages_window.js.map +1 -0
- package/build/utils/client/request_helpers.js +1 -1
- package/build/utils/client/request_helpers.js.map +1 -1
- package/build/utils/client/types.d.ts +1 -0
- package/build/utils/client/types.d.ts.map +1 -1
- package/build/utils/client/types.js.map +1 -1
- package/build/utils/group_messages.js +4 -1
- package/build/utils/group_messages.js.map +1 -1
- package/build/utils/request/get_search_results.d.ts +13 -0
- package/build/utils/request/get_search_results.d.ts.map +1 -0
- package/build/utils/request/get_search_results.js +20 -0
- package/build/utils/request/get_search_results.js.map +1 -0
- package/package.json +3 -3
- package/src/__tests__/components/conversation/attachments/giphy_attachment.test.tsx +76 -0
- package/src/__tests__/hooks/use_direct_message_eligibility.test.tsx +83 -0
- package/src/__tests__/hooks/use_features.test.ts +10 -2
- package/src/__tests__/screens/conversation_new/components/services_form.test.tsx +91 -0
- package/src/__tests__/screens/get_help_screen.test.ts +40 -0
- package/src/__tests__/screens/message_actions_screen.test.tsx +136 -0
- package/src/__tests__/utils/client.ts +3 -4
- package/src/__utils__/query_client.ts +3 -0
- package/src/components/conversation/__tests__/message_form.test.tsx +78 -0
- package/src/components/conversation/attachments/giphy_attachment.tsx +2 -3
- package/src/components/conversation/message_form.tsx +31 -3
- package/src/components/conversation/message_list.tsx +88 -4
- package/src/components/conversation/missing_message.tsx +66 -0
- package/src/components/conversation/system_message.tsx +3 -3
- package/src/components/display/conversation_avatar.tsx +1 -10
- package/src/hooks/__tests__/use_conversation_messages.test.tsx +333 -0
- package/src/hooks/__tests__/use_conversation_messages_jolt_events.test.tsx +87 -0
- package/src/hooks/__tests__/use_debounced_search_term.test.tsx +38 -0
- package/src/hooks/__tests__/use_mark_latest_message_read.test.tsx +33 -0
- package/src/hooks/__tests__/use_message_create_or_update.test.tsx +2 -7
- package/src/hooks/__tests__/use_search_results.test.tsx +88 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use_conversation_messages.ts +103 -17
- package/src/hooks/use_conversation_messages_jolt_events.ts +12 -2
- package/src/hooks/use_debounced_search_term.ts +20 -0
- package/src/hooks/use_direct_message_eligibility.ts +40 -0
- package/src/hooks/use_features.ts +3 -2
- package/src/hooks/use_mark_latest_message_read.ts +4 -3
- package/src/hooks/use_search_results.ts +78 -0
- package/src/hooks/use_suspense_api.ts +14 -6
- package/src/navigation/index.tsx +5 -0
- package/src/screens/age_check/age_check_underage_screen.tsx +3 -2
- package/src/screens/bug_report_screen.tsx +2 -10
- package/src/screens/conversation_new/components/services_form.tsx +5 -5
- package/src/screens/conversation_screen.tsx +62 -13
- package/src/screens/conversation_select_recipients/components/view_more_link_row.tsx +12 -3
- package/src/screens/conversation_select_recipients/conversation_select_direct_message_recipients_screen.tsx +3 -8
- package/src/screens/conversations/components/__tests__/search_list_header_component.test.tsx +62 -0
- package/src/screens/conversations/components/search_list_header_component.tsx +11 -0
- package/src/screens/get_help_screen.tsx +4 -4
- package/src/screens/message_actions_screen.tsx +18 -3
- package/src/screens/search/__tests__/search_screen.test.tsx +64 -0
- package/src/screens/search/components/__tests__/conversation_results.test.tsx +55 -0
- package/src/screens/search/components/__tests__/message_result_row.test.tsx +65 -0
- package/src/screens/search/components/__tests__/result_row.test.tsx +33 -0
- package/src/screens/search/components/__tests__/search_blank_states.test.tsx +20 -0
- package/src/screens/search/components/__tests__/search_field.test.tsx +29 -0
- package/src/screens/search/components/__tests__/search_results_list.test.tsx +135 -0
- package/src/screens/search/components/conversation_result_row.tsx +36 -0
- package/src/screens/search/components/conversation_results.tsx +39 -0
- package/src/screens/search/components/message_result_row.tsx +48 -0
- package/src/screens/search/components/result_row.tsx +58 -0
- package/src/screens/search/components/results_section.tsx +34 -0
- package/src/screens/search/components/search_blank_states.tsx +34 -0
- package/src/screens/search/components/search_field.tsx +81 -0
- package/src/screens/search/components/search_results_list.tsx +147 -0
- package/src/screens/search/components/snippet.tsx +37 -0
- package/src/screens/search/search_screen.tsx +49 -0
- package/src/types/api_primitives.ts +1 -0
- package/src/types/resources/conversation.ts +9 -0
- package/src/types/resources/index.ts +1 -0
- package/src/types/resources/member.ts +1 -0
- package/src/types/resources/search_result.ts +32 -0
- package/src/utils/__tests__/get_search_results.test.ts +24 -0
- package/src/utils/__tests__/group_messages.test.ts +29 -0
- package/src/utils/cache/__tests__/messages_cache.test.ts +2 -1
- package/src/utils/cache/__tests__/messages_cache_deletion.test.ts +97 -0
- package/src/utils/cache/__tests__/messages_cache_reply_roots.test.ts +3 -2
- package/src/utils/cache/__tests__/messages_window.test.ts +78 -0
- package/src/utils/cache/messages_cache.ts +45 -1
- package/src/utils/cache/messages_window.ts +55 -0
- package/src/utils/client/__tests__/request_helpers.test.ts +40 -0
- package/src/utils/client/request_helpers.ts +1 -1
- package/src/utils/client/types.ts +1 -0
- package/src/utils/group_messages.ts +4 -1
- package/src/utils/request/get_search_results.ts +23 -0
|
@@ -28,7 +28,10 @@ import { ConversationContextProvider } from '../contexts/conversation_context'
|
|
|
28
28
|
import { useMessageAvailableMembersAction } from '../hooks/direct_messages/use_message_available_members_action'
|
|
29
29
|
import { useConversation } from '../hooks/use_conversation'
|
|
30
30
|
import { useConversationJoltEvents } from '../hooks/use_conversation_jolt_events'
|
|
31
|
-
import {
|
|
31
|
+
import {
|
|
32
|
+
dropMessagesWindowIfBehind,
|
|
33
|
+
useConversationMessages,
|
|
34
|
+
} from '../hooks/use_conversation_messages'
|
|
32
35
|
import { useConversationMessagesJoltEvents } from '../hooks/use_conversation_messages_jolt_events'
|
|
33
36
|
import { useMarkLatestMessageRead } from '../hooks/use_mark_latest_message_read'
|
|
34
37
|
import {
|
|
@@ -41,10 +44,12 @@ import { useVideoModerationJoltEvents } from '../hooks/use_video_moderation_jolt
|
|
|
41
44
|
import { ConversationResource } from '../types/resources/conversation'
|
|
42
45
|
import { ConversationBadgeResource } from '../types/resources/conversation_badge'
|
|
43
46
|
import { MessageResource } from '../types/resources/message'
|
|
47
|
+
import { Log } from '../utils'
|
|
44
48
|
|
|
45
49
|
export type ConversationRouteProps = {
|
|
46
50
|
conversation_id: number
|
|
47
51
|
reply_root_id?: string | null
|
|
52
|
+
initial_message_id?: string | null
|
|
48
53
|
reply_root_author_name?: string
|
|
49
54
|
chat_group_graph_id?: string
|
|
50
55
|
clear_input?: boolean
|
|
@@ -81,18 +86,25 @@ export function ConversationScreen({ route }: ConversationScreenProps) {
|
|
|
81
86
|
function ConversationScreenContent({ route }: ConversationScreenProps) {
|
|
82
87
|
const styles = useStyles()
|
|
83
88
|
const navigation = useNavigation()
|
|
84
|
-
const {
|
|
85
|
-
route.params
|
|
86
|
-
const { data: conversation } = useConversation(route.params)
|
|
87
|
-
const { messages, fetchNextPage, hasNextPage } = useConversationMessages({
|
|
89
|
+
const {
|
|
88
90
|
conversation_id,
|
|
91
|
+
editing_message_id,
|
|
89
92
|
reply_root_id,
|
|
90
|
-
|
|
93
|
+
reply_root_author_name,
|
|
94
|
+
initial_message_id,
|
|
95
|
+
} = route.params
|
|
96
|
+
const { data: conversation } = useConversation(route.params)
|
|
97
|
+
const { messages, behind, fetchNextPage, fetchNewer, fetchLiveWindow, hasNextPage } =
|
|
98
|
+
useConversationMessages({
|
|
99
|
+
conversation_id,
|
|
100
|
+
reply_root_id,
|
|
101
|
+
anchor: initial_message_id,
|
|
102
|
+
})
|
|
91
103
|
useConversationJoltEvents({ conversationId: conversation_id })
|
|
92
104
|
useConversationMessagesJoltEvents({ conversationId: conversation_id })
|
|
93
105
|
const { markHandledByMessageForm } = useVideoModerationJoltEvents()
|
|
94
106
|
useEnsureConversationsRouteExists()
|
|
95
|
-
useMarkLatestMessageRead({ conversation, messages })
|
|
107
|
+
useMarkLatestMessageRead({ conversation, messages, enabled: !behind })
|
|
96
108
|
const noMessages = messages.length === 0
|
|
97
109
|
|
|
98
110
|
const { repliesDisabled, memberAbility, badges, title } = conversation
|
|
@@ -120,11 +132,24 @@ function ConversationScreenContent({ route }: ConversationScreenProps) {
|
|
|
120
132
|
enabled: Platform.OS === 'ios',
|
|
121
133
|
})
|
|
122
134
|
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
135
|
+
const [anchorMessageId, setAnchorMessageId] = useState(initial_message_id)
|
|
136
|
+
const releaseAnchor = useCallback(() => setAnchorMessageId(null), [])
|
|
137
|
+
|
|
138
|
+
const handleReturnToBottom = useCallback(
|
|
139
|
+
(animated = true) => {
|
|
140
|
+
releaseAnchor()
|
|
141
|
+
listRef.current?.scrollToOffset({ offset: restOffset, animated })
|
|
142
|
+
},
|
|
143
|
+
[releaseAnchor, restOffset]
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
const logWindowFetchFailure = (error: unknown) =>
|
|
147
|
+
Log.error('conversation window fetch failed', error)
|
|
148
|
+
|
|
149
|
+
const returnToLatest = async () => {
|
|
150
|
+
if (behind) await fetchLiveWindow()
|
|
151
|
+
handleReturnToBottom(false)
|
|
152
|
+
}
|
|
128
153
|
|
|
129
154
|
useEffect(() => {
|
|
130
155
|
if (reply_root_id) {
|
|
@@ -141,6 +166,18 @@ function ConversationScreenContent({ route }: ConversationScreenProps) {
|
|
|
141
166
|
}
|
|
142
167
|
}, [navigation, title, badges, conversation?.deleted, reply_root_id, replyHeaderTitle, muted])
|
|
143
168
|
|
|
169
|
+
useEffect(() => {
|
|
170
|
+
if (!initial_message_id) return
|
|
171
|
+
|
|
172
|
+
navigation.setParams({ initial_message_id: null })
|
|
173
|
+
}, [initial_message_id, navigation])
|
|
174
|
+
|
|
175
|
+
// A window left behind the live edge would make the next open from the list start
|
|
176
|
+
// mid-history with no pill, so we only keep windows that are live.
|
|
177
|
+
useEffect(() => {
|
|
178
|
+
return () => dropMessagesWindowIfBehind({ conversation_id, reply_root_id })
|
|
179
|
+
}, [conversation_id, reply_root_id])
|
|
180
|
+
|
|
144
181
|
if (!conversation || conversation.deleted) {
|
|
145
182
|
return (
|
|
146
183
|
<View style={styles.container}>
|
|
@@ -174,8 +211,11 @@ function ConversationScreenContent({ route }: ConversationScreenProps) {
|
|
|
174
211
|
conversationId={conversation_id}
|
|
175
212
|
messages={messages}
|
|
176
213
|
replyRootId={reply_root_id}
|
|
214
|
+
anchorMessageId={anchorMessageId}
|
|
215
|
+
behind={behind}
|
|
177
216
|
hasNextPage={hasNextPage}
|
|
178
217
|
onEndReached={() => fetchNextPage()}
|
|
218
|
+
onStartReached={() => fetchNewer().catch(logWindowFetchFailure)}
|
|
179
219
|
onScroll={trackScroll}
|
|
180
220
|
onLayout={onLayout}
|
|
181
221
|
onContentSizeChange={onContentSizeChange}
|
|
@@ -183,7 +223,12 @@ function ConversationScreenContent({ route }: ConversationScreenProps) {
|
|
|
183
223
|
onMomentumScrollEnd={onMomentumScrollEnd}
|
|
184
224
|
/>
|
|
185
225
|
)}
|
|
186
|
-
<JumpToBottomButton
|
|
226
|
+
<JumpToBottomButton
|
|
227
|
+
onPress={() =>
|
|
228
|
+
behind ? returnToLatest().catch(logWindowFetchFailure) : handleReturnToBottom()
|
|
229
|
+
}
|
|
230
|
+
visible={showJumpToBottomButton || behind}
|
|
231
|
+
/>
|
|
187
232
|
{!noMessages && <TypingIndicator />}
|
|
188
233
|
{showLeaderDisabledReplyBanner && <LeaderMessagesDisabledBanner />}
|
|
189
234
|
<ConversationBottomBar
|
|
@@ -193,6 +238,7 @@ function ConversationScreenContent({ route }: ConversationScreenProps) {
|
|
|
193
238
|
replyRootId={reply_root_id}
|
|
194
239
|
currentlyEditingMessage={currentlyEditingMessage}
|
|
195
240
|
onFlaggedInMessageForm={markHandledByMessageForm}
|
|
241
|
+
onBeforeSubmit={returnToLatest}
|
|
196
242
|
/>
|
|
197
243
|
</KeyboardView>
|
|
198
244
|
</View>
|
|
@@ -206,6 +252,7 @@ interface ConversationBottomBarProps {
|
|
|
206
252
|
replyRootId: string | null | undefined
|
|
207
253
|
currentlyEditingMessage: MessageResource | undefined
|
|
208
254
|
onFlaggedInMessageForm?: (id: string) => void
|
|
255
|
+
onBeforeSubmit?: () => void
|
|
209
256
|
}
|
|
210
257
|
|
|
211
258
|
function ConversationBottomBar({
|
|
@@ -215,6 +262,7 @@ function ConversationBottomBar({
|
|
|
215
262
|
replyRootId,
|
|
216
263
|
currentlyEditingMessage,
|
|
217
264
|
onFlaggedInMessageForm,
|
|
265
|
+
onBeforeSubmit,
|
|
218
266
|
}: ConversationBottomBarProps) {
|
|
219
267
|
const messageLink = useMessageAvailableMembersAction(conversation)
|
|
220
268
|
|
|
@@ -233,6 +281,7 @@ function ConversationBottomBar({
|
|
|
233
281
|
replyRootId={replyRootId}
|
|
234
282
|
currentlyEditingMessage={currentlyEditingMessage}
|
|
235
283
|
onFlaggedInMessageForm={onFlaggedInMessageForm}
|
|
284
|
+
onBeforeSubmit={onBeforeSubmit}
|
|
236
285
|
key={
|
|
237
286
|
currentlyEditingMessage
|
|
238
287
|
? `edit-message-form-${currentlyEditingMessage.id}`
|
|
@@ -4,15 +4,24 @@ import { TextButton } from '../../../components'
|
|
|
4
4
|
interface ViewMoreLinkRowProps {
|
|
5
5
|
onPress: () => void
|
|
6
6
|
accessibilityHint: string
|
|
7
|
+
expanded?: boolean
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
export const ViewMoreLinkRow = ({
|
|
10
|
+
export const ViewMoreLinkRow = ({
|
|
11
|
+
accessibilityHint,
|
|
12
|
+
expanded = false,
|
|
13
|
+
onPress,
|
|
14
|
+
}: ViewMoreLinkRowProps) => {
|
|
10
15
|
const styles = useRowStyles()
|
|
11
16
|
|
|
12
17
|
return (
|
|
13
18
|
<View style={[styles.row]}>
|
|
14
|
-
<TextButton
|
|
15
|
-
|
|
19
|
+
<TextButton
|
|
20
|
+
onPress={onPress}
|
|
21
|
+
accessibilityHint={accessibilityHint}
|
|
22
|
+
accessibilityState={{ expanded }}
|
|
23
|
+
>
|
|
24
|
+
{expanded ? 'View less' : 'View more'}
|
|
16
25
|
</TextButton>
|
|
17
26
|
</View>
|
|
18
27
|
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PlatformPressable } from '@react-navigation/elements'
|
|
2
2
|
import { StackActions, useNavigation } from '@react-navigation/native'
|
|
3
|
-
import { RefObject,
|
|
3
|
+
import { RefObject, useRef, useState } from 'react'
|
|
4
4
|
import { FlatList, Pressable, StyleSheet, TextInput, View } from 'react-native'
|
|
5
5
|
import { Avatar, Badge, Banner, Icon, KeyboardView, Spinner, Text } from '../../components'
|
|
6
6
|
import { ActionButton } from '../../components/display/action_button'
|
|
@@ -11,6 +11,7 @@ import { useDirectMessageAffiliations } from '../../hooks/direct_messages/use_di
|
|
|
11
11
|
import { useDirectMessageCandidates } from '../../hooks/direct_messages/use_direct_message_candidates'
|
|
12
12
|
import { useDirectMessageConversationValidate } from '../../hooks/direct_messages/use_direct_message_conversation_validate'
|
|
13
13
|
import { useFindOrCreateDirectMessageConversation } from '../../hooks/direct_messages/use_find_or_create_direct_message_conversation'
|
|
14
|
+
import { useDebouncedSearchTerm } from '../../hooks/use_debounced_search_term'
|
|
14
15
|
import { availableFeatures, useFeatures } from '../../hooks/use_features'
|
|
15
16
|
import { DirectMessageCandidateResource } from '../../types/resources/direct_message_candidate'
|
|
16
17
|
import { ResultsHeading } from './components/results_heading'
|
|
@@ -26,7 +27,7 @@ export function ConversationSelectDirectMessageRecipientsScreen({
|
|
|
26
27
|
const navigation = useNavigation()
|
|
27
28
|
const { featureEnabled } = useFeatures()
|
|
28
29
|
const [searchTerm, setSearchTerm] = useState('')
|
|
29
|
-
const
|
|
30
|
+
const debouncedTerm = useDebouncedSearchTerm(searchTerm)
|
|
30
31
|
const [selectedPeople, setSelectedPeople] = useState<Map<string, DirectMessageCandidateResource>>(
|
|
31
32
|
() =>
|
|
32
33
|
new Map(
|
|
@@ -45,16 +46,10 @@ export function ConversationSelectDirectMessageRecipientsScreen({
|
|
|
45
46
|
)
|
|
46
47
|
const searchInputRef = useRef<TextInput>(null)
|
|
47
48
|
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
const timer = setTimeout(() => setDebouncedTerm(searchTerm), 200)
|
|
50
|
-
return () => clearTimeout(timer)
|
|
51
|
-
}, [searchTerm])
|
|
52
|
-
|
|
53
49
|
const selectPerson = (person: DirectMessageCandidateResource) => {
|
|
54
50
|
if (selectedPeople.size >= MAX_RECIPIENTS) return
|
|
55
51
|
setSelectedPeople(prev => new Map(prev).set(person.id, person))
|
|
56
52
|
setSearchTerm('')
|
|
57
|
-
setDebouncedTerm('')
|
|
58
53
|
// Controlled TextInput can retain stale native text on iOS when the value
|
|
59
54
|
// is cleared while it stays focused (keyboardShouldPersistTaps keeps it
|
|
60
55
|
// focused through the tap) — clear() forces the native view to sync. Gated
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { fireEvent, render } from '@testing-library/react-native'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { SearchListHeaderComponent } from '../search_list_header_component'
|
|
4
|
+
|
|
5
|
+
const mockNavigate = jest.fn()
|
|
6
|
+
|
|
7
|
+
jest.mock('@react-navigation/native', () => ({
|
|
8
|
+
...jest.requireActual('@react-navigation/native'),
|
|
9
|
+
useNavigation: () => ({ setParams: jest.fn(), navigate: mockNavigate }),
|
|
10
|
+
useRoute: () => ({ params: {} }),
|
|
11
|
+
}))
|
|
12
|
+
|
|
13
|
+
jest.mock('../../../../hooks/use_groups', () => ({
|
|
14
|
+
useCanDisplayGroups: () => true,
|
|
15
|
+
}))
|
|
16
|
+
jest.mock('../../../../hooks/use_direct_messages_eligible', () => ({
|
|
17
|
+
useDirectMessagesEligible: () => true,
|
|
18
|
+
}))
|
|
19
|
+
jest.mock('../../../../hooks/use_has_direct_messages', () => ({
|
|
20
|
+
useHasDirectMessages: () => true,
|
|
21
|
+
}))
|
|
22
|
+
jest.mock('../../../../hooks/use_chat_permissions', () => ({
|
|
23
|
+
useCanCreateConversations: () => true,
|
|
24
|
+
}))
|
|
25
|
+
jest.mock('../../../../hooks/use_new_conversation_entry', () => ({
|
|
26
|
+
useNewConversationEntry: () => 'select_type',
|
|
27
|
+
}))
|
|
28
|
+
jest.mock('../../../../hooks/use_current_person', () => ({
|
|
29
|
+
useCurrentPersonCache: () => ({ update: jest.fn() }),
|
|
30
|
+
}))
|
|
31
|
+
jest.mock('../../../../hooks/use_conversations_actions', () => ({
|
|
32
|
+
useMarkAllRead: () => ({ markAllRead: jest.fn(), isPending: false }),
|
|
33
|
+
}))
|
|
34
|
+
jest.mock('../../../../hooks/use_new_conversation_from_filter', () => ({
|
|
35
|
+
useNewConversationFromFilter: () => undefined,
|
|
36
|
+
}))
|
|
37
|
+
jest.mock('../../../../hooks/use_api', () => ({
|
|
38
|
+
useApiGet: () => ({ data: undefined }),
|
|
39
|
+
}))
|
|
40
|
+
|
|
41
|
+
describe('SearchListHeaderComponent search button', () => {
|
|
42
|
+
beforeEach(() => mockNavigate.mockClear())
|
|
43
|
+
|
|
44
|
+
it('navigates to Search on press', () => {
|
|
45
|
+
const view = render(<SearchListHeaderComponent />)
|
|
46
|
+
|
|
47
|
+
fireEvent.press(view.getByTestId('conversations-search-button'))
|
|
48
|
+
|
|
49
|
+
expect(mockNavigate).toHaveBeenCalledTimes(1)
|
|
50
|
+
expect(mockNavigate).toHaveBeenCalledWith('Search')
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('renders the search button after the other actions', () => {
|
|
54
|
+
const view = render(<SearchListHeaderComponent />)
|
|
55
|
+
|
|
56
|
+
const buttons = view.getAllByRole('button').map(button => button.props.accessibilityLabel)
|
|
57
|
+
|
|
58
|
+
expect(buttons.indexOf('Search')).toBeGreaterThanOrEqual(0)
|
|
59
|
+
expect(buttons.indexOf('Search')).toBeGreaterThan(buttons.indexOf('Chat settings'))
|
|
60
|
+
expect(buttons.indexOf('Search')).toBeGreaterThan(buttons.indexOf('New conversation'))
|
|
61
|
+
})
|
|
62
|
+
})
|
|
@@ -110,6 +110,10 @@ export const SearchListHeaderComponent = () => {
|
|
|
110
110
|
[navigation]
|
|
111
111
|
)
|
|
112
112
|
|
|
113
|
+
const handleSearch = useCallback(() => {
|
|
114
|
+
navigation.navigate('Search')
|
|
115
|
+
}, [navigation])
|
|
116
|
+
|
|
113
117
|
const handleChatSettings = useCallback(() => {
|
|
114
118
|
navigation.navigate('ChatSettings', {})
|
|
115
119
|
}, [navigation])
|
|
@@ -188,6 +192,13 @@ export const SearchListHeaderComponent = () => {
|
|
|
188
192
|
maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER_LANDMARK}
|
|
189
193
|
/>
|
|
190
194
|
)}
|
|
195
|
+
<ListHeaderActionButton
|
|
196
|
+
name="general.search"
|
|
197
|
+
onPress={handleSearch}
|
|
198
|
+
accessibilityLabel="Search"
|
|
199
|
+
testID="conversations-search-button"
|
|
200
|
+
maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER_LANDMARK}
|
|
201
|
+
/>
|
|
191
202
|
{shouldShowHeaderFiltersButton && <ToggleButton {...moreFiltersButtonProps} />}
|
|
192
203
|
</View>
|
|
193
204
|
</View>
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { StaticScreenProps, useNavigation } from '@react-navigation/native'
|
|
2
2
|
import { useCallback, useMemo } from 'react'
|
|
3
|
-
import { Alert, Linking, StyleSheet, View } from 'react-native'
|
|
3
|
+
import { Alert, Linking as RNLinking, StyleSheet, View } from 'react-native'
|
|
4
4
|
import { Heading, PressableRow, Text, TextInlineButton } from '../components'
|
|
5
5
|
import { useApiGet, useTheme } from '../hooks'
|
|
6
6
|
import { useAppName } from '../hooks/use_app_name'
|
|
7
7
|
import { useOrganization } from '../hooks/use_organization'
|
|
8
8
|
import { ResourceObject } from '../types'
|
|
9
|
-
import { Clipboard } from '../utils'
|
|
9
|
+
import { Clipboard, Linking } from '../utils'
|
|
10
10
|
|
|
11
11
|
type GetHelpScreenRouteProps = {
|
|
12
12
|
type?: 'chat' | 'general'
|
|
@@ -119,7 +119,7 @@ export function sendEmail(email: string) {
|
|
|
119
119
|
|
|
120
120
|
const url = encodeURI(`mailto:${email}`)
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
RNLinking.openURL(url).catch(() => {
|
|
123
123
|
Alert.alert('Oops', `Unable to open: ${email}`, [
|
|
124
124
|
{ text: 'Copy to clipboard', onPress: () => Clipboard.setStringAsync(email) },
|
|
125
125
|
{ text: 'OK' },
|
|
@@ -132,7 +132,7 @@ export function placePhoneCall(phoneNumber: string) {
|
|
|
132
132
|
|
|
133
133
|
const url = encodeURI(`tel:${phoneNumber}`)
|
|
134
134
|
|
|
135
|
-
|
|
135
|
+
RNLinking.openURL(url).catch(() => {
|
|
136
136
|
Alert.alert('Oops', `Unable to open: ${phoneNumber}`, [
|
|
137
137
|
{ text: 'Copy to clipboard', onPress: () => Clipboard.setStringAsync(phoneNumber) },
|
|
138
138
|
{ text: 'OK' },
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PlatformPressable } from '@react-navigation/elements'
|
|
2
2
|
import { StackActions, StaticScreenProps, useNavigation } from '@react-navigation/native'
|
|
3
|
-
import { useMutation } from '@tanstack/react-query'
|
|
3
|
+
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
4
4
|
import { isNil, omitBy } from 'lodash'
|
|
5
5
|
import React, { useCallback } from 'react'
|
|
6
6
|
import { Alert, Platform, StyleSheet, View } from 'react-native'
|
|
@@ -15,6 +15,10 @@ import { useMessageReactionToggle } from '../hooks/use_message_reaction_toggle'
|
|
|
15
15
|
import { MessageResource } from '../types'
|
|
16
16
|
import { ReactionCountResource } from '../types/resources/reaction'
|
|
17
17
|
import { REACTION_EMOJIS } from '../utils'
|
|
18
|
+
import {
|
|
19
|
+
applyMessageDeletionToCaches,
|
|
20
|
+
getThreadedMessagesQueryKey,
|
|
21
|
+
} from '../utils/cache/messages_cache'
|
|
18
22
|
import { Clipboard, Haptic } from '../utils/native_adapters'
|
|
19
23
|
|
|
20
24
|
export const MessageActionsScreenOptions = getFormSheetScreenOptions({
|
|
@@ -81,6 +85,7 @@ function MessageActionsScreenContent({
|
|
|
81
85
|
}) {
|
|
82
86
|
const navigation = useNavigation()
|
|
83
87
|
const apiClient = useApiClient()
|
|
88
|
+
const queryClient = useQueryClient()
|
|
84
89
|
const styles = useStyles()
|
|
85
90
|
const { featureEnabled } = useFeatures()
|
|
86
91
|
const expandedLink = message.attachments.find(attachment => attachment.type === 'ExpandedLink')
|
|
@@ -119,8 +124,12 @@ function MessageActionsScreenContent({
|
|
|
119
124
|
})
|
|
120
125
|
}, [navigation, conversation_id, message.id, message.replyRootId, replyRootAuthorName])
|
|
121
126
|
|
|
122
|
-
const handleCopyPress = () => {
|
|
123
|
-
|
|
127
|
+
const handleCopyPress = async () => {
|
|
128
|
+
const textToCopy = message?.text || attachmentForCopy()
|
|
129
|
+
if (textToCopy) {
|
|
130
|
+
await Clipboard.setStringAsync(textToCopy)
|
|
131
|
+
Haptic.notificationSuccess()
|
|
132
|
+
}
|
|
124
133
|
navigation.goBack()
|
|
125
134
|
}
|
|
126
135
|
|
|
@@ -147,6 +156,12 @@ function MessageActionsScreenContent({
|
|
|
147
156
|
mutationFn: deleteMessage,
|
|
148
157
|
mutationKey: ['deleteMessage', message.id],
|
|
149
158
|
onSuccess: () => {
|
|
159
|
+
applyMessageDeletionToCaches(queryClient, conversation_id, message)
|
|
160
|
+
if (message.replyRootId) {
|
|
161
|
+
queryClient.invalidateQueries({
|
|
162
|
+
queryKey: getThreadedMessagesQueryKey(conversation_id, message.replyRootId),
|
|
163
|
+
})
|
|
164
|
+
}
|
|
150
165
|
refetchMessages()
|
|
151
166
|
Haptic.notificationSuccess()
|
|
152
167
|
},
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { act, fireEvent, render } from '@testing-library/react-native'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import type { useSearchResults } from '../../../hooks/use_search_results'
|
|
4
|
+
import { SearchScreen } from '../search_screen'
|
|
5
|
+
|
|
6
|
+
const mockUseSearchResults = jest.fn<ReturnType<typeof useSearchResults>, [string]>()
|
|
7
|
+
jest.mock('../../../hooks/use_search_results', () => ({
|
|
8
|
+
useSearchResults: (term: string) => mockUseSearchResults(term),
|
|
9
|
+
}))
|
|
10
|
+
jest.mock('../../../components/display/keyboard_view', () => ({
|
|
11
|
+
...jest.requireActual('../../../components/display/keyboard_view'),
|
|
12
|
+
KeyboardView: ({ children }: { children: React.ReactNode }) => children,
|
|
13
|
+
}))
|
|
14
|
+
|
|
15
|
+
const inputLabel = 'Search titles and messages'
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
jest.useFakeTimers()
|
|
19
|
+
mockUseSearchResults.mockReset().mockReturnValue({
|
|
20
|
+
results: [],
|
|
21
|
+
failedTypes: [],
|
|
22
|
+
isPending: true,
|
|
23
|
+
isError: false,
|
|
24
|
+
isFetchNextPageError: false,
|
|
25
|
+
loadMore: jest.fn(),
|
|
26
|
+
hasNextPage: false,
|
|
27
|
+
isFetchingNextPage: false,
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
afterEach(() => jest.useRealTimers())
|
|
32
|
+
|
|
33
|
+
describe('SearchScreen', () => {
|
|
34
|
+
it('searches once with the trimmed term after typing settles', () => {
|
|
35
|
+
const view = render(<SearchScreen />)
|
|
36
|
+
const input = view.getByLabelText(inputLabel)
|
|
37
|
+
|
|
38
|
+
fireEvent.changeText(input, 'bud')
|
|
39
|
+
fireEvent.changeText(input, ' budget ')
|
|
40
|
+
|
|
41
|
+
expect(view.getByText('Search chat')).toBeTruthy()
|
|
42
|
+
expect(mockUseSearchResults).not.toHaveBeenCalled()
|
|
43
|
+
|
|
44
|
+
act(() => jest.advanceTimersByTime(200))
|
|
45
|
+
|
|
46
|
+
const searchedTerms = new Set(mockUseSearchResults.mock.calls.map(([term]) => term))
|
|
47
|
+
expect([...searchedTerms]).toEqual(['budget'])
|
|
48
|
+
expect(view.queryByText('Search chat')).toBeNull()
|
|
49
|
+
expect(view.getByLabelText('Loading results')).toBeTruthy()
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('returns to the prompt as soon as the term is cleared', () => {
|
|
53
|
+
const view = render(<SearchScreen />)
|
|
54
|
+
const input = view.getByLabelText(inputLabel)
|
|
55
|
+
|
|
56
|
+
fireEvent.changeText(input, 'budget')
|
|
57
|
+
act(() => jest.advanceTimersByTime(200))
|
|
58
|
+
expect(view.queryByText('Search chat')).toBeNull()
|
|
59
|
+
|
|
60
|
+
fireEvent.changeText(input, ' ')
|
|
61
|
+
|
|
62
|
+
expect(view.getByText('Search chat')).toBeTruthy()
|
|
63
|
+
})
|
|
64
|
+
})
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { fireEvent, render } from '@testing-library/react-native'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import type { ConversationSearchResultResource } from '../../../../types'
|
|
4
|
+
import { ConversationResults } from '../conversation_results'
|
|
5
|
+
|
|
6
|
+
const buildResults = (count: number, prefix = 'Conversation') =>
|
|
7
|
+
Array.from({ length: count }, (_, index) => ({
|
|
8
|
+
type: 'conversation' as const,
|
|
9
|
+
id: `${prefix}-${index + 1}`,
|
|
10
|
+
title: `${prefix} ${index + 1}`,
|
|
11
|
+
url: `/conversations/${index + 1}`,
|
|
12
|
+
extra: { avatar: { previewAvatarUrls: [] } },
|
|
13
|
+
})) satisfies ConversationSearchResultResource[]
|
|
14
|
+
|
|
15
|
+
describe('ConversationResults', () => {
|
|
16
|
+
it('caps at five rows until View more is pressed, then offers View less', () => {
|
|
17
|
+
const view = render(<ConversationResults results={buildResults(6)} onSelect={jest.fn()} />)
|
|
18
|
+
|
|
19
|
+
expect(view.getByText('Conversation 5')).toBeTruthy()
|
|
20
|
+
expect(view.queryByText('Conversation 6')).toBeNull()
|
|
21
|
+
|
|
22
|
+
fireEvent.press(view.getByText('View more'))
|
|
23
|
+
|
|
24
|
+
expect(view.getByText('Conversation 6')).toBeTruthy()
|
|
25
|
+
expect(view.getByText('View less')).toBeTruthy()
|
|
26
|
+
expect(view.queryByText('View more')).toBeNull()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('renders no footer for five or fewer results', () => {
|
|
30
|
+
const view = render(<ConversationResults results={buildResults(4)} onSelect={jest.fn()} />)
|
|
31
|
+
|
|
32
|
+
expect(view.getByText('Conversation 4')).toBeTruthy()
|
|
33
|
+
expect(view.queryByText('View more')).toBeNull()
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('stays expanded when the parent re-renders with a new results array', () => {
|
|
37
|
+
const view = render(<ConversationResults results={buildResults(6)} onSelect={jest.fn()} />)
|
|
38
|
+
fireEvent.press(view.getByText('View more'))
|
|
39
|
+
|
|
40
|
+
view.rerender(<ConversationResults results={buildResults(6)} onSelect={jest.fn()} />)
|
|
41
|
+
|
|
42
|
+
expect(view.getByText('Conversation 6')).toBeTruthy()
|
|
43
|
+
expect(view.getByText('View less')).toBeTruthy()
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('passes the pressed result to onSelect', () => {
|
|
47
|
+
const onSelect = jest.fn()
|
|
48
|
+
const results = buildResults(2)
|
|
49
|
+
const view = render(<ConversationResults results={results} onSelect={onSelect} />)
|
|
50
|
+
|
|
51
|
+
fireEvent.press(view.getByText('Conversation 2'))
|
|
52
|
+
|
|
53
|
+
expect(onSelect).toHaveBeenCalledWith(results[1])
|
|
54
|
+
})
|
|
55
|
+
})
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { fireEvent, render } from '@testing-library/react-native'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import type { MessageSearchResultResource } from '../../../../types/resources/search_result'
|
|
4
|
+
import { formatDatePreview } from '../../../../utils/date'
|
|
5
|
+
import { defaultTheme } from '../../../../utils/theme'
|
|
6
|
+
import { MessageResultRow } from '../message_result_row'
|
|
7
|
+
|
|
8
|
+
const result: MessageSearchResultResource = {
|
|
9
|
+
id: '42',
|
|
10
|
+
type: 'message',
|
|
11
|
+
title: 'Worship Team',
|
|
12
|
+
url: '/conversations/7?message_id=42',
|
|
13
|
+
extra: {
|
|
14
|
+
conversationId: 7,
|
|
15
|
+
authorName: 'Ada Lovelace',
|
|
16
|
+
snippet: [
|
|
17
|
+
{ text: '…planning the ', match: false },
|
|
18
|
+
{ text: 'budget', match: true },
|
|
19
|
+
{ text: ' meeting for next week', match: false },
|
|
20
|
+
],
|
|
21
|
+
createdAt: '2026-03-04T15:30:00Z',
|
|
22
|
+
avatar: {
|
|
23
|
+
customAvatarType: null,
|
|
24
|
+
customAvatarKey: null,
|
|
25
|
+
customAvatarColor: null,
|
|
26
|
+
customAvatarImageUrl: null,
|
|
27
|
+
previewAvatarUrls: [],
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const interactionColor = defaultTheme('light').colors.interaction
|
|
33
|
+
|
|
34
|
+
describe('MessageResultRow', () => {
|
|
35
|
+
it('renders the title, author, snippet, and date', () => {
|
|
36
|
+
const view = render(<MessageResultRow result={result} onPress={jest.fn()} />)
|
|
37
|
+
|
|
38
|
+
expect(view.getByText('Worship Team')).toBeTruthy()
|
|
39
|
+
expect(view.getByText('Ada Lovelace:', { exact: false })).toBeTruthy()
|
|
40
|
+
expect(view.getByText('…planning the ')).toBeTruthy()
|
|
41
|
+
expect(view.getByText('budget')).toBeTruthy()
|
|
42
|
+
expect(view.getByText(' meeting for next week')).toBeTruthy()
|
|
43
|
+
expect(view.getByText(formatDatePreview(result.extra.createdAt))).toBeTruthy()
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('colors matched segments with the interaction color', () => {
|
|
47
|
+
const view = render(<MessageResultRow result={result} onPress={jest.fn()} />)
|
|
48
|
+
|
|
49
|
+
expect(view.getByText('budget')).toHaveStyle({ color: interactionColor })
|
|
50
|
+
expect(view.getByText('…planning the ')).not.toHaveStyle({ color: interactionColor })
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('exposes the row as a button with a composed label and reports presses', () => {
|
|
54
|
+
const onPress = jest.fn()
|
|
55
|
+
const date = formatDatePreview(result.extra.createdAt)
|
|
56
|
+
const view = render(<MessageResultRow result={result} onPress={onPress} />)
|
|
57
|
+
|
|
58
|
+
const row = view.getByRole('button', {
|
|
59
|
+
name: `Worship Team, Ada Lovelace: …planning the budget meeting for next week, ${date}`,
|
|
60
|
+
})
|
|
61
|
+
fireEvent.press(row)
|
|
62
|
+
|
|
63
|
+
expect(onPress).toHaveBeenCalledWith(result)
|
|
64
|
+
})
|
|
65
|
+
})
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { render } from '@testing-library/react-native'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { Text } from 'react-native'
|
|
4
|
+
import { useAtFontScaleBreakpoint } from '../../../../hooks/use_at_font_scale_breakpoint'
|
|
5
|
+
import { ResultRow } from '../result_row'
|
|
6
|
+
|
|
7
|
+
jest.mock('../../../../hooks/use_at_font_scale_breakpoint')
|
|
8
|
+
|
|
9
|
+
const mockUseAtFontScaleBreakpoint = jest.mocked(useAtFontScaleBreakpoint)
|
|
10
|
+
|
|
11
|
+
describe('ResultRow', () => {
|
|
12
|
+
it('lays children out in a row below the font scale breakpoint', () => {
|
|
13
|
+
mockUseAtFontScaleBreakpoint.mockReturnValue(false)
|
|
14
|
+
const view = render(
|
|
15
|
+
<ResultRow accessibilityLabel="Row" onPress={jest.fn()} alignItems="center">
|
|
16
|
+
<Text>child</Text>
|
|
17
|
+
</ResultRow>
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
expect(view.getByRole('button')).toHaveStyle({ flexDirection: 'row', alignItems: 'center' })
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('stacks children at the font scale breakpoint', () => {
|
|
24
|
+
mockUseAtFontScaleBreakpoint.mockReturnValue(true)
|
|
25
|
+
const view = render(
|
|
26
|
+
<ResultRow accessibilityLabel="Row" onPress={jest.fn()} alignItems="center">
|
|
27
|
+
<Text>child</Text>
|
|
28
|
+
</ResultRow>
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
expect(view.getByRole('button')).toHaveStyle({ flexDirection: 'column', alignItems: 'stretch' })
|
|
32
|
+
})
|
|
33
|
+
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { render } from '@testing-library/react-native'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { NoResultsBlankState, SearchPromptBlankState } from '../search_blank_states'
|
|
4
|
+
|
|
5
|
+
describe('SearchPromptBlankState', () => {
|
|
6
|
+
it('renders the prompt heading', () => {
|
|
7
|
+
const view = render(<SearchPromptBlankState />)
|
|
8
|
+
|
|
9
|
+
expect(view.getByText('Search chat')).toBeTruthy()
|
|
10
|
+
})
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
describe('NoResultsBlankState', () => {
|
|
14
|
+
it('renders the heading and the searched term', () => {
|
|
15
|
+
const view = render(<NoResultsBlankState term="budget" />)
|
|
16
|
+
|
|
17
|
+
expect(view.getByText('No results')).toBeTruthy()
|
|
18
|
+
expect(view.getByText(/Nothing matches “budget\.”/)).toBeTruthy()
|
|
19
|
+
})
|
|
20
|
+
})
|