@planningcenter/chat-react-native 4.7.1-qa-staging.8 → 4.7.1-qa-1119.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/conversations/bulk_conversation_actions_bar.d.ts +2 -0
- package/build/components/conversations/bulk_conversation_actions_bar.d.ts.map +1 -0
- package/build/components/conversations/bulk_conversation_actions_bar.js +215 -0
- package/build/components/conversations/bulk_conversation_actions_bar.js.map +1 -0
- 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 +173 -130
- 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 +168 -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/icon.d.ts +3 -1
- package/build/components/display/icon.d.ts.map +1 -1
- package/build/components/display/icon.js +2 -0
- package/build/components/display/icon.js.map +1 -1
- 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/api_provider.d.ts.map +1 -1
- package/build/contexts/api_provider.js +2 -0
- package/build/contexts/api_provider.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/contexts/session_context.d.ts +0 -1
- package/build/contexts/session_context.d.ts.map +1 -1
- package/build/contexts/session_context.js +3 -0
- package/build/contexts/session_context.js.map +1 -1
- package/build/hooks/use_bulk_conversation_actions.d.ts +8 -0
- package/build/hooks/use_bulk_conversation_actions.d.ts.map +1 -0
- package/build/hooks/use_bulk_conversation_actions.js +309 -0
- package/build/hooks/use_bulk_conversation_actions.js.map +1 -0
- package/build/hooks/use_conversation_jolt_events.d.ts.map +1 -1
- package/build/hooks/use_conversation_jolt_events.js +3 -2
- package/build/hooks/use_conversation_jolt_events.js.map +1 -1
- package/build/hooks/use_conversations_actions.d.ts +9 -9
- package/build/hooks/use_conversations_actions.d.ts.map +1 -1
- package/build/hooks/use_conversations_actions.js +12 -7
- package/build/hooks/use_conversations_actions.js.map +1 -1
- package/build/hooks/use_conversations_cache.d.ts +15 -5
- package/build/hooks/use_conversations_cache.d.ts.map +1 -1
- package/build/hooks/use_conversations_cache.js +170 -122
- package/build/hooks/use_conversations_cache.js.map +1 -1
- package/build/hooks/use_conversations_jolt_events.d.ts.map +1 -1
- package/build/hooks/use_conversations_jolt_events.js +47 -20
- package/build/hooks/use_conversations_jolt_events.js.map +1 -1
- package/build/hooks/use_mark_latest_message_read.d.ts.map +1 -1
- package/build/hooks/use_mark_latest_message_read.js +5 -4
- package/build/hooks/use_mark_latest_message_read.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_actions_screen.d.ts +2 -0
- package/build/screens/conversation_actions_screen.d.ts.map +1 -1
- package/build/screens/conversation_actions_screen.js +380 -46
- package/build/screens/conversation_actions_screen.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 +5 -0
- package/build/screens/conversations/conversations_screen.d.ts.map +1 -1
- package/build/screens/conversations/conversations_screen.js +156 -31
- package/build/screens/conversations/conversations_screen.js.map +1 -1
- package/build/types/jolt_events/index.d.ts +2 -0
- package/build/types/jolt_events/index.d.ts.map +1 -1
- package/build/types/jolt_events/index.js.map +1 -1
- package/build/types/jolt_events/person_events.d.ts +9 -0
- package/build/types/jolt_events/person_events.d.ts.map +1 -0
- package/build/types/jolt_events/person_events.js +2 -0
- package/build/types/jolt_events/person_events.js.map +1 -0
- package/build/utils/jolt/parse_stream_user_event_type.d.ts +3 -0
- package/build/utils/jolt/parse_stream_user_event_type.d.ts.map +1 -0
- package/build/utils/jolt/parse_stream_user_event_type.js +9 -0
- package/build/utils/jolt/parse_stream_user_event_type.js.map +1 -0
- package/build/utils/native_adapters/configuration.d.ts +3 -0
- package/build/utils/native_adapters/configuration.d.ts.map +1 -1
- package/build/utils/native_adapters/configuration.js +3 -0
- package/build/utils/native_adapters/configuration.js.map +1 -1
- package/build/utils/native_adapters/index.d.ts +1 -0
- package/build/utils/native_adapters/index.d.ts.map +1 -1
- package/build/utils/native_adapters/index.js +1 -0
- package/build/utils/native_adapters/index.js.map +1 -1
- package/build/utils/native_adapters/updates.d.ts +11 -0
- package/build/utils/native_adapters/updates.d.ts.map +1 -0
- package/build/utils/native_adapters/updates.js +8 -0
- package/build/utils/native_adapters/updates.js.map +1 -0
- package/build/utils/throttled_refresh.d.ts +7 -0
- package/build/utils/throttled_refresh.d.ts.map +1 -0
- package/build/utils/throttled_refresh.js +42 -0
- package/build/utils/throttled_refresh.js.map +1 -0
- package/package.json +3 -3
- package/src/__tests__/contexts/session_context.tsx +19 -39
- 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__/bulk_conversation_actions_bar.test.tsx +95 -0
- package/src/components/conversations/__tests__/conversation_actions.test.tsx +35 -3
- 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/bulk_conversation_actions_bar.tsx +140 -0
- package/src/components/conversations/conversation_actions.tsx +17 -9
- package/src/components/conversations/conversation_preview.tsx +20 -2
- package/src/components/conversations/conversations.tsx +2 -1
- package/src/components/display/__tests__/filter_dropdown.test.tsx +1 -19
- package/src/components/display/__tests__/icon_tile.test.tsx +24 -7
- package/src/components/display/checkbox.tsx +47 -0
- package/src/components/display/icon.tsx +3 -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/api_provider.tsx +2 -0
- package/src/contexts/conversations_context.tsx +69 -2
- package/src/contexts/session_context.tsx +3 -1
- package/src/hooks/__tests__/jolt_refresh_throttling.test.tsx +194 -0
- package/src/hooks/__tests__/use_bulk_conversation_actions.test.tsx +119 -0
- package/src/hooks/__tests__/use_conversations_jolt_events.test.tsx +1 -0
- package/src/hooks/__tests__/use_conversations_mark_read.test.tsx +38 -12
- package/src/hooks/__tests__/use_hide_conversation.test.tsx +15 -3
- package/src/hooks/__tests__/use_mark_latest_message_read.test.tsx +23 -2
- package/src/hooks/use_bulk_conversation_actions.ts +173 -0
- package/src/hooks/use_conversation_jolt_events.ts +2 -1
- package/src/hooks/use_conversations_actions.ts +7 -4
- package/src/hooks/use_conversations_cache.ts +33 -26
- package/src/hooks/use_conversations_jolt_events.ts +24 -10
- package/src/hooks/use_mark_latest_message_read.ts +6 -5
- package/src/navigation/index.tsx +8 -8
- package/src/screens/__tests__/conversation_actions_screen.test.tsx +48 -6
- 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_actions_screen.tsx +145 -12
- package/src/screens/conversation_filter_recipients/components/checkbox_row.tsx +3 -35
- package/src/screens/conversations/__tests__/conversations_screen.test.tsx +35 -9
- 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 +67 -3
- package/src/screens/search/components/__tests__/search_results_list.test.tsx +1 -0
- package/src/types/jolt_events/index.ts +2 -0
- package/src/types/jolt_events/person_events.ts +16 -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__/throttled_refresh.test.ts +101 -0
- package/src/utils/__tests__/uri.test.ts +51 -0
- package/src/utils/jolt/__tests__/parse_stream_user_event_type.test.ts +27 -0
- package/src/utils/jolt/parse_stream_user_event_type.ts +16 -0
- package/src/utils/native_adapters/configuration.ts +5 -0
- package/src/utils/native_adapters/index.ts +1 -0
- package/src/utils/native_adapters/updates.ts +16 -0
- package/src/utils/throttled_refresh.ts +62 -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__/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
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { StreamUserUpdatedEvent } from '../../../types/jolt_events'
|
|
2
|
+
import { parseStreamUserEventType } from '../parse_stream_user_event_type'
|
|
3
|
+
|
|
4
|
+
const event = (data: unknown) =>
|
|
5
|
+
({
|
|
6
|
+
event: 'STREAM_USER_UPDATED',
|
|
7
|
+
channel: 'chat.people.1',
|
|
8
|
+
data: { data },
|
|
9
|
+
}) as StreamUserUpdatedEvent
|
|
10
|
+
|
|
11
|
+
describe('parseStreamUserEventType', () => {
|
|
12
|
+
it('reads the event type out of the JSON payload', () => {
|
|
13
|
+
expect(parseStreamUserEventType(event('{"event_type":"message.created"}'))).toBe(
|
|
14
|
+
'message.created'
|
|
15
|
+
)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('treats an empty payload as missing', () => {
|
|
19
|
+
expect(parseStreamUserEventType(event('{}'))).toBeUndefined()
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('treats a payload that fails to parse as missing', () => {
|
|
23
|
+
expect(parseStreamUserEventType(event('not json'))).toBeUndefined()
|
|
24
|
+
expect(parseStreamUserEventType(event(undefined))).toBeUndefined()
|
|
25
|
+
expect(parseStreamUserEventType(event('null'))).toBeUndefined()
|
|
26
|
+
})
|
|
27
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { StreamUserEventType, StreamUserUpdatedEvent } from '../../types/jolt_events'
|
|
2
|
+
|
|
3
|
+
interface StreamUserEventData {
|
|
4
|
+
event_type?: StreamUserEventType
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const parseStreamUserEventType = (
|
|
8
|
+
event: StreamUserUpdatedEvent
|
|
9
|
+
): StreamUserEventType | undefined => {
|
|
10
|
+
try {
|
|
11
|
+
const parsed = JSON.parse(event.data.data) as StreamUserEventData | null
|
|
12
|
+
return parsed?.event_type
|
|
13
|
+
} catch {
|
|
14
|
+
return undefined
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -9,6 +9,7 @@ import { LinkingAdapter } from './linking'
|
|
|
9
9
|
import { LogAdapter } from './log'
|
|
10
10
|
import { MenuAdapter } from './menu'
|
|
11
11
|
import { StorageAdapter } from './storage_adapter'
|
|
12
|
+
import { UpdatesAdapter } from './updates'
|
|
12
13
|
import { VideoAdapter } from './video'
|
|
13
14
|
|
|
14
15
|
type ChatConfigurations = {
|
|
@@ -21,6 +22,7 @@ type ChatConfigurations = {
|
|
|
21
22
|
linking?: LinkingAdapter
|
|
22
23
|
haptic?: HapticAdapter
|
|
23
24
|
menu?: MenuAdapter
|
|
25
|
+
updates?: UpdatesAdapter
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
export class ChatAdapters {
|
|
@@ -34,6 +36,7 @@ export class ChatAdapters {
|
|
|
34
36
|
Linking = configurations.linking || new LinkingAdapter(RNLinking)
|
|
35
37
|
Haptic = configurations.haptic || new HapticAdapter()
|
|
36
38
|
Menu = configurations.menu || new MenuAdapter()
|
|
39
|
+
Updates = configurations.updates || new UpdatesAdapter()
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
42
|
|
|
@@ -87,6 +90,8 @@ export let Haptic: HapticAdapter = new HapticAdapter()
|
|
|
87
90
|
|
|
88
91
|
export let Menu: MenuAdapter = new MenuAdapter()
|
|
89
92
|
|
|
93
|
+
export let Updates: UpdatesAdapter = new UpdatesAdapter()
|
|
94
|
+
|
|
90
95
|
export let Storage = new StorageAdapter({
|
|
91
96
|
getItem: AsyncStorage.getItem,
|
|
92
97
|
setItem: AsyncStorage.setItem,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { noop } from 'lodash'
|
|
2
|
+
|
|
3
|
+
interface Updates {
|
|
4
|
+
useDownloadedUpdateId: () => string | undefined
|
|
5
|
+
restart: () => void
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export class UpdatesAdapter {
|
|
9
|
+
useDownloadedUpdateId: () => string | undefined
|
|
10
|
+
restart: () => void
|
|
11
|
+
|
|
12
|
+
constructor(methods?: Updates) {
|
|
13
|
+
this.useDownloadedUpdateId = methods?.useDownloadedUpdateId ?? (() => undefined)
|
|
14
|
+
this.restart = methods?.restart ?? noop
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { hashKey, QueryClient, QueryKey } from '@tanstack/react-query'
|
|
2
|
+
import { DebouncedFuncLeading, throttle } from 'lodash'
|
|
3
|
+
|
|
4
|
+
export const REFRESH_THROTTLE_MS = 3000
|
|
5
|
+
|
|
6
|
+
type Refresh = () => unknown
|
|
7
|
+
|
|
8
|
+
interface ThrottledRefresh {
|
|
9
|
+
run: DebouncedFuncLeading<(refresh: Refresh) => void>
|
|
10
|
+
lastEvent?: object
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const refreshesByClient = new WeakMap<QueryClient, Map<string, ThrottledRefresh>>()
|
|
14
|
+
|
|
15
|
+
const refreshesFor = (queryClient: QueryClient) => {
|
|
16
|
+
const existing = refreshesByClient.get(queryClient)
|
|
17
|
+
if (existing) return existing
|
|
18
|
+
|
|
19
|
+
const refreshes = new Map<string, ThrottledRefresh>()
|
|
20
|
+
refreshesByClient.set(queryClient, refreshes)
|
|
21
|
+
return refreshes
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const throttledRefreshFor = (queryClient: QueryClient, key: QueryKey) => {
|
|
25
|
+
const refreshes = refreshesFor(queryClient)
|
|
26
|
+
const hashedKey = hashKey(key)
|
|
27
|
+
const existing = refreshes.get(hashedKey)
|
|
28
|
+
if (existing) return existing
|
|
29
|
+
|
|
30
|
+
const created: ThrottledRefresh = {
|
|
31
|
+
run: throttle(
|
|
32
|
+
(refresh: Refresh) => {
|
|
33
|
+
refresh()
|
|
34
|
+
},
|
|
35
|
+
REFRESH_THROTTLE_MS,
|
|
36
|
+
{ leading: true, trailing: true }
|
|
37
|
+
),
|
|
38
|
+
}
|
|
39
|
+
refreshes.set(hashedKey, created)
|
|
40
|
+
return created
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const throttledRefresh = (
|
|
44
|
+
queryClient: QueryClient,
|
|
45
|
+
key: QueryKey,
|
|
46
|
+
event: object,
|
|
47
|
+
refresh: Refresh
|
|
48
|
+
) => {
|
|
49
|
+
const throttled = throttledRefreshFor(queryClient, key)
|
|
50
|
+
if (throttled.lastEvent === event) return
|
|
51
|
+
|
|
52
|
+
throttled.lastEvent = event
|
|
53
|
+
throttled.run(refresh)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const cancelThrottledRefreshes = (queryClient: QueryClient) => {
|
|
57
|
+
const refreshes = refreshesByClient.get(queryClient)
|
|
58
|
+
if (!refreshes) return
|
|
59
|
+
|
|
60
|
+
refreshes.forEach(({ run }) => run.cancel())
|
|
61
|
+
refreshesByClient.delete(queryClient)
|
|
62
|
+
}
|
|
@@ -1,313 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for Event/CustomEvent/EventTarget polyfills
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { CustomEvent } from '../polyfills/events/CustomEvent'
|
|
6
|
-
// Set up global polyfill for tests
|
|
7
|
-
import Event from '../polyfills/events/Event'
|
|
8
|
-
import EventTarget from '../polyfills/events/EventTarget'
|
|
9
|
-
;(global as any).Event = Event
|
|
10
|
-
;(global as any).CustomEvent = CustomEvent
|
|
11
|
-
|
|
12
|
-
describe('Event Polyfill', () => {
|
|
13
|
-
describe('Event', () => {
|
|
14
|
-
it('should create a basic event', () => {
|
|
15
|
-
const event = new Event('test')
|
|
16
|
-
expect(event.type).toBe('test')
|
|
17
|
-
expect(event.bubbles).toBe(false)
|
|
18
|
-
expect(event.cancelable).toBe(false)
|
|
19
|
-
expect(event.composed).toBe(false)
|
|
20
|
-
expect(event.defaultPrevented).toBe(false)
|
|
21
|
-
expect(event.isTrusted).toBe(false)
|
|
22
|
-
expect(event.eventPhase).toBe(Event.NONE)
|
|
23
|
-
expect(typeof event.timeStamp).toBe('number')
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
it('should create an event with options', () => {
|
|
27
|
-
const event = new Event('test', {
|
|
28
|
-
bubbles: true,
|
|
29
|
-
cancelable: true,
|
|
30
|
-
composed: true,
|
|
31
|
-
})
|
|
32
|
-
expect(event.bubbles).toBe(true)
|
|
33
|
-
expect(event.cancelable).toBe(true)
|
|
34
|
-
expect(event.composed).toBe(true)
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
it('should have correct phase constants', () => {
|
|
38
|
-
expect(Event.NONE).toBe(0)
|
|
39
|
-
expect(Event.CAPTURING_PHASE).toBe(1)
|
|
40
|
-
expect(Event.AT_TARGET).toBe(2)
|
|
41
|
-
expect(Event.BUBBLING_PHASE).toBe(3)
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
it('should prevent default when cancelable', () => {
|
|
45
|
-
const event = new Event('test', { cancelable: true })
|
|
46
|
-
expect(event.defaultPrevented).toBe(false)
|
|
47
|
-
event.preventDefault()
|
|
48
|
-
expect(event.defaultPrevented).toBe(true)
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
it('should not prevent default when not cancelable', () => {
|
|
52
|
-
const event = new Event('test', { cancelable: false })
|
|
53
|
-
event.preventDefault()
|
|
54
|
-
expect(event.defaultPrevented).toBe(false)
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
it('should support stopPropagation', () => {
|
|
58
|
-
const event = new Event('test')
|
|
59
|
-
// No error thrown - internal flags are set
|
|
60
|
-
event.stopPropagation()
|
|
61
|
-
event.stopImmediatePropagation()
|
|
62
|
-
})
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
describe('CustomEvent', () => {
|
|
66
|
-
it('should create a custom event with detail', () => {
|
|
67
|
-
const detail = { foo: 'bar', count: 42 }
|
|
68
|
-
const event = new CustomEvent('custom', { detail })
|
|
69
|
-
expect(event.type).toBe('custom')
|
|
70
|
-
expect(event.detail).toEqual(detail)
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
it('should inherit from Event', () => {
|
|
74
|
-
const event = new CustomEvent('custom', {
|
|
75
|
-
bubbles: true,
|
|
76
|
-
cancelable: true,
|
|
77
|
-
detail: 'test',
|
|
78
|
-
})
|
|
79
|
-
expect(event instanceof Event).toBe(true)
|
|
80
|
-
expect(event.bubbles).toBe(true)
|
|
81
|
-
expect(event.cancelable).toBe(true)
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
it('should handle undefined detail', () => {
|
|
85
|
-
const event = new CustomEvent('custom')
|
|
86
|
-
expect(event.detail).toBeUndefined()
|
|
87
|
-
})
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
describe('EventTarget', () => {
|
|
91
|
-
let target: EventTarget
|
|
92
|
-
|
|
93
|
-
beforeEach(() => {
|
|
94
|
-
target = new EventTarget()
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
it('should add and remove event listeners', () => {
|
|
98
|
-
const listener = jest.fn()
|
|
99
|
-
target.addEventListener('test', listener)
|
|
100
|
-
|
|
101
|
-
const event = new Event('test')
|
|
102
|
-
const result = target.dispatchEvent(event)
|
|
103
|
-
|
|
104
|
-
expect(listener).toHaveBeenCalledWith(event)
|
|
105
|
-
expect(listener).toHaveBeenCalledTimes(1)
|
|
106
|
-
expect(result).toBe(true) // not prevented
|
|
107
|
-
|
|
108
|
-
target.removeEventListener('test', listener)
|
|
109
|
-
target.dispatchEvent(new Event('test'))
|
|
110
|
-
expect(listener).toHaveBeenCalledTimes(1) // not called again
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
it('should handle multiple listeners for the same event', () => {
|
|
114
|
-
const listener1 = jest.fn()
|
|
115
|
-
const listener2 = jest.fn()
|
|
116
|
-
|
|
117
|
-
target.addEventListener('test', listener1)
|
|
118
|
-
target.addEventListener('test', listener2)
|
|
119
|
-
|
|
120
|
-
target.dispatchEvent(new Event('test'))
|
|
121
|
-
|
|
122
|
-
expect(listener1).toHaveBeenCalledTimes(1)
|
|
123
|
-
expect(listener2).toHaveBeenCalledTimes(1)
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
it('should handle once option', () => {
|
|
127
|
-
const listener = jest.fn()
|
|
128
|
-
target.addEventListener('test', listener, { once: true })
|
|
129
|
-
|
|
130
|
-
target.dispatchEvent(new Event('test'))
|
|
131
|
-
target.dispatchEvent(new Event('test'))
|
|
132
|
-
|
|
133
|
-
expect(listener).toHaveBeenCalledTimes(1)
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
it('should handle capture option', () => {
|
|
137
|
-
const listener = jest.fn()
|
|
138
|
-
target.addEventListener('test', listener, { capture: true })
|
|
139
|
-
|
|
140
|
-
target.dispatchEvent(new Event('test'))
|
|
141
|
-
expect(listener).toHaveBeenCalledTimes(1)
|
|
142
|
-
|
|
143
|
-
target.removeEventListener('test', listener, { capture: true })
|
|
144
|
-
target.dispatchEvent(new Event('test'))
|
|
145
|
-
expect(listener).toHaveBeenCalledTimes(1)
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
it('should handle passive option', () => {
|
|
149
|
-
const listener = jest.fn()
|
|
150
|
-
target.addEventListener('test', listener, { passive: true })
|
|
151
|
-
|
|
152
|
-
target.dispatchEvent(new Event('test'))
|
|
153
|
-
expect(listener).toHaveBeenCalledTimes(1)
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
it('should handle object listeners with handleEvent', () => {
|
|
157
|
-
const listener = {
|
|
158
|
-
handleEvent: jest.fn(),
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
target.addEventListener('test', listener)
|
|
162
|
-
target.dispatchEvent(new Event('test'))
|
|
163
|
-
|
|
164
|
-
expect(listener.handleEvent).toHaveBeenCalledTimes(1)
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
it('should return false when event is prevented', () => {
|
|
168
|
-
const listener = (event: Event) => {
|
|
169
|
-
event.preventDefault()
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
target.addEventListener('test', listener)
|
|
173
|
-
const event = new Event('test', { cancelable: true })
|
|
174
|
-
const result = target.dispatchEvent(event)
|
|
175
|
-
|
|
176
|
-
expect(result).toBe(false)
|
|
177
|
-
expect(event.defaultPrevented).toBe(true)
|
|
178
|
-
})
|
|
179
|
-
|
|
180
|
-
it('should set event properties during dispatch', () => {
|
|
181
|
-
let capturedEvent: Event | null = null
|
|
182
|
-
|
|
183
|
-
const listener = (event: Event) => {
|
|
184
|
-
capturedEvent = event
|
|
185
|
-
expect(event.target).toBe(target)
|
|
186
|
-
expect(event.currentTarget).toBe(target)
|
|
187
|
-
expect(event.eventPhase).toBe(Event.AT_TARGET)
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
target.addEventListener('test', listener)
|
|
191
|
-
target.dispatchEvent(new Event('test'))
|
|
192
|
-
|
|
193
|
-
expect(capturedEvent).not.toBeNull()
|
|
194
|
-
// After dispatch, these should be reset
|
|
195
|
-
expect(capturedEvent!.currentTarget).toBeNull()
|
|
196
|
-
expect(capturedEvent!.eventPhase).toBe(Event.NONE)
|
|
197
|
-
})
|
|
198
|
-
|
|
199
|
-
it('should handle bubbling events', () => {
|
|
200
|
-
const listener = jest.fn()
|
|
201
|
-
target.addEventListener('test', listener)
|
|
202
|
-
|
|
203
|
-
const bubblingEvent = new Event('test', { bubbles: true })
|
|
204
|
-
target.dispatchEvent(bubblingEvent)
|
|
205
|
-
|
|
206
|
-
expect(listener).toHaveBeenCalledWith(bubblingEvent)
|
|
207
|
-
})
|
|
208
|
-
|
|
209
|
-
it('should handle error in listener gracefully', () => {
|
|
210
|
-
const errorListener = () => {
|
|
211
|
-
throw new Error('Test error')
|
|
212
|
-
}
|
|
213
|
-
const normalListener = jest.fn()
|
|
214
|
-
|
|
215
|
-
// Mock console.error to avoid test output noise
|
|
216
|
-
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation()
|
|
217
|
-
|
|
218
|
-
target.addEventListener('test', errorListener)
|
|
219
|
-
target.addEventListener('test', normalListener)
|
|
220
|
-
|
|
221
|
-
target.dispatchEvent(new Event('test'))
|
|
222
|
-
|
|
223
|
-
expect(normalListener).toHaveBeenCalledTimes(1)
|
|
224
|
-
expect(consoleErrorSpy).toHaveBeenCalled()
|
|
225
|
-
|
|
226
|
-
consoleErrorSpy.mockRestore()
|
|
227
|
-
})
|
|
228
|
-
|
|
229
|
-
it('should ignore null listeners', () => {
|
|
230
|
-
// Should not throw
|
|
231
|
-
target.addEventListener('test', null)
|
|
232
|
-
target.removeEventListener('test', null)
|
|
233
|
-
target.dispatchEvent(new Event('test'))
|
|
234
|
-
})
|
|
235
|
-
|
|
236
|
-
it('should handle composed path', () => {
|
|
237
|
-
let composedPath: readonly EventTarget[] | null = null
|
|
238
|
-
|
|
239
|
-
const listener = (event: Event) => {
|
|
240
|
-
composedPath = event.composedPath()
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
target.addEventListener('test', listener)
|
|
244
|
-
target.dispatchEvent(new Event('test'))
|
|
245
|
-
|
|
246
|
-
expect(composedPath).toEqual([target])
|
|
247
|
-
})
|
|
248
|
-
|
|
249
|
-
it('should prevent duplicate listeners', () => {
|
|
250
|
-
const listener = jest.fn()
|
|
251
|
-
|
|
252
|
-
target.addEventListener('test', listener)
|
|
253
|
-
target.addEventListener('test', listener) // Same listener
|
|
254
|
-
|
|
255
|
-
target.dispatchEvent(new Event('test'))
|
|
256
|
-
expect(listener).toHaveBeenCalledTimes(1) // Only called once
|
|
257
|
-
})
|
|
258
|
-
})
|
|
259
|
-
|
|
260
|
-
describe('Event flow integration', () => {
|
|
261
|
-
it('should work with CustomEvent dispatch', () => {
|
|
262
|
-
const target = new EventTarget()
|
|
263
|
-
const listener = jest.fn()
|
|
264
|
-
const detail = { message: 'hello' }
|
|
265
|
-
|
|
266
|
-
target.addEventListener('custom', listener)
|
|
267
|
-
|
|
268
|
-
const event = new CustomEvent('custom', {
|
|
269
|
-
detail,
|
|
270
|
-
bubbles: true,
|
|
271
|
-
cancelable: true,
|
|
272
|
-
})
|
|
273
|
-
|
|
274
|
-
const result = target.dispatchEvent(event)
|
|
275
|
-
|
|
276
|
-
expect(listener).toHaveBeenCalledWith(event)
|
|
277
|
-
expect(listener.mock.calls[0][0].detail).toEqual(detail)
|
|
278
|
-
expect(result).toBe(true)
|
|
279
|
-
})
|
|
280
|
-
|
|
281
|
-
it('should handle stopImmediatePropagation', () => {
|
|
282
|
-
const target = new EventTarget()
|
|
283
|
-
const listener1 = jest.fn((event: Event) => {
|
|
284
|
-
event.stopImmediatePropagation()
|
|
285
|
-
})
|
|
286
|
-
const listener2 = jest.fn()
|
|
287
|
-
|
|
288
|
-
target.addEventListener('test', listener1)
|
|
289
|
-
target.addEventListener('test', listener2)
|
|
290
|
-
|
|
291
|
-
target.dispatchEvent(new Event('test'))
|
|
292
|
-
|
|
293
|
-
expect(listener1).toHaveBeenCalledTimes(1)
|
|
294
|
-
expect(listener2).toHaveBeenCalledTimes(0) // Stopped
|
|
295
|
-
})
|
|
296
|
-
})
|
|
297
|
-
|
|
298
|
-
describe('Global polyfill installation', () => {
|
|
299
|
-
it('should make Event available globally', () => {
|
|
300
|
-
// This tests that our polyfill setup works
|
|
301
|
-
expect(typeof (global as any).Event).toBe('function')
|
|
302
|
-
expect(typeof (global as any).CustomEvent).toBe('function')
|
|
303
|
-
|
|
304
|
-
const globalEvent = new (global as any).Event('test')
|
|
305
|
-
expect(globalEvent.type).toBe('test')
|
|
306
|
-
|
|
307
|
-
const globalCustomEvent = new (global as any).CustomEvent('custom', {
|
|
308
|
-
detail: 'test',
|
|
309
|
-
})
|
|
310
|
-
expect(globalCustomEvent.detail).toBe('test')
|
|
311
|
-
})
|
|
312
|
-
})
|
|
313
|
-
})
|
package/src/__tests__/index.tsx
DELETED
package/src/__tests__/jest.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { jestTransformPackages } from '../jest'
|
|
2
|
-
|
|
3
|
-
describe('jestTransformPackages', () => {
|
|
4
|
-
it('exports an array of package patterns', () => {
|
|
5
|
-
expect(jestTransformPackages).toEqual([
|
|
6
|
-
'@planningcenter/chat-react-native',
|
|
7
|
-
'@planningcenter/emoji-keyboard',
|
|
8
|
-
'@fortawesome',
|
|
9
|
-
])
|
|
10
|
-
})
|
|
11
|
-
})
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { Session, Uri } from '../../utils'
|
|
2
|
-
|
|
3
|
-
describe('URI', () => {
|
|
4
|
-
it('should be defined', () => {
|
|
5
|
-
expect(Uri).toBeDefined()
|
|
6
|
-
})
|
|
7
|
-
|
|
8
|
-
it('should create a new instance', () => {
|
|
9
|
-
const uri = new Uri({
|
|
10
|
-
session: new Session({ env: 'production', type: 'OAuth' }),
|
|
11
|
-
})
|
|
12
|
-
expect(uri).toBeDefined()
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
describe('baseUrl', () => {
|
|
16
|
-
describe('planning center', () => {
|
|
17
|
-
it('should return the correct base URL for production', () => {
|
|
18
|
-
const uri = new Uri({
|
|
19
|
-
session: new Session({ env: 'production', type: 'OAuth' }),
|
|
20
|
-
})
|
|
21
|
-
expect(uri.baseUrl).toBe('https://api.planningcenteronline.com')
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
it('should return the correct base URL for staging', () => {
|
|
25
|
-
const uri = new Uri({
|
|
26
|
-
session: new Session({ env: 'staging', type: 'OAuth' }),
|
|
27
|
-
})
|
|
28
|
-
expect(uri.baseUrl).toBe('https://api-staging.planningcenteronline.com')
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
it('should return the correct base URL for development', () => {
|
|
32
|
-
const uri = new Uri({
|
|
33
|
-
session: new Session({ env: 'development', type: 'OAuth' }),
|
|
34
|
-
})
|
|
35
|
-
expect(uri.baseUrl).toBe('https://api.pco.test')
|
|
36
|
-
})
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
describe('church center', () => {
|
|
40
|
-
it('should return the correct base URL for production', () => {
|
|
41
|
-
const uri = new Uri({
|
|
42
|
-
session: new Session({ env: 'production', type: 'ChurchCenterOauth' }),
|
|
43
|
-
graph: 'churchcenter',
|
|
44
|
-
})
|
|
45
|
-
expect(uri.baseUrl).toBe('https://api.churchcenter.com')
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
it('should return the correct base URL for staging', () => {
|
|
49
|
-
const uri = new Uri({
|
|
50
|
-
session: new Session({ env: 'staging', type: 'ChurchCenterOauth' }),
|
|
51
|
-
graph: 'churchcenter',
|
|
52
|
-
})
|
|
53
|
-
expect(uri.baseUrl).toBe('https://api.staging.churchcenter.com')
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
it('should return the correct base URL for development', () => {
|
|
57
|
-
const uri = new Uri({
|
|
58
|
-
session: new Session({ env: 'development', type: 'ChurchCenterOauth' }),
|
|
59
|
-
graph: 'churchcenter',
|
|
60
|
-
})
|
|
61
|
-
expect(uri.baseUrl).toBe('https://api.churchcenter.test')
|
|
62
|
-
})
|
|
63
|
-
})
|
|
64
|
-
})
|
|
65
|
-
})
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
2
|
-
import { render } from '@testing-library/react-native'
|
|
3
|
-
import React from 'react'
|
|
4
|
-
import { buildTestQueryClient } from '../../../__utils__/query_client'
|
|
5
|
-
import { ChatProvider } from '../../../contexts/chat_context'
|
|
6
|
-
import { VersionFooter } from '../version_footer'
|
|
7
|
-
|
|
8
|
-
const { version: packageVersion } = require('../../../../package.json') as { version: string }
|
|
9
|
-
|
|
10
|
-
let queryClient: QueryClient
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
queryClient = buildTestQueryClient()
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
afterEach(() => {
|
|
17
|
-
queryClient.clear()
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
const Wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
21
|
-
<QueryClientProvider client={queryClient}>
|
|
22
|
-
<ChatProvider
|
|
23
|
-
value={{
|
|
24
|
-
token: {
|
|
25
|
-
access_token: '',
|
|
26
|
-
created_at: 0,
|
|
27
|
-
expires_in: 0,
|
|
28
|
-
scope: '',
|
|
29
|
-
refresh_token: '',
|
|
30
|
-
token_type: '',
|
|
31
|
-
},
|
|
32
|
-
onUnauthorizedResponse: () => {},
|
|
33
|
-
theme: { theme: { colors: {} }, colorScheme: 'light' },
|
|
34
|
-
}}
|
|
35
|
-
>
|
|
36
|
-
{children}
|
|
37
|
-
</ChatProvider>
|
|
38
|
-
</QueryClientProvider>
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
describe('VersionFooter', () => {
|
|
42
|
-
it('shows the published chat-react-native version', () => {
|
|
43
|
-
const { getByText } = render(<VersionFooter />, { wrapper: Wrapper })
|
|
44
|
-
|
|
45
|
-
expect(packageVersion).toMatch(/^\d+\.\d+\.\d+/)
|
|
46
|
-
expect(getByText(`Chat v${packageVersion}`)).toBeTruthy()
|
|
47
|
-
})
|
|
48
|
-
})
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
})
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { membershipSyncInfoText } from '../membership_sync_info_text'
|
|
2
|
-
|
|
3
|
-
describe('membershipSyncInfoText', () => {
|
|
4
|
-
it('explains membership sync and history visibility for a group', () => {
|
|
5
|
-
expect(membershipSyncInfoText('the group')).toBe(
|
|
6
|
-
'This conversation will stay in sync with the group. Members will automatically be added or removed, and new members will see the history.'
|
|
7
|
-
)
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
it('explains membership sync and history visibility for teams', () => {
|
|
11
|
-
expect(membershipSyncInfoText('the teams')).toBe(
|
|
12
|
-
'This conversation will stay in sync with the teams. Members will automatically be added or removed, and new members will see the history.'
|
|
13
|
-
)
|
|
14
|
-
})
|
|
15
|
-
})
|