@planningcenter/chat-react-native 4.8.0-rc.4 → 4.8.0-rc.6
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/conversations/conversation_actions.d.ts +2 -1
- package/build/components/conversations/conversation_actions.d.ts.map +1 -1
- package/build/components/conversations/conversation_actions.js +137 -99
- package/build/components/conversations/conversation_actions.js.map +1 -1
- package/build/components/conversations/conversation_preview.d.ts.map +1 -1
- package/build/components/conversations/conversation_preview.js +154 -110
- package/build/components/conversations/conversation_preview.js.map +1 -1
- package/build/components/conversations/conversations.d.ts.map +1 -1
- package/build/components/conversations/conversations.js +50 -48
- package/build/components/conversations/conversations.js.map +1 -1
- package/build/components/display/checkbox.d.ts +8 -0
- package/build/components/display/checkbox.d.ts.map +1 -0
- package/build/components/display/checkbox.js +87 -0
- package/build/components/display/checkbox.js.map +1 -0
- package/build/components/display/index.d.ts +1 -0
- package/build/components/display/index.d.ts.map +1 -1
- package/build/components/display/index.js +1 -0
- package/build/components/display/index.js.map +1 -1
- package/build/contexts/conversations_context.d.ts +5 -0
- package/build/contexts/conversations_context.d.ts.map +1 -1
- package/build/contexts/conversations_context.js +121 -32
- package/build/contexts/conversations_context.js.map +1 -1
- package/build/navigation/index.d.ts.map +1 -1
- package/build/navigation/index.js +5 -7
- package/build/navigation/index.js.map +1 -1
- package/build/screens/conversation_filter_recipients/components/checkbox_row.d.ts.map +1 -1
- package/build/screens/conversation_filter_recipients/components/checkbox_row.js +9 -64
- package/build/screens/conversation_filter_recipients/components/checkbox_row.js.map +1 -1
- package/build/screens/conversations/conversations_screen.d.ts +4 -0
- package/build/screens/conversations/conversations_screen.d.ts.map +1 -1
- package/build/screens/conversations/conversations_screen.js +102 -31
- package/build/screens/conversations/conversations_screen.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/contexts/session_context.tsx +2 -83
- package/src/__tests__/hooks/useTheme.tsx +0 -7
- package/src/__tests__/hooks/use_async_storage.test.tsx +1 -87
- package/src/__tests__/hooks/use_attachment_uploader.test.tsx +0 -11
- package/src/__tests__/hooks/use_font_scale.test.ts +0 -25
- package/src/__tests__/utils/cache/page_mutations.ts +3 -68
- package/src/__tests__/utils/client.ts +6 -15
- package/src/__tests__/utils/native_adapters/configuration.ts +15 -50
- package/src/__tests__/utils/parse_simple_markdown.ts +0 -6
- package/src/__tests__/utils/session.ts +0 -11
- package/src/__tests__/utils/theme.ts +0 -17
- package/src/components/conversations/__tests__/conversation_actions.test.tsx +30 -2
- package/src/components/conversations/__tests__/conversation_preview.test.tsx +69 -3
- package/src/components/conversations/__tests__/conversations.test.tsx +4 -1
- package/src/components/conversations/conversation_actions.tsx +13 -6
- package/src/components/conversations/conversation_preview.tsx +12 -1
- package/src/components/conversations/conversations.tsx +2 -1
- package/src/components/display/__tests__/filter_dropdown.test.tsx +1 -19
- package/src/components/display/checkbox.tsx +47 -0
- package/src/components/display/index.ts +1 -0
- package/src/components/page/__tests__/component_error_boundary.test.tsx +0 -12
- package/src/contexts/__tests__/conversations_context.test.tsx +86 -0
- package/src/contexts/conversations_context.tsx +69 -2
- package/src/hooks/__tests__/jolt_refresh_throttling.test.tsx +0 -35
- package/src/navigation/index.tsx +8 -8
- package/src/screens/__tests__/conversation_details_screen.test.tsx +0 -19
- package/src/screens/avatar_picker/__tests__/avatar_picker_state.test.ts +0 -14
- package/src/screens/conversation_filter_recipients/components/checkbox_row.tsx +3 -35
- package/src/screens/conversations/__tests__/conversations_screen.test.tsx +5 -6
- package/src/screens/conversations/components/__tests__/filter_dropdown_list_header_component.test.tsx +0 -8
- package/src/screens/conversations/components/__tests__/search_list_header_component.test.tsx +0 -10
- package/src/screens/conversations/conversations_screen.tsx +49 -3
- package/src/screens/search/components/__tests__/search_results_list.test.tsx +1 -0
- package/src/utils/__tests__/attachment_kind.test.ts +0 -4
- package/src/utils/__tests__/convert_attachments_for_create.test.ts +0 -28
- package/src/utils/__tests__/is_input_editable.test.ts +1 -2
- package/src/utils/__tests__/message_text.test.ts +0 -5
- package/src/utils/__tests__/session_manager.test.ts +0 -83
- package/src/utils/__tests__/sha_256.test.ts +0 -34
- package/src/utils/__tests__/uri.test.ts +51 -0
- package/src/__tests__/event-polyfill.test.ts +0 -313
- package/src/__tests__/index.tsx +0 -5
- package/src/__tests__/jest.ts +0 -11
- package/src/__tests__/utils/uri.ts +0 -65
- package/src/components/display/__tests__/icon_tile.test.tsx +0 -16
- package/src/components/display/__tests__/version_footer.test.tsx +0 -48
- package/src/screens/search/components/__tests__/search_blank_states.test.tsx +0 -20
- package/src/utils/__tests__/membership_sync_info_text.test.ts +0 -15
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fireEvent } from '@testing-library/react-native'
|
|
1
2
|
import React from 'react'
|
|
2
3
|
import { renderWithQueryClient } from '../../../__utils__/render_with_query_client'
|
|
3
4
|
import { ConversationFiltersParams } from '../../../screens/conversation_filters/screen_props'
|
|
@@ -6,19 +7,40 @@ import { formatDatePreview } from '../../../utils/date'
|
|
|
6
7
|
import { ConversationPreview } from '../conversation_preview'
|
|
7
8
|
|
|
8
9
|
let mockArgs: ConversationFiltersParams = {}
|
|
10
|
+
let mockSelectMode = false
|
|
11
|
+
let mockSelectedIds: number[] = []
|
|
12
|
+
const mockToggleSelected = jest.fn()
|
|
9
13
|
jest.mock('../../../contexts/conversations_context', () => ({
|
|
10
|
-
useConversationsContext: () => ({
|
|
14
|
+
useConversationsContext: () => ({
|
|
15
|
+
args: mockArgs,
|
|
16
|
+
selectMode: mockSelectMode,
|
|
17
|
+
selectedIds: mockSelectedIds,
|
|
18
|
+
toggleSelected: mockToggleSelected,
|
|
19
|
+
}),
|
|
11
20
|
}))
|
|
12
21
|
jest.mock('../conversation_actions', () => ({
|
|
13
22
|
ConversationActions: ({
|
|
14
23
|
children,
|
|
15
24
|
accessibilityLabel,
|
|
25
|
+
onPress,
|
|
26
|
+
selected,
|
|
16
27
|
}: {
|
|
17
28
|
children: React.ReactNode
|
|
18
29
|
accessibilityLabel?: string
|
|
30
|
+
onPress: () => void
|
|
31
|
+
selected?: boolean
|
|
19
32
|
}) => {
|
|
20
|
-
const {
|
|
21
|
-
return
|
|
33
|
+
const { Pressable: MockPressable } = jest.requireActual('react-native')
|
|
34
|
+
return (
|
|
35
|
+
<MockPressable
|
|
36
|
+
accessibilityLabel={accessibilityLabel}
|
|
37
|
+
accessibilityRole="checkbox"
|
|
38
|
+
accessibilityState={{ checked: selected }}
|
|
39
|
+
onPress={onPress}
|
|
40
|
+
>
|
|
41
|
+
{children}
|
|
42
|
+
</MockPressable>
|
|
43
|
+
)
|
|
22
44
|
},
|
|
23
45
|
}))
|
|
24
46
|
|
|
@@ -131,4 +153,48 @@ describe('ConversationPreview', () => {
|
|
|
131
153
|
).toBeNull()
|
|
132
154
|
})
|
|
133
155
|
})
|
|
156
|
+
|
|
157
|
+
describe('select mode', () => {
|
|
158
|
+
const onPress = jest.fn()
|
|
159
|
+
const renderSelectable = () =>
|
|
160
|
+
renderWithQueryClient(
|
|
161
|
+
<ConversationPreview conversation={conversation(messagePreview)} onPress={onPress} />
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
beforeEach(() => {
|
|
165
|
+
mockSelectMode = true
|
|
166
|
+
mockSelectedIds = []
|
|
167
|
+
jest.clearAllMocks()
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
afterAll(() => {
|
|
171
|
+
mockSelectMode = false
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
it('toggles the conversation instead of opening it', () => {
|
|
175
|
+
const view = renderSelectable()
|
|
176
|
+
|
|
177
|
+
fireEvent.press(view.getByText('Worship Team'))
|
|
178
|
+
|
|
179
|
+
expect(mockToggleSelected).toHaveBeenCalledWith(7)
|
|
180
|
+
expect(onPress).not.toHaveBeenCalled()
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
it('marks a selected conversation as checked', () => {
|
|
184
|
+
mockSelectedIds = [7]
|
|
185
|
+
const view = renderSelectable()
|
|
186
|
+
|
|
187
|
+
expect(view.getByRole('checkbox', { checked: true })).toBeTruthy()
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
it('opens the conversation outside select mode', () => {
|
|
191
|
+
mockSelectMode = false
|
|
192
|
+
const view = renderSelectable()
|
|
193
|
+
|
|
194
|
+
fireEvent.press(view.getByText('Worship Team'))
|
|
195
|
+
|
|
196
|
+
expect(onPress).toHaveBeenCalled()
|
|
197
|
+
expect(mockToggleSelected).not.toHaveBeenCalled()
|
|
198
|
+
})
|
|
199
|
+
})
|
|
134
200
|
})
|
|
@@ -58,12 +58,15 @@ describe('Conversations archived footer', () => {
|
|
|
58
58
|
|
|
59
59
|
fireEvent.press(view.getByLabelText('View active conversations'))
|
|
60
60
|
|
|
61
|
-
expect(mockSetParams).
|
|
61
|
+
expect(mockSetParams).toHaveBeenCalledTimes(1)
|
|
62
|
+
expect(mockSetParams.mock.calls[0][0]).toStrictEqual({
|
|
62
63
|
title: undefined,
|
|
63
64
|
chat_group_graph_id: undefined,
|
|
64
65
|
group_source_app_name: undefined,
|
|
65
66
|
show_direct_messages: undefined,
|
|
66
67
|
show_archived: undefined,
|
|
68
|
+
show_hidden: undefined,
|
|
69
|
+
show_unread: undefined,
|
|
67
70
|
})
|
|
68
71
|
})
|
|
69
72
|
|
|
@@ -32,12 +32,14 @@ export function ConversationActions({
|
|
|
32
32
|
style,
|
|
33
33
|
onPress,
|
|
34
34
|
accessibilityLabel,
|
|
35
|
+
selected,
|
|
35
36
|
}: {
|
|
36
37
|
children: ReactNode
|
|
37
38
|
conversation: ConversationResource
|
|
38
39
|
onPress: () => void
|
|
39
40
|
style?: StyleProp<ViewStyle>
|
|
40
41
|
accessibilityLabel?: string
|
|
42
|
+
selected?: boolean
|
|
41
43
|
}) {
|
|
42
44
|
const swipeableRef = useRef<SwipeableMethods>(null)
|
|
43
45
|
const navigation = useNavigation()
|
|
@@ -67,6 +69,7 @@ export function ConversationActions({
|
|
|
67
69
|
const isConversationEmpty = conversation.lastMessageCreatedAt === null
|
|
68
70
|
const canMute = !isArchivedConversation(conversation)
|
|
69
71
|
const canHide = hideable && hideConversationsEnabled && !isArchivedConversation(conversation)
|
|
72
|
+
const selectMode = selected !== undefined
|
|
70
73
|
|
|
71
74
|
const handleSwipeableClose = useCallback(() => {
|
|
72
75
|
setDisabled(false)
|
|
@@ -132,11 +135,9 @@ export function ConversationActions({
|
|
|
132
135
|
]
|
|
133
136
|
: []
|
|
134
137
|
|
|
135
|
-
const accessibilityActions =
|
|
136
|
-
|
|
137
|
-
...hideAccessibilityAction,
|
|
138
|
-
...readAccessibilityAction,
|
|
139
|
-
]
|
|
138
|
+
const accessibilityActions = selectMode
|
|
139
|
+
? []
|
|
140
|
+
: [...muteAccessibilityAction, ...hideAccessibilityAction, ...readAccessibilityAction]
|
|
140
141
|
|
|
141
142
|
const handleAccessibilityAction = useCallback(
|
|
142
143
|
(event: AccessibilityActionEvent) => {
|
|
@@ -162,6 +163,10 @@ export function ConversationActions({
|
|
|
162
163
|
[handleLatestMessageUnread, handleMute, handleHide]
|
|
163
164
|
)
|
|
164
165
|
|
|
166
|
+
useEffect(() => {
|
|
167
|
+
if (selectMode) handleSwipeableClose()
|
|
168
|
+
}, [selectMode, handleSwipeableClose])
|
|
169
|
+
|
|
165
170
|
useEffect(() => {
|
|
166
171
|
if (activeConversationId === conversation.id) return
|
|
167
172
|
|
|
@@ -171,6 +176,7 @@ export function ConversationActions({
|
|
|
171
176
|
return (
|
|
172
177
|
<ReanimatedSwipeable
|
|
173
178
|
ref={swipeableRef}
|
|
179
|
+
enabled={!selectMode}
|
|
174
180
|
childrenContainerStyle={styles.swipeableChildContainer}
|
|
175
181
|
containerStyle={styles.swipeableContainer}
|
|
176
182
|
overshootFriction={8}
|
|
@@ -203,7 +209,8 @@ export function ConversationActions({
|
|
|
203
209
|
style={({ pressed }) => [style, pressed && platformPressedOpacityStyle]}
|
|
204
210
|
android_ripple={{ color: androidRippleColor, borderless: false, foreground: true }}
|
|
205
211
|
accessibilityLabel={accessibilityLabel}
|
|
206
|
-
accessibilityRole=
|
|
212
|
+
accessibilityRole={selectMode ? 'checkbox' : 'button'}
|
|
213
|
+
accessibilityState={selectMode ? { checked: selected } : undefined}
|
|
207
214
|
accessibilityActions={accessibilityActions}
|
|
208
215
|
onAccessibilityAction={handleAccessibilityAction}
|
|
209
216
|
>
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
IconTile,
|
|
20
20
|
Text,
|
|
21
21
|
Badge,
|
|
22
|
+
Checkbox,
|
|
22
23
|
type BadgeProps,
|
|
23
24
|
} from '../display'
|
|
24
25
|
import { ConversationActions } from './conversation_actions'
|
|
@@ -44,8 +45,12 @@ export const ConversationPreview = ({
|
|
|
44
45
|
const styles = useStyles()
|
|
45
46
|
const {
|
|
46
47
|
args: { show_hidden: hidden = false },
|
|
48
|
+
selectMode,
|
|
49
|
+
selectedIds,
|
|
50
|
+
toggleSelected,
|
|
47
51
|
} = useConversationsContext()
|
|
48
52
|
const {
|
|
53
|
+
id,
|
|
49
54
|
conversationPreview,
|
|
50
55
|
lastMessageCreatedAt,
|
|
51
56
|
title,
|
|
@@ -61,6 +66,7 @@ export const ConversationPreview = ({
|
|
|
61
66
|
const fallbackIconName = emptyConversation ? 'people.noTextMessage' : 'general.person'
|
|
62
67
|
const hasMetaContent = lastMessageCreatedAt || unreadCount > 0 || muted || hidden
|
|
63
68
|
const isUnread = unreadCount > 0 || unreadReaction
|
|
69
|
+
const selected = selectMode ? selectedIds.includes(id) : undefined
|
|
64
70
|
|
|
65
71
|
const numberOfLinesScaledTitle = useScalableNumberOfLines(1)
|
|
66
72
|
const numberOfLinesScaledPreviewText = useScalableNumberOfLines(2)
|
|
@@ -80,9 +86,11 @@ export const ConversationPreview = ({
|
|
|
80
86
|
<ConversationActions
|
|
81
87
|
conversation={conversation}
|
|
82
88
|
style={[styles.previewRow, disabled && !archived && styles.disabled, style]}
|
|
83
|
-
onPress={onPress}
|
|
89
|
+
onPress={selectMode ? () => toggleSelected(id) : onPress}
|
|
84
90
|
accessibilityLabel={conversationAccessibilityLabel}
|
|
91
|
+
selected={selected}
|
|
85
92
|
>
|
|
93
|
+
{selected !== undefined && <Checkbox checked={selected} style={styles.checkbox} />}
|
|
86
94
|
{archived ? (
|
|
87
95
|
<IconTile
|
|
88
96
|
icon={faBoxArchive}
|
|
@@ -284,6 +292,9 @@ const useStyles = () => {
|
|
|
284
292
|
disabled: {
|
|
285
293
|
opacity: 0.4,
|
|
286
294
|
},
|
|
295
|
+
checkbox: {
|
|
296
|
+
alignSelf: 'center',
|
|
297
|
+
},
|
|
287
298
|
title: {
|
|
288
299
|
fontSize: 16,
|
|
289
300
|
color: colors.textColorDefaultPrimary,
|
|
@@ -32,6 +32,7 @@ export const Conversations = ({ ListHeaderComponent }: ConversationsProps) => {
|
|
|
32
32
|
isRefetching,
|
|
33
33
|
isFetched,
|
|
34
34
|
hasNextPage,
|
|
35
|
+
selectMode,
|
|
35
36
|
args: {
|
|
36
37
|
chat_group_graph_id,
|
|
37
38
|
group_source_app_name,
|
|
@@ -88,7 +89,7 @@ export const Conversations = ({ ListHeaderComponent }: ConversationsProps) => {
|
|
|
88
89
|
contentInsetAdjustmentBehavior="automatic"
|
|
89
90
|
onRefresh={refetch}
|
|
90
91
|
refreshing={!isFetched && isRefetching}
|
|
91
|
-
ListHeaderComponent={ListHeaderComponent}
|
|
92
|
+
ListHeaderComponent={selectMode ? null : ListHeaderComponent}
|
|
92
93
|
ListEmptyComponent={
|
|
93
94
|
<ConversationsBlankState
|
|
94
95
|
isFilterApplied={isFilterApplied}
|
|
@@ -62,7 +62,7 @@ const options = [
|
|
|
62
62
|
{ id: 'teams', label: 'Teams' },
|
|
63
63
|
]
|
|
64
64
|
|
|
65
|
-
const renderFilterDropdown = (
|
|
65
|
+
const renderFilterDropdown = () => {
|
|
66
66
|
const onSelect = jest.fn()
|
|
67
67
|
const onMoreFilters = jest.fn()
|
|
68
68
|
|
|
@@ -73,7 +73,6 @@ const renderFilterDropdown = ({ showMoreFilters }: { showMoreFilters?: boolean }
|
|
|
73
73
|
onSelect={onSelect}
|
|
74
74
|
onMoreFilters={onMoreFilters}
|
|
75
75
|
triggerLabel="Groups"
|
|
76
|
-
showMoreFilters={showMoreFilters}
|
|
77
76
|
/>
|
|
78
77
|
)
|
|
79
78
|
|
|
@@ -81,16 +80,6 @@ const renderFilterDropdown = ({ showMoreFilters }: { showMoreFilters?: boolean }
|
|
|
81
80
|
}
|
|
82
81
|
|
|
83
82
|
describe('FilterDropdown', () => {
|
|
84
|
-
it('hands the menu every option, the selected one checked, then More filters', () => {
|
|
85
|
-
renderFilterDropdown()
|
|
86
|
-
|
|
87
|
-
expect(screen.getByRole('button', { name: 'Groups' })).toBeTruthy()
|
|
88
|
-
expect(
|
|
89
|
-
screen.getAllByRole('menuitem').map(item => [item.props.accessibilityState.selected])
|
|
90
|
-
).toEqual([[false], [true], [false], [false]])
|
|
91
|
-
expect(screen.getByRole('menuitem', { name: 'More filters' })).toBeTruthy()
|
|
92
|
-
})
|
|
93
|
-
|
|
94
83
|
it('calls onSelect with the id of the pressed option', () => {
|
|
95
84
|
const { onSelect, onMoreFilters } = renderFilterDropdown()
|
|
96
85
|
|
|
@@ -100,13 +89,6 @@ describe('FilterDropdown', () => {
|
|
|
100
89
|
expect(onMoreFilters).not.toHaveBeenCalled()
|
|
101
90
|
})
|
|
102
91
|
|
|
103
|
-
it('leaves More filters out when showMoreFilters is false', () => {
|
|
104
|
-
renderFilterDropdown({ showMoreFilters: false })
|
|
105
|
-
|
|
106
|
-
expect(screen.queryByRole('menuitem', { name: 'More filters' })).toBeNull()
|
|
107
|
-
expect(screen.getAllByRole('menuitem')).toHaveLength(options.length)
|
|
108
|
-
})
|
|
109
|
-
|
|
110
92
|
it('calls onMoreFilters for the More filters action', () => {
|
|
111
93
|
const { onSelect, onMoreFilters } = renderFilterDropdown()
|
|
112
94
|
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native'
|
|
3
|
+
import { useTheme } from '../../hooks'
|
|
4
|
+
import { tokens } from '../../vendor/tapestry/tokens'
|
|
5
|
+
import { Icon } from './icon'
|
|
6
|
+
|
|
7
|
+
interface CheckboxProps {
|
|
8
|
+
checked: boolean
|
|
9
|
+
style?: StyleProp<ViewStyle>
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function Checkbox({ checked, style }: CheckboxProps) {
|
|
13
|
+
const styles = useStyles()
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<View style={[checked ? styles.checkedContainer : styles.uncheckedContainer, style]}>
|
|
17
|
+
{checked && <Icon name="general.thickCheckmark" style={styles.checkedIcon} />}
|
|
18
|
+
</View>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const useStyles = () => {
|
|
23
|
+
const { colors } = useTheme()
|
|
24
|
+
|
|
25
|
+
const baseCheckboxStyles: ViewStyle = {
|
|
26
|
+
width: 20,
|
|
27
|
+
height: 20,
|
|
28
|
+
borderRadius: 40,
|
|
29
|
+
alignItems: 'center',
|
|
30
|
+
justifyContent: 'center',
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return StyleSheet.create({
|
|
34
|
+
checkedContainer: {
|
|
35
|
+
...baseCheckboxStyles,
|
|
36
|
+
backgroundColor: colors.statusSuccessIcon,
|
|
37
|
+
},
|
|
38
|
+
uncheckedContainer: {
|
|
39
|
+
...baseCheckboxStyles,
|
|
40
|
+
borderWidth: 2,
|
|
41
|
+
borderColor: colors.borderColorDefaultDarker,
|
|
42
|
+
},
|
|
43
|
+
checkedIcon: {
|
|
44
|
+
color: tokens.colorNeutral100White,
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { render } from '@testing-library/react-native'
|
|
2
2
|
import React from 'react'
|
|
3
|
-
import { Text } from 'react-native'
|
|
4
3
|
import { Log } from '../../../utils/native_adapters/configuration'
|
|
5
4
|
import { ComponentErrorBoundary } from '../component_error_boundary'
|
|
6
5
|
|
|
@@ -32,15 +31,4 @@ describe('ComponentErrorBoundary', () => {
|
|
|
32
31
|
expect(toJSON()).toBeNull()
|
|
33
32
|
expect(reportError.mock.calls[0][1]).toMatchObject({ scope: 'component' })
|
|
34
33
|
})
|
|
35
|
-
|
|
36
|
-
it('lets callers override the defaults', () => {
|
|
37
|
-
const { getByText } = render(
|
|
38
|
-
<ComponentErrorBoundary scope="screen" fallback={<Text>overridden</Text>}>
|
|
39
|
-
<Boom thrown={new Error('boom')} />
|
|
40
|
-
</ComponentErrorBoundary>
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
expect(getByText('overridden')).toBeTruthy()
|
|
44
|
-
expect(reportError.mock.calls[0][1]).toMatchObject({ scope: 'screen' })
|
|
45
|
-
})
|
|
46
34
|
})
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { act, renderHook } from '@testing-library/react-native'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { ConversationFiltersParams } from '../../screens/conversation_filters/screen_props'
|
|
4
|
+
import { ConversationsContextProvider, useConversationsContext } from '../conversations_context'
|
|
5
|
+
|
|
6
|
+
let mockHideEnabled = true
|
|
7
|
+
jest.mock('../../hooks/use_hide_conversations_enabled', () => ({
|
|
8
|
+
useHideConversationsEnabled: () => mockHideEnabled,
|
|
9
|
+
}))
|
|
10
|
+
jest.mock('../../hooks/use_conversations', () => ({
|
|
11
|
+
useConversations: () => ({ conversations: [] }),
|
|
12
|
+
}))
|
|
13
|
+
|
|
14
|
+
let mockArgs: ConversationFiltersParams = {}
|
|
15
|
+
|
|
16
|
+
const renderContext = () =>
|
|
17
|
+
renderHook(() => useConversationsContext(), {
|
|
18
|
+
wrapper: ({ children }: { children: React.ReactNode }) => (
|
|
19
|
+
<ConversationsContextProvider args={mockArgs}>{children}</ConversationsContextProvider>
|
|
20
|
+
),
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
describe('ConversationsContextProvider selection', () => {
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
mockHideEnabled = true
|
|
26
|
+
mockArgs = {}
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('toggles conversations in and out of the selection', () => {
|
|
30
|
+
const { result } = renderContext()
|
|
31
|
+
|
|
32
|
+
act(() => result.current.enterSelectMode(1))
|
|
33
|
+
act(() => result.current.toggleSelected(2))
|
|
34
|
+
|
|
35
|
+
expect(result.current.selectMode).toBe(true)
|
|
36
|
+
expect(result.current.selectedIds).toEqual([1, 2])
|
|
37
|
+
|
|
38
|
+
act(() => result.current.toggleSelected(1))
|
|
39
|
+
|
|
40
|
+
expect(result.current.selectedIds).toEqual([2])
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('leaves select mode on clear', () => {
|
|
44
|
+
const { result } = renderContext()
|
|
45
|
+
|
|
46
|
+
act(() => result.current.enterSelectMode(1))
|
|
47
|
+
act(() => result.current.clearSelection())
|
|
48
|
+
|
|
49
|
+
expect(result.current.selectMode).toBe(false)
|
|
50
|
+
expect(result.current.selectedIds).toEqual([])
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('clears the selection when the filter changes', () => {
|
|
54
|
+
const { result, rerender } = renderContext()
|
|
55
|
+
|
|
56
|
+
act(() => result.current.enterSelectMode(1))
|
|
57
|
+
mockArgs = { show_unread: true }
|
|
58
|
+
rerender({})
|
|
59
|
+
|
|
60
|
+
expect(result.current.selectMode).toBe(false)
|
|
61
|
+
expect(result.current.selectedIds).toEqual([])
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('stays out of select mode when the flag is off', () => {
|
|
65
|
+
mockHideEnabled = false
|
|
66
|
+
const { result } = renderContext()
|
|
67
|
+
|
|
68
|
+
act(() => result.current.enterSelectMode(1))
|
|
69
|
+
|
|
70
|
+
expect(result.current.selectMode).toBe(false)
|
|
71
|
+
expect(result.current.selectedIds).toEqual([])
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('does not revive the selection when the flag flips off and back on', () => {
|
|
75
|
+
const { result, rerender } = renderContext()
|
|
76
|
+
|
|
77
|
+
act(() => result.current.enterSelectMode(1))
|
|
78
|
+
mockHideEnabled = false
|
|
79
|
+
rerender({})
|
|
80
|
+
mockHideEnabled = true
|
|
81
|
+
rerender({})
|
|
82
|
+
|
|
83
|
+
expect(result.current.selectMode).toBe(false)
|
|
84
|
+
expect(result.current.selectedIds).toEqual([])
|
|
85
|
+
})
|
|
86
|
+
})
|
|
@@ -3,9 +3,18 @@ import {
|
|
|
3
3
|
InfiniteQueryObserverResult,
|
|
4
4
|
InfiniteData,
|
|
5
5
|
} from '@tanstack/react-query'
|
|
6
|
-
import React, {
|
|
6
|
+
import React, {
|
|
7
|
+
createContext,
|
|
8
|
+
PropsWithChildren,
|
|
9
|
+
useCallback,
|
|
10
|
+
useContext,
|
|
11
|
+
useEffect,
|
|
12
|
+
useMemo,
|
|
13
|
+
useState,
|
|
14
|
+
} from 'react'
|
|
7
15
|
import { ApiGetQueryOptions } from '../hooks'
|
|
8
16
|
import { useConversations, UseConversationsValue } from '../hooks/use_conversations'
|
|
17
|
+
import { useHideConversationsEnabled } from '../hooks/use_hide_conversations_enabled'
|
|
9
18
|
import { ConversationFiltersParams } from '../screens/conversation_filters/screen_props'
|
|
10
19
|
import { ApiCollection, ConversationResource } from '../types'
|
|
11
20
|
import { ResponseError } from '../utils/response_error'
|
|
@@ -15,6 +24,11 @@ interface ConversationsContextValue extends UseConversationsValue {
|
|
|
15
24
|
setActiveConversationId: (_id: number) => void
|
|
16
25
|
args: ConversationFiltersParams
|
|
17
26
|
hideable: boolean
|
|
27
|
+
selectMode: boolean
|
|
28
|
+
selectedIds: number[]
|
|
29
|
+
enterSelectMode: (_id?: number) => void
|
|
30
|
+
toggleSelected: (_id: number) => void
|
|
31
|
+
clearSelection: () => void
|
|
18
32
|
}
|
|
19
33
|
|
|
20
34
|
const defaultQueryValue: UseConversationsValue = {
|
|
@@ -35,6 +49,11 @@ const ConversationsContext = createContext<ConversationsContextValue>({
|
|
|
35
49
|
activeConversationId: undefined,
|
|
36
50
|
setActiveConversationId: () => {},
|
|
37
51
|
hideable: true,
|
|
52
|
+
selectMode: false,
|
|
53
|
+
selectedIds: [],
|
|
54
|
+
enterSelectMode: () => {},
|
|
55
|
+
toggleSelected: () => {},
|
|
56
|
+
clearSelection: () => {},
|
|
38
57
|
...defaultQueryValue,
|
|
39
58
|
})
|
|
40
59
|
|
|
@@ -49,6 +68,10 @@ export const ConversationsContextProvider = ({
|
|
|
49
68
|
hideable?: boolean
|
|
50
69
|
}>) => {
|
|
51
70
|
const [activeConversationId, setActiveConversationId] = useState<number | undefined>()
|
|
71
|
+
const hideConversationsEnabled = useHideConversationsEnabled()
|
|
72
|
+
const [selecting, setSelecting] = useState(false)
|
|
73
|
+
const [selectedIds, setSelectedIds] = useState<number[]>([])
|
|
74
|
+
const selectMode = hideConversationsEnabled && selecting
|
|
52
75
|
const {
|
|
53
76
|
chat_group_graph_id,
|
|
54
77
|
group_source_app_name,
|
|
@@ -70,15 +93,59 @@ export const ConversationsContextProvider = ({
|
|
|
70
93
|
paginatorOptions
|
|
71
94
|
)
|
|
72
95
|
|
|
96
|
+
const enterSelectMode = useCallback((id?: number) => {
|
|
97
|
+
setSelecting(true)
|
|
98
|
+
setSelectedIds(id === undefined ? [] : [id])
|
|
99
|
+
}, [])
|
|
100
|
+
|
|
101
|
+
const toggleSelected = useCallback((id: number) => {
|
|
102
|
+
setSelectedIds(ids =>
|
|
103
|
+
ids.includes(id) ? ids.filter(selectedId => selectedId !== id) : [...ids, id]
|
|
104
|
+
)
|
|
105
|
+
}, [])
|
|
106
|
+
|
|
107
|
+
const clearSelection = useCallback(() => {
|
|
108
|
+
setSelecting(false)
|
|
109
|
+
setSelectedIds([])
|
|
110
|
+
}, [])
|
|
111
|
+
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
clearSelection()
|
|
114
|
+
}, [
|
|
115
|
+
clearSelection,
|
|
116
|
+
hideConversationsEnabled,
|
|
117
|
+
chat_group_graph_id,
|
|
118
|
+
group_source_app_name,
|
|
119
|
+
show_direct_messages,
|
|
120
|
+
show_archived,
|
|
121
|
+
show_hidden,
|
|
122
|
+
show_unread,
|
|
123
|
+
])
|
|
124
|
+
|
|
73
125
|
const value = useMemo(
|
|
74
126
|
() => ({
|
|
75
127
|
args,
|
|
76
128
|
activeConversationId,
|
|
77
129
|
setActiveConversationId,
|
|
78
130
|
hideable,
|
|
131
|
+
selectMode,
|
|
132
|
+
selectedIds: selectMode ? selectedIds : [],
|
|
133
|
+
enterSelectMode,
|
|
134
|
+
toggleSelected,
|
|
135
|
+
clearSelection,
|
|
79
136
|
...query,
|
|
80
137
|
}),
|
|
81
|
-
[
|
|
138
|
+
[
|
|
139
|
+
args,
|
|
140
|
+
activeConversationId,
|
|
141
|
+
hideable,
|
|
142
|
+
selectMode,
|
|
143
|
+
selectedIds,
|
|
144
|
+
enterSelectMode,
|
|
145
|
+
toggleSelected,
|
|
146
|
+
clearSelection,
|
|
147
|
+
query,
|
|
148
|
+
]
|
|
82
149
|
)
|
|
83
150
|
|
|
84
151
|
return <ConversationsContext.Provider value={value}>{children}</ConversationsContext.Provider>
|
|
@@ -155,41 +155,6 @@ describe('conversation.updated across two lists and two screens', () => {
|
|
|
155
155
|
expect(requestsFor(listUrl)).toBe(2)
|
|
156
156
|
expect(requestsFor(conversationUrl)).toBe(2)
|
|
157
157
|
})
|
|
158
|
-
|
|
159
|
-
it('refreshes immediately for a lone event and makes no second request', async () => {
|
|
160
|
-
conversationUpdated()
|
|
161
|
-
await advance(1)
|
|
162
|
-
|
|
163
|
-
expect(requestsFor(listUrl)).toBe(1)
|
|
164
|
-
expect(requestsFor(conversationUrl)).toBe(1)
|
|
165
|
-
|
|
166
|
-
await advance(REFRESH_THROTTLE_MS * 2)
|
|
167
|
-
|
|
168
|
-
expect(requestsFor(listUrl)).toBe(1)
|
|
169
|
-
expect(requestsFor(conversationUrl)).toBe(1)
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
it('gives an event inside the window a trailing refresh opened its own trailing refresh', async () => {
|
|
173
|
-
conversationUpdated()
|
|
174
|
-
await advance(1000)
|
|
175
|
-
conversationUpdated()
|
|
176
|
-
await advance(REFRESH_THROTTLE_MS - 1000)
|
|
177
|
-
|
|
178
|
-
expect(requestsFor(listUrl)).toBe(2)
|
|
179
|
-
expect(requestsFor(conversationUrl)).toBe(2)
|
|
180
|
-
|
|
181
|
-
await advance(500)
|
|
182
|
-
conversationUpdated()
|
|
183
|
-
await advance(1)
|
|
184
|
-
|
|
185
|
-
expect(requestsFor(listUrl)).toBe(2)
|
|
186
|
-
expect(requestsFor(conversationUrl)).toBe(2)
|
|
187
|
-
|
|
188
|
-
await advance(REFRESH_THROTTLE_MS)
|
|
189
|
-
|
|
190
|
-
expect(requestsFor(listUrl)).toBe(3)
|
|
191
|
-
expect(requestsFor(conversationUrl)).toBe(3)
|
|
192
|
-
})
|
|
193
158
|
})
|
|
194
159
|
|
|
195
160
|
describe('/me refreshes', () => {
|
package/src/navigation/index.tsx
CHANGED
|
@@ -60,7 +60,10 @@ import {
|
|
|
60
60
|
ConversationSelectTypeScreen,
|
|
61
61
|
ConversationSelectTypeScreenOptions,
|
|
62
62
|
} from '../screens/conversation_select_type_screen'
|
|
63
|
-
import {
|
|
63
|
+
import {
|
|
64
|
+
ConversationsScreen,
|
|
65
|
+
conversationsScreenOptions,
|
|
66
|
+
} from '../screens/conversations/conversations_screen'
|
|
64
67
|
import { GetHelpScreen } from '../screens/get_help_screen'
|
|
65
68
|
import {
|
|
66
69
|
GroupNotificationLevelSelectScreen,
|
|
@@ -181,13 +184,10 @@ export const ChatStack = createNativeStackNavigator({
|
|
|
181
184
|
Conversations: {
|
|
182
185
|
screen: ConversationsScreen,
|
|
183
186
|
options: ({ route, navigation }) =>
|
|
184
|
-
|
|
185
|
-
{
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
},
|
|
189
|
-
withRightClose({ onPress: navigation.goBack })
|
|
190
|
-
),
|
|
187
|
+
conversationsScreenOptions({
|
|
188
|
+
title: (route.params as { title?: string })?.title,
|
|
189
|
+
onClose: navigation.goBack,
|
|
190
|
+
}),
|
|
191
191
|
},
|
|
192
192
|
ConversationFilters: {
|
|
193
193
|
screen: ConversationFiltersScreen,
|
|
@@ -257,16 +257,6 @@ describe('ConversationDetailsScreen archive', () => {
|
|
|
257
257
|
expect(queryByText('Archive conversation…')).toBeNull()
|
|
258
258
|
})
|
|
259
259
|
|
|
260
|
-
it.each(['QA_MOBILE_manual_archiving', 'ROLLOUT_MOBILE_manual_archiving'])(
|
|
261
|
-
'offers archiving with only %s on',
|
|
262
|
-
flag => {
|
|
263
|
-
mockEnabledFeatures = [flag]
|
|
264
|
-
const { getByText } = renderScreen()
|
|
265
|
-
|
|
266
|
-
expect(getByText('Archive conversation…')).toBeTruthy()
|
|
267
|
-
}
|
|
268
|
-
)
|
|
269
|
-
|
|
270
260
|
it('hides archiving when neither mobile flag is on', () => {
|
|
271
261
|
mockEnabledFeatures = ['ROLLOUT_WEB_manual_archiving']
|
|
272
262
|
const { queryByText } = renderScreen()
|
|
@@ -299,15 +289,6 @@ describe('ConversationDetailsScreen archive', () => {
|
|
|
299
289
|
expect(mockNavigation.goBack).not.toHaveBeenCalled()
|
|
300
290
|
expect(mockNavigation.navigate).not.toHaveBeenCalled()
|
|
301
291
|
})
|
|
302
|
-
|
|
303
|
-
it('does nothing when the confirmation is cancelled', () => {
|
|
304
|
-
const { getByText } = renderScreen()
|
|
305
|
-
fireEvent.press(getByText('Archive conversation…'))
|
|
306
|
-
|
|
307
|
-
alertButton('Cancel')?.onPress?.()
|
|
308
|
-
|
|
309
|
-
expect(mockArchive).not.toHaveBeenCalled()
|
|
310
|
-
})
|
|
311
292
|
})
|
|
312
293
|
|
|
313
294
|
describe('ConversationDetailsScreen hide', () => {
|