@planningcenter/chat-react-native 4.6.0-rc.6 → 4.6.0-rc.8
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/display/conversation_avatar.d.ts +3 -1
- package/build/components/display/conversation_avatar.d.ts.map +1 -1
- package/build/components/display/conversation_avatar.js +77 -66
- package/build/components/display/conversation_avatar.js.map +1 -1
- package/build/hooks/use_conversation_avatar_update.d.ts +4 -3
- package/build/hooks/use_conversation_avatar_update.d.ts.map +1 -1
- package/build/hooks/use_conversation_avatar_update.js +146 -48
- package/build/hooks/use_conversation_avatar_update.js.map +1 -1
- package/build/icons/font_awesome.js +6 -6
- package/build/icons/font_awesome.js.map +1 -1
- package/build/screens/avatar_picker/avatar_picker_screen.d.ts.map +1 -1
- package/build/screens/avatar_picker/avatar_picker_screen.js +76 -66
- package/build/screens/avatar_picker/avatar_picker_screen.js.map +1 -1
- package/build/screens/avatar_picker/constants.d.ts.map +1 -1
- package/build/screens/avatar_picker/constants.js +5 -3
- package/build/screens/avatar_picker/constants.js.map +1 -1
- package/build/screens/conversation_details_screen.d.ts.map +1 -1
- package/build/screens/conversation_details_screen.js +2 -1
- package/build/screens/conversation_details_screen.js.map +1 -1
- package/build/screens/design_system_screen.js +6 -3
- package/build/screens/design_system_screen.js.map +1 -1
- package/build/vendor/font_awesome_pro_solid_icons.d.ts +6 -6
- package/build/vendor/font_awesome_pro_solid_icons.d.ts.map +1 -1
- package/build/vendor/font_awesome_pro_solid_icons.js +6 -6
- package/build/vendor/font_awesome_pro_solid_icons.js.map +1 -1
- package/package.json +5 -5
- package/src/__utils__/render_with_query_client.tsx +13 -0
- package/src/components/conversations/__tests__/conversation_preview.test.tsx +2 -2
- package/src/components/display/__tests__/conversation_avatar.test.tsx +94 -0
- package/src/components/display/conversation_avatar.tsx +9 -2
- package/src/hooks/__tests__/use_conversation_avatar_update.test.tsx +40 -0
- package/src/hooks/use_conversation_avatar_update.ts +67 -11
- package/src/icons/font_awesome.ts +12 -12
- package/src/screens/avatar_picker/__tests__/avatar_picker_screen.test.tsx +67 -0
- package/src/screens/avatar_picker/__tests__/constants.test.ts +16 -0
- package/src/screens/avatar_picker/avatar_picker_screen.tsx +7 -1
- package/src/screens/avatar_picker/constants.ts +11 -6
- package/src/screens/conversation_details_screen.tsx +1 -0
- package/src/screens/design_system_screen.tsx +10 -6
- package/src/screens/search/__tests__/search_screen.test.tsx +6 -5
- package/src/screens/search/components/__tests__/conversation_results.test.tsx +14 -5
- package/src/screens/search/components/__tests__/message_result_row.test.tsx +5 -4
- package/src/screens/search/components/__tests__/search_results_list.test.tsx +4 -3
- package/src/vendor/font_awesome_pro_solid_icons.ts +6 -6
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
2
|
-
import { Alert } from 'react-native'
|
|
3
|
-
import type {
|
|
4
|
-
|
|
1
|
+
import { InfiniteData, useMutation, useMutationState, useQueryClient } from '@tanstack/react-query'
|
|
2
|
+
import { Alert, Image } from 'react-native'
|
|
3
|
+
import type {
|
|
4
|
+
ApiCollection,
|
|
5
|
+
ApiResource,
|
|
6
|
+
ConversationAvatarData,
|
|
7
|
+
ConversationResource,
|
|
8
|
+
} from '../types'
|
|
9
|
+
import { updateAllRecordsInPagesData } from '../utils/cache/page_mutations'
|
|
5
10
|
import { transformGetToPost } from '../utils/client/request_helpers'
|
|
6
11
|
import type { ImagePickerAsset } from '../utils/native_adapters/image_picker'
|
|
7
12
|
import { ApiClient, useApiClient } from './use_api_client'
|
|
@@ -16,6 +21,18 @@ export type AvatarUpdatePayload =
|
|
|
16
21
|
| { kind: Extract<AvatarType, 'image'>; imageAsset: ImagePickerAsset; color: string }
|
|
17
22
|
| { kind: 'clear' }
|
|
18
23
|
|
|
24
|
+
const MUTATION_KEY = 'updateConversationAvatar'
|
|
25
|
+
|
|
26
|
+
export const usePendingConversationAvatarUpdate = (conversationId: number | undefined) => {
|
|
27
|
+
const newest = useMutationState({
|
|
28
|
+
filters: { mutationKey: [MUTATION_KEY, conversationId], exact: true },
|
|
29
|
+
select: mutation => mutation.state,
|
|
30
|
+
}).at(-1)
|
|
31
|
+
|
|
32
|
+
if (conversationId === undefined || newest?.status !== 'pending') return undefined
|
|
33
|
+
return newest.variables as AvatarUpdatePayload
|
|
34
|
+
}
|
|
35
|
+
|
|
19
36
|
export const useConversationAvatarUpdate = ({ conversationId }: { conversationId: number }) => {
|
|
20
37
|
const apiClient = useApiClient()
|
|
21
38
|
const uploadClient = useUploadClient()
|
|
@@ -23,11 +40,18 @@ export const useConversationAvatarUpdate = ({ conversationId }: { conversationId
|
|
|
23
40
|
const requestArgs = getConversationRequestArgs({ conversation_id: conversationId })
|
|
24
41
|
const queryKey = getRequestQueryKey(requestArgs)
|
|
25
42
|
|
|
43
|
+
const isSuperseded = (payload: AvatarUpdatePayload) =>
|
|
44
|
+
queryClient
|
|
45
|
+
.getMutationCache()
|
|
46
|
+
.findAll({ mutationKey: [MUTATION_KEY, conversationId], exact: true })
|
|
47
|
+
.at(-1)?.state.variables !== payload
|
|
48
|
+
|
|
26
49
|
return useMutation({
|
|
27
|
-
mutationKey: [
|
|
50
|
+
mutationKey: [MUTATION_KEY, conversationId],
|
|
28
51
|
mutationFn: async (payload: AvatarUpdatePayload) => {
|
|
29
52
|
const postArgs = transformGetToPost(requestArgs).data
|
|
30
53
|
const attributes = await buildAttributes(payload, uploadClient)
|
|
54
|
+
if (isSuperseded(payload)) return null
|
|
31
55
|
|
|
32
56
|
return apiClient.chat.patch<ApiResource<ConversationResource>>({
|
|
33
57
|
url: `/me/conversations/${conversationId}/`,
|
|
@@ -41,16 +65,35 @@ export const useConversationAvatarUpdate = ({ conversationId }: { conversationId
|
|
|
41
65
|
|
|
42
66
|
queryClient.setQueryData<ApiResource<ConversationResource>>(queryKey, prev => {
|
|
43
67
|
if (!prev?.data) return prev
|
|
44
|
-
return { ...prev, data:
|
|
68
|
+
return { ...prev, data: applyAvatarUpdate(prev.data, payload) }
|
|
45
69
|
})
|
|
46
70
|
|
|
47
71
|
return { previous }
|
|
48
72
|
},
|
|
49
|
-
onSuccess: (response, _payload, _context) => {
|
|
73
|
+
onSuccess: async (response, _payload, _context) => {
|
|
74
|
+
if (!response) return
|
|
75
|
+
|
|
50
76
|
queryClient.setQueryData<ApiResource<ConversationResource>>(queryKey, () => response)
|
|
77
|
+
queryClient.setQueriesData<InfiniteData<ApiCollection<ConversationResource>>>(
|
|
78
|
+
{ queryKey: ['/me/conversations'] },
|
|
79
|
+
prev => {
|
|
80
|
+
if (!prev?.pages) return prev
|
|
81
|
+
|
|
82
|
+
return updateAllRecordsInPagesData({
|
|
83
|
+
data: prev,
|
|
84
|
+
processRecord: record =>
|
|
85
|
+
record.id === conversationId ? applySavedAvatar(record, response.data) : record,
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
)
|
|
51
89
|
queryClient.invalidateQueries({ queryKey: ['/me/conversations'] })
|
|
90
|
+
|
|
91
|
+
const imageUrl = response.data.customAvatarImageUrl
|
|
92
|
+
if (imageUrl) await Image.prefetch(imageUrl).catch(() => false)
|
|
52
93
|
},
|
|
53
|
-
onError: (_error,
|
|
94
|
+
onError: (_error, payload, context) => {
|
|
95
|
+
if (isSuperseded(payload)) return
|
|
96
|
+
|
|
54
97
|
if (context?.previous) {
|
|
55
98
|
queryClient.setQueryData(queryKey, context.previous)
|
|
56
99
|
}
|
|
@@ -83,10 +126,23 @@ export async function patchConversationAvatar(
|
|
|
83
126
|
}
|
|
84
127
|
}
|
|
85
128
|
|
|
86
|
-
function
|
|
87
|
-
data:
|
|
129
|
+
function applySavedAvatar<T extends ConversationAvatarData>(
|
|
130
|
+
data: T,
|
|
131
|
+
saved: ConversationAvatarData
|
|
132
|
+
): T {
|
|
133
|
+
return {
|
|
134
|
+
...data,
|
|
135
|
+
customAvatarType: saved.customAvatarType,
|
|
136
|
+
customAvatarKey: saved.customAvatarKey,
|
|
137
|
+
customAvatarColor: saved.customAvatarColor,
|
|
138
|
+
customAvatarImageUrl: saved.customAvatarImageUrl,
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function applyAvatarUpdate<T extends ConversationAvatarData>(
|
|
143
|
+
data: T,
|
|
88
144
|
payload: AvatarUpdatePayload
|
|
89
|
-
):
|
|
145
|
+
): T {
|
|
90
146
|
switch (payload.kind) {
|
|
91
147
|
case 'icon':
|
|
92
148
|
return {
|
|
@@ -5,9 +5,9 @@ import {
|
|
|
5
5
|
faChurch,
|
|
6
6
|
faCross,
|
|
7
7
|
faDove,
|
|
8
|
-
|
|
8
|
+
faHandsHoldingHeart,
|
|
9
9
|
faPersonRays,
|
|
10
|
-
|
|
10
|
+
faHandsPraying,
|
|
11
11
|
faPodium,
|
|
12
12
|
faDroplet,
|
|
13
13
|
faPersonDrowning,
|
|
@@ -22,13 +22,13 @@ import {
|
|
|
22
22
|
faBaby,
|
|
23
23
|
faChildren,
|
|
24
24
|
faMugHot,
|
|
25
|
-
|
|
25
|
+
faVideo,
|
|
26
26
|
faMusic,
|
|
27
27
|
faPianoKeyboard,
|
|
28
28
|
faDrum,
|
|
29
29
|
faUserGraduate,
|
|
30
30
|
faCommentsQuestion,
|
|
31
|
-
|
|
31
|
+
faPresentationScreen,
|
|
32
32
|
faMicrophoneStand,
|
|
33
33
|
faIdBadge,
|
|
34
34
|
faBookUser,
|
|
@@ -44,10 +44,10 @@ import {
|
|
|
44
44
|
faPersonDress,
|
|
45
45
|
faPerson,
|
|
46
46
|
faSeedling,
|
|
47
|
-
|
|
47
|
+
faMessages,
|
|
48
48
|
faGlobe,
|
|
49
49
|
faBookOpenReader,
|
|
50
|
-
|
|
50
|
+
faPersonRunning,
|
|
51
51
|
faLeaf,
|
|
52
52
|
// General
|
|
53
53
|
faPlateUtensils,
|
|
@@ -62,9 +62,9 @@ library.add(
|
|
|
62
62
|
faChurch,
|
|
63
63
|
faCross,
|
|
64
64
|
faDove,
|
|
65
|
-
|
|
65
|
+
faHandsHoldingHeart,
|
|
66
66
|
faPersonRays,
|
|
67
|
-
|
|
67
|
+
faHandsPraying,
|
|
68
68
|
faPodium,
|
|
69
69
|
faDroplet,
|
|
70
70
|
faPersonDrowning,
|
|
@@ -79,13 +79,13 @@ library.add(
|
|
|
79
79
|
faBaby,
|
|
80
80
|
faChildren,
|
|
81
81
|
faMugHot,
|
|
82
|
-
|
|
82
|
+
faVideo,
|
|
83
83
|
faMusic,
|
|
84
84
|
faPianoKeyboard,
|
|
85
85
|
faDrum,
|
|
86
86
|
faUserGraduate,
|
|
87
87
|
faCommentsQuestion,
|
|
88
|
-
|
|
88
|
+
faPresentationScreen,
|
|
89
89
|
faMicrophoneStand,
|
|
90
90
|
faIdBadge,
|
|
91
91
|
faBookUser,
|
|
@@ -101,10 +101,10 @@ library.add(
|
|
|
101
101
|
faPersonDress,
|
|
102
102
|
faPerson,
|
|
103
103
|
faSeedling,
|
|
104
|
-
|
|
104
|
+
faMessages,
|
|
105
105
|
faGlobe,
|
|
106
106
|
faBookOpenReader,
|
|
107
|
-
|
|
107
|
+
faPersonRunning,
|
|
108
108
|
faLeaf,
|
|
109
109
|
// General
|
|
110
110
|
faPlateUtensils,
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { HeaderHeightContext } from '@react-navigation/elements'
|
|
2
|
+
import { DefaultTheme, ThemeProvider } from '@react-navigation/native'
|
|
3
|
+
import { QueryClientProvider } from '@tanstack/react-query'
|
|
4
|
+
import { render } from '@testing-library/react-native'
|
|
5
|
+
import React from 'react'
|
|
6
|
+
import { Image } from 'react-native'
|
|
7
|
+
import { SafeAreaProvider } from 'react-native-safe-area-context'
|
|
8
|
+
import { buildTestQueryClient } from '../../../__utils__/query_client'
|
|
9
|
+
import type { AvatarUpdatePayload } from '../../../hooks/use_conversation_avatar_update'
|
|
10
|
+
import { AvatarPickerScreen } from '../avatar_picker_screen'
|
|
11
|
+
|
|
12
|
+
jest.mock('@react-navigation/native', () => ({
|
|
13
|
+
...jest.requireActual('@react-navigation/native'),
|
|
14
|
+
useNavigation: () => ({ goBack: jest.fn(), dispatch: jest.fn() }),
|
|
15
|
+
}))
|
|
16
|
+
jest.mock('../../../hooks/use_api_client', () => ({ useApiClient: () => ({}) }))
|
|
17
|
+
jest.mock('../../../hooks/use_upload_client', () => ({ useUploadClient: () => ({}) }))
|
|
18
|
+
jest.mock('../../../hooks/use_conversation', () => ({
|
|
19
|
+
...jest.requireActual('../../../hooks/use_conversation'),
|
|
20
|
+
useConversation: () => ({
|
|
21
|
+
data: { id: 7, customAvatarType: 'icon', customAvatarKey: 'star', customAvatarColor: 'cosmic' },
|
|
22
|
+
}),
|
|
23
|
+
}))
|
|
24
|
+
|
|
25
|
+
const safeAreaMetrics = {
|
|
26
|
+
frame: { x: 0, y: 0, width: 390, height: 844 },
|
|
27
|
+
insets: { top: 0, right: 0, bottom: 0, left: 0 },
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe('AvatarPickerScreen', () => {
|
|
31
|
+
it('opens on a photo that is still uploading instead of the cached avatar', async () => {
|
|
32
|
+
const queryClient = buildTestQueryClient()
|
|
33
|
+
const photo: AvatarUpdatePayload = {
|
|
34
|
+
kind: 'image',
|
|
35
|
+
color: 'cosmic',
|
|
36
|
+
imageAsset: { uri: 'file:///photo.jpg', width: 100, height: 100 },
|
|
37
|
+
}
|
|
38
|
+
let finishUpload = () => {}
|
|
39
|
+
const uploading = new Promise<void>(resolve => (finishUpload = resolve))
|
|
40
|
+
const upload = queryClient
|
|
41
|
+
.getMutationCache()
|
|
42
|
+
.build(queryClient, {
|
|
43
|
+
mutationKey: ['updateConversationAvatar', 7],
|
|
44
|
+
mutationFn: () => uploading,
|
|
45
|
+
networkMode: 'always',
|
|
46
|
+
})
|
|
47
|
+
.execute(photo)
|
|
48
|
+
|
|
49
|
+
const view = render(
|
|
50
|
+
<SafeAreaProvider initialMetrics={safeAreaMetrics}>
|
|
51
|
+
<ThemeProvider value={DefaultTheme}>
|
|
52
|
+
<HeaderHeightContext.Provider value={0}>
|
|
53
|
+
<QueryClientProvider client={queryClient}>
|
|
54
|
+
<AvatarPickerScreen route={{ params: { conversation_id: 7 } } as never} />
|
|
55
|
+
</QueryClientProvider>
|
|
56
|
+
</HeaderHeightContext.Provider>
|
|
57
|
+
</ThemeProvider>
|
|
58
|
+
</SafeAreaProvider>
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
const sources = view.UNSAFE_getAllByType(Image).map(image => image.props.source)
|
|
62
|
+
expect(sources).toContainEqual({ uri: 'file:///photo.jpg' })
|
|
63
|
+
|
|
64
|
+
finishUpload()
|
|
65
|
+
await upload
|
|
66
|
+
})
|
|
67
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as vendoredIcons from '../../../vendor/font_awesome_pro_solid_icons'
|
|
2
|
+
import { AVATAR_ICON_KEYS } from '../constants'
|
|
3
|
+
|
|
4
|
+
const canonicalIconNames: string[] = Object.values(vendoredIcons).map(icon => icon.iconName)
|
|
5
|
+
|
|
6
|
+
describe('AVATAR_ICON_KEYS', () => {
|
|
7
|
+
it('only offers canonical icon names, never Font Awesome aliases', () => {
|
|
8
|
+
const aliases = AVATAR_ICON_KEYS.filter(key => !canonicalIconNames.includes(key))
|
|
9
|
+
|
|
10
|
+
expect(aliases).toEqual([])
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
it('has no duplicates', () => {
|
|
14
|
+
expect(new Set(AVATAR_ICON_KEYS).size).toBe(AVATAR_ICON_KEYS.length)
|
|
15
|
+
})
|
|
16
|
+
})
|
|
@@ -11,6 +11,7 @@ import { useTheme } from '../../hooks'
|
|
|
11
11
|
import { useConversation } from '../../hooks/use_conversation'
|
|
12
12
|
import {
|
|
13
13
|
useConversationAvatarUpdate,
|
|
14
|
+
usePendingConversationAvatarUpdate,
|
|
14
15
|
type AvatarUpdatePayload,
|
|
15
16
|
} from '../../hooks/use_conversation_avatar_update'
|
|
16
17
|
import { useFontScale } from '../../hooks/use_font_scale'
|
|
@@ -79,9 +80,14 @@ function EditModeContent({ conversationId }: { conversationId: number }) {
|
|
|
79
80
|
const navigation = useNavigation()
|
|
80
81
|
const { data: conversation } = useConversation({ conversation_id: conversationId })
|
|
81
82
|
const mutation = useConversationAvatarUpdate({ conversationId })
|
|
83
|
+
const pendingUpdate = usePendingConversationAvatarUpdate(conversationId)
|
|
82
84
|
const previewDiameter = usePreviewAvatarDiameter()
|
|
83
85
|
|
|
84
|
-
const [state, dispatch] = useReducer(avatarPickerReducer,
|
|
86
|
+
const [state, dispatch] = useReducer(avatarPickerReducer, undefined, () =>
|
|
87
|
+
pendingUpdate
|
|
88
|
+
? initAvatarPickerStateFromPayload(pendingUpdate)
|
|
89
|
+
: initAvatarPickerState(conversation)
|
|
90
|
+
)
|
|
85
91
|
|
|
86
92
|
const hasAvatar = state.selectedType !== null
|
|
87
93
|
|
|
@@ -4,9 +4,9 @@ export const AVATAR_ICON_KEYS: string[] = [
|
|
|
4
4
|
'church',
|
|
5
5
|
'cross',
|
|
6
6
|
'dove',
|
|
7
|
-
'hands-heart',
|
|
7
|
+
'hands-holding-heart',
|
|
8
8
|
'person-rays',
|
|
9
|
-
'praying
|
|
9
|
+
'hands-praying',
|
|
10
10
|
'podium',
|
|
11
11
|
'droplet',
|
|
12
12
|
'person-drowning',
|
|
@@ -21,13 +21,13 @@ export const AVATAR_ICON_KEYS: string[] = [
|
|
|
21
21
|
'baby',
|
|
22
22
|
'children',
|
|
23
23
|
'mug-hot',
|
|
24
|
-
'video
|
|
24
|
+
'video',
|
|
25
25
|
'music',
|
|
26
26
|
'piano-keyboard',
|
|
27
27
|
'drum',
|
|
28
28
|
'user-graduate',
|
|
29
29
|
'comments-question',
|
|
30
|
-
'presentation',
|
|
30
|
+
'presentation-screen',
|
|
31
31
|
'microphone-stand',
|
|
32
32
|
'id-badge',
|
|
33
33
|
'book-user',
|
|
@@ -43,11 +43,16 @@ export const AVATAR_ICON_KEYS: string[] = [
|
|
|
43
43
|
'person-dress',
|
|
44
44
|
'person',
|
|
45
45
|
'seedling',
|
|
46
|
-
'
|
|
46
|
+
'messages',
|
|
47
47
|
'globe',
|
|
48
48
|
'book-open-reader',
|
|
49
|
-
'running',
|
|
49
|
+
'person-running',
|
|
50
50
|
'leaf',
|
|
51
|
+
// General
|
|
52
|
+
'plate-utensils',
|
|
53
|
+
'bullhorn',
|
|
54
|
+
'car',
|
|
55
|
+
'tag',
|
|
51
56
|
]
|
|
52
57
|
|
|
53
58
|
export const GRID_COLUMNS = 6
|
|
@@ -1128,9 +1128,9 @@ const FA_ICONS: { category: string; icons: IconName[] }[] = [
|
|
|
1128
1128
|
'church',
|
|
1129
1129
|
'cross',
|
|
1130
1130
|
'dove',
|
|
1131
|
-
'hands-heart',
|
|
1131
|
+
'hands-holding-heart',
|
|
1132
1132
|
'person-rays',
|
|
1133
|
-
'praying
|
|
1133
|
+
'hands-praying',
|
|
1134
1134
|
'podium',
|
|
1135
1135
|
'droplet',
|
|
1136
1136
|
'person-drowning',
|
|
@@ -1149,13 +1149,13 @@ const FA_ICONS: { category: string; icons: IconName[] }[] = [
|
|
|
1149
1149
|
'baby',
|
|
1150
1150
|
'children',
|
|
1151
1151
|
'mug-hot',
|
|
1152
|
-
'video
|
|
1152
|
+
'video',
|
|
1153
1153
|
'music',
|
|
1154
1154
|
'piano-keyboard',
|
|
1155
1155
|
'drum',
|
|
1156
1156
|
'user-graduate',
|
|
1157
1157
|
'comments-question',
|
|
1158
|
-
'presentation',
|
|
1158
|
+
'presentation-screen',
|
|
1159
1159
|
'microphone-stand',
|
|
1160
1160
|
'id-badge',
|
|
1161
1161
|
'book-user',
|
|
@@ -1175,13 +1175,17 @@ const FA_ICONS: { category: string; icons: IconName[] }[] = [
|
|
|
1175
1175
|
'person-dress',
|
|
1176
1176
|
'person',
|
|
1177
1177
|
'seedling',
|
|
1178
|
-
'
|
|
1178
|
+
'messages',
|
|
1179
1179
|
'globe',
|
|
1180
1180
|
'book-open-reader',
|
|
1181
|
-
'running',
|
|
1181
|
+
'person-running',
|
|
1182
1182
|
'leaf',
|
|
1183
1183
|
],
|
|
1184
1184
|
},
|
|
1185
|
+
{
|
|
1186
|
+
category: 'General',
|
|
1187
|
+
icons: ['plate-utensils', 'bullhorn', 'car', 'tag'],
|
|
1188
|
+
},
|
|
1185
1189
|
]
|
|
1186
1190
|
|
|
1187
1191
|
function FontAwesomeIconsSection({ isLast }: SectionProps) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { act, fireEvent
|
|
1
|
+
import { act, fireEvent } from '@testing-library/react-native'
|
|
2
2
|
import React from 'react'
|
|
3
3
|
import { Keyboard, ScrollView } from 'react-native'
|
|
4
|
+
import { renderWithQueryClient } from '../../../__utils__/render_with_query_client'
|
|
4
5
|
import type { useSearchResults } from '../../../hooks/use_search_results'
|
|
5
6
|
import type {
|
|
6
7
|
ConversationSearchResultResource,
|
|
@@ -71,7 +72,7 @@ const renderWithResults = () => {
|
|
|
71
72
|
hasNextPage: false,
|
|
72
73
|
isFetchingNextPage: false,
|
|
73
74
|
})
|
|
74
|
-
const view =
|
|
75
|
+
const view = renderWithQueryClient(<SearchScreen />)
|
|
75
76
|
const input = view.getByLabelText(inputLabel)
|
|
76
77
|
fireEvent.changeText(input, 'bud')
|
|
77
78
|
fireEvent.changeText(input, 'budget')
|
|
@@ -99,7 +100,7 @@ afterEach(() => jest.useRealTimers())
|
|
|
99
100
|
|
|
100
101
|
describe('SearchScreen', () => {
|
|
101
102
|
it('searches once with the trimmed term after typing settles', () => {
|
|
102
|
-
const view =
|
|
103
|
+
const view = renderWithQueryClient(<SearchScreen />)
|
|
103
104
|
const input = view.getByLabelText(inputLabel)
|
|
104
105
|
|
|
105
106
|
fireEvent.changeText(input, 'bud')
|
|
@@ -118,7 +119,7 @@ describe('SearchScreen', () => {
|
|
|
118
119
|
})
|
|
119
120
|
|
|
120
121
|
it('lets the prompt scroll while taps still reach the field', () => {
|
|
121
|
-
const view =
|
|
122
|
+
const view = renderWithQueryClient(<SearchScreen />)
|
|
122
123
|
|
|
123
124
|
const scrollView = view.UNSAFE_getByType(ScrollView)
|
|
124
125
|
expect(scrollView.props.keyboardShouldPersistTaps).toBe('handled')
|
|
@@ -127,7 +128,7 @@ describe('SearchScreen', () => {
|
|
|
127
128
|
})
|
|
128
129
|
|
|
129
130
|
it('returns to the prompt as soon as the term is cleared', () => {
|
|
130
|
-
const view =
|
|
131
|
+
const view = renderWithQueryClient(<SearchScreen />)
|
|
131
132
|
const input = view.getByLabelText(inputLabel)
|
|
132
133
|
|
|
133
134
|
fireEvent.changeText(input, 'budget')
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { fireEvent
|
|
1
|
+
import { fireEvent } from '@testing-library/react-native'
|
|
2
2
|
import React from 'react'
|
|
3
|
+
import { renderWithQueryClient } from '../../../../__utils__/render_with_query_client'
|
|
3
4
|
import type { ConversationSearchResultResource } from '../../../../types'
|
|
4
5
|
import { ConversationResults } from '../conversation_results'
|
|
5
6
|
|
|
@@ -14,7 +15,9 @@ const buildResults = (count: number, prefix = 'Conversation') =>
|
|
|
14
15
|
|
|
15
16
|
describe('ConversationResults', () => {
|
|
16
17
|
it('caps at five rows until View more is pressed, then offers View less', () => {
|
|
17
|
-
const view =
|
|
18
|
+
const view = renderWithQueryClient(
|
|
19
|
+
<ConversationResults results={buildResults(6)} onSelect={jest.fn()} />
|
|
20
|
+
)
|
|
18
21
|
|
|
19
22
|
expect(view.getByText('Conversation 5')).toBeTruthy()
|
|
20
23
|
expect(view.queryByText('Conversation 6')).toBeNull()
|
|
@@ -27,14 +30,18 @@ describe('ConversationResults', () => {
|
|
|
27
30
|
})
|
|
28
31
|
|
|
29
32
|
it('renders no footer for five or fewer results', () => {
|
|
30
|
-
const view =
|
|
33
|
+
const view = renderWithQueryClient(
|
|
34
|
+
<ConversationResults results={buildResults(4)} onSelect={jest.fn()} />
|
|
35
|
+
)
|
|
31
36
|
|
|
32
37
|
expect(view.getByText('Conversation 4')).toBeTruthy()
|
|
33
38
|
expect(view.queryByText('View more')).toBeNull()
|
|
34
39
|
})
|
|
35
40
|
|
|
36
41
|
it('stays expanded when the parent re-renders with a new results array', () => {
|
|
37
|
-
const view =
|
|
42
|
+
const view = renderWithQueryClient(
|
|
43
|
+
<ConversationResults results={buildResults(6)} onSelect={jest.fn()} />
|
|
44
|
+
)
|
|
38
45
|
fireEvent.press(view.getByText('View more'))
|
|
39
46
|
|
|
40
47
|
view.rerender(<ConversationResults results={buildResults(6)} onSelect={jest.fn()} />)
|
|
@@ -46,7 +53,9 @@ describe('ConversationResults', () => {
|
|
|
46
53
|
it('passes the pressed result and its position to onSelect', () => {
|
|
47
54
|
const onSelect = jest.fn()
|
|
48
55
|
const results = buildResults(2)
|
|
49
|
-
const view =
|
|
56
|
+
const view = renderWithQueryClient(
|
|
57
|
+
<ConversationResults results={results} onSelect={onSelect} />
|
|
58
|
+
)
|
|
50
59
|
|
|
51
60
|
fireEvent.press(view.getByText('Conversation 2'))
|
|
52
61
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { fireEvent
|
|
1
|
+
import { fireEvent } from '@testing-library/react-native'
|
|
2
2
|
import React from 'react'
|
|
3
|
+
import { renderWithQueryClient } from '../../../../__utils__/render_with_query_client'
|
|
3
4
|
import type { MessageSearchResultResource } from '../../../../types/resources/search_result'
|
|
4
5
|
import { formatDatePreview } from '../../../../utils/date'
|
|
5
6
|
import { defaultTheme } from '../../../../utils/theme'
|
|
@@ -33,7 +34,7 @@ const interactionColor = defaultTheme('light').colors.interaction
|
|
|
33
34
|
|
|
34
35
|
describe('MessageResultRow', () => {
|
|
35
36
|
it('renders the title, author, snippet, and date', () => {
|
|
36
|
-
const view =
|
|
37
|
+
const view = renderWithQueryClient(<MessageResultRow result={result} onPress={jest.fn()} />)
|
|
37
38
|
|
|
38
39
|
expect(view.getByText('Worship Team')).toBeTruthy()
|
|
39
40
|
expect(view.getByText('Ada Lovelace:', { exact: false })).toBeTruthy()
|
|
@@ -44,7 +45,7 @@ describe('MessageResultRow', () => {
|
|
|
44
45
|
})
|
|
45
46
|
|
|
46
47
|
it('colors matched segments with the interaction color', () => {
|
|
47
|
-
const view =
|
|
48
|
+
const view = renderWithQueryClient(<MessageResultRow result={result} onPress={jest.fn()} />)
|
|
48
49
|
|
|
49
50
|
expect(view.getByText('budget')).toHaveStyle({ color: interactionColor })
|
|
50
51
|
expect(view.getByText('…planning the ')).not.toHaveStyle({ color: interactionColor })
|
|
@@ -53,7 +54,7 @@ describe('MessageResultRow', () => {
|
|
|
53
54
|
it('exposes the row as a button with a composed label and reports presses', () => {
|
|
54
55
|
const onPress = jest.fn()
|
|
55
56
|
const date = formatDatePreview(result.extra.createdAt)
|
|
56
|
-
const view =
|
|
57
|
+
const view = renderWithQueryClient(<MessageResultRow result={result} onPress={onPress} />)
|
|
57
58
|
|
|
58
59
|
const row = view.getByRole('button', {
|
|
59
60
|
name: `Worship Team, Ada Lovelace: …planning the budget meeting for next week, ${date}`,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { fireEvent
|
|
1
|
+
import { fireEvent } from '@testing-library/react-native'
|
|
2
2
|
import React from 'react'
|
|
3
3
|
import { FlatList } from 'react-native'
|
|
4
|
+
import { renderWithQueryClient } from '../../../../__utils__/render_with_query_client'
|
|
4
5
|
import type { useSearchResults } from '../../../../hooks/use_search_results'
|
|
5
6
|
import type {
|
|
6
7
|
ConversationSearchResultResource,
|
|
@@ -56,7 +57,7 @@ const renderList = (state: Partial<SearchState>, onSettled = jest.fn()) => {
|
|
|
56
57
|
const list = () => (
|
|
57
58
|
<SearchResultsList term="potluck" onSelect={jest.fn()} onSettled={onSettled} {...slots} />
|
|
58
59
|
)
|
|
59
|
-
const view =
|
|
60
|
+
const view = renderWithQueryClient(list())
|
|
60
61
|
const rerenderWith = (next: Partial<SearchState>) => {
|
|
61
62
|
mockUseSearchResults.mockReturnValue(searchState(next))
|
|
62
63
|
view.rerender(list())
|
|
@@ -133,7 +134,7 @@ describe('SearchResultsList', () => {
|
|
|
133
134
|
const onSelect = jest.fn()
|
|
134
135
|
const results = [conversationResult('1'), messageResult('1'), messageResult('2')]
|
|
135
136
|
mockUseSearchResults.mockReturnValue(searchState({ results }))
|
|
136
|
-
const view =
|
|
137
|
+
const view = renderWithQueryClient(
|
|
137
138
|
<SearchResultsList term="potluck" onSelect={onSelect} onSettled={jest.fn()} {...slots} />
|
|
138
139
|
)
|
|
139
140
|
|
|
@@ -55,7 +55,7 @@ export const faDove: IconDefinition = {
|
|
|
55
55
|
],
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
export const
|
|
58
|
+
export const faHandsHoldingHeart: IconDefinition = {
|
|
59
59
|
prefix: 'fas',
|
|
60
60
|
iconName: 'hands-holding-heart',
|
|
61
61
|
icon: [
|
|
@@ -79,7 +79,7 @@ export const faPersonRays: IconDefinition = {
|
|
|
79
79
|
],
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
export const
|
|
82
|
+
export const faHandsPraying: IconDefinition = {
|
|
83
83
|
prefix: 'fas',
|
|
84
84
|
iconName: 'hands-praying',
|
|
85
85
|
icon: [
|
|
@@ -247,7 +247,7 @@ export const faMugHot: IconDefinition = {
|
|
|
247
247
|
],
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
-
export const
|
|
250
|
+
export const faVideo: IconDefinition = {
|
|
251
251
|
prefix: 'fas',
|
|
252
252
|
iconName: 'video',
|
|
253
253
|
icon: [
|
|
@@ -319,7 +319,7 @@ export const faCommentsQuestion: IconDefinition = {
|
|
|
319
319
|
],
|
|
320
320
|
}
|
|
321
321
|
|
|
322
|
-
export const
|
|
322
|
+
export const faPresentationScreen: IconDefinition = {
|
|
323
323
|
prefix: 'fas',
|
|
324
324
|
iconName: 'presentation-screen',
|
|
325
325
|
icon: [
|
|
@@ -499,7 +499,7 @@ export const faSeedling: IconDefinition = {
|
|
|
499
499
|
],
|
|
500
500
|
}
|
|
501
501
|
|
|
502
|
-
export const
|
|
502
|
+
export const faMessages: IconDefinition = {
|
|
503
503
|
prefix: 'fas',
|
|
504
504
|
iconName: 'messages',
|
|
505
505
|
icon: [
|
|
@@ -535,7 +535,7 @@ export const faBookOpenReader: IconDefinition = {
|
|
|
535
535
|
],
|
|
536
536
|
}
|
|
537
537
|
|
|
538
|
-
export const
|
|
538
|
+
export const faPersonRunning: IconDefinition = {
|
|
539
539
|
prefix: 'fas',
|
|
540
540
|
iconName: 'person-running',
|
|
541
541
|
icon: [
|