@openpeepshq/rn-components 0.13.3 → 0.14.1
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/README.md +2 -0
- package/package.json +4 -3
- package/src/components/buttonOverflow.test.tsx +455 -0
- package/src/components/groups/GroupCard.tsx +26 -23
- package/src/components/groups/JoinGroupButton.tsx +7 -2
- package/src/components/jams/JamCapacityGate.tsx +9 -1
- package/src/components/jams/JamDeviceSelectors.tsx +2 -2
- package/src/components/jams/JamFooter.tsx +26 -22
- package/src/components/jams/JamLobby.tsx +5 -3
- package/src/components/jams/JamParticipantConference.tsx +6 -1
- package/src/components/jams/JamPeopleDrawer.tsx +19 -3
- package/src/components/jams/JamRequestJoin.tsx +30 -3
- package/src/components/jams/JamRoomIndicators.test.tsx +80 -4
- package/src/components/jams/JamRoomIndicators.tsx +34 -1
- package/src/components/jams/JamVideoCall.tsx +5 -5
- package/src/components/jams/LeaveCloseButton.tsx +5 -1
- package/src/components/post/pieces/FeedPostStats.tsx +15 -11
- package/src/components/post/pieces/PollContent.tsx +1 -1
- package/src/components/post/pieces/PostMenu.test.tsx +333 -0
- package/src/components/post/pieces/PostMenu.tsx +19 -15
- package/src/components/post/post-form/ReplyModal.tsx +1 -1
- package/src/components/post/types/Event.tsx +6 -2
- package/src/components/profile/Avatar.tsx +4 -1
- package/src/components/profile/ProfileWithActionCard.tsx +14 -6
- package/src/components/resources/ResourceLibrary.tsx +0 -1
- package/src/hooks/use-controlled-sheet.test.tsx +140 -0
- package/src/hooks/use-controlled-sheet.ts +25 -2
- package/src/lib/post.ts +0 -128
- package/src/pages/Explore.tsx +1 -3
- package/src/pages/conversations/Info.tsx +1 -1
- package/src/pages/conversations/New.tsx +1 -1
- package/src/pages/posts/Edit.tsx +1 -1
- package/src/pages/posts/New.carryover.test.tsx +245 -0
- package/src/pages/posts/New.tsx +19 -3
- package/src/pages/posts/Reply.tsx +19 -4
- package/src/stores/useLocalPostStore.ts +7 -4
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostMenu mount-gated reaction/repost sheets (issue #2109 round 2).
|
|
3
|
+
*
|
|
4
|
+
* These pin the call-site contract after the mount-gating rework: both sheet
|
|
5
|
+
* call sites (Reactions, Reposts) render their modal only while their `open`
|
|
6
|
+
* prop is true, and `open` is a required prop on the modal components. This
|
|
7
|
+
* file's regression guard is that PostMenu never mounts a sheet while its
|
|
8
|
+
* state is closed, so a closed modal can never race its own `present()` on
|
|
9
|
+
* mount.
|
|
10
|
+
*
|
|
11
|
+
* Mirrors FullEvent.test.tsx: every external import is mocked (node jest env,
|
|
12
|
+
* no native modules); the decision tree under test is the modal mount logic.
|
|
13
|
+
*/
|
|
14
|
+
import { type ReactNode } from 'react';
|
|
15
|
+
import ReactTestRenderer from 'react-test-renderer';
|
|
16
|
+
import Toast from 'react-native-toast-message';
|
|
17
|
+
|
|
18
|
+
// --- shared mutable state read by the module mocks (mock* = hoisting-safe) --
|
|
19
|
+
let mockProfile: { id: string; displayName?: string; handle?: string } | null =
|
|
20
|
+
{ id: 'u-1', displayName: 'Me', handle: 'me', following: [] };
|
|
21
|
+
const mockClient = {
|
|
22
|
+
posts: { deletePost: jest.fn(), pinPost: jest.fn() },
|
|
23
|
+
profiles: { followProfile: jest.fn() },
|
|
24
|
+
};
|
|
25
|
+
// ReactionsModal/RepostModal record their mount + open props for assertions.
|
|
26
|
+
const mountedReactions: { open: boolean | undefined; onClose?: () => void }[] =
|
|
27
|
+
[];
|
|
28
|
+
const mountedReposts: { open: boolean | undefined; onClose?: () => void }[] =
|
|
29
|
+
[];
|
|
30
|
+
|
|
31
|
+
// --- react-native: host elements render as plain host tags ----------------
|
|
32
|
+
// Each factory uses `require('react')` (not a top-level `import React`) because
|
|
33
|
+
// jest.mock factories run during hoisted import resolution, before top-level
|
|
34
|
+
// bindings exist — the same convention FullEvent.test.tsx documents.
|
|
35
|
+
jest.mock('react-native', () => {
|
|
36
|
+
const React = require('react');
|
|
37
|
+
const make = (tag: string) => (props: { children?: ReactNode }) =>
|
|
38
|
+
React.createElement(tag, props, props.children);
|
|
39
|
+
return {
|
|
40
|
+
View: make('View'),
|
|
41
|
+
Pressable: make('Pressable'),
|
|
42
|
+
TouchableOpacity: make('TouchableOpacity'),
|
|
43
|
+
ActivityIndicator: () => null,
|
|
44
|
+
Share: { share: jest.fn() },
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// --- i18n: resolve keys to their defaultValue -----------------------------
|
|
49
|
+
jest.mock('react-i18next', () => ({
|
|
50
|
+
useTranslation: () => ({
|
|
51
|
+
t: (_key: string, opts?: { defaultValue?: string }) =>
|
|
52
|
+
opts?.defaultValue ?? _key,
|
|
53
|
+
}),
|
|
54
|
+
}));
|
|
55
|
+
|
|
56
|
+
// --- openpeeps context -----------------------------------------------------
|
|
57
|
+
jest.mock('@openpeepshq/react', () => ({
|
|
58
|
+
useOpenpeeps: () => ({
|
|
59
|
+
currentProfile: mockProfile,
|
|
60
|
+
openpeepsApi: {
|
|
61
|
+
useCurrentProfile: () => ({ data: mockProfile, refetch: jest.fn() }),
|
|
62
|
+
useServerInfo: () => ({
|
|
63
|
+
data: { feature_flags: { groups: true, events: true } },
|
|
64
|
+
}),
|
|
65
|
+
useCurrentProfileBookmarkedIds: () => ({ data: [], refetch: jest.fn() }),
|
|
66
|
+
bookmarkPostAction: () => jest.fn(),
|
|
67
|
+
unbookmarkPostAction: () => jest.fn(),
|
|
68
|
+
deletePostAction: () => jest.fn(),
|
|
69
|
+
updateGroupAction: () => jest.fn(),
|
|
70
|
+
pinPostOnProfileAction: () => jest.fn(),
|
|
71
|
+
followProfileAction: () => jest.fn().mockResolvedValue({ success: true }),
|
|
72
|
+
unfollowProfileAction: () =>
|
|
73
|
+
jest.fn().mockResolvedValue({ success: true }),
|
|
74
|
+
admin: { pinPostGloballyAction: () => jest.fn() },
|
|
75
|
+
},
|
|
76
|
+
client: mockClient,
|
|
77
|
+
}),
|
|
78
|
+
}));
|
|
79
|
+
|
|
80
|
+
// --- local modules ---------------------------------------------------------
|
|
81
|
+
jest.mock('../../../hooks/use-controlled-sheet', () => ({
|
|
82
|
+
useControlledSheet: () => ({ current: {} }),
|
|
83
|
+
}));
|
|
84
|
+
jest.mock('../../../lib/utils', () => ({
|
|
85
|
+
profileName: (p?: { displayName?: string; handle?: string }) =>
|
|
86
|
+
p?.displayName ?? p?.handle ?? '',
|
|
87
|
+
handleInternalURLNavigation: jest.fn(),
|
|
88
|
+
}));
|
|
89
|
+
jest.mock('../../../components/navigation/helpers', () => ({
|
|
90
|
+
buildGoto: () => jest.fn(),
|
|
91
|
+
}));
|
|
92
|
+
jest.mock('@react-navigation/native', () => ({
|
|
93
|
+
useNavigation: () => ({ navigate: jest.fn() }),
|
|
94
|
+
}));
|
|
95
|
+
jest.mock('@react-navigation/native-stack', () => ({}));
|
|
96
|
+
jest.mock('react-native-toast-message', () => ({
|
|
97
|
+
__esModule: true,
|
|
98
|
+
default: { show: jest.fn() },
|
|
99
|
+
}));
|
|
100
|
+
jest.mock('@gorhom/bottom-sheet', () => ({
|
|
101
|
+
BottomSheetModal: () => null,
|
|
102
|
+
}));
|
|
103
|
+
|
|
104
|
+
// --- ui primitives ---------------------------------------------------------
|
|
105
|
+
// PostMenu imports its UI primitives from the `../../ui` barrel (mocked
|
|
106
|
+
// below); direct-path mocks for the individual modules are unreachable
|
|
107
|
+
// because jest resolves `jest.mock` by exact module path, so they are not
|
|
108
|
+
// kept here.
|
|
109
|
+
|
|
110
|
+
// Delete/confirm flow renders nothing under test.
|
|
111
|
+
jest.mock('./modals/DeletePostModal', () => ({
|
|
112
|
+
DeletePostModal: () => null,
|
|
113
|
+
}));
|
|
114
|
+
|
|
115
|
+
// Current main's PostMenu also mounts the edit-history sheet; it is out of
|
|
116
|
+
// scope here, and its real module graph reaches ESM-only react-native-config,
|
|
117
|
+
// which Jest's CommonJS runtime cannot parse. Stub it out for the test.
|
|
118
|
+
jest.mock('./modals/PostEditHistoryModal', () => ({
|
|
119
|
+
PostEditHistoryModal: () => null,
|
|
120
|
+
}));
|
|
121
|
+
|
|
122
|
+
// The two modals under test: record mount + open prop.
|
|
123
|
+
jest.mock('./modals/ReactionsModal', () => ({
|
|
124
|
+
ReactionsModal: (props: { open?: boolean; onClose?: () => void }) => {
|
|
125
|
+
mountedReactions.push({ open: props.open, onClose: props.onClose });
|
|
126
|
+
return null;
|
|
127
|
+
},
|
|
128
|
+
}));
|
|
129
|
+
jest.mock('./modals/RepostModal', () => ({
|
|
130
|
+
RepostModal: (props: { open?: boolean; onClose?: () => void }) => {
|
|
131
|
+
mountedReposts.push({ open: props.open, onClose: props.onClose });
|
|
132
|
+
return null;
|
|
133
|
+
},
|
|
134
|
+
}));
|
|
135
|
+
|
|
136
|
+
jest.mock('../../icons/index', () => ({
|
|
137
|
+
PencilIcon: () => null,
|
|
138
|
+
Trash2Icon: () => null,
|
|
139
|
+
FlagIcon: () => null,
|
|
140
|
+
UserXIcon: () => null,
|
|
141
|
+
UsersPlusIcon: () => null,
|
|
142
|
+
PinIcon: () => null,
|
|
143
|
+
BookmarkPlusIcon: () => null,
|
|
144
|
+
BookmarkMinusIcon: () => null,
|
|
145
|
+
Repeat2Icon: () => null,
|
|
146
|
+
HeartIcon: () => null,
|
|
147
|
+
MessageCircleIcon: () => null,
|
|
148
|
+
MoreVerticalIcon: () => null,
|
|
149
|
+
LogOutIcon: () => null,
|
|
150
|
+
MessageSquareReplyIcon: () => null,
|
|
151
|
+
SaveIcon: () => null,
|
|
152
|
+
RadioIcon: () => null,
|
|
153
|
+
TriangleAlertIcon: () => null,
|
|
154
|
+
FileTextIcon: () => null,
|
|
155
|
+
BellOffIcon: () => null,
|
|
156
|
+
BellPlusIcon: () => null,
|
|
157
|
+
BadgeCheckIcon: () => null,
|
|
158
|
+
ShareIcon: () => null,
|
|
159
|
+
DownloadIcon: () => null,
|
|
160
|
+
MapPinIcon: () => null,
|
|
161
|
+
LinkIcon: () => null,
|
|
162
|
+
Link2Icon: () => null,
|
|
163
|
+
PhoneCallIcon: () => null,
|
|
164
|
+
SendIcon: () => null,
|
|
165
|
+
MessageSquareLockIcon: () => null,
|
|
166
|
+
MessageSquarePlusIcon: () => null,
|
|
167
|
+
}));
|
|
168
|
+
|
|
169
|
+
jest.mock('../../ui/index', () => {
|
|
170
|
+
const React = require('react');
|
|
171
|
+
return {
|
|
172
|
+
// The full barrel drags in avatar/dropdown natives; expose only the menu
|
|
173
|
+
// surface PostMenu uses, backed by the same mock fakes as the direct mocks.
|
|
174
|
+
PopupMenu: (props: { children?: ReactNode }) =>
|
|
175
|
+
React.createElement('View', props, props.children),
|
|
176
|
+
PopupMenuButton: (props: {
|
|
177
|
+
text?: string;
|
|
178
|
+
action?: unknown;
|
|
179
|
+
onPress?: () => void;
|
|
180
|
+
}) =>
|
|
181
|
+
React.createElement('View', {
|
|
182
|
+
testID: `menu-${props.text}`,
|
|
183
|
+
onPress: typeof props.action === 'function' ? props.action : undefined,
|
|
184
|
+
}),
|
|
185
|
+
PopupSeparator: () => null,
|
|
186
|
+
Avatar: () => null,
|
|
187
|
+
Badge: () => null,
|
|
188
|
+
Button: () => null,
|
|
189
|
+
};
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
jest.mock('@openpeepshq/common', () => ({
|
|
193
|
+
checkGroupCapabilities: () => ({}),
|
|
194
|
+
checkRoleCapabilities: () => ({}),
|
|
195
|
+
}));
|
|
196
|
+
jest.mock('@openpeepshq/common/lib', () => ({
|
|
197
|
+
checkRoleCapabilities: () => ({}),
|
|
198
|
+
// Current main's PostMenu gates the edit-history action on this; the edit
|
|
199
|
+
// history is out of scope for these tests, so it stays hidden.
|
|
200
|
+
postHasEditHistory: () => false,
|
|
201
|
+
}));
|
|
202
|
+
jest.mock('@openpeepshq/common/types', () => ({}), { virtual: true });
|
|
203
|
+
|
|
204
|
+
jest.mock('../../profile/ReportProfileOrPostModal', () => ({
|
|
205
|
+
ReportProfileOrPostModal: () => null,
|
|
206
|
+
}));
|
|
207
|
+
|
|
208
|
+
jest.mock('../post-form/EditPostModalContext', () => ({
|
|
209
|
+
useEditPostModal: () => ({ openEditPost: jest.fn() }),
|
|
210
|
+
}));
|
|
211
|
+
|
|
212
|
+
import { PostMenu } from './PostMenu';
|
|
213
|
+
|
|
214
|
+
// A "Join Jam" button is the host View that carries the label AND forwards
|
|
215
|
+
// onPress (only Button does). Search deepest-first so the button itself — not
|
|
216
|
+
// an ancestor container that merely contains the label — is returned.
|
|
217
|
+
type TreeNode = {
|
|
218
|
+
type?: string;
|
|
219
|
+
props?: Record<string, unknown> | null;
|
|
220
|
+
children?: (TreeNode | string | null)[];
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
function findByTestID(json: unknown, testID: string): TreeNode | undefined {
|
|
224
|
+
if (json === null || typeof json !== 'object') return undefined;
|
|
225
|
+
const node = json as TreeNode;
|
|
226
|
+
if (node.props?.testID === testID) return node;
|
|
227
|
+
for (const c of node.children || []) {
|
|
228
|
+
if (typeof c !== 'string' && c !== null) {
|
|
229
|
+
const found = findByTestID(c, testID);
|
|
230
|
+
if (found) return found;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return undefined;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const BASE_POST = {
|
|
237
|
+
id: 'post-1',
|
|
238
|
+
profile: { id: 'owner-1', displayName: 'Owner' },
|
|
239
|
+
visibility: 'public',
|
|
240
|
+
repostCount: 2,
|
|
241
|
+
reactionCount: 3,
|
|
242
|
+
data: { type: 'note', content: 'hello' },
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
function render(): ReactTestRenderer.ReactTestRenderer {
|
|
246
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
247
|
+
ReactTestRenderer.act(() => {
|
|
248
|
+
tree = ReactTestRenderer.create(
|
|
249
|
+
<PostMenu post={BASE_POST as never} deleteCallback={jest.fn()} />
|
|
250
|
+
);
|
|
251
|
+
});
|
|
252
|
+
return tree;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
beforeEach(() => {
|
|
256
|
+
mockProfile = { id: 'u-1', displayName: 'Me', handle: 'me', following: [] };
|
|
257
|
+
mountedReactions.length = 0;
|
|
258
|
+
mountedReposts.length = 0;
|
|
259
|
+
(Toast.show as jest.Mock).mockClear();
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
test('1. closed state: no modal mounted, sheet does not present on mount', () => {
|
|
263
|
+
const tree = render();
|
|
264
|
+
expect(mountedReactions).toHaveLength(0);
|
|
265
|
+
expect(mountedReposts).toHaveLength(0);
|
|
266
|
+
tree.unmount();
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
test('2. reposts menu action mounts RepostModal with open=true', () => {
|
|
270
|
+
const tree = render();
|
|
271
|
+
const repostsItem = findByTestID(tree.toJSON(), 'menu-Reposts');
|
|
272
|
+
expect(typeof repostsItem?.props?.onPress).toBe('function');
|
|
273
|
+
ReactTestRenderer.act(() => {
|
|
274
|
+
(repostsItem?.props?.onPress as () => void)();
|
|
275
|
+
});
|
|
276
|
+
expect(mountedReposts).toHaveLength(1);
|
|
277
|
+
expect(mountedReposts[0].open).toBe(true);
|
|
278
|
+
tree.unmount();
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
test('3. reactions menu action mounts ReactionsModal with open=true', () => {
|
|
282
|
+
const tree = render();
|
|
283
|
+
const reactionsItem = findByTestID(tree.toJSON(), 'menu-Reactions');
|
|
284
|
+
expect(typeof reactionsItem?.props?.onPress).toBe('function');
|
|
285
|
+
ReactTestRenderer.act(() => {
|
|
286
|
+
(reactionsItem?.props?.onPress as () => void)();
|
|
287
|
+
});
|
|
288
|
+
expect(mountedReactions).toHaveLength(1);
|
|
289
|
+
expect(mountedReactions[0].open).toBe(true);
|
|
290
|
+
tree.unmount();
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
test('4. closing the modal via onClose fully unmounts it (no remount with open=false)', () => {
|
|
294
|
+
const tree = render();
|
|
295
|
+
const repostsItem = findByTestID(tree.toJSON(), 'menu-Reposts');
|
|
296
|
+
ReactTestRenderer.act(() => {
|
|
297
|
+
(repostsItem?.props?.onPress as () => void)();
|
|
298
|
+
});
|
|
299
|
+
expect(mountedReposts).toHaveLength(1);
|
|
300
|
+
// onClose flips state closed -> conditional unmount
|
|
301
|
+
// (no {open:false} remount).
|
|
302
|
+
ReactTestRenderer.act(() => {
|
|
303
|
+
mountedReposts[0].onClose?.();
|
|
304
|
+
});
|
|
305
|
+
expect(mountedReposts).toHaveLength(1); // no remount with open=false
|
|
306
|
+
tree.unmount();
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
test('5. follow/unfollow toasts render the shared profile.follow.* keys (#2110)', async () => {
|
|
310
|
+
const tree = render();
|
|
311
|
+
const followItem = findByTestID(tree.toJSON(), 'menu-Follow');
|
|
312
|
+
expect(typeof followItem?.props?.onPress).toBe('function');
|
|
313
|
+
await ReactTestRenderer.act(async () => {
|
|
314
|
+
await (followItem?.props?.onPress as () => Promise<void>)();
|
|
315
|
+
});
|
|
316
|
+
expect(Toast.show).toHaveBeenCalledWith(
|
|
317
|
+
expect.objectContaining({ text1: 'profile.follow.followedSuccess' })
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
// Flip to following so the menu exposes Unfollow, then assert its toast.
|
|
321
|
+
mockProfile = { ...mockProfile, following: [{ id: BASE_POST.profile.id }] };
|
|
322
|
+
const tree2 = render();
|
|
323
|
+
const unfollowItem = findByTestID(tree2.toJSON(), 'menu-Unfollow');
|
|
324
|
+
expect(typeof unfollowItem?.props?.onPress).toBe('function');
|
|
325
|
+
await ReactTestRenderer.act(async () => {
|
|
326
|
+
await (unfollowItem?.props?.onPress as () => Promise<void>)();
|
|
327
|
+
});
|
|
328
|
+
expect(Toast.show).toHaveBeenCalledWith(
|
|
329
|
+
expect.objectContaining({ text1: 'profile.follow.unfollowedSuccess' })
|
|
330
|
+
);
|
|
331
|
+
tree.unmount();
|
|
332
|
+
tree2.unmount();
|
|
333
|
+
});
|
|
@@ -54,7 +54,7 @@ export const PostMenu = ({ post, deleteCallback }: PostMenuProps) => {
|
|
|
54
54
|
const [isBookmarkActionPending, setIsBookmarkActionPending] =
|
|
55
55
|
React.useState(false);
|
|
56
56
|
const [isFollowing, setIsFollowing] = React.useState(false);
|
|
57
|
-
const [
|
|
57
|
+
const [repostModalOpen, setRepostModalOpen] = React.useState(false);
|
|
58
58
|
const [reactionsModalOpen, setReactionsModalOpen] = React.useState(false);
|
|
59
59
|
const [historyModalOpen, setHistoryModalOpen] = React.useState(false);
|
|
60
60
|
|
|
@@ -139,7 +139,7 @@ export const PostMenu = ({ post, deleteCallback }: PostMenuProps) => {
|
|
|
139
139
|
setIsFollowing(true);
|
|
140
140
|
Toast.show({
|
|
141
141
|
type: 'success',
|
|
142
|
-
text1: t('profile.
|
|
142
|
+
text1: t('profile.follow.followedSuccess'),
|
|
143
143
|
});
|
|
144
144
|
} else {
|
|
145
145
|
Toast.show({ type: 'error', text1: t('profile.follow.error') });
|
|
@@ -152,7 +152,7 @@ export const PostMenu = ({ post, deleteCallback }: PostMenuProps) => {
|
|
|
152
152
|
setIsFollowing(false);
|
|
153
153
|
Toast.show({
|
|
154
154
|
type: 'success',
|
|
155
|
-
text1: t('profile.
|
|
155
|
+
text1: t('profile.follow.unfollowedSuccess'),
|
|
156
156
|
});
|
|
157
157
|
} else {
|
|
158
158
|
Toast.show({ type: 'error', text1: t('profile.follow.error') });
|
|
@@ -296,7 +296,7 @@ export const PostMenu = ({ post, deleteCallback }: PostMenuProps) => {
|
|
|
296
296
|
title={t('posts.menu.reposts', { defaultValue: 'Reposts' })}
|
|
297
297
|
text={t('posts.menu.reposts', { defaultValue: 'Reposts' })}
|
|
298
298
|
icon={Repeat2Icon}
|
|
299
|
-
action={() =>
|
|
299
|
+
action={() => setRepostModalOpen(true)}
|
|
300
300
|
/>
|
|
301
301
|
<PopupMenuButton
|
|
302
302
|
title={t('posts.menu.reactions', { defaultValue: 'Reactions' })}
|
|
@@ -467,17 +467,21 @@ export const PostMenu = ({ post, deleteCallback }: PostMenuProps) => {
|
|
|
467
467
|
) : null}
|
|
468
468
|
</PopupMenu>
|
|
469
469
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
470
|
+
{repostModalOpen && (
|
|
471
|
+
<RepostModal
|
|
472
|
+
open
|
|
473
|
+
reposts={post.reposts ?? []}
|
|
474
|
+
repostCount={post.repostCount ?? 0}
|
|
475
|
+
onClose={() => setRepostModalOpen(false)}
|
|
476
|
+
/>
|
|
477
|
+
)}
|
|
478
|
+
{reactionsModalOpen && (
|
|
479
|
+
<ReactionsModal
|
|
480
|
+
open
|
|
481
|
+
reactions={post.reactions ?? []}
|
|
482
|
+
onClose={() => setReactionsModalOpen(false)}
|
|
483
|
+
/>
|
|
484
|
+
)}
|
|
481
485
|
{showEditHistory ? (
|
|
482
486
|
<PostEditHistoryModal
|
|
483
487
|
post={post}
|
|
@@ -22,7 +22,7 @@ export const ReplyModal = forwardRef<BottomSheetModal, ReplySheetProps>(
|
|
|
22
22
|
<BaseSheet ref={ref} enableOverDrag={false}>
|
|
23
23
|
<View className="flex-1 px-4 pt-2 pb-8">
|
|
24
24
|
<ThemedText className="text-center text-xl tracking-wider font-semibold">
|
|
25
|
-
{t('posts.
|
|
25
|
+
{t('posts.replyModal.title')}
|
|
26
26
|
</ThemedText>
|
|
27
27
|
{post && (
|
|
28
28
|
<ThreadPost
|
|
@@ -32,8 +32,11 @@ export const FeedEvent = ({ post }: { post: PublicPost }) => {
|
|
|
32
32
|
</View>
|
|
33
33
|
)}
|
|
34
34
|
|
|
35
|
-
<View className="flex-row items-center justify-between">
|
|
36
|
-
<ThemedText
|
|
35
|
+
<View className="flex-row items-center justify-between gap-x-2">
|
|
36
|
+
<ThemedText
|
|
37
|
+
className="min-w-0 flex-1 text-muted-foreground text-sm"
|
|
38
|
+
numberOfLines={1}
|
|
39
|
+
>
|
|
37
40
|
{formatEventDate(start)}
|
|
38
41
|
{end && ` - ${formatEventDate(end)}`}
|
|
39
42
|
{eventData.timeZone && ` (${eventData.timeZone})`}
|
|
@@ -41,6 +44,7 @@ export const FeedEvent = ({ post }: { post: PublicPost }) => {
|
|
|
41
44
|
<Button
|
|
42
45
|
variant="outline"
|
|
43
46
|
size="sm"
|
|
47
|
+
className="shrink-0"
|
|
44
48
|
onPress={() => navigation.navigate('Post', { id: post.id })}
|
|
45
49
|
>
|
|
46
50
|
<ThemedText className="text-xs">
|
|
@@ -28,7 +28,10 @@ export const ProfileAvatar = ({
|
|
|
28
28
|
profile,
|
|
29
29
|
className,
|
|
30
30
|
}: {
|
|
31
|
-
|
|
31
|
+
/** `Profile`-shaped; only `displayName`/`handle`/`avatar` are read. */
|
|
32
|
+
profile: Partial<
|
|
33
|
+
Pick<Profile, 'displayName' | 'handle' | 'avatar' | 'deletedAt'>
|
|
34
|
+
>;
|
|
32
35
|
className?: string;
|
|
33
36
|
}) => {
|
|
34
37
|
const { t } = useTranslation();
|
|
@@ -16,20 +16,28 @@ export const ProfileWithActionCard = ({
|
|
|
16
16
|
leading,
|
|
17
17
|
}: ProfileWithActionCardProps) => (
|
|
18
18
|
<View className="mb-4 w-full flex-row items-center justify-between">
|
|
19
|
-
<View className="flex-row items-center gap-2">
|
|
19
|
+
<View className="flex min-w-0 flex-1 flex-row items-center gap-2">
|
|
20
20
|
{leading}
|
|
21
|
-
<ProfileLink
|
|
21
|
+
<ProfileLink
|
|
22
|
+
profile={profile}
|
|
23
|
+
className="flex min-w-0 flex-1 flex-row items-center gap-2"
|
|
24
|
+
>
|
|
22
25
|
<ProfileAvatar profile={profile} />
|
|
23
|
-
<View>
|
|
24
|
-
<ThemedText className="font-bold">
|
|
26
|
+
<View className="min-w-0 flex-1">
|
|
27
|
+
<ThemedText className="font-bold" numberOfLines={1}>
|
|
25
28
|
{profile.displayName || profile.handle}
|
|
26
29
|
</ThemedText>
|
|
27
|
-
<ThemedText
|
|
30
|
+
<ThemedText
|
|
31
|
+
className="text-sm text-muted-foreground"
|
|
32
|
+
numberOfLines={1}
|
|
33
|
+
>
|
|
28
34
|
@{profile.handle}
|
|
29
35
|
</ThemedText>
|
|
30
36
|
</View>
|
|
31
37
|
</ProfileLink>
|
|
32
38
|
</View>
|
|
33
|
-
<
|
|
39
|
+
<View className="shrink-0">
|
|
40
|
+
<FollowUnfollowButton profile={profile} compact />
|
|
41
|
+
</View>
|
|
34
42
|
</View>
|
|
35
43
|
);
|
|
@@ -358,7 +358,6 @@ export const ResourceLibrary = ({ groupId }: ResourceLibraryProps) => {
|
|
|
358
358
|
{library.posts.length > 0 ? (
|
|
359
359
|
<ThemedText className="text-xs text-muted-foreground">
|
|
360
360
|
{t('resources.library.resourceCount', {
|
|
361
|
-
defaultValue: 'Showing {{count}} resources',
|
|
362
361
|
count: library.posts.length,
|
|
363
362
|
})}
|
|
364
363
|
</ThemedText>
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useControlledSheet regression coverage (issue #2110 round 5).
|
|
3
|
+
*
|
|
4
|
+
* Pins the guard the round-4 review asked to protect: an open with a
|
|
5
|
+
* never-attached sheet ref (missing <BottomSheetModalProvider>, or a sheet
|
|
6
|
+
* that unmounted before the effect ran) must fail loudly — console.error plus
|
|
7
|
+
* exactly one console.warn — instead of silently dropping the present.
|
|
8
|
+
*
|
|
9
|
+
* Node jest env (no native modules): the bottom-sheet ref module is mocked so
|
|
10
|
+
* present/dismiss are observable spies; the component never mounts a real
|
|
11
|
+
* BottomSheetModal, it only holds (or deliberately drops) the ref.
|
|
12
|
+
*/
|
|
13
|
+
import { createElement, type ReactNode } from 'react';
|
|
14
|
+
import ReactTestRenderer from 'react-test-renderer';
|
|
15
|
+
|
|
16
|
+
// React 19 act() requires the act environment flag, or it warns on every act().
|
|
17
|
+
(
|
|
18
|
+
globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }
|
|
19
|
+
).IS_REACT_ACT_ENVIRONMENT = true;
|
|
20
|
+
|
|
21
|
+
// --- bottom sheet: drive the attached instance like the real lib does -------
|
|
22
|
+
const presentSpy = jest.fn();
|
|
23
|
+
const dismissSpy = jest.fn();
|
|
24
|
+
jest.mock('../lib/bottom-sheet-ref', () => ({
|
|
25
|
+
bottomSheetPresent: (ref: { current: unknown } | null) =>
|
|
26
|
+
presentSpy(ref?.current),
|
|
27
|
+
bottomSheetDismiss: (ref: { current: unknown } | null) =>
|
|
28
|
+
dismissSpy(ref?.current),
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
import { useControlledSheet } from './use-controlled-sheet';
|
|
32
|
+
|
|
33
|
+
// Stands in for the BottomSheetModal instance a real <BottomSheetModal ref>
|
|
34
|
+
// would attach to the hook's ref. The hook's present/dismiss path requires
|
|
35
|
+
// ref.current to be non-null (the detached-ref guard is what tests #2/#3 probe).
|
|
36
|
+
const FAKE_SHEET = { present: jest.fn(), dismiss: jest.fn() };
|
|
37
|
+
|
|
38
|
+
// Drives the hook and, when `attach` is true, simulates the sheet mounting by
|
|
39
|
+
// attaching the fake instance to the ref (as a real BottomSheetModal would).
|
|
40
|
+
const FakeSheet = ({
|
|
41
|
+
open,
|
|
42
|
+
attach = true,
|
|
43
|
+
}: {
|
|
44
|
+
open: boolean;
|
|
45
|
+
attach?: boolean;
|
|
46
|
+
}) => {
|
|
47
|
+
const ref = useControlledSheet(open);
|
|
48
|
+
if (attach) {
|
|
49
|
+
ref.current = FAKE_SHEET;
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// Same hook, but the ref is never handed to a sheet: ref.current stays null,
|
|
55
|
+
// which is the detached-ref / missing-provider case the guard must catch.
|
|
56
|
+
const DetachedSheet = ({ open }: { open: boolean }) => {
|
|
57
|
+
useControlledSheet(open);
|
|
58
|
+
return null;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const render = (element: ReactNode): ReactTestRenderer.ReactTestRenderer => {
|
|
62
|
+
let renderer!: ReactTestRenderer.ReactTestRenderer;
|
|
63
|
+
ReactTestRenderer.act(() => {
|
|
64
|
+
renderer = ReactTestRenderer.create(element);
|
|
65
|
+
});
|
|
66
|
+
return renderer;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
describe('useControlledSheet', () => {
|
|
70
|
+
let errorSpy: jest.SpyInstance;
|
|
71
|
+
let warnSpy: jest.SpyInstance;
|
|
72
|
+
|
|
73
|
+
// React's own deprecation/act warnings also route through console.error, so
|
|
74
|
+
// count only this hook's messages rather than raw call counts.
|
|
75
|
+
const noSheetErrors = () =>
|
|
76
|
+
errorSpy.mock.calls.filter((c) =>
|
|
77
|
+
String(c[0]).includes('no bottom sheet instance')
|
|
78
|
+
).length;
|
|
79
|
+
const noSheetWarns = () =>
|
|
80
|
+
warnSpy.mock.calls.filter((c) =>
|
|
81
|
+
String(c[0]).includes('no sheet instance on first open')
|
|
82
|
+
).length;
|
|
83
|
+
|
|
84
|
+
beforeEach(() => {
|
|
85
|
+
presentSpy.mockClear();
|
|
86
|
+
dismissSpy.mockClear();
|
|
87
|
+
errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
88
|
+
warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
afterEach(() => {
|
|
92
|
+
errorSpy.mockRestore();
|
|
93
|
+
warnSpy.mockRestore();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('presents when open and the sheet ref is attached', () => {
|
|
97
|
+
const renderer = render(createElement(FakeSheet, { open: true }));
|
|
98
|
+
expect(presentSpy).toHaveBeenCalledTimes(1);
|
|
99
|
+
expect(presentSpy).toHaveBeenCalledWith(FAKE_SHEET);
|
|
100
|
+
expect(noSheetErrors()).toBe(0);
|
|
101
|
+
expect(noSheetWarns()).toBe(0);
|
|
102
|
+
ReactTestRenderer.act(() => renderer.unmount());
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('dismisses when open goes false', () => {
|
|
106
|
+
const renderer = render(createElement(FakeSheet, { open: true }));
|
|
107
|
+
expect(presentSpy).toHaveBeenCalledTimes(1);
|
|
108
|
+
expect(dismissSpy).not.toHaveBeenCalled();
|
|
109
|
+
ReactTestRenderer.act(() => {
|
|
110
|
+
renderer.update(createElement(FakeSheet, { open: false }));
|
|
111
|
+
});
|
|
112
|
+
expect(dismissSpy).toHaveBeenCalledTimes(1);
|
|
113
|
+
expect(dismissSpy).toHaveBeenCalledWith(FAKE_SHEET);
|
|
114
|
+
expect(noSheetErrors()).toBe(0);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('errors on a detached ref and warns exactly once per hook instance', () => {
|
|
118
|
+
const renderer = render(createElement(DetachedSheet, { open: false }));
|
|
119
|
+
expect(presentSpy).not.toHaveBeenCalled();
|
|
120
|
+
expect(noSheetErrors()).toBe(0);
|
|
121
|
+
expect(noSheetWarns()).toBe(0);
|
|
122
|
+
|
|
123
|
+
// First open with a never-attached ref: loud error + one provider warning.
|
|
124
|
+
ReactTestRenderer.act(() => {
|
|
125
|
+
renderer.update(createElement(DetachedSheet, { open: true }));
|
|
126
|
+
});
|
|
127
|
+
expect(noSheetErrors()).toBe(1);
|
|
128
|
+
expect(noSheetWarns()).toBe(1);
|
|
129
|
+
|
|
130
|
+
// Re-open after a dismiss must not re-spam the provider warning.
|
|
131
|
+
ReactTestRenderer.act(() => {
|
|
132
|
+
renderer.update(createElement(DetachedSheet, { open: false }));
|
|
133
|
+
});
|
|
134
|
+
ReactTestRenderer.act(() => {
|
|
135
|
+
renderer.update(createElement(DetachedSheet, { open: true }));
|
|
136
|
+
});
|
|
137
|
+
expect(noSheetErrors()).toBe(2);
|
|
138
|
+
expect(noSheetWarns()).toBe(1);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
@@ -8,9 +8,32 @@ import {
|
|
|
8
8
|
/** Drives an imperative bottom sheet from web-style `open`/`onClose` props. */
|
|
9
9
|
export const useControlledSheet = (open: boolean) => {
|
|
10
10
|
const ref = useRef<BottomSheetModal>(null);
|
|
11
|
+
// Fired once per hook instance so a missing provider can't spam on every
|
|
12
|
+
// open attempt.
|
|
13
|
+
const warnedMissingProvider = useRef(false);
|
|
11
14
|
useEffect(() => {
|
|
12
|
-
if (open)
|
|
13
|
-
|
|
15
|
+
if (open) {
|
|
16
|
+
if (!ref.current) {
|
|
17
|
+
// The sheet instance never attached: the modal subtree either failed
|
|
18
|
+
// to mount or unmounted before this effect ran.
|
|
19
|
+
console.error(
|
|
20
|
+
'useControlledSheet: no bottom sheet instance to present — the ' +
|
|
21
|
+
'sheet never mounted.'
|
|
22
|
+
);
|
|
23
|
+
if (!warnedMissingProvider.current) {
|
|
24
|
+
warnedMissingProvider.current = true;
|
|
25
|
+
console.warn(
|
|
26
|
+
'useControlledSheet: no sheet instance on first open. If this ' +
|
|
27
|
+
'happens for every sheet, the app root is missing ' +
|
|
28
|
+
'<BottomSheetModalProvider> from @gorhom/bottom-sheet.'
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
bottomSheetPresent(ref);
|
|
34
|
+
} else {
|
|
35
|
+
bottomSheetDismiss(ref);
|
|
36
|
+
}
|
|
14
37
|
}, [open]);
|
|
15
38
|
return ref;
|
|
16
39
|
};
|