@openpeepshq/rn-components 0.24.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.
- package/package.json +2 -2
- package/src/components/conversations/ConversationPreviewCard.test.tsx +345 -0
- package/src/components/conversations/ConversationPreviewCard.tsx +29 -24
- package/src/components/custom/navigation/side-menu.test.tsx +9 -0
- package/src/components/custom/navigation/side-menu.tsx +19 -3
- package/src/components/groups/GroupAvatar.test.tsx +20 -2
- package/src/components/groups/GroupAvatar.tsx +7 -1
- package/src/components/jams/JamCallParticipant.test.tsx +303 -0
- package/src/components/jams/JamCallParticipant.tsx +7 -1
- package/src/components/jams/useLateTrackMediaStream.test.ts +139 -25
- package/src/components/jams/useLateTrackMediaStream.ts +62 -19
- package/src/components/post/pieces/ShareMenu.test.tsx +105 -11
- package/src/components/post/pieces/ShareMenu.tsx +55 -10
- package/src/components/post/pieces/modals/SendToConversationModal.tsx +140 -0
- package/src/components/post/pieces/modals/ShareIntoGroupModal.tsx +121 -0
- package/src/components/post/pieces/modals/index.ts +2 -0
- package/src/components/post/pieces/sharePickers.test.tsx +819 -0
- package/src/components/profile/Avatar.test.tsx +19 -0
- package/src/components/profile/Avatar.tsx +9 -1
- package/src/lib/push-notifications.test.ts +244 -0
- package/src/lib/push-notifications.ts +65 -0
- package/src/pages/auth/Login.tsx +16 -2
- package/src/pages/conversations/Index.test.tsx +235 -0
- package/src/pages/conversations/Index.tsx +15 -16
- package/src/pages/settings/Account.test.tsx +4 -0
- package/src/pages/settings/Account.tsx +14 -0
|
@@ -0,0 +1,819 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Share-into-group / send-to-conversation modal behavior (issue #1851, review
|
|
3
|
+
* round 7 S2).
|
|
4
|
+
*
|
|
5
|
+
* The ShareMenu tests pin that tapping the two new items *opens* these modals;
|
|
6
|
+
* these tests exercise the modals' own behavior that was previously only
|
|
7
|
+
* smoke-tested: the group list is filtered by the `core-posts-create-note`
|
|
8
|
+
* capability, the conversation list loads from `useConversations()`, and the
|
|
9
|
+
* `onShare` / `onSend` callbacks fire with the chosen target and drive the
|
|
10
|
+
* success/error toasts plus close.
|
|
11
|
+
*
|
|
12
|
+
* Mirrors the inline-mock pattern of ShareMenu.test.tsx: node jest env, every
|
|
13
|
+
* external import mocked, and the common/lib capability predicate mirrored
|
|
14
|
+
* inline (its real semantics are exhaustively unit-tested in platform/common).
|
|
15
|
+
*
|
|
16
|
+
* Mock-downgrade (review round 7 S2): the real `BaseSheet` renders a
|
|
17
|
+
* `@gorhom/bottom-sheet` sheet driven by `react-native-gesture-handler`,
|
|
18
|
+
* whose native modules are unavailable in the node jest env. It is therefore
|
|
19
|
+
* mocked to a plain pass-through (as is `use-controlled-sheet`), so these
|
|
20
|
+
* tests exercise the modal's *logic* — the capability/conversation filters,
|
|
21
|
+
* the `onShare`/`onSend` wiring, the in-flight guard, and the toasts — but
|
|
22
|
+
* not the bottom-sheet presentation itself. The sheet presentation is
|
|
23
|
+
* covered by the native app's own UI.
|
|
24
|
+
*/
|
|
25
|
+
import React from 'react';
|
|
26
|
+
import ReactTestRenderer from 'react-test-renderer';
|
|
27
|
+
import Toast from 'react-native-toast-message';
|
|
28
|
+
import fs from 'node:fs';
|
|
29
|
+
import path from 'node:path';
|
|
30
|
+
|
|
31
|
+
const state = {
|
|
32
|
+
me: null as unknown,
|
|
33
|
+
authData: {} as Record<string, unknown>,
|
|
34
|
+
conversations: [] as unknown[],
|
|
35
|
+
conversationsLoading: false,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
jest.mock('react-native', () => ({
|
|
39
|
+
View: (props: { children?: unknown }) =>
|
|
40
|
+
React.createElement('View', null, props.children),
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
jest.mock('react-i18next', () => ({
|
|
44
|
+
useTranslation: () => ({
|
|
45
|
+
t: (key: string, opts?: { defaultValue?: string; name?: string }) =>
|
|
46
|
+
opts?.defaultValue?.replace(/\{\{name\}\}/g, opts.name ?? '') ?? key,
|
|
47
|
+
}),
|
|
48
|
+
}));
|
|
49
|
+
|
|
50
|
+
jest.mock('react-native-toast-message', () => ({
|
|
51
|
+
__esModule: true,
|
|
52
|
+
default: { show: jest.fn() },
|
|
53
|
+
}));
|
|
54
|
+
|
|
55
|
+
// Mirrors the real predicate closely enough to prove the modal's filter runs
|
|
56
|
+
// against the membership role (the real scope/role merge is covered in
|
|
57
|
+
// platform/common). `authData.profile.memberships[].roles` × `group.capabilities`
|
|
58
|
+
// is the only thing this path reads.
|
|
59
|
+
jest.mock('@openpeepshq/common/lib', () => ({
|
|
60
|
+
checkGroupCapabilities: (
|
|
61
|
+
authData: {
|
|
62
|
+
profile?: {
|
|
63
|
+
memberships?: { group: { id: string }; roles: string[] }[];
|
|
64
|
+
} | null;
|
|
65
|
+
},
|
|
66
|
+
needed: string[],
|
|
67
|
+
group: { id: string; capabilities?: Record<string, { add: string[] }> }
|
|
68
|
+
) => {
|
|
69
|
+
const roles =
|
|
70
|
+
authData.profile?.memberships?.find((m) => m.group.id === group.id)
|
|
71
|
+
?.roles ?? [];
|
|
72
|
+
const add = roles.flatMap((r) => group.capabilities?.[r]?.add ?? []);
|
|
73
|
+
const ok = needed.every((c) => add.includes(c));
|
|
74
|
+
return { success: ok, missingCapabilities: ok ? [] : needed };
|
|
75
|
+
},
|
|
76
|
+
truncateText: (
|
|
77
|
+
text?: string | null,
|
|
78
|
+
maxLength: number = 15
|
|
79
|
+
): string | undefined => {
|
|
80
|
+
const t = (text ?? '').trim();
|
|
81
|
+
return t.length > maxLength ? `${t.slice(0, maxLength - 1)}…` : t;
|
|
82
|
+
},
|
|
83
|
+
}));
|
|
84
|
+
|
|
85
|
+
jest.mock('@openpeepshq/react', () => {
|
|
86
|
+
// Load the *real* `conversationTitle` so the modal runs against the single
|
|
87
|
+
// shared implementation instead of a mirror that can drift (its full
|
|
88
|
+
// semantics are unit-tested against the real code in platform/react). The
|
|
89
|
+
// module's only import is a type (`@openpeepshq/common/types`), elided by
|
|
90
|
+
// ts-jest, so it has no runtime deps to pull into the node jest env. The
|
|
91
|
+
// hooks/providers around it stay mocked below.
|
|
92
|
+
const {
|
|
93
|
+
conversationTitle,
|
|
94
|
+
} = require('../../../../../react/src/hooks/conversations/conversationTitle');
|
|
95
|
+
return {
|
|
96
|
+
conversationTitle,
|
|
97
|
+
useCurrentProfile: () => state.me,
|
|
98
|
+
useAuthData: () => state.authData,
|
|
99
|
+
useOpenpeeps: () => ({
|
|
100
|
+
openpeepsApi: {
|
|
101
|
+
useConversations: () => ({
|
|
102
|
+
data: state.conversations,
|
|
103
|
+
isLoading: state.conversationsLoading,
|
|
104
|
+
}),
|
|
105
|
+
},
|
|
106
|
+
}),
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
jest.mock('../../../hooks/use-controlled-sheet', () => ({
|
|
111
|
+
useControlledSheet: () => ({ current: null }),
|
|
112
|
+
}));
|
|
113
|
+
|
|
114
|
+
jest.mock('../../custom/modals/common', () => {
|
|
115
|
+
const React = require('react');
|
|
116
|
+
return {
|
|
117
|
+
// The real BaseSheet renders its children unconditionally; presentation
|
|
118
|
+
// is driven by the (mocked) useControlledSheet, so the mock does the same.
|
|
119
|
+
BaseSheet: (props: { children?: unknown }) =>
|
|
120
|
+
React.createElement('BaseSheet', null, props.children),
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
jest.mock('../../ui/themed-text', () => {
|
|
125
|
+
const React = require('react');
|
|
126
|
+
return {
|
|
127
|
+
ThemedText: (props: { children?: unknown }) =>
|
|
128
|
+
React.createElement('ThemedText', null, props.children),
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
jest.mock('../../ui/loading-spinner', () => ({
|
|
133
|
+
LoadingSpinner: () => null,
|
|
134
|
+
}));
|
|
135
|
+
|
|
136
|
+
jest.mock('../../ui/button', () => {
|
|
137
|
+
const React = require('react');
|
|
138
|
+
return {
|
|
139
|
+
// The real Button forwards the pressable props; mirror it so tests can
|
|
140
|
+
// reach `onPress` on the rendered node.
|
|
141
|
+
Button: (props: Record<string, unknown>) =>
|
|
142
|
+
React.createElement('View', props, props.children),
|
|
143
|
+
};
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
import { ShareIntoGroupModal } from './modals/ShareIntoGroupModal';
|
|
147
|
+
import { SendToConversationModal } from './modals/SendToConversationModal';
|
|
148
|
+
|
|
149
|
+
type TreeNode = {
|
|
150
|
+
type?: string;
|
|
151
|
+
props?: Record<string, unknown> | null;
|
|
152
|
+
children?: (TreeNode | string | null)[];
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
function collectText(node: unknown, out: string[] = []): string[] {
|
|
156
|
+
if (node === null || typeof node !== 'object') return out;
|
|
157
|
+
const nodes = Array.isArray(node) ? node : [node];
|
|
158
|
+
for (const entry of nodes) {
|
|
159
|
+
if (typeof entry === 'string') {
|
|
160
|
+
out.push(entry);
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
if (!entry) continue;
|
|
164
|
+
const n = entry as TreeNode;
|
|
165
|
+
for (const c of n.children || []) {
|
|
166
|
+
if (typeof c === 'string') out.push(c);
|
|
167
|
+
else if (c) collectText(c, out);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return out;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Find the string `text` in the tree, then walk up to the nearest ancestor
|
|
175
|
+
* carrying an `onPress` (the mocked Button) and invoke it.
|
|
176
|
+
*/
|
|
177
|
+
function pressByText(json: unknown, text: string): void {
|
|
178
|
+
const visit = (node: unknown, path: unknown[]): void => {
|
|
179
|
+
if (typeof node === 'string') {
|
|
180
|
+
if (node === text) {
|
|
181
|
+
for (let i = path.length - 1; i >= 0; i--) {
|
|
182
|
+
const ancestor = path[i] as TreeNode;
|
|
183
|
+
if (typeof ancestor?.props?.onPress === 'function') {
|
|
184
|
+
(ancestor.props.onPress as () => void)();
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
if (node === null || typeof node !== 'object') return;
|
|
192
|
+
const children = (node as TreeNode).children;
|
|
193
|
+
if (!Array.isArray(children)) return;
|
|
194
|
+
for (const c of children) visit(c, [...path, node]);
|
|
195
|
+
};
|
|
196
|
+
visit(json, []);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const GROUP_YES = {
|
|
200
|
+
id: 'g-yes',
|
|
201
|
+
handle: 'yes',
|
|
202
|
+
displayName: 'Yes Group',
|
|
203
|
+
capabilities: { member: { add: ['core-posts-create-note'] } },
|
|
204
|
+
};
|
|
205
|
+
const GROUP_NO = {
|
|
206
|
+
id: 'g-no',
|
|
207
|
+
handle: 'no',
|
|
208
|
+
displayName: 'No Group',
|
|
209
|
+
capabilities: { member: { add: [] } },
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
beforeEach(() => {
|
|
213
|
+
// react-test-renderer's act() needs this to skip the "not configured" warning.
|
|
214
|
+
(
|
|
215
|
+
globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }
|
|
216
|
+
).IS_REACT_ACT_ENVIRONMENT = true;
|
|
217
|
+
state.me = null;
|
|
218
|
+
state.authData = {};
|
|
219
|
+
state.conversations = [];
|
|
220
|
+
state.conversationsLoading = false;
|
|
221
|
+
(Toast.show as jest.Mock).mockClear();
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
// ---------- ShareIntoGroupModal ----------
|
|
225
|
+
|
|
226
|
+
test('group modal lists only groups the viewer can post notes to (#1851 S4)', () => {
|
|
227
|
+
state.me = {
|
|
228
|
+
id: 'me-1',
|
|
229
|
+
memberships: [
|
|
230
|
+
{ group: GROUP_YES, roles: ['member'] },
|
|
231
|
+
{ group: GROUP_NO, roles: ['member'] },
|
|
232
|
+
],
|
|
233
|
+
};
|
|
234
|
+
state.authData = {
|
|
235
|
+
profile: {
|
|
236
|
+
id: 'me-1',
|
|
237
|
+
memberships: [
|
|
238
|
+
{ group: { id: 'g-yes' }, roles: ['member'] },
|
|
239
|
+
{ group: { id: 'g-no' }, roles: ['member'] },
|
|
240
|
+
],
|
|
241
|
+
},
|
|
242
|
+
};
|
|
243
|
+
const onShare = jest.fn();
|
|
244
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
245
|
+
ReactTestRenderer.act(() => {
|
|
246
|
+
tree = ReactTestRenderer.create(
|
|
247
|
+
React.createElement(ShareIntoGroupModal, {
|
|
248
|
+
open: true,
|
|
249
|
+
onClose: jest.fn(),
|
|
250
|
+
onShare,
|
|
251
|
+
})
|
|
252
|
+
);
|
|
253
|
+
});
|
|
254
|
+
const text = collectText(tree.toJSON());
|
|
255
|
+
expect(text).toContain('Yes Group');
|
|
256
|
+
expect(text).not.toContain('No Group');
|
|
257
|
+
tree.unmount();
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
test('group modal shows the empty state when no group is postable (#1851 S4)', () => {
|
|
261
|
+
state.me = {
|
|
262
|
+
id: 'me-1',
|
|
263
|
+
memberships: [{ group: GROUP_NO, roles: ['member'] }],
|
|
264
|
+
};
|
|
265
|
+
state.authData = {
|
|
266
|
+
profile: {
|
|
267
|
+
id: 'me-1',
|
|
268
|
+
memberships: [{ group: { id: 'g-no' }, roles: ['member'] }],
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
272
|
+
ReactTestRenderer.act(() => {
|
|
273
|
+
tree = ReactTestRenderer.create(
|
|
274
|
+
React.createElement(ShareIntoGroupModal, {
|
|
275
|
+
open: true,
|
|
276
|
+
onClose: jest.fn(),
|
|
277
|
+
onShare: jest.fn(),
|
|
278
|
+
})
|
|
279
|
+
);
|
|
280
|
+
});
|
|
281
|
+
expect(collectText(tree.toJSON())).toContain("You can't post to any group");
|
|
282
|
+
tree.unmount();
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
test('group modal: sharing calls onShare with the group id, toasts success, closes (#1851 S4)', async () => {
|
|
286
|
+
state.me = {
|
|
287
|
+
id: 'me-1',
|
|
288
|
+
memberships: [{ group: GROUP_YES, roles: ['member'] }],
|
|
289
|
+
};
|
|
290
|
+
state.authData = {
|
|
291
|
+
profile: {
|
|
292
|
+
id: 'me-1',
|
|
293
|
+
memberships: [{ group: { id: 'g-yes' }, roles: ['member'] }],
|
|
294
|
+
},
|
|
295
|
+
};
|
|
296
|
+
const onShare = jest.fn().mockResolvedValue(undefined);
|
|
297
|
+
const onClose = jest.fn();
|
|
298
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
299
|
+
ReactTestRenderer.act(() => {
|
|
300
|
+
tree = ReactTestRenderer.create(
|
|
301
|
+
React.createElement(ShareIntoGroupModal, {
|
|
302
|
+
open: true,
|
|
303
|
+
onClose,
|
|
304
|
+
onShare,
|
|
305
|
+
})
|
|
306
|
+
);
|
|
307
|
+
});
|
|
308
|
+
await ReactTestRenderer.act(async () => {
|
|
309
|
+
pressByText(tree.toJSON(), 'Yes Group');
|
|
310
|
+
});
|
|
311
|
+
expect(onShare).toHaveBeenCalledWith('g-yes');
|
|
312
|
+
expect(Toast.show).toHaveBeenCalledWith(
|
|
313
|
+
expect.objectContaining({ type: 'success', text1: 'Shared into Yes Group' })
|
|
314
|
+
);
|
|
315
|
+
expect(onClose).toHaveBeenCalled();
|
|
316
|
+
tree.unmount();
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
test('group modal: a failed share toasts the error and keeps the sheet open (#1851 S4)', async () => {
|
|
320
|
+
state.me = {
|
|
321
|
+
id: 'me-1',
|
|
322
|
+
memberships: [{ group: GROUP_YES, roles: ['member'] }],
|
|
323
|
+
};
|
|
324
|
+
state.authData = {
|
|
325
|
+
profile: {
|
|
326
|
+
id: 'me-1',
|
|
327
|
+
memberships: [{ group: { id: 'g-yes' }, roles: ['member'] }],
|
|
328
|
+
},
|
|
329
|
+
};
|
|
330
|
+
const onShare = jest.fn().mockRejectedValue(new Error('boom'));
|
|
331
|
+
const onClose = jest.fn();
|
|
332
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
333
|
+
ReactTestRenderer.act(() => {
|
|
334
|
+
tree = ReactTestRenderer.create(
|
|
335
|
+
React.createElement(ShareIntoGroupModal, {
|
|
336
|
+
open: true,
|
|
337
|
+
onClose,
|
|
338
|
+
onShare,
|
|
339
|
+
})
|
|
340
|
+
);
|
|
341
|
+
});
|
|
342
|
+
await ReactTestRenderer.act(async () => {
|
|
343
|
+
pressByText(tree.toJSON(), 'Yes Group');
|
|
344
|
+
});
|
|
345
|
+
expect(onShare).toHaveBeenCalledWith('g-yes');
|
|
346
|
+
expect(Toast.show).toHaveBeenCalledWith(
|
|
347
|
+
expect.objectContaining({
|
|
348
|
+
type: 'error',
|
|
349
|
+
text1: "Couldn't share the post",
|
|
350
|
+
})
|
|
351
|
+
);
|
|
352
|
+
expect(onClose).not.toHaveBeenCalled();
|
|
353
|
+
tree.unmount();
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
// Review round 11 S2: the conversation modal pins its in-flight window (round
|
|
357
|
+
// 9 S2) and its failed-send guard reset (round 7 S3); the group modal only
|
|
358
|
+
// asserted settled outcomes. Mirror both onto `ShareIntoGroupModal` so the two
|
|
359
|
+
// new modals pin the same guard semantics — `sharing` disables the row in
|
|
360
|
+
// flight, a second press is swallowed by the guard, and `finally` re-enables
|
|
361
|
+
// the row after a failure. This is the RN twin of the statement-level guard
|
|
362
|
+
// the round-10 rework added on web.
|
|
363
|
+
test('group modal: the in-flight guard disables the row and swallows a second press (round 11 S2)', async () => {
|
|
364
|
+
state.me = {
|
|
365
|
+
id: 'me-1',
|
|
366
|
+
memberships: [{ group: GROUP_YES, roles: ['member'] }],
|
|
367
|
+
};
|
|
368
|
+
state.authData = {
|
|
369
|
+
profile: {
|
|
370
|
+
id: 'me-1',
|
|
371
|
+
memberships: [{ group: { id: 'g-yes' }, roles: ['member'] }],
|
|
372
|
+
},
|
|
373
|
+
};
|
|
374
|
+
let resolveShare: (v: undefined) => void = () => {};
|
|
375
|
+
const onShare = jest.fn(
|
|
376
|
+
() =>
|
|
377
|
+
new Promise<undefined>((resolve) => {
|
|
378
|
+
resolveShare = resolve;
|
|
379
|
+
})
|
|
380
|
+
);
|
|
381
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
382
|
+
ReactTestRenderer.act(() => {
|
|
383
|
+
tree = ReactTestRenderer.create(
|
|
384
|
+
React.createElement(ShareIntoGroupModal, {
|
|
385
|
+
open: true,
|
|
386
|
+
onClose: jest.fn(),
|
|
387
|
+
onShare,
|
|
388
|
+
})
|
|
389
|
+
);
|
|
390
|
+
});
|
|
391
|
+
// First press starts the share.
|
|
392
|
+
await ReactTestRenderer.act(async () => {
|
|
393
|
+
pressByText(tree.toJSON(), 'Yes Group');
|
|
394
|
+
});
|
|
395
|
+
expect(onShare).toHaveBeenCalledTimes(1);
|
|
396
|
+
// In-flight: the row is disabled.
|
|
397
|
+
expect(rowDisabled(tree.toJSON())).toBe(true);
|
|
398
|
+
// A second press during the window is swallowed by the `if (sharing) return`
|
|
399
|
+
// guard (the mocked Button forwards `onPress` even when `disabled`, so the
|
|
400
|
+
// guard — not the presentation layer — is what's pinned).
|
|
401
|
+
await ReactTestRenderer.act(async () => {
|
|
402
|
+
pressByText(tree.toJSON(), 'Yes Group');
|
|
403
|
+
});
|
|
404
|
+
expect(onShare).toHaveBeenCalledTimes(1);
|
|
405
|
+
// Settling the share re-enables the row.
|
|
406
|
+
await ReactTestRenderer.act(async () => {
|
|
407
|
+
resolveShare(undefined);
|
|
408
|
+
await Promise.resolve();
|
|
409
|
+
await Promise.resolve();
|
|
410
|
+
});
|
|
411
|
+
expect(rowDisabled(tree.toJSON())).toBe(false);
|
|
412
|
+
tree.unmount();
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
test('group modal: a failed share resets the transient guard and re-enables the row (round 11 S2)', async () => {
|
|
416
|
+
state.me = {
|
|
417
|
+
id: 'me-1',
|
|
418
|
+
memberships: [{ group: GROUP_YES, roles: ['member'] }],
|
|
419
|
+
};
|
|
420
|
+
state.authData = {
|
|
421
|
+
profile: {
|
|
422
|
+
id: 'me-1',
|
|
423
|
+
memberships: [{ group: { id: 'g-yes' }, roles: ['member'] }],
|
|
424
|
+
},
|
|
425
|
+
};
|
|
426
|
+
const onShare = jest.fn().mockRejectedValue(new Error('boom'));
|
|
427
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
428
|
+
ReactTestRenderer.act(() => {
|
|
429
|
+
tree = ReactTestRenderer.create(
|
|
430
|
+
React.createElement(ShareIntoGroupModal, {
|
|
431
|
+
open: true,
|
|
432
|
+
onClose: jest.fn(),
|
|
433
|
+
onShare,
|
|
434
|
+
})
|
|
435
|
+
);
|
|
436
|
+
});
|
|
437
|
+
// The rejected share settles (and `finally` clears `sharing`), re-enabling
|
|
438
|
+
// the row rather than leaving it stuck disabled.
|
|
439
|
+
expect(rowDisabled(tree.toJSON())).toBe(false);
|
|
440
|
+
await ReactTestRenderer.act(async () => {
|
|
441
|
+
pressByText(tree.toJSON(), 'Yes Group');
|
|
442
|
+
// Let the microtask queue (settle the promise, then `finally`) flush.
|
|
443
|
+
await Promise.resolve();
|
|
444
|
+
await Promise.resolve();
|
|
445
|
+
});
|
|
446
|
+
expect(rowDisabled(tree.toJSON())).toBe(false);
|
|
447
|
+
tree.unmount();
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
// ---------- SendToConversationModal ----------
|
|
451
|
+
|
|
452
|
+
const CONVERSATION = [
|
|
453
|
+
{ id: 'root-1', visibility: 'direct', data: { type: 'note' } },
|
|
454
|
+
{
|
|
455
|
+
id: 'last-1',
|
|
456
|
+
visibility: 'direct',
|
|
457
|
+
profile: { id: 'other-1', handle: 'ada' },
|
|
458
|
+
audience: [
|
|
459
|
+
{ id: 'me-1', handle: 'me' },
|
|
460
|
+
{ id: 'other-1', handle: 'ada', displayName: 'Ada' },
|
|
461
|
+
],
|
|
462
|
+
data: { type: 'note', content: 'hello there' },
|
|
463
|
+
},
|
|
464
|
+
];
|
|
465
|
+
|
|
466
|
+
test('conversation modal lists conversations loaded from useConversations (#1851 S4)', () => {
|
|
467
|
+
state.me = { id: 'me-1' };
|
|
468
|
+
state.conversations = [CONVERSATION];
|
|
469
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
470
|
+
ReactTestRenderer.act(() => {
|
|
471
|
+
tree = ReactTestRenderer.create(
|
|
472
|
+
React.createElement(SendToConversationModal, {
|
|
473
|
+
open: true,
|
|
474
|
+
onClose: jest.fn(),
|
|
475
|
+
onSend: jest.fn(),
|
|
476
|
+
})
|
|
477
|
+
);
|
|
478
|
+
});
|
|
479
|
+
const text = collectText(tree.toJSON());
|
|
480
|
+
// Title comes from the other participant (self excluded).
|
|
481
|
+
expect(text).toContain('Ada');
|
|
482
|
+
// Last-message snippet is the note content.
|
|
483
|
+
expect(text).toContain('hello there');
|
|
484
|
+
tree.unmount();
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
test('conversation modal shows a spinner while the list is loading (#1851 S4)', () => {
|
|
488
|
+
state.me = { id: 'me-1' };
|
|
489
|
+
state.conversationsLoading = true;
|
|
490
|
+
state.conversations = [];
|
|
491
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
492
|
+
ReactTestRenderer.act(() => {
|
|
493
|
+
tree = ReactTestRenderer.create(
|
|
494
|
+
React.createElement(SendToConversationModal, {
|
|
495
|
+
open: true,
|
|
496
|
+
onClose: jest.fn(),
|
|
497
|
+
onSend: jest.fn(),
|
|
498
|
+
})
|
|
499
|
+
);
|
|
500
|
+
});
|
|
501
|
+
// No rows, no empty-state copy, no buttons while loading.
|
|
502
|
+
expect(collectText(tree.toJSON())).not.toContain('Ada');
|
|
503
|
+
expect(collectText(tree.toJSON())).not.toContain(
|
|
504
|
+
"You don't have any conversations yet"
|
|
505
|
+
);
|
|
506
|
+
tree.unmount();
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
test('conversation modal shows the empty state when there are none (#1851 S4)', () => {
|
|
510
|
+
state.me = { id: 'me-1' };
|
|
511
|
+
state.conversations = [];
|
|
512
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
513
|
+
ReactTestRenderer.act(() => {
|
|
514
|
+
tree = ReactTestRenderer.create(
|
|
515
|
+
React.createElement(SendToConversationModal, {
|
|
516
|
+
open: true,
|
|
517
|
+
onClose: jest.fn(),
|
|
518
|
+
onSend: jest.fn(),
|
|
519
|
+
})
|
|
520
|
+
);
|
|
521
|
+
});
|
|
522
|
+
expect(collectText(tree.toJSON())).toContain(
|
|
523
|
+
"You don't have any conversations yet"
|
|
524
|
+
);
|
|
525
|
+
tree.unmount();
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
test('conversation modal: sending calls onSend with the conversation, toasts success, closes (#1851 S4)', async () => {
|
|
529
|
+
state.me = { id: 'me-1' };
|
|
530
|
+
state.conversations = [CONVERSATION];
|
|
531
|
+
const onSend = jest.fn().mockResolvedValue(undefined);
|
|
532
|
+
const onClose = jest.fn();
|
|
533
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
534
|
+
ReactTestRenderer.act(() => {
|
|
535
|
+
tree = ReactTestRenderer.create(
|
|
536
|
+
React.createElement(SendToConversationModal, {
|
|
537
|
+
open: true,
|
|
538
|
+
onClose,
|
|
539
|
+
onSend,
|
|
540
|
+
})
|
|
541
|
+
);
|
|
542
|
+
});
|
|
543
|
+
await ReactTestRenderer.act(async () => {
|
|
544
|
+
pressByText(tree.toJSON(), 'Ada');
|
|
545
|
+
});
|
|
546
|
+
expect(onSend).toHaveBeenCalledWith(CONVERSATION);
|
|
547
|
+
expect(Toast.show).toHaveBeenCalledWith(
|
|
548
|
+
expect.objectContaining({ type: 'success', text1: 'Sent to Ada' })
|
|
549
|
+
);
|
|
550
|
+
expect(onClose).toHaveBeenCalled();
|
|
551
|
+
tree.unmount();
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
test('conversation modal: a failed send toasts the error and keeps the sheet open (#1851 S4)', async () => {
|
|
555
|
+
state.me = { id: 'me-1' };
|
|
556
|
+
state.conversations = [CONVERSATION];
|
|
557
|
+
const onSend = jest.fn().mockRejectedValue(new Error('boom'));
|
|
558
|
+
const onClose = jest.fn();
|
|
559
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
560
|
+
ReactTestRenderer.act(() => {
|
|
561
|
+
tree = ReactTestRenderer.create(
|
|
562
|
+
React.createElement(SendToConversationModal, {
|
|
563
|
+
open: true,
|
|
564
|
+
onClose,
|
|
565
|
+
onSend,
|
|
566
|
+
})
|
|
567
|
+
);
|
|
568
|
+
});
|
|
569
|
+
await ReactTestRenderer.act(async () => {
|
|
570
|
+
pressByText(tree.toJSON(), 'Ada');
|
|
571
|
+
});
|
|
572
|
+
expect(onSend).toHaveBeenCalledWith(CONVERSATION);
|
|
573
|
+
expect(Toast.show).toHaveBeenCalledWith(
|
|
574
|
+
expect.objectContaining({
|
|
575
|
+
type: 'error',
|
|
576
|
+
text1: "Couldn't share the post",
|
|
577
|
+
})
|
|
578
|
+
);
|
|
579
|
+
expect(onClose).not.toHaveBeenCalled();
|
|
580
|
+
tree.unmount();
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
/** Extract the row title text, so the assertion can't be satisfied by the
|
|
584
|
+
* "You:" snippet prefix of the last-message line. The mocked ThemedText
|
|
585
|
+
* drops `className`, so the row title is identified structurally: a
|
|
586
|
+
* ThemedText with exactly one text child that sits inside a row (an
|
|
587
|
+
* ancestor View carrying `onPress`, the mocked Button). The snippet line
|
|
588
|
+
* always renders three text pieces, and the sheet header is outside any
|
|
589
|
+
* row. */
|
|
590
|
+
const rowTitleTexts = (json: unknown): string[] => {
|
|
591
|
+
const out: string[] = [];
|
|
592
|
+
const visit = (node: unknown, inRow: boolean): void => {
|
|
593
|
+
if (!node || typeof node !== 'object') return;
|
|
594
|
+
const nodes = (Array.isArray(node) ? node : [node]) as {
|
|
595
|
+
type?: unknown;
|
|
596
|
+
props?: { onPress?: unknown };
|
|
597
|
+
children?: unknown[];
|
|
598
|
+
}[];
|
|
599
|
+
for (const n of nodes) {
|
|
600
|
+
if (!n) continue;
|
|
601
|
+
const children = (n.children ?? []).filter(
|
|
602
|
+
(c) => c !== null && c !== undefined
|
|
603
|
+
) as unknown[];
|
|
604
|
+
const row = inRow || typeof n.props?.onPress === 'function';
|
|
605
|
+
if (
|
|
606
|
+
n.type === 'ThemedText' &&
|
|
607
|
+
row &&
|
|
608
|
+
children.length === 1 &&
|
|
609
|
+
typeof children[0] === 'string'
|
|
610
|
+
) {
|
|
611
|
+
out.push(children[0]);
|
|
612
|
+
}
|
|
613
|
+
visit(n.children, row);
|
|
614
|
+
}
|
|
615
|
+
};
|
|
616
|
+
visit(json, false);
|
|
617
|
+
return out;
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
test('conversation modal: last post names only the viewer → title falls back to the root post participant (#1851 S4)', () => {
|
|
621
|
+
state.me = { id: 'me-1' };
|
|
622
|
+
state.conversations = [
|
|
623
|
+
[
|
|
624
|
+
{
|
|
625
|
+
id: 'root-1',
|
|
626
|
+
visibility: 'direct',
|
|
627
|
+
profile: { id: 'other-1', handle: 'ada' },
|
|
628
|
+
audience: [
|
|
629
|
+
{ id: 'me-1', handle: 'me' },
|
|
630
|
+
{ id: 'other-1', handle: 'ada', displayName: 'Ada' },
|
|
631
|
+
],
|
|
632
|
+
data: { type: 'note', content: 'hello' },
|
|
633
|
+
},
|
|
634
|
+
{
|
|
635
|
+
id: 'last-1',
|
|
636
|
+
visibility: 'direct',
|
|
637
|
+
profile: { id: 'me-1', handle: 'me' },
|
|
638
|
+
// The other participant left: the current audience is just the viewer.
|
|
639
|
+
audience: [{ id: 'me-1', handle: 'me' }],
|
|
640
|
+
data: { type: 'note', content: 'note to self' },
|
|
641
|
+
},
|
|
642
|
+
],
|
|
643
|
+
];
|
|
644
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
645
|
+
ReactTestRenderer.act(() => {
|
|
646
|
+
tree = ReactTestRenderer.create(
|
|
647
|
+
React.createElement(SendToConversationModal, {
|
|
648
|
+
open: true,
|
|
649
|
+
onClose: jest.fn(),
|
|
650
|
+
onSend: jest.fn(),
|
|
651
|
+
})
|
|
652
|
+
);
|
|
653
|
+
});
|
|
654
|
+
// The row is titled by the root participant, not "You".
|
|
655
|
+
expect(rowTitleTexts(tree.toJSON())).toEqual(['Ada']);
|
|
656
|
+
tree.unmount();
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
test('conversation modal: "You" title only when neither last nor root post names anyone else (#1851 S4)', () => {
|
|
660
|
+
state.me = { id: 'me-1' };
|
|
661
|
+
state.conversations = [
|
|
662
|
+
[
|
|
663
|
+
{
|
|
664
|
+
id: 'root-1',
|
|
665
|
+
visibility: 'direct',
|
|
666
|
+
profile: { id: 'me-1', handle: 'me' },
|
|
667
|
+
audience: [{ id: 'me-1', handle: 'me' }],
|
|
668
|
+
data: { type: 'note', content: 'hello me' },
|
|
669
|
+
},
|
|
670
|
+
],
|
|
671
|
+
];
|
|
672
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
673
|
+
ReactTestRenderer.act(() => {
|
|
674
|
+
tree = ReactTestRenderer.create(
|
|
675
|
+
React.createElement(SendToConversationModal, {
|
|
676
|
+
open: true,
|
|
677
|
+
onClose: jest.fn(),
|
|
678
|
+
onSend: jest.fn(),
|
|
679
|
+
})
|
|
680
|
+
);
|
|
681
|
+
});
|
|
682
|
+
expect(rowTitleTexts(tree.toJSON())).toEqual(['You']);
|
|
683
|
+
tree.unmount();
|
|
684
|
+
});
|
|
685
|
+
|
|
686
|
+
// Review round 7 S3: the modal's transient state is the in-flight
|
|
687
|
+
// `sending` guard (no separate selected-item state exists to lift). It can't
|
|
688
|
+
// survive a re-open: ShareMenu mounts the modal conditionally
|
|
689
|
+
// (`{conversationPickerOpen ? <SendToConversationModal/> : null}`), so
|
|
690
|
+
// closing the picker unmounts it and its state is discarded. A failing send
|
|
691
|
+
// also resets `sending` (the `finally` clears it), so the list re-enables
|
|
692
|
+
// rather than staying stuck disabled. `ShareIntoGroupModal` mirrors this with
|
|
693
|
+
// its `sharing` guard. A behavioral pin follows, plus a source-contract pin
|
|
694
|
+
// so a later refactor can't keep the sheet mounted (state-preserving) without
|
|
695
|
+
// re-proving the reset.
|
|
696
|
+
test('conversation modal: a failed send resets the transient guard and re-enables the rows (#1851 round 7 S3)', async () => {
|
|
697
|
+
state.me = { id: 'me-1' };
|
|
698
|
+
state.conversations = [CONVERSATION];
|
|
699
|
+
const onSend = jest.fn().mockRejectedValue(new Error('boom'));
|
|
700
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
701
|
+
ReactTestRenderer.act(() => {
|
|
702
|
+
tree = ReactTestRenderer.create(
|
|
703
|
+
React.createElement(SendToConversationModal, {
|
|
704
|
+
open: true,
|
|
705
|
+
onClose: jest.fn(),
|
|
706
|
+
onSend,
|
|
707
|
+
})
|
|
708
|
+
);
|
|
709
|
+
});
|
|
710
|
+
const row = rowTitleTexts(tree.toJSON());
|
|
711
|
+
expect(row).toEqual(['Ada']);
|
|
712
|
+
// While a send is in flight the rows are disabled; after the rejected send
|
|
713
|
+
// settles the `finally` clears `sending`, re-enabling the list (and, since
|
|
714
|
+
// the modal unmounts on close, a re-open would start clean regardless).
|
|
715
|
+
expect(rowDisabled(tree.toJSON())).toBe(false);
|
|
716
|
+
await ReactTestRenderer.act(async () => {
|
|
717
|
+
pressByText(tree.toJSON(), 'Ada');
|
|
718
|
+
// Let the microtask queue (settle the promise, then `finally`) flush.
|
|
719
|
+
await Promise.resolve();
|
|
720
|
+
await Promise.resolve();
|
|
721
|
+
});
|
|
722
|
+
expect(rowDisabled(tree.toJSON())).toBe(false);
|
|
723
|
+
tree.unmount();
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
// Review round 9 S2: the settled-state test above only observes the guard
|
|
727
|
+
// before and after the send; the in-flight window itself is what the state
|
|
728
|
+
// machine exists to protect (a double-press would fire a second send). Drive
|
|
729
|
+
// `onSend` with a promise the test resolves manually so the window can be
|
|
730
|
+
// observed: every row is disabled while `sending !== null`, and a second
|
|
731
|
+
// press inside the window is swallowed by the `if (!root || sending) return`
|
|
732
|
+
// guard (the mocked Button forwards `onPress` even when `disabled`, so the
|
|
733
|
+
// guard — not the presentation layer — is what's pinned).
|
|
734
|
+
test('conversation modal: the in-flight guard disables rows and swallows a second press (round 9 S2)', async () => {
|
|
735
|
+
state.me = { id: 'me-1' };
|
|
736
|
+
state.conversations = [CONVERSATION];
|
|
737
|
+
let resolveSend: (v: undefined) => void = () => {};
|
|
738
|
+
const onSend = jest.fn(
|
|
739
|
+
() =>
|
|
740
|
+
new Promise<undefined>((resolve) => {
|
|
741
|
+
resolveSend = resolve;
|
|
742
|
+
})
|
|
743
|
+
);
|
|
744
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
745
|
+
ReactTestRenderer.act(() => {
|
|
746
|
+
tree = ReactTestRenderer.create(
|
|
747
|
+
React.createElement(SendToConversationModal, {
|
|
748
|
+
open: true,
|
|
749
|
+
onClose: jest.fn(),
|
|
750
|
+
onSend,
|
|
751
|
+
})
|
|
752
|
+
);
|
|
753
|
+
});
|
|
754
|
+
// First press starts the send.
|
|
755
|
+
await ReactTestRenderer.act(async () => {
|
|
756
|
+
pressByText(tree.toJSON(), 'Ada');
|
|
757
|
+
});
|
|
758
|
+
expect(onSend).toHaveBeenCalledTimes(1);
|
|
759
|
+
// In-flight: every row is disabled.
|
|
760
|
+
expect(rowDisabled(tree.toJSON())).toBe(true);
|
|
761
|
+
// A second press during the window is swallowed by the guard.
|
|
762
|
+
await ReactTestRenderer.act(async () => {
|
|
763
|
+
pressByText(tree.toJSON(), 'Ada');
|
|
764
|
+
});
|
|
765
|
+
expect(onSend).toHaveBeenCalledTimes(1);
|
|
766
|
+
// Settling the send re-enables the rows.
|
|
767
|
+
await ReactTestRenderer.act(async () => {
|
|
768
|
+
resolveSend(undefined);
|
|
769
|
+
await Promise.resolve();
|
|
770
|
+
await Promise.resolve();
|
|
771
|
+
});
|
|
772
|
+
expect(rowDisabled(tree.toJSON())).toBe(false);
|
|
773
|
+
tree.unmount();
|
|
774
|
+
});
|
|
775
|
+
|
|
776
|
+
/** True if any row (a View with an `onPress`) is currently disabled. */
|
|
777
|
+
const rowDisabled = (json: unknown): boolean => {
|
|
778
|
+
let disabled = false;
|
|
779
|
+
const visit = (node: unknown): void => {
|
|
780
|
+
if (!node || typeof node !== 'object') return;
|
|
781
|
+
for (const n of (Array.isArray(node) ? node : [node]) as {
|
|
782
|
+
props?: { onPress?: unknown; disabled?: unknown };
|
|
783
|
+
children?: unknown[];
|
|
784
|
+
}[]) {
|
|
785
|
+
if (!n) continue;
|
|
786
|
+
if (
|
|
787
|
+
typeof n.props?.onPress === 'function' &&
|
|
788
|
+
n.props?.disabled === true
|
|
789
|
+
) {
|
|
790
|
+
disabled = true;
|
|
791
|
+
}
|
|
792
|
+
visit(n.children);
|
|
793
|
+
}
|
|
794
|
+
};
|
|
795
|
+
visit(json);
|
|
796
|
+
return disabled;
|
|
797
|
+
};
|
|
798
|
+
|
|
799
|
+
// The re-open reset is guaranteed by conditional mounting, not by a
|
|
800
|
+
// `useEffect` cleanup inside the modal. Pin the contract in the source so a
|
|
801
|
+
// later refactor can't keep the sheet mounted (e.g. an `open`-gated
|
|
802
|
+
// BottomSheet that preserves state across open/close) without re-proving the
|
|
803
|
+
// reset. Mirrors the web-side pin in ShareMenu.test.tsx.
|
|
804
|
+
test('ShareMenu mounts the conversation modal conditionally, so its transient state is discarded on close (#1851 round 7 S3)', () => {
|
|
805
|
+
const src = fs.readFileSync(path.join(__dirname, 'ShareMenu.tsx'), 'utf8');
|
|
806
|
+
// The modal is rendered only while `conversationPickerOpen` is true;
|
|
807
|
+
// closing the picker unmounts it (and thus clears `sending`).
|
|
808
|
+
expect(src).toMatch(
|
|
809
|
+
/conversationPickerOpen\s*\?\s*\(\s*<SendToConversationModal/
|
|
810
|
+
);
|
|
811
|
+
expect(src).toMatch(/groupPickerOpen\s*\?\s*\(\s*<ShareIntoGroupModal/);
|
|
812
|
+
// The modal itself owns no mount-lifecycle state reset (it relies on the
|
|
813
|
+
// conditional mount above, not a `useEffect`).
|
|
814
|
+
const modal = fs.readFileSync(
|
|
815
|
+
path.join(__dirname, 'modals', 'SendToConversationModal.tsx'),
|
|
816
|
+
'utf8'
|
|
817
|
+
);
|
|
818
|
+
expect(modal).not.toMatch(/useEffect/);
|
|
819
|
+
});
|