@openpeepshq/rn-components 0.23.0 → 0.24.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 +3 -3
- package/src/components/jams/JamPeopleDrawer.test.tsx +104 -9
- package/src/components/jams/JamPeopleDrawer.tsx +48 -11
- package/src/components/jams/JamRequestJoin.test.tsx +163 -0
- package/src/components/jams/JamRequestJoin.tsx +31 -15
- package/src/components/navigation/main-navigator.tsx +5 -0
- package/src/components/navigation/nativeRouter.tsx +1 -0
- package/src/components/navigation/parent-back.ts +1 -0
- package/src/components/navigation/types/main.ts +1 -0
- package/src/pages/index.ts +1 -0
- package/src/pages/settings/CalendarFeed.test.tsx +269 -0
- package/src/pages/settings/CalendarFeed.tsx +77 -0
- package/src/pages/settings/Index.tsx +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpeepshq/rn-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "React Native community screens and shared UI (extracted from the Black Ambition app) for the OpenPeeps stack.",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -142,9 +142,9 @@
|
|
|
142
142
|
"timezones-list": "^3.1.0",
|
|
143
143
|
"validator": "^13.15.23",
|
|
144
144
|
"zustand": "^5.0.3",
|
|
145
|
-
"@openpeepshq/common": "^0.
|
|
145
|
+
"@openpeepshq/common": "^0.17.0",
|
|
146
146
|
"@openpeepshq/fetch-client": "^0.2.1",
|
|
147
|
-
"@openpeepshq/react": "^0.
|
|
147
|
+
"@openpeepshq/react": "^0.26.0"
|
|
148
148
|
},
|
|
149
149
|
"devDependencies": {
|
|
150
150
|
"@babel/core": "^7.26.7",
|
|
@@ -26,10 +26,21 @@ let mockHasWaitingRoom = false;
|
|
|
26
26
|
let mockWaitingProfiles: unknown[] = [];
|
|
27
27
|
let mockBannedIds: string[] = [];
|
|
28
28
|
const mockPressHandlers: Array<() => void> = [];
|
|
29
|
+
// Busy state for the waiting-room action row (mirrors `useJamPeople`).
|
|
30
|
+
let mockAdmittingId: string | null = null;
|
|
31
|
+
let mockRejectingId: string | null = null;
|
|
32
|
+
// Every rendered action-button and its props, in document order.
|
|
33
|
+
const mockButtonProps: Array<Record<string, unknown>> = [];
|
|
34
|
+
// Every rendered View className (pins the action group's layout classes).
|
|
35
|
+
const mockViewClasses: string[] = [];
|
|
36
|
+
// Every rendered icon, in document order (recorded by the icon stub).
|
|
37
|
+
const mockIconNames: string[] = [];
|
|
29
38
|
|
|
30
39
|
jest.mock('react-native', () => ({
|
|
31
|
-
View: (props: { children?: unknown }) =>
|
|
32
|
-
|
|
40
|
+
View: (props: { children?: unknown; className?: string }) => {
|
|
41
|
+
if (props.className) mockViewClasses.push(props.className);
|
|
42
|
+
return React.createElement('View', null, props.children);
|
|
43
|
+
},
|
|
33
44
|
ScrollView: (props: { children?: unknown }) =>
|
|
34
45
|
React.createElement('ScrollView', null, props.children),
|
|
35
46
|
// Records every press handler in render order so a test can fire the
|
|
@@ -58,6 +69,10 @@ jest.mock('react-i18next', () => ({
|
|
|
58
69
|
if (key === 'jams.people.observers') return 'Observers';
|
|
59
70
|
if (key === 'jams.people.inWaitingRoom') return 'Waiting room';
|
|
60
71
|
if (key === 'jams.people.noParticipants') return 'No participants found';
|
|
72
|
+
if (key === 'jams.waitingRoom.admitParticipant') return 'Admit';
|
|
73
|
+
if (key === 'jams.waitingRoom.admitting') return 'Admitting\u2026';
|
|
74
|
+
if (key === 'jams.waitingRoom.rejectParticipant') return 'Reject';
|
|
75
|
+
if (key === 'jams.waitingRoom.rejecting') return 'Rejecting\u2026';
|
|
61
76
|
if (key === 'jams.drawer.peopleTitle') return 'People';
|
|
62
77
|
if (key === 'jams.drawer.close') return 'Close';
|
|
63
78
|
if (key === 'jams.drawer.searchPeoplePlaceholder') return 'Search';
|
|
@@ -84,8 +99,10 @@ jest.mock('@openpeepshq/react', () => ({
|
|
|
84
99
|
setQuery: () => {},
|
|
85
100
|
listedParticipants: mockParticipants,
|
|
86
101
|
waitingProfiles: mockWaitingProfiles,
|
|
87
|
-
admittingId:
|
|
102
|
+
admittingId: mockAdmittingId,
|
|
103
|
+
rejectingId: mockRejectingId,
|
|
88
104
|
admit: () => {},
|
|
105
|
+
reject: () => {},
|
|
89
106
|
// Mirror the real hook's banned-sublist contract (the drawer reads
|
|
90
107
|
// bannedIds/liftingId/liftBan when isModerator is true); empty keeps the
|
|
91
108
|
// "Removed" section hidden so these assertions stay on the Observers pin.
|
|
@@ -109,8 +126,10 @@ jest.mock('@openpeepshq/common/lib', () => ({
|
|
|
109
126
|
}));
|
|
110
127
|
|
|
111
128
|
jest.mock('../icons/index', () => {
|
|
112
|
-
const make = (name: string) => (props: Record<string, unknown>) =>
|
|
113
|
-
|
|
129
|
+
const make = (name: string) => (props: Record<string, unknown>) => {
|
|
130
|
+
mockIconNames.push(name);
|
|
131
|
+
return React.createElement(name, props);
|
|
132
|
+
};
|
|
114
133
|
return {
|
|
115
134
|
AudioLinesIcon: make('AudioLinesIcon'),
|
|
116
135
|
ChevronDownIcon: make('ChevronDownIcon'),
|
|
@@ -121,13 +140,16 @@ jest.mock('../icons/index', () => {
|
|
|
121
140
|
MicOffIcon: make('MicOffIcon'),
|
|
122
141
|
SearchIcon: make('SearchIcon'),
|
|
123
142
|
UserRoundCheckIcon: make('UserRoundCheckIcon'),
|
|
143
|
+
UserRoundXIcon: make('UserRoundXIcon'),
|
|
124
144
|
WifiOffIcon: make('WifiOffIcon'),
|
|
125
145
|
};
|
|
126
146
|
});
|
|
127
147
|
|
|
128
148
|
jest.mock('../ui/button', () => ({
|
|
129
|
-
Button: (props: { children?: unknown }) =>
|
|
130
|
-
|
|
149
|
+
Button: (props: { children?: unknown }) => {
|
|
150
|
+
mockButtonProps.push(props as unknown as Record<string, unknown>);
|
|
151
|
+
return React.createElement('Button', null, props.children);
|
|
152
|
+
},
|
|
131
153
|
}));
|
|
132
154
|
|
|
133
155
|
jest.mock('../ui/input', () => ({
|
|
@@ -170,8 +192,8 @@ jest.mock('../ui/themed-text', () => ({
|
|
|
170
192
|
}));
|
|
171
193
|
|
|
172
194
|
// The package ships ESM-only source (see the jest.config.cjs notes); the
|
|
173
|
-
// drawer only calls Toast.show for
|
|
174
|
-
// reach, so an inert mock keeps the suite parseable.
|
|
195
|
+
// drawer only calls Toast.show for waiting-room action feedback, which these
|
|
196
|
+
// cases never reach, so an inert mock keeps the suite parseable.
|
|
175
197
|
jest.mock('react-native-toast-message', () => {
|
|
176
198
|
const Toast = { show: jest.fn() };
|
|
177
199
|
return { __esModule: true, default: Toast };
|
|
@@ -182,6 +204,7 @@ const { JamPeopleDrawer } = require('./JamPeopleDrawer');
|
|
|
182
204
|
const renderDrawer = (
|
|
183
205
|
sessions: number,
|
|
184
206
|
waitingRoom: boolean = false,
|
|
207
|
+
busy: { admittingId?: string | null; rejectingId?: string | null } = {},
|
|
185
208
|
bannedIds: string[] = []
|
|
186
209
|
) => {
|
|
187
210
|
mockSessions = sessions;
|
|
@@ -189,7 +212,12 @@ const renderDrawer = (
|
|
|
189
212
|
mockHasWaitingRoom = waitingRoom;
|
|
190
213
|
mockWaitingProfiles = waitingRoom ? [{ id: 'w1' }] : [];
|
|
191
214
|
mockBannedIds = bannedIds;
|
|
215
|
+
mockAdmittingId = busy.admittingId ?? null;
|
|
216
|
+
mockRejectingId = busy.rejectingId ?? null;
|
|
192
217
|
mockRenderedTexts.length = 0;
|
|
218
|
+
mockButtonProps.length = 0;
|
|
219
|
+
mockViewClasses.length = 0;
|
|
220
|
+
mockIconNames.length = 0;
|
|
193
221
|
mockPressHandlers.length = 0;
|
|
194
222
|
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
195
223
|
ReactTestRenderer.act(() => {
|
|
@@ -252,6 +280,68 @@ describe('JamPeopleDrawer observers section (RN)', () => {
|
|
|
252
280
|
});
|
|
253
281
|
});
|
|
254
282
|
|
|
283
|
+
describe('JamPeopleDrawer waiting-room action row (RN)', () => {
|
|
284
|
+
it('pins the admit/reject row: labels, order, group layout, and icons', () => {
|
|
285
|
+
renderDrawer(0, true);
|
|
286
|
+
const texts = mockRenderedTexts;
|
|
287
|
+
|
|
288
|
+
expect(texts).toContain('Waiting room');
|
|
289
|
+
expect(texts).toContain('waiting');
|
|
290
|
+
expect(texts).toContain('Admit');
|
|
291
|
+
expect(texts).toContain('Reject');
|
|
292
|
+
// The action row follows the queued profile name…
|
|
293
|
+
expect(texts.indexOf('waiting')).toBeLessThan(texts.indexOf('Admit'));
|
|
294
|
+
// …and Admit precedes Reject within the row.
|
|
295
|
+
expect(texts.indexOf('Admit')).toBeLessThan(texts.indexOf('Reject'));
|
|
296
|
+
|
|
297
|
+
// Exactly the two action buttons render, in order, both enabled.
|
|
298
|
+
expect(mockButtonProps).toHaveLength(2);
|
|
299
|
+
expect(mockButtonProps[0].accessibilityLabel).toBe('Admit');
|
|
300
|
+
expect(mockButtonProps[1].accessibilityLabel).toBe('Reject');
|
|
301
|
+
expect(mockButtonProps[0].disabled).toBe(false);
|
|
302
|
+
expect(mockButtonProps[1].disabled).toBe(false);
|
|
303
|
+
|
|
304
|
+
// The button group carries the non-wrapping layout class (round-2
|
|
305
|
+
// finding), so it survives narrow-width Yoga shrinking.
|
|
306
|
+
expect(mockViewClasses).toContain('flex-row shrink-0 items-center gap-1');
|
|
307
|
+
|
|
308
|
+
// Both action icons render, check (admit) before x (reject).
|
|
309
|
+
expect(mockIconNames).toContain('UserRoundCheckIcon');
|
|
310
|
+
expect(mockIconNames).toContain('UserRoundXIcon');
|
|
311
|
+
expect(mockIconNames.indexOf('UserRoundCheckIcon')).toBeLessThan(
|
|
312
|
+
mockIconNames.indexOf('UserRoundXIcon')
|
|
313
|
+
);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it('swaps the busy accessibilityLabel and disables both buttons while admitting', () => {
|
|
317
|
+
renderDrawer(0, true, { admittingId: 'w1' });
|
|
318
|
+
|
|
319
|
+
expect(mockButtonProps[0].accessibilityLabel).toBe('Admitting\u2026');
|
|
320
|
+
expect(mockButtonProps[1].accessibilityLabel).toBe('Reject');
|
|
321
|
+
expect(mockButtonProps[0].disabled).toBe(true);
|
|
322
|
+
expect(mockButtonProps[1].disabled).toBe(true);
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it('swaps the busy accessibilityLabel and disables both buttons while rejecting', () => {
|
|
326
|
+
renderDrawer(0, true, { rejectingId: 'w1' });
|
|
327
|
+
|
|
328
|
+
expect(mockButtonProps[0].accessibilityLabel).toBe('Admit');
|
|
329
|
+
expect(mockButtonProps[1].accessibilityLabel).toBe('Rejecting\u2026');
|
|
330
|
+
expect(mockButtonProps[0].disabled).toBe(true);
|
|
331
|
+
expect(mockButtonProps[1].disabled).toBe(true);
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
it('hides the action row for non-moderators and without a waiting room', () => {
|
|
335
|
+
renderDrawer(0);
|
|
336
|
+
|
|
337
|
+
expect(mockButtonProps).toHaveLength(0);
|
|
338
|
+
expect(mockRenderedTexts).not.toContain('Waiting room');
|
|
339
|
+
expect(mockViewClasses).not.toContain(
|
|
340
|
+
'flex-row shrink-0 items-center gap-1'
|
|
341
|
+
);
|
|
342
|
+
});
|
|
343
|
+
});
|
|
344
|
+
|
|
255
345
|
describe('JamPeopleDrawer "Removed" sublist fallback (RN, issue #303 round-15 suggestion 2)', () => {
|
|
256
346
|
// Independent of the observers renderDrawer: the fallback case needs a
|
|
257
347
|
// moderator with a non-empty banned list but no waiting room / participants,
|
|
@@ -261,7 +351,12 @@ describe('JamPeopleDrawer "Removed" sublist fallback (RN, issue #303 round-15 su
|
|
|
261
351
|
mockHasWaitingRoom = false;
|
|
262
352
|
mockWaitingProfiles = [];
|
|
263
353
|
mockBannedIds = bannedIds;
|
|
354
|
+
mockAdmittingId = null;
|
|
355
|
+
mockRejectingId = null;
|
|
264
356
|
mockRenderedTexts.length = 0;
|
|
357
|
+
mockButtonProps.length = 0;
|
|
358
|
+
mockViewClasses.length = 0;
|
|
359
|
+
mockIconNames.length = 0;
|
|
265
360
|
mockPressHandlers.length = 0;
|
|
266
361
|
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
267
362
|
ReactTestRenderer.act(() => {
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
MicOffIcon,
|
|
23
23
|
SearchIcon,
|
|
24
24
|
UserRoundCheckIcon,
|
|
25
|
+
UserRoundXIcon,
|
|
25
26
|
WifiOffIcon,
|
|
26
27
|
} from '../icons/index';
|
|
27
28
|
import { Button } from '../ui/button';
|
|
@@ -118,8 +119,8 @@ const JamObserversSection = ({ count }: { count: number }) => {
|
|
|
118
119
|
|
|
119
120
|
/**
|
|
120
121
|
* In-room participants list with mic / raised-hand / moderator indicators,
|
|
121
|
-
* plus a moderator-only waiting-room admit
|
|
122
|
-
* external-session count.
|
|
122
|
+
* plus a moderator-only waiting-room section with admit and reject and the
|
|
123
|
+
* hidden external-session count.
|
|
123
124
|
*/
|
|
124
125
|
export const JamPeopleDrawer = ({ open, onClose }: JamPeopleDrawerProps) => {
|
|
125
126
|
const { t } = useTranslation();
|
|
@@ -137,7 +138,9 @@ export const JamPeopleDrawer = ({ open, onClose }: JamPeopleDrawerProps) => {
|
|
|
137
138
|
listedParticipants,
|
|
138
139
|
waitingProfiles,
|
|
139
140
|
admittingId,
|
|
141
|
+
rejectingId,
|
|
140
142
|
admit,
|
|
143
|
+
reject,
|
|
141
144
|
bannedIds,
|
|
142
145
|
liftingId,
|
|
143
146
|
liftBan,
|
|
@@ -145,6 +148,8 @@ export const JamPeopleDrawer = ({ open, onClose }: JamPeopleDrawerProps) => {
|
|
|
145
148
|
room,
|
|
146
149
|
participants,
|
|
147
150
|
onLiftError: (text1) => Toast.show({ type: 'error', text1 }),
|
|
151
|
+
onActionSuccess: (text1) => Toast.show({ type: 'success', text1 }),
|
|
152
|
+
onActionError: (text1) => Toast.show({ type: 'error', text1 }),
|
|
148
153
|
});
|
|
149
154
|
|
|
150
155
|
if (!open) return null;
|
|
@@ -206,15 +211,47 @@ export const JamPeopleDrawer = ({ open, onClose }: JamPeopleDrawerProps) => {
|
|
|
206
211
|
{waitingRoomEntryName(profile)}
|
|
207
212
|
</ThemedText>
|
|
208
213
|
</View>
|
|
209
|
-
<
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
214
|
+
<View className="flex-row shrink-0 items-center gap-1">
|
|
215
|
+
<Button
|
|
216
|
+
variant="outline"
|
|
217
|
+
size="sm"
|
|
218
|
+
onPress={() => admit(profile)}
|
|
219
|
+
disabled={
|
|
220
|
+
admittingId === profile.id || rejectingId === profile.id
|
|
221
|
+
}
|
|
222
|
+
accessibilityLabel={
|
|
223
|
+
admittingId === profile.id
|
|
224
|
+
? t('jams.waitingRoom.admitting')
|
|
225
|
+
: t('jams.waitingRoom.admitParticipant')
|
|
226
|
+
}
|
|
227
|
+
>
|
|
228
|
+
<UserRoundCheckIcon
|
|
229
|
+
size={16}
|
|
230
|
+
className="text-foreground"
|
|
231
|
+
/>
|
|
232
|
+
<ThemedText className="text-xs">
|
|
233
|
+
{t('jams.waitingRoom.admitParticipant')}
|
|
234
|
+
</ThemedText>
|
|
235
|
+
</Button>
|
|
236
|
+
<Button
|
|
237
|
+
variant="destructive"
|
|
238
|
+
size="sm"
|
|
239
|
+
onPress={() => reject(profile)}
|
|
240
|
+
disabled={
|
|
241
|
+
admittingId === profile.id || rejectingId === profile.id
|
|
242
|
+
}
|
|
243
|
+
accessibilityLabel={
|
|
244
|
+
rejectingId === profile.id
|
|
245
|
+
? t('jams.waitingRoom.rejecting')
|
|
246
|
+
: t('jams.waitingRoom.rejectParticipant')
|
|
247
|
+
}
|
|
248
|
+
>
|
|
249
|
+
<UserRoundXIcon size={16} className="text-foreground" />
|
|
250
|
+
<ThemedText className="text-xs">
|
|
251
|
+
{t('jams.waitingRoom.rejectParticipant')}
|
|
252
|
+
</ThemedText>
|
|
253
|
+
</Button>
|
|
254
|
+
</View>
|
|
218
255
|
</View>
|
|
219
256
|
))}
|
|
220
257
|
</View>
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web/native parity pin for the request-to-join phase machine (issue #1781).
|
|
3
|
+
*
|
|
4
|
+
* The web twin is pinned in `platform/react/src/components/jams/
|
|
5
|
+
* JamRequestJoin.test.tsx` (same idle → waiting → denied → re-request
|
|
6
|
+
* flow). The RN component gained the identical phase machine in this PR;
|
|
7
|
+
* this file pins it on native: the waiting copy renders only while the
|
|
8
|
+
* join stream is open, the denial copy renders after the stream reports a
|
|
9
|
+
* denial, and the request affordance returns so the guest can try again.
|
|
10
|
+
*
|
|
11
|
+
* Only RN, i18n, and the shared join hook are stubbed. `ThemedText` is the
|
|
12
|
+
* single text primitive the component renders through, so the mock records
|
|
13
|
+
* every rendered label in document order (`mockRenderedTexts`) — the
|
|
14
|
+
* assertions read that ordered log instead of walking the rendered tree.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const React = require('react');
|
|
18
|
+
const ReactTestRenderer = require('react-test-renderer');
|
|
19
|
+
|
|
20
|
+
let mockOnJoin: ((params: unknown) => void) | undefined;
|
|
21
|
+
let mockOnDenied: (() => void) | undefined;
|
|
22
|
+
let mockButtonOnPress: (() => void) | undefined;
|
|
23
|
+
let mockButtonComponent: unknown;
|
|
24
|
+
const mockRenderedTexts: string[] = [];
|
|
25
|
+
|
|
26
|
+
jest.mock('react-native', () => ({
|
|
27
|
+
View: (props: { children?: unknown; className?: string }) =>
|
|
28
|
+
React.createElement('View', null, props.children),
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
jest.mock('react-i18next', () => ({
|
|
32
|
+
useTranslation: () => ({
|
|
33
|
+
// Values mirror `platform/i18n/src/locales/en.json` so the rendered
|
|
34
|
+
// copy pins the key usage.
|
|
35
|
+
t: (key: string) => {
|
|
36
|
+
if (key === 'jams.join.requestToJoin') return 'Request to join';
|
|
37
|
+
if (key === 'jams.join.waitingForModerator')
|
|
38
|
+
return 'Waiting for a moderator to let you in';
|
|
39
|
+
if (key === 'jams.join.rejected')
|
|
40
|
+
return 'The moderator declined your request to join';
|
|
41
|
+
return key;
|
|
42
|
+
},
|
|
43
|
+
}),
|
|
44
|
+
}));
|
|
45
|
+
|
|
46
|
+
// The hook is the only thing that talks to the join stream; capturing its
|
|
47
|
+
// callbacks lets the test drive the denied transition directly (a real
|
|
48
|
+
// stream would emit `{ denied: true }`).
|
|
49
|
+
jest.mock('@openpeepshq/react', () => ({
|
|
50
|
+
apiErrorMessage: () => '',
|
|
51
|
+
useJoinWaitingRoomToken: (
|
|
52
|
+
onJoin: (params: unknown) => void,
|
|
53
|
+
_onError: unknown,
|
|
54
|
+
onDenied?: () => void
|
|
55
|
+
) => {
|
|
56
|
+
mockOnJoin = onJoin;
|
|
57
|
+
mockOnDenied = onDenied;
|
|
58
|
+
},
|
|
59
|
+
}));
|
|
60
|
+
|
|
61
|
+
jest.mock('../ui/button', () => {
|
|
62
|
+
mockButtonComponent = (props: {
|
|
63
|
+
children?: unknown;
|
|
64
|
+
onPress?: () => void;
|
|
65
|
+
}) => {
|
|
66
|
+
mockButtonOnPress = props.onPress;
|
|
67
|
+
return React.createElement('Button', null, props.children);
|
|
68
|
+
};
|
|
69
|
+
return { Button: mockButtonComponent };
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
jest.mock('../ui/themed-text', () => ({
|
|
73
|
+
ThemedText: (props: { children?: unknown; className?: string }) => {
|
|
74
|
+
const c = props.children;
|
|
75
|
+
if (typeof c === 'string' && c) mockRenderedTexts.push(c);
|
|
76
|
+
return React.createElement('ThemedText', { className: props.className }, c);
|
|
77
|
+
},
|
|
78
|
+
}));
|
|
79
|
+
|
|
80
|
+
const { JamRequestJoin } = require('./JamRequestJoin');
|
|
81
|
+
|
|
82
|
+
const pressButton = () => {
|
|
83
|
+
ReactTestRenderer.act(() => {
|
|
84
|
+
mockButtonOnPress?.();
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
describe('JamRequestJoin denied phase (RN)', () => {
|
|
89
|
+
let tree: ReactTestRenderer.ReactTestRenderer | undefined;
|
|
90
|
+
|
|
91
|
+
beforeEach(() => {
|
|
92
|
+
mockOnJoin = undefined;
|
|
93
|
+
mockOnDenied = undefined;
|
|
94
|
+
mockButtonOnPress = undefined;
|
|
95
|
+
mockRenderedTexts.length = 0;
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
afterEach(() => {
|
|
99
|
+
ReactTestRenderer.act(() => {
|
|
100
|
+
tree?.unmount();
|
|
101
|
+
});
|
|
102
|
+
tree = undefined;
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('shows the rejection message and offers the request again after a denial', () => {
|
|
106
|
+
ReactTestRenderer.act(() => {
|
|
107
|
+
tree = ReactTestRenderer.create(
|
|
108
|
+
React.createElement(JamRequestJoin, { onJoin: () => {} })
|
|
109
|
+
);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// Idle: only the request button, no waiting or rejection copy.
|
|
113
|
+
expect(mockButtonOnPress).toBeDefined();
|
|
114
|
+
expect(mockRenderedTexts).toEqual(['Request to join']);
|
|
115
|
+
expect(mockOnJoin).toBeUndefined();
|
|
116
|
+
expect(mockOnDenied).toBeUndefined();
|
|
117
|
+
|
|
118
|
+
// Requesting starts the waiting phase (the join stream is opened).
|
|
119
|
+
pressButton();
|
|
120
|
+
expect(mockOnJoin).toBeDefined();
|
|
121
|
+
expect(mockOnDenied).toBeDefined();
|
|
122
|
+
expect(mockRenderedTexts).toContain(
|
|
123
|
+
'Waiting for a moderator to let you in'
|
|
124
|
+
);
|
|
125
|
+
expect(mockRenderedTexts).not.toContain('The moderator declined');
|
|
126
|
+
// The request button is replaced by the waiting copy.
|
|
127
|
+
expect(
|
|
128
|
+
(tree as ReactTestRenderer.ReactTestRenderer).root.findAllByType(
|
|
129
|
+
mockButtonComponent as never
|
|
130
|
+
)
|
|
131
|
+
).toHaveLength(0);
|
|
132
|
+
|
|
133
|
+
// The stream reports a denial: the phase switches to denied.
|
|
134
|
+
mockRenderedTexts.length = 0;
|
|
135
|
+
ReactTestRenderer.act(() => {
|
|
136
|
+
mockOnDenied?.();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// The rejection copy is shown and the request is offered again; the
|
|
140
|
+
// waiting copy is gone (asserted on the phase's own render, since the
|
|
141
|
+
// log accumulates across renders).
|
|
142
|
+
expect(mockRenderedTexts).toEqual([
|
|
143
|
+
'The moderator declined your request to join',
|
|
144
|
+
'Request to join',
|
|
145
|
+
]);
|
|
146
|
+
expect(mockButtonOnPress).toBeDefined();
|
|
147
|
+
|
|
148
|
+
// Requesting again goes back to the waiting phase.
|
|
149
|
+
mockRenderedTexts.length = 0;
|
|
150
|
+
pressButton();
|
|
151
|
+
expect(mockRenderedTexts).toContain(
|
|
152
|
+
'Waiting for a moderator to let you in'
|
|
153
|
+
);
|
|
154
|
+
expect(mockRenderedTexts).not.toContain(
|
|
155
|
+
'The moderator declined your request to join'
|
|
156
|
+
);
|
|
157
|
+
expect(
|
|
158
|
+
(tree as ReactTestRenderer.ReactTestRenderer).root.findAllByType(
|
|
159
|
+
mockButtonComponent as never
|
|
160
|
+
)
|
|
161
|
+
).toHaveLength(0);
|
|
162
|
+
});
|
|
163
|
+
});
|
|
@@ -16,8 +16,10 @@ export interface JamRequestJoinProps {
|
|
|
16
16
|
|
|
17
17
|
const JamWaitingRoomListener = ({
|
|
18
18
|
onJoin,
|
|
19
|
+
onDenied,
|
|
19
20
|
}: {
|
|
20
21
|
onJoin: JamRequestJoinProps['onJoin'];
|
|
22
|
+
onDenied: () => void;
|
|
21
23
|
}) => {
|
|
22
24
|
const { t } = useTranslation();
|
|
23
25
|
const [error, setError] = useState<string | null>(null);
|
|
@@ -33,13 +35,17 @@ const JamWaitingRoomListener = ({
|
|
|
33
35
|
[onJoin]
|
|
34
36
|
);
|
|
35
37
|
|
|
36
|
-
useJoinWaitingRoomToken(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
useJoinWaitingRoomToken(
|
|
39
|
+
joinAndClearError,
|
|
40
|
+
(e?: SseError) => {
|
|
41
|
+
// Reuse the shared key→message mapping (`errorKey ?? key`, translate
|
|
42
|
+
// `error.*` keys). The SSE path passes an empty fallback so a keyless,
|
|
43
|
+
// message-less error renders nothing rather than a generic "Error".
|
|
44
|
+
const message = apiErrorMessage(e, t, '');
|
|
45
|
+
setError(message.length > 0 ? message : null);
|
|
46
|
+
},
|
|
47
|
+
onDenied
|
|
48
|
+
);
|
|
43
49
|
|
|
44
50
|
return error ? (
|
|
45
51
|
<ThemedText className="text-center text-sm text-destructive">
|
|
@@ -50,23 +56,33 @@ const JamWaitingRoomListener = ({
|
|
|
50
56
|
|
|
51
57
|
export const JamRequestJoin = ({ onJoin }: JamRequestJoinProps) => {
|
|
52
58
|
const { t } = useTranslation();
|
|
53
|
-
const [
|
|
59
|
+
const [phase, setPhase] = useState<'idle' | 'waiting' | 'denied'>('idle');
|
|
54
60
|
|
|
55
61
|
return (
|
|
56
62
|
<View className="w-full flex-1 items-center justify-center gap-4 p-4">
|
|
57
|
-
{
|
|
63
|
+
{phase === 'waiting' ? (
|
|
58
64
|
<>
|
|
59
|
-
<JamWaitingRoomListener
|
|
65
|
+
<JamWaitingRoomListener
|
|
66
|
+
onJoin={onJoin}
|
|
67
|
+
onDenied={() => setPhase('denied')}
|
|
68
|
+
/>
|
|
60
69
|
<ThemedText className="text-center text-sm text-muted-foreground">
|
|
61
70
|
{t('jams.join.waitingForModerator')}
|
|
62
71
|
</ThemedText>
|
|
63
72
|
</>
|
|
64
73
|
) : (
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
74
|
+
<>
|
|
75
|
+
{phase === 'denied' ? (
|
|
76
|
+
<ThemedText className="text-center text-sm text-muted-foreground">
|
|
77
|
+
{t('jams.join.rejected')}
|
|
78
|
+
</ThemedText>
|
|
79
|
+
) : null}
|
|
80
|
+
<Button onPress={() => setPhase('waiting')}>
|
|
81
|
+
<ThemedText className="text-primary-foreground">
|
|
82
|
+
{t('jams.join.requestToJoin')}
|
|
83
|
+
</ThemedText>
|
|
84
|
+
</Button>
|
|
85
|
+
</>
|
|
70
86
|
)}
|
|
71
87
|
</View>
|
|
72
88
|
);
|
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
AccountSettings,
|
|
28
28
|
ThemeSettings,
|
|
29
29
|
AccessTokensSettings,
|
|
30
|
+
CalendarFeedSettings,
|
|
30
31
|
FeedSettings,
|
|
31
32
|
BlockedSettings,
|
|
32
33
|
VideoPlayer,
|
|
@@ -153,6 +154,10 @@ export const MainNavigator = () => {
|
|
|
153
154
|
name="AccessTokensSettings"
|
|
154
155
|
component={AccessTokensSettings}
|
|
155
156
|
/>
|
|
157
|
+
<Stack.Screen
|
|
158
|
+
name="CalendarFeedSettings"
|
|
159
|
+
component={CalendarFeedSettings}
|
|
160
|
+
/>
|
|
156
161
|
<Stack.Screen name="BlockedSettings" component={BlockedSettings} />
|
|
157
162
|
<Stack.Screen name="LanguageSettings" component={LanguageSettings} />
|
|
158
163
|
<Stack.Screen name="TimezoneSettings" component={TimezoneSettings} />
|
|
@@ -21,6 +21,7 @@ const SETTINGS_SCREENS: Record<string, keyof MainStackParamList | undefined> = {
|
|
|
21
21
|
'language': 'LanguageSettings',
|
|
22
22
|
'timezone': 'TimezoneSettings',
|
|
23
23
|
'feed': 'FeedSettings',
|
|
24
|
+
'calendar-feed': 'CalendarFeedSettings',
|
|
24
25
|
};
|
|
25
26
|
|
|
26
27
|
const go = (name: string, params?: object) => {
|
package/src/pages/index.ts
CHANGED
|
@@ -42,6 +42,7 @@ export { NotificationPreferences } from './settings/NotificationPreferences';
|
|
|
42
42
|
export { AccountSettings } from './settings/Account';
|
|
43
43
|
export { ThemeSettings } from './settings/Theme';
|
|
44
44
|
export { AccessTokensSettings } from './settings/AccessTokens';
|
|
45
|
+
export { CalendarFeedSettings } from './settings/CalendarFeed';
|
|
45
46
|
export { FeedSettings } from './settings/Feed';
|
|
46
47
|
export { BlockedSettings } from './settings/Blocked';
|
|
47
48
|
export { Notifications } from './Notifications';
|
|
@@ -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
|
);
|