@openpeepshq/rn-components 0.23.0 → 0.28.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.
Files changed (38) hide show
  1. package/package.json +4 -4
  2. package/src/components/conversations/ConversationPreviewCard.test.tsx +345 -0
  3. package/src/components/conversations/ConversationPreviewCard.tsx +29 -24
  4. package/src/components/custom/navigation/side-menu.test.tsx +9 -0
  5. package/src/components/custom/navigation/side-menu.tsx +19 -3
  6. package/src/components/groups/GroupAvatar.test.tsx +20 -2
  7. package/src/components/groups/GroupAvatar.tsx +7 -1
  8. package/src/components/jams/JamCallParticipant.test.tsx +303 -0
  9. package/src/components/jams/JamCallParticipant.tsx +7 -1
  10. package/src/components/jams/JamPeopleDrawer.test.tsx +104 -9
  11. package/src/components/jams/JamPeopleDrawer.tsx +48 -11
  12. package/src/components/jams/JamRequestJoin.test.tsx +163 -0
  13. package/src/components/jams/JamRequestJoin.tsx +31 -15
  14. package/src/components/jams/useLateTrackMediaStream.test.ts +139 -25
  15. package/src/components/jams/useLateTrackMediaStream.ts +62 -19
  16. package/src/components/navigation/main-navigator.tsx +5 -0
  17. package/src/components/navigation/nativeRouter.tsx +1 -0
  18. package/src/components/navigation/parent-back.ts +1 -0
  19. package/src/components/navigation/types/main.ts +1 -0
  20. package/src/components/post/pieces/ShareMenu.test.tsx +105 -11
  21. package/src/components/post/pieces/ShareMenu.tsx +55 -10
  22. package/src/components/post/pieces/modals/SendToConversationModal.tsx +140 -0
  23. package/src/components/post/pieces/modals/ShareIntoGroupModal.tsx +121 -0
  24. package/src/components/post/pieces/modals/index.ts +2 -0
  25. package/src/components/post/pieces/sharePickers.test.tsx +819 -0
  26. package/src/components/profile/Avatar.test.tsx +19 -0
  27. package/src/components/profile/Avatar.tsx +9 -1
  28. package/src/lib/push-notifications.test.ts +244 -0
  29. package/src/lib/push-notifications.ts +65 -0
  30. package/src/pages/auth/Login.tsx +16 -2
  31. package/src/pages/conversations/Index.test.tsx +235 -0
  32. package/src/pages/conversations/Index.tsx +15 -16
  33. package/src/pages/index.ts +1 -0
  34. package/src/pages/settings/Account.test.tsx +4 -0
  35. package/src/pages/settings/Account.tsx +14 -0
  36. package/src/pages/settings/CalendarFeed.test.tsx +269 -0
  37. package/src/pages/settings/CalendarFeed.tsx +77 -0
  38. package/src/pages/settings/Index.tsx +4 -0
@@ -101,6 +101,10 @@ jest.mock('../../lib/downloadFile', () => ({
101
101
  downloadDocument,
102
102
  }));
103
103
 
104
+ jest.mock('../../lib/push-notifications', () => ({
105
+ unregisterPushForLogout: jest.fn(async () => 'ok'),
106
+ }));
107
+
104
108
  jest.mock('../../components/ui/themed-view', () => ({
105
109
  ThemedView: (props: { children?: unknown }) =>
106
110
  React.createElement('ThemedView', null, props.children),
@@ -13,6 +13,7 @@ import { Account } from '@openpeepshq/common';
13
13
  import { ActivityIndicator, View } from 'react-native';
14
14
  import { useTranslation } from 'react-i18next';
15
15
  import { downloadDocument } from '../../lib/downloadFile';
16
+ import { unregisterPushForLogout } from '../../lib/push-notifications';
16
17
 
17
18
  type AccountSettingsProps = MainScreenProps<'AccountSettings'>;
18
19
 
@@ -139,7 +140,20 @@ export const AccountSettings: React.FC<AccountSettingsProps> = () => {
139
140
  await queryClient.invalidateQueries({
140
141
  queryKey: ['profile'],
141
142
  });
143
+ // Best-effort cleanup (never throws); logout always follows. The RN
144
+ // side owns FCM cleanup, so this outcome — not the web pushCleanup
145
+ // flag — is what the logout toast reflects on native.
146
+ const pushResult = await unregisterPushForLogout(client);
142
147
  await logout();
148
+ if (pushResult === 'failed') {
149
+ Toast.show({
150
+ type: 'error',
151
+ text1: t('settings.notifications.pushCleanupFailed', {
152
+ defaultValue:
153
+ 'Could not remove push notifications for this device.',
154
+ }),
155
+ });
156
+ }
143
157
  })
144
158
  .catch((err) => {
145
159
  console.log('response', err);
@@ -0,0 +1,269 @@
1
+ /**
2
+ * Coverage for the native CalendarFeedSettings screen (issue #408 fast-rework
3
+ * review, item 1). The web counterpart is covered by
4
+ * `platform/react/src/pages/settings/CalendarFeed.test.tsx`; this pins the RN
5
+ * mirror: the same feedUrl/busy/toast surface rendered through the RN
6
+ * primitives (Button, ThemedText, Toast.show, Clipboard.setString), the
7
+ * state-specific busy labels, and the create/delete wiring to the shared
8
+ * `useCalendarFeedLink` hook.
9
+ *
10
+ * The node jest env has no native modules, so react-native, toast, clipboard,
11
+ * i18n, the page-chrome barrel and the shared hook are mocked (mirroring
12
+ * Welcome.test.tsx / Members.test.tsx); the screen itself renders for real
13
+ * under react-test-renderer. The Button mock synthesizes a testID from the
14
+ * variant/size props so the copy (ghost icon), delete (outline) and create
15
+ * (default) buttons are queryable without asserting on style props.
16
+ */
17
+ const React = require('react');
18
+ const ReactTestRenderer = require('react-test-renderer');
19
+ const { act } = React;
20
+
21
+ let mockHook: {
22
+ feedUrl: string | undefined;
23
+ creating: boolean;
24
+ revoking: boolean;
25
+ status: { type: 'success' | 'error'; message: string } | null;
26
+ createLink: () => Promise<unknown>;
27
+ revokeLink: () => Promise<unknown>;
28
+ };
29
+
30
+ const toastShowMock = jest.fn();
31
+ const setStringMock = jest.fn();
32
+ const setPageHeaderSpy = jest.fn();
33
+
34
+ jest.mock('react-native', () => ({
35
+ View: (props: { className?: string; children?: unknown }) =>
36
+ React.createElement('View', { className: props.className }, props.children),
37
+ }));
38
+
39
+ jest.mock('@react-native-clipboard/clipboard', () => ({
40
+ __esModule: true,
41
+ default: { setString: setStringMock },
42
+ }));
43
+
44
+ jest.mock('react-native-toast-message', () => ({
45
+ __esModule: true,
46
+ default: { show: toastShowMock },
47
+ }));
48
+
49
+ // The screen calls t(key) without defaultValue — resolve keys verbatim.
50
+ jest.mock('react-i18next', () => ({
51
+ useTranslation: () => ({ t: (key: string) => key }),
52
+ }));
53
+
54
+ jest.mock('../../components/layout', () => ({
55
+ useSetPageHeader: (...args: unknown[]) => setPageHeaderSpy(...args),
56
+ }));
57
+
58
+ jest.mock('../../components/icons/index', () => ({
59
+ CopyIcon: () => React.createElement('CopyIcon'),
60
+ }));
61
+
62
+ jest.mock('../../components/ui/button', () => ({
63
+ Button: (props: {
64
+ children?: unknown;
65
+ onPress?: () => void;
66
+ disabled?: boolean;
67
+ accessibilityLabel?: string;
68
+ variant?: string;
69
+ size?: string;
70
+ }) =>
71
+ React.createElement(
72
+ 'Button',
73
+ {
74
+ 'testID':
75
+ props.variant === 'outline'
76
+ ? 'delete-button'
77
+ : props.size === 'icon'
78
+ ? 'copy-button'
79
+ : 'action-button',
80
+ 'onPress': props.onPress,
81
+ 'disabled': props.disabled,
82
+ 'aria-label': props.accessibilityLabel,
83
+ },
84
+ props.children
85
+ ),
86
+ }));
87
+
88
+ jest.mock('../../components/ui/themed-text', () => ({
89
+ ThemedText: (props: { children?: unknown; selectable?: boolean }) =>
90
+ React.createElement('ThemedText', null, props.children),
91
+ }));
92
+
93
+ jest.mock('../../components/ui/themed-view', () => ({
94
+ ThemedView: (props: { children?: unknown }) =>
95
+ React.createElement('ThemedView', null, props.children),
96
+ }));
97
+
98
+ jest.mock('@openpeepshq/react', () => ({
99
+ useCalendarFeedLink: () => mockHook,
100
+ }));
101
+
102
+ import { CalendarFeedSettings } from './CalendarFeed';
103
+
104
+ const FEED_URL =
105
+ 'https://ap.social/api/openpeeps/core/v1/events/feed?token=abc123';
106
+
107
+ const resetHook = () => {
108
+ mockHook = {
109
+ feedUrl: undefined,
110
+ creating: false,
111
+ revoking: false,
112
+ status: null,
113
+ createLink: jest.fn(() => Promise.resolve({ token: 'abc123' })),
114
+ revokeLink: jest.fn(() => Promise.resolve({})),
115
+ };
116
+ };
117
+
118
+ const screenElement = () =>
119
+ React.createElement(CalendarFeedSettings, {
120
+ navigation: { navigate: () => {} },
121
+ } as unknown as never);
122
+
123
+ const renderScreen = () => {
124
+ let renderer: ReturnType<typeof ReactTestRenderer.create>;
125
+ ReactTestRenderer.act(() => {
126
+ renderer = ReactTestRenderer.create(screenElement());
127
+ });
128
+ return renderer as ReturnType<typeof ReactTestRenderer.create>;
129
+ };
130
+
131
+ const updateScreen = (
132
+ renderer: ReturnType<typeof ReactTestRenderer.create>
133
+ ) => {
134
+ ReactTestRenderer.act(() => {
135
+ renderer.update(screenElement());
136
+ });
137
+ };
138
+
139
+ describe('RN CalendarFeedSettings screen', () => {
140
+ beforeEach(() => {
141
+ (
142
+ globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }
143
+ ).IS_REACT_ACT_ENVIRONMENT = true;
144
+ resetHook();
145
+ toastShowMock.mockClear();
146
+ setStringMock.mockClear();
147
+ setPageHeaderSpy.mockClear();
148
+ });
149
+
150
+ it('renders the create action and sets the page header', () => {
151
+ const renderer = renderScreen();
152
+ const json = JSON.stringify(renderer.toJSON());
153
+ expect(json).toContain('settings.calendarFeed.introTitle');
154
+ expect(json).toContain('settings.calendarFeed.create');
155
+ // No link box before a link exists.
156
+ expect(json).not.toContain(FEED_URL);
157
+ expect(setPageHeaderSpy).toHaveBeenCalledWith(
158
+ 'settings.calendarFeed.title'
159
+ );
160
+ // No toast before any action.
161
+ expect(toastShowMock).not.toHaveBeenCalled();
162
+ });
163
+
164
+ it('shows the state-specific creating copy and disables the action while creating', () => {
165
+ mockHook.creating = true;
166
+ const renderer = renderScreen();
167
+ const json = JSON.stringify(renderer.toJSON());
168
+ expect(json).toContain('settings.calendarFeed.creating');
169
+ expect(json).not.toContain('settings.calendarFeed.create"');
170
+ const button = renderer.root.findAllByProps({ testID: 'action-button' })[0];
171
+ expect(button.props.disabled).toBe(true);
172
+ });
173
+
174
+ it('create flow: pressing create calls the hook; the URL renders and the copy button is wired to the clipboard', async () => {
175
+ const renderer = renderScreen();
176
+ const createButton = renderer.root.findAllByProps({
177
+ testID: 'action-button',
178
+ })[0];
179
+ expect(createButton.props.disabled).toBe(false);
180
+ await act(async () => {
181
+ createButton.props.onPress();
182
+ });
183
+ expect(mockHook.createLink).toHaveBeenCalledTimes(1);
184
+
185
+ // The hook resolved the feed URL — re-render with it.
186
+ mockHook.feedUrl = FEED_URL;
187
+ updateScreen(renderer);
188
+ const json = JSON.stringify(renderer.toJSON());
189
+ // The URL is rendered in the link box.
190
+ expect(json).toContain(FEED_URL);
191
+ // Copy button (icon size, ghost variant) is wired to the clipboard.
192
+ const copyButton = renderer.root.findAllByProps({
193
+ testID: 'copy-button',
194
+ })[0];
195
+ expect(copyButton.props['aria-label']).toBe('settings.calendarFeed.copy');
196
+ act(() => {
197
+ copyButton.props.onPress();
198
+ });
199
+ expect(setStringMock).toHaveBeenCalledWith(FEED_URL);
200
+ // The delete action is present and enabled.
201
+ const deleteButton = renderer.root.findAllByProps({
202
+ testID: 'delete-button',
203
+ })[0];
204
+ expect(deleteButton.props.disabled).toBe(false);
205
+ expect(json).toContain('settings.calendarFeed.delete');
206
+ });
207
+
208
+ it('shows the state-specific deleting copy and disables the delete action while revoking', () => {
209
+ mockHook.feedUrl = FEED_URL;
210
+ mockHook.revoking = true;
211
+ const renderer = renderScreen();
212
+ const json = JSON.stringify(renderer.toJSON());
213
+ expect(json).toContain('settings.calendarFeed.deleting');
214
+ expect(json).not.toContain('settings.calendarFeed.delete"');
215
+ const deleteButton = renderer.root.findAllByProps({
216
+ testID: 'delete-button',
217
+ })[0];
218
+ expect(deleteButton.props.disabled).toBe(true);
219
+ });
220
+
221
+ it('revoke flow: pressing delete calls the hook; the toast carries the hook status and the screen returns to create', async () => {
222
+ const renderer = renderScreen();
223
+ mockHook.feedUrl = FEED_URL;
224
+ updateScreen(renderer);
225
+ const deleteButton = renderer.root.findAllByProps({
226
+ testID: 'delete-button',
227
+ })[0];
228
+ await act(async () => {
229
+ deleteButton.props.onPress();
230
+ });
231
+ expect(mockHook.revokeLink).toHaveBeenCalledTimes(1);
232
+
233
+ // The hook revoked the link — re-render with the cleared feed and the
234
+ // success status the real hook sets.
235
+ mockHook.feedUrl = undefined;
236
+ mockHook.status = {
237
+ type: 'success',
238
+ message: 'settings.calendarFeed.revokeSuccess',
239
+ };
240
+ updateScreen(renderer);
241
+ // Toast.show received the hook's status type and message.
242
+ expect(toastShowMock).toHaveBeenCalledWith({
243
+ type: 'success',
244
+ text1: 'settings.calendarFeed.revokeSuccess',
245
+ });
246
+ // Back to the create action, no link box.
247
+ const json = JSON.stringify(renderer.toJSON());
248
+ expect(json).not.toContain(FEED_URL);
249
+ expect(json).toContain('settings.calendarFeed.create');
250
+ expect(
251
+ renderer.root.findAllByProps({ testID: 'delete-button' })
252
+ ).toHaveLength(0);
253
+ });
254
+
255
+ it('renders an error status as an error toast', () => {
256
+ const renderer = renderScreen();
257
+ mockHook.status = {
258
+ type: 'error',
259
+ message: 'Could not create the calendar link.',
260
+ };
261
+ updateScreen(renderer);
262
+ // Toast.show received the hook's error status — the native branch that
263
+ // maps a failed create/revoke to the error (destructive) toast layout.
264
+ expect(toastShowMock).toHaveBeenCalledWith({
265
+ type: 'error',
266
+ text1: 'Could not create the calendar link.',
267
+ });
268
+ });
269
+ });
@@ -0,0 +1,77 @@
1
+ import React from 'react';
2
+ import { View } from 'react-native';
3
+ import { useTranslation } from 'react-i18next';
4
+ import Clipboard from '@react-native-clipboard/clipboard';
5
+ import Toast from 'react-native-toast-message';
6
+ import { useCalendarFeedLink } from '@openpeepshq/react';
7
+ import { useSetPageHeader } from '../../components/layout';
8
+ import { CopyIcon } from '../../components/icons/index';
9
+ import { MainScreenProps } from '../../components/navigation/types/index';
10
+ import { Button } from '../../components/ui/button';
11
+ import { ThemedText } from '../../components/ui/themed-text';
12
+ import { ThemedView } from '../../components/ui/themed-view';
13
+
14
+ type CalendarFeedSettingsProps = MainScreenProps<'CalendarFeedSettings'>;
15
+
16
+ export const CalendarFeedSettings: React.FC<CalendarFeedSettingsProps> = () => {
17
+ const { t } = useTranslation();
18
+ const { feedUrl, creating, revoking, status, createLink, revokeLink } =
19
+ useCalendarFeedLink();
20
+
21
+ React.useEffect(() => {
22
+ if (!status) return;
23
+ Toast.show({ type: status.type, text1: status.message });
24
+ }, [status]);
25
+
26
+ useSetPageHeader(t('settings.calendarFeed.title'));
27
+
28
+ return (
29
+ <ThemedView className="flex-1">
30
+ <ThemedView className="flex-1 p-4 gap-3">
31
+ <ThemedText className="text-lg font-medium">
32
+ {t('settings.calendarFeed.introTitle')}
33
+ </ThemedText>
34
+ <ThemedText className="text-sm text-muted-foreground">
35
+ {t('settings.calendarFeed.introDescription')}
36
+ </ThemedText>
37
+
38
+ {feedUrl ? (
39
+ <View className="gap-2 rounded-md border border-border p-3">
40
+ <View className="flex-row items-start gap-2">
41
+ <ThemedText className="flex-1 text-sm" selectable>
42
+ {feedUrl}
43
+ </ThemedText>
44
+ <Button
45
+ size="icon"
46
+ variant="ghost"
47
+ accessibilityLabel={t('settings.calendarFeed.copy')}
48
+ onPress={() => Clipboard.setString(feedUrl)}
49
+ >
50
+ <CopyIcon size={16} className="text-foreground" />
51
+ </Button>
52
+ </View>
53
+ <Button
54
+ variant="outline"
55
+ disabled={revoking}
56
+ onPress={() => void revokeLink()}
57
+ >
58
+ <ThemedText>
59
+ {revoking
60
+ ? t('settings.calendarFeed.deleting')
61
+ : t('settings.calendarFeed.delete')}
62
+ </ThemedText>
63
+ </Button>
64
+ </View>
65
+ ) : (
66
+ <Button disabled={creating} onPress={() => void createLink()}>
67
+ <ThemedText className="text-primary-foreground">
68
+ {creating
69
+ ? t('settings.calendarFeed.creating')
70
+ : t('settings.calendarFeed.create')}
71
+ </ThemedText>
72
+ </Button>
73
+ )}
74
+ </ThemedView>
75
+ </ThemedView>
76
+ );
77
+ };
@@ -68,6 +68,10 @@ export const Settings = (
68
68
  translationPrefix="settings.feed"
69
69
  onPress={() => navigation.navigate('FeedSettings')}
70
70
  />
71
+ <ConfigMenuButton
72
+ translationPrefix="settings.calendarFeed"
73
+ onPress={() => navigation.navigate('CalendarFeedSettings')}
74
+ />
71
75
  </View>
72
76
  </ThemedView>
73
77
  );