@openpeepshq/rn-components 0.19.0 → 0.21.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 +4 -5
- package/src/components/conversations/ConversationMessageBubble.test.tsx +158 -0
- package/src/components/conversations/ConversationMessageBubble.tsx +43 -25
- package/src/components/jams/JamCallParticipant.tsx +84 -16
- package/src/components/jams/JamChatMessage.test.tsx +139 -0
- package/src/components/jams/JamChatMessage.tsx +13 -0
- package/src/components/jams/JamPeopleDrawer.test.tsx +77 -3
- package/src/components/jams/JamPeopleDrawer.tsx +94 -3
- package/src/components/jams/JamReactionMenu.tsx +10 -31
- package/src/components/jams/JamRoom.tsx +15 -0
- package/src/components/markdown/OpenpeepsMarkdown.tsx +10 -3
- package/src/components/markdown/theme.test.ts +78 -0
- package/src/components/markdown/theme.ts +30 -12
- package/src/components/post/CompactReplyParent.test.tsx +337 -0
- package/src/components/post/CompactReplyParent.tsx +21 -5
- package/src/components/post/TruncatedMarkdown.test.tsx +201 -0
- package/src/components/post/TruncatedMarkdown.tsx +98 -10
- package/src/components/post/pieces/PostActions.test.tsx +27 -19
- package/src/components/post/pieces/PostActions.tsx +7 -11
- package/src/components/post/pieces/ReactionButton.tsx +41 -0
- package/src/components/post/pieces/ReactionPicker.test.tsx +80 -161
- package/src/components/post/pieces/ReactionPicker.tsx +32 -33
- package/src/components/post/pieces/index.ts +1 -0
- package/src/components/preview-link/local/WelcomePreview.tsx +1 -0
- package/src/components/resources/CategoryPathPicker.tsx +8 -2
- package/src/components/resources/ResourceCard.test.tsx +48 -4
- package/src/components/resources/ResourceCard.tsx +8 -2
- package/src/components/resources/ResourceLibrary.test.tsx +40 -2
- package/src/components/resources/ResourceLibrary.tsx +11 -6
- package/src/lib/moduleResolverRootGuard.test.ts +281 -0
|
@@ -2,17 +2,25 @@ import { useMemo } from 'react';
|
|
|
2
2
|
import type { ReactNode } from 'react';
|
|
3
3
|
import { truncateMarkdown } from '@openpeepshq/common/lib';
|
|
4
4
|
import { useTranslation } from 'react-i18next';
|
|
5
|
+
import { TextStyle } from 'react-native';
|
|
5
6
|
import { OpenpeepsMarkdown } from '../markdown';
|
|
6
7
|
import { MarkdownOverlay } from '../markdown/MarkdownOverlay';
|
|
8
|
+
import { useOpenPeepsTheme } from '../../theme/OpenPeepsThemeProvider';
|
|
9
|
+
import type { ColorName } from '../../theme/types';
|
|
7
10
|
|
|
8
11
|
export interface TruncatedMarkdownProps {
|
|
9
12
|
/** Full markdown; rendered in the overlay when `interactive`. */
|
|
10
13
|
source: string;
|
|
11
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Pre-truncated excerpt (e.g. `firstNWords`). Computed via
|
|
16
|
+
* `truncateMarkdown` when omitted. When `maxLines` is set, a
|
|
17
|
+
* caller-provided snippet is re-truncated to the same per-line char budget
|
|
18
|
+
* as the computed path, so it cannot exceed the line budget.
|
|
19
|
+
*/
|
|
12
20
|
snippet?: string;
|
|
13
21
|
maxBlocks?: number;
|
|
14
22
|
maxChars?: number;
|
|
15
|
-
/** Lines the excerpt
|
|
23
|
+
/** Lines the excerpt is bounded to via a tightened char budget. */
|
|
16
24
|
maxLines?: number;
|
|
17
25
|
/**
|
|
18
26
|
* When true, the excerpt lives in a long-press trigger that opens a
|
|
@@ -20,41 +28,121 @@ export interface TruncatedMarkdownProps {
|
|
|
20
28
|
* renders (callers own their own navigation).
|
|
21
29
|
*/
|
|
22
30
|
interactive?: boolean;
|
|
23
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Sizing classes (`text-sm`, `text-xs`) map to text metrics and color
|
|
33
|
+
* classes (`text-foreground`, `text-muted-foreground`) to theme tokens,
|
|
34
|
+
* then reach the markdown body via the `baseTextStyle` merge (see
|
|
35
|
+
* `theme.ts`) — accepted so an RN call site can pass the exact string its
|
|
36
|
+
* web twin uses. `break-words` is a no-op on RN (markdown text wraps by
|
|
37
|
+
* default); any other unknown class is ignored.
|
|
38
|
+
*/
|
|
24
39
|
className?: string;
|
|
25
40
|
}
|
|
26
41
|
|
|
42
|
+
/** Tailwind text-size classes callers use, mapped to RN text metrics. */
|
|
43
|
+
const SIZE_CLASSES: Record<string, TextStyle> = {
|
|
44
|
+
'text-xs': { fontSize: 12, lineHeight: 16 },
|
|
45
|
+
'text-sm': { fontSize: 14, lineHeight: 20 },
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/** Tailwind text-color classes callers use, mapped to theme color tokens. */
|
|
49
|
+
const COLOR_CLASSES: Record<string, ColorName> = {
|
|
50
|
+
'text-foreground': 'foreground',
|
|
51
|
+
'text-muted-foreground': 'muted-foreground',
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Approximate characters per line at the sizes above (short lines bound the
|
|
56
|
+
* budget). Intentionally divergent from the web twin, which line-clamps the
|
|
57
|
+
* rendered lines via CSS: RN cannot line-clamp rendered markdown nodes, so it
|
|
58
|
+
* bounds the excerpt by a char budget instead. The constant is calibrated for
|
|
59
|
+
* `text-sm`; a `text-xs` line fits more than 40 chars, so the `maxLines`
|
|
60
|
+
* budget is conservative at that size (never too long, just shorter).
|
|
61
|
+
*/
|
|
62
|
+
const CHARS_PER_LINE = 40;
|
|
63
|
+
|
|
27
64
|
/**
|
|
28
|
-
* RN mirror of the web `TruncatedMarkdown`.
|
|
29
|
-
*
|
|
30
|
-
*
|
|
65
|
+
* RN mirror of the web `TruncatedMarkdown`. `maxLines` and the sizing/color
|
|
66
|
+
* classes are honored here by bounding the excerpt to
|
|
67
|
+
* `maxLines * CHARS_PER_LINE` characters and merging the mapped text metrics
|
|
68
|
+
* and color over the markdown theme (RN cannot line-clamp rendered markdown
|
|
69
|
+
* nodes); the full markdown is revealed via the reusable `MarkdownOverlay`
|
|
70
|
+
* on long-press.
|
|
71
|
+
*
|
|
72
|
+
* Divergences from the web twin, kept in sync by convention (see AGENTS.md
|
|
73
|
+
* mirror rule):
|
|
74
|
+
* - The char-budget clamp above is the RN stand-in for web's CSS line-clamp
|
|
75
|
+
* (already documented at `CHARS_PER_LINE`).
|
|
76
|
+
* - Web defaults `maxLines` to `2`; RN leaves it `undefined` so an RN
|
|
77
|
+
* caller that omits it is not silently re-truncated. Every RN caller that
|
|
78
|
+
* wants a bound passes `maxLines` explicitly; `Article` intentionally
|
|
79
|
+
* omits it, as does its web twin — if a new caller omits it without a
|
|
80
|
+
* bound, align the default deliberately.
|
|
81
|
+
* - Web only applies its line-clamp when `interactive`; RN bounds the
|
|
82
|
+
* excerpt to the `maxLines` char budget in both modes. Callers that keep
|
|
83
|
+
* `interactive` off (they own their own "show more") still get the bound,
|
|
84
|
+
* which matches how every current RN caller uses it.
|
|
31
85
|
*/
|
|
32
86
|
export const TruncatedMarkdown = ({
|
|
33
87
|
source,
|
|
34
88
|
snippet: snippetProp,
|
|
35
89
|
maxBlocks = 2,
|
|
36
90
|
maxChars = 240,
|
|
91
|
+
maxLines,
|
|
37
92
|
interactive = true,
|
|
93
|
+
className,
|
|
38
94
|
}: TruncatedMarkdownProps): ReactNode => {
|
|
39
95
|
const { t } = useTranslation();
|
|
96
|
+
const { colors } = useOpenPeepsTheme();
|
|
97
|
+
const classes = (className ?? '').split(/\s+/).filter(Boolean);
|
|
98
|
+
const sizeStyle = classes.map((c) => SIZE_CLASSES[c]).find(Boolean);
|
|
99
|
+
const colorToken = classes.map((c) => COLOR_CLASSES[c]).find(Boolean);
|
|
100
|
+
const baseTextStyle = useMemo(() => {
|
|
101
|
+
const color = colorToken ? colors[colorToken] : undefined;
|
|
102
|
+
if (!sizeStyle && color === undefined) return undefined;
|
|
103
|
+
return { ...sizeStyle, ...(color !== undefined ? { color } : {}) };
|
|
104
|
+
}, [colors, sizeStyle, colorToken]);
|
|
105
|
+
const budget =
|
|
106
|
+
maxLines && maxLines > 0
|
|
107
|
+
? Math.min(maxChars, maxLines * CHARS_PER_LINE)
|
|
108
|
+
: undefined;
|
|
40
109
|
const excerpt = useMemo(
|
|
41
|
-
() =>
|
|
42
|
-
|
|
110
|
+
() =>
|
|
111
|
+
budget !== undefined
|
|
112
|
+
? // A caller-provided snippet is pre-truncated, but the maxLines
|
|
113
|
+
// budget must still bound it: re-truncate to the same budget.
|
|
114
|
+
truncateMarkdown(snippetProp ?? source, maxBlocks, budget)
|
|
115
|
+
: (snippetProp ?? truncateMarkdown(source, maxBlocks, maxChars)),
|
|
116
|
+
[snippetProp, source, maxBlocks, maxChars, budget]
|
|
43
117
|
);
|
|
44
118
|
if (!excerpt) return null;
|
|
45
119
|
|
|
46
120
|
if (!interactive) {
|
|
47
|
-
return
|
|
121
|
+
return (
|
|
122
|
+
<OpenpeepsMarkdown
|
|
123
|
+
source={excerpt}
|
|
124
|
+
linkPreviewMode="none"
|
|
125
|
+
baseTextStyle={baseTextStyle}
|
|
126
|
+
/>
|
|
127
|
+
);
|
|
48
128
|
}
|
|
49
129
|
|
|
50
130
|
return (
|
|
51
131
|
<MarkdownOverlay
|
|
52
132
|
source={source}
|
|
133
|
+
// Web-inherited copy: the web twin's `aria-label` uses the same key,
|
|
134
|
+
// whose locale value ("Long press or hover to read the full text") is
|
|
135
|
+
// hint wording, not an exact label — do not "fix" it here without
|
|
136
|
+
// updating the web twin.
|
|
53
137
|
label={t('posts.truncatedMarkdown.showHint', {
|
|
54
138
|
defaultValue: 'Show more',
|
|
55
139
|
})}
|
|
56
140
|
>
|
|
57
|
-
<OpenpeepsMarkdown
|
|
141
|
+
<OpenpeepsMarkdown
|
|
142
|
+
source={excerpt}
|
|
143
|
+
linkPreviewMode="none"
|
|
144
|
+
baseTextStyle={baseTextStyle}
|
|
145
|
+
/>
|
|
58
146
|
</MarkdownOverlay>
|
|
59
147
|
);
|
|
60
148
|
};
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Native PostActions reaction-picker wiring (issue #
|
|
2
|
+
* Native PostActions reaction-picker wiring (issue #276, round-15 review item
|
|
3
|
+
* #2 — this suite was removed when the RN picker switched to the allowed-set
|
|
4
|
+
* model and is restored here).
|
|
3
5
|
*
|
|
4
|
-
* Pins that the RN PostActions
|
|
5
|
-
* `myReactions
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Pins that the RN PostActions Like button opens the picker and threads
|
|
7
|
+
* `myReactions`, the community `reactions` (from useAllowedReactions) and
|
|
8
|
+
* `onToggle` through to it. Mirrors PostMenu.test.tsx: node jest env, every
|
|
9
|
+
* external import mocked — the decision under test is the button→picker
|
|
10
|
+
* threading.
|
|
9
11
|
*/
|
|
10
12
|
import { type ReactNode } from 'react';
|
|
11
13
|
import ReactTestRenderer from 'react-test-renderer';
|
|
@@ -22,8 +24,8 @@ let mockCanReact = true;
|
|
|
22
24
|
let lastPickerProps:
|
|
23
25
|
| {
|
|
24
26
|
myReactions: string[];
|
|
27
|
+
reactions: readonly string[];
|
|
25
28
|
onToggle: (r: string) => void;
|
|
26
|
-
onClose: () => void;
|
|
27
29
|
}
|
|
28
30
|
| undefined;
|
|
29
31
|
const buttonInstances: { onPress?: () => void }[] = [];
|
|
@@ -47,12 +49,12 @@ jest.mock('react-i18next', () => ({
|
|
|
47
49
|
}),
|
|
48
50
|
}));
|
|
49
51
|
|
|
50
|
-
// --- the feed action
|
|
52
|
+
// --- the feed action hooks under test --------------------------------------
|
|
51
53
|
jest.mock('@openpeepshq/react', () => ({
|
|
52
54
|
useFeedPostActions: () => ({
|
|
53
55
|
me: { id: 'me-1' },
|
|
54
56
|
myRepost: undefined,
|
|
55
|
-
|
|
57
|
+
iLiked: mockMyReactions.includes('👍'),
|
|
56
58
|
myReactions: mockMyReactions,
|
|
57
59
|
canReply: true,
|
|
58
60
|
canRepost: true,
|
|
@@ -61,14 +63,15 @@ jest.mock('@openpeepshq/react', () => ({
|
|
|
61
63
|
toggleRepost,
|
|
62
64
|
toggleReaction,
|
|
63
65
|
}),
|
|
66
|
+
useAllowedReactions: () => REACTION_TYPES,
|
|
64
67
|
}));
|
|
65
68
|
|
|
66
69
|
// --- local UI: capture picker props and button presses --------------------
|
|
67
70
|
jest.mock('./ReactionPicker', () => ({
|
|
68
71
|
ReactionPicker: (props: {
|
|
69
72
|
myReactions: string[];
|
|
73
|
+
reactions: readonly string[];
|
|
70
74
|
onToggle: (r: string) => void;
|
|
71
|
-
onClose: () => void;
|
|
72
75
|
}) => {
|
|
73
76
|
lastPickerProps = props;
|
|
74
77
|
return null;
|
|
@@ -151,24 +154,24 @@ const renderPostActions = (
|
|
|
151
154
|
return { tree };
|
|
152
155
|
};
|
|
153
156
|
|
|
154
|
-
/** The
|
|
157
|
+
/** The Like button is the one whose text is the react footer label. */
|
|
155
158
|
const reactButtonPress = (json: unknown): (() => void) | undefined => {
|
|
156
159
|
let found: (() => void) | undefined;
|
|
157
160
|
walk(json, (n) => {
|
|
158
161
|
if (found || n.type !== 'Button') return;
|
|
159
|
-
if (collectText(n).includes('posts.footer.
|
|
162
|
+
if (collectText(n).includes('posts.footer.like')) {
|
|
160
163
|
found = n.props?.onPress as () => void;
|
|
161
164
|
}
|
|
162
165
|
});
|
|
163
166
|
return found;
|
|
164
167
|
};
|
|
165
168
|
|
|
166
|
-
/** The
|
|
169
|
+
/** The Like button's `disabled` prop (undefined when the button is absent). */
|
|
167
170
|
const reactButtonDisabled = (json: unknown): boolean | undefined => {
|
|
168
171
|
let found: boolean | undefined;
|
|
169
172
|
walk(json, (n) => {
|
|
170
173
|
if (found !== undefined || n.type !== 'Button') return;
|
|
171
|
-
if (collectText(n).includes('posts.footer.
|
|
174
|
+
if (collectText(n).includes('posts.footer.like')) {
|
|
172
175
|
found = n.props?.disabled as boolean | undefined;
|
|
173
176
|
}
|
|
174
177
|
});
|
|
@@ -186,7 +189,7 @@ beforeEach(() => {
|
|
|
186
189
|
buttonInstances.length = 0;
|
|
187
190
|
});
|
|
188
191
|
|
|
189
|
-
test('tapping the
|
|
192
|
+
test('tapping the Like button opens the picker wired to the feed actions', () => {
|
|
190
193
|
const { tree } = renderPostActions(makePost());
|
|
191
194
|
const press = reactButtonPress(tree.toJSON());
|
|
192
195
|
expect(press).toBeTruthy();
|
|
@@ -198,6 +201,7 @@ test('tapping the React button opens the picker wired to the feed actions', () =
|
|
|
198
201
|
|
|
199
202
|
expect(lastPickerProps).toBeDefined();
|
|
200
203
|
expect(lastPickerProps?.myReactions).toEqual(['❤️']);
|
|
204
|
+
expect(lastPickerProps?.reactions).toEqual(REACTION_TYPES);
|
|
201
205
|
tree.unmount();
|
|
202
206
|
});
|
|
203
207
|
|
|
@@ -217,7 +221,10 @@ test('picking an emoji from the open picker calls toggleReaction with it', () =>
|
|
|
217
221
|
tree.unmount();
|
|
218
222
|
});
|
|
219
223
|
|
|
220
|
-
test('
|
|
224
|
+
test('an orphan (no longer allowed) reaction still toggles', () => {
|
|
225
|
+
// The picker renders the profile's own reactions that are no longer in the
|
|
226
|
+
// community allowed set (orphans) so they stay retractable; the RN wrapper
|
|
227
|
+
// must thread them through onToggle the same as allowed reactions.
|
|
221
228
|
const { tree } = renderPostActions(makePost());
|
|
222
229
|
ReactTestRenderer.act(() => {
|
|
223
230
|
reactButtonPress(tree.toJSON())!();
|
|
@@ -225,14 +232,15 @@ test('the picker close control calls onClose without toggling a reaction', () =>
|
|
|
225
232
|
expect(lastPickerProps).toBeDefined();
|
|
226
233
|
|
|
227
234
|
ReactTestRenderer.act(() => {
|
|
228
|
-
lastPickerProps?.
|
|
235
|
+
lastPickerProps?.onToggle('🎉');
|
|
229
236
|
});
|
|
230
237
|
|
|
231
|
-
expect(toggleReaction).
|
|
238
|
+
expect(toggleReaction).toHaveBeenCalledTimes(1);
|
|
239
|
+
expect(toggleReaction).toHaveBeenCalledWith('🎉');
|
|
232
240
|
tree.unmount();
|
|
233
241
|
});
|
|
234
242
|
|
|
235
|
-
test('the
|
|
243
|
+
test('the Like button renders disabled when the profile cannot react and has no reactions', () => {
|
|
236
244
|
// Native mirror of the web ReactionPicker contract: without the react
|
|
237
245
|
// capability and no existing reaction, the trigger is inert (the web path
|
|
238
246
|
// pins this in ReactionPicker.test.tsx).
|
|
@@ -11,26 +11,24 @@ import {
|
|
|
11
11
|
} from '../../icons/index';
|
|
12
12
|
import { type PublicPost } from '@openpeepshq/common';
|
|
13
13
|
import { useTranslation } from 'react-i18next';
|
|
14
|
-
import { useFeedPostActions } from '@openpeepshq/react';
|
|
14
|
+
import { useFeedPostActions, useAllowedReactions } from '@openpeepshq/react';
|
|
15
15
|
import { ReactionPicker } from './ReactionPicker';
|
|
16
16
|
import { ShareMenu } from './ShareMenu';
|
|
17
17
|
|
|
18
18
|
interface PostActionsProps {
|
|
19
19
|
post: PublicPost;
|
|
20
20
|
previewMode?: boolean;
|
|
21
|
-
compact?: boolean;
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
export const PostActions = ({
|
|
25
24
|
post,
|
|
26
25
|
previewMode = false,
|
|
27
|
-
compact: _compact = false,
|
|
28
26
|
}: PostActionsProps) => {
|
|
29
27
|
const { t } = useTranslation();
|
|
30
28
|
const {
|
|
31
29
|
me,
|
|
32
30
|
myRepost,
|
|
33
|
-
|
|
31
|
+
iLiked,
|
|
34
32
|
myReactions,
|
|
35
33
|
canReply,
|
|
36
34
|
canRepost,
|
|
@@ -39,6 +37,7 @@ export const PostActions = ({
|
|
|
39
37
|
toggleRepost,
|
|
40
38
|
toggleReaction,
|
|
41
39
|
} = useFeedPostActions(post);
|
|
40
|
+
const allowedReactions = useAllowedReactions();
|
|
42
41
|
const [reactionPickerOpen, setReactionPickerOpen] = useState(false);
|
|
43
42
|
|
|
44
43
|
const replyActive = !previewMode && canReply;
|
|
@@ -145,12 +144,9 @@ export const PostActions = ({
|
|
|
145
144
|
onPress={() => setReactionPickerOpen((open) => !open)}
|
|
146
145
|
className={cn(actionClass, 'justify-end', !reactActive && idleClass)}
|
|
147
146
|
>
|
|
148
|
-
<ThumbsUpIcon
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
/>
|
|
152
|
-
<ThemedText className={labelClass(reactActive, iReacted)}>
|
|
153
|
-
{t('posts.footer.react')}
|
|
147
|
+
<ThumbsUpIcon size={16} className={iconClass(reactActive, iLiked)} />
|
|
148
|
+
<ThemedText className={labelClass(reactActive, iLiked)}>
|
|
149
|
+
{t('posts.footer.like')}
|
|
154
150
|
</ThemedText>
|
|
155
151
|
</Button>
|
|
156
152
|
<View className="flex-1 items-end">{shareButton}</View>
|
|
@@ -159,7 +155,7 @@ export const PostActions = ({
|
|
|
159
155
|
<View className="flex-row gap-1 px-4 pb-2">
|
|
160
156
|
<ReactionPicker
|
|
161
157
|
myReactions={myReactions}
|
|
162
|
-
|
|
158
|
+
reactions={allowedReactions}
|
|
163
159
|
onToggle={(reaction) => {
|
|
164
160
|
setReactionPickerOpen(false);
|
|
165
161
|
void toggleReaction(reaction);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Pressable } from 'react-native';
|
|
3
|
+
import { ThemedText } from '../../ui/themed-text';
|
|
4
|
+
import { cn } from '../../../lib/utils';
|
|
5
|
+
|
|
6
|
+
export interface ReactionButtonProps {
|
|
7
|
+
reaction: string;
|
|
8
|
+
/** Accessible label; defaults to the emoji itself. */
|
|
9
|
+
title?: string;
|
|
10
|
+
/** Highlight the emoji the profile has already attached. */
|
|
11
|
+
active?: boolean;
|
|
12
|
+
/** An emoji no longer in the allowed set but still attached — dim it. */
|
|
13
|
+
orphan?: boolean;
|
|
14
|
+
onPress: () => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A single emoji reaction control, shared by the post reaction picker and the
|
|
19
|
+
* jam reaction menu so tap/active styling lives in one place instead of
|
|
20
|
+
* drifting across copies.
|
|
21
|
+
*/
|
|
22
|
+
export const ReactionButton = ({
|
|
23
|
+
reaction,
|
|
24
|
+
title,
|
|
25
|
+
active = false,
|
|
26
|
+
orphan = false,
|
|
27
|
+
onPress,
|
|
28
|
+
}: ReactionButtonProps) => (
|
|
29
|
+
<Pressable
|
|
30
|
+
accessibilityRole="button"
|
|
31
|
+
accessibilityLabel={title ?? reaction}
|
|
32
|
+
onPress={onPress}
|
|
33
|
+
className={cn(
|
|
34
|
+
'shrink-0 rounded-md p-2',
|
|
35
|
+
active && 'bg-border',
|
|
36
|
+
orphan && 'opacity-60'
|
|
37
|
+
)}
|
|
38
|
+
>
|
|
39
|
+
<ThemedText className="text-lg">{reaction}</ThemedText>
|
|
40
|
+
</Pressable>
|
|
41
|
+
);
|
|
@@ -1,184 +1,103 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Regression test for the native `ReactionPicker` orphaned-reaction path
|
|
3
|
+
* (issue #276, round-5 review item #2) — the mirror of the web picker test.
|
|
4
|
+
* Orphans — reactions attached before the community removed the emoji from its
|
|
5
|
+
* allowed set — render after a divider, flagged `orphan` (dimmed by
|
|
6
|
+
* `ReactionButton`), and stay retractable; there is no divider/orphan section
|
|
7
|
+
* when every attached reaction is still allowed.
|
|
3
8
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* profile's own reactions are highlighted, a tap calls `onToggle` with the
|
|
8
|
-
* tapped emoji, and the close button fires `onClose`.
|
|
9
|
-
*
|
|
10
|
-
* Mirrors the inline-mock pattern of PostMenu.test.tsx / ShareMenu.test.tsx:
|
|
11
|
-
* node jest env, every external import mocked; `@openpeepshq/common` is
|
|
12
|
-
* stubbed with the real curated set so the row is asserted against the
|
|
13
|
-
* actual REACTION_TYPES values.
|
|
9
|
+
* The RN primitives, i18n, and `ReactionButton` are stubbed to self-describing
|
|
10
|
+
* host tags (`RB_ALLOWED` / `RB_ORPHAN` / `DIVIDER`) so the assertions read the
|
|
11
|
+
* real picker's orphan computation and render order from the rendered tree.
|
|
14
12
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const REACTION_TYPES = ['👍', '👎', '❤️', '😂', '😮', '😢', '🎉'];
|
|
19
|
-
const CLOSE_LABEL = 'posts.actions.closeReactionPicker';
|
|
13
|
+
const React = require('react');
|
|
14
|
+
const ReactTestRenderer = require('react-test-renderer');
|
|
20
15
|
|
|
21
16
|
jest.mock('react-native', () => {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
17
|
+
const V = (props: { className?: string; children?: unknown }) =>
|
|
18
|
+
React.createElement(
|
|
19
|
+
props.className === 'mx-1 h-8 w-px shrink-0 bg-border'
|
|
20
|
+
? 'DIVIDER'
|
|
21
|
+
: 'DIV',
|
|
22
|
+
null,
|
|
23
|
+
props.children
|
|
24
|
+
);
|
|
25
|
+
const T = (props: { children?: unknown }) =>
|
|
26
|
+
React.createElement('Text', null, props.children);
|
|
27
|
+
const P = (props: { children?: unknown }) =>
|
|
28
|
+
React.createElement('Pressable', null, props.children);
|
|
29
|
+
return { View: V, Text: T, Pressable: P };
|
|
31
30
|
});
|
|
32
|
-
|
|
33
31
|
jest.mock('react-i18next', () => ({
|
|
34
|
-
useTranslation: () => ({
|
|
35
|
-
t: (key: string, opts?: { defaultValue?: string }) =>
|
|
36
|
-
opts?.defaultValue ?? key,
|
|
37
|
-
}),
|
|
32
|
+
useTranslation: () => ({ t: (key: string) => key }),
|
|
38
33
|
}));
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
jest.mock('./ReactionButton', () => ({
|
|
35
|
+
ReactionButton: (props: {
|
|
36
|
+
reaction?: string;
|
|
37
|
+
orphan?: boolean;
|
|
38
|
+
onPress?: () => void;
|
|
39
|
+
}) =>
|
|
40
|
+
React.createElement(
|
|
41
|
+
props.orphan ? 'RB_ORPHAN' : 'RB_ALLOWED',
|
|
42
|
+
{ onPress: props.onPress },
|
|
43
|
+
props.reaction
|
|
44
|
+
),
|
|
42
45
|
}));
|
|
43
46
|
|
|
44
|
-
|
|
45
|
-
const React = require('react');
|
|
46
|
-
return {
|
|
47
|
-
ThemedText: (props: { children?: ReactNode }) =>
|
|
48
|
-
React.createElement('Text', null, props.children),
|
|
49
|
-
};
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
jest.mock('../../icons/index', () => ({
|
|
53
|
-
XIcon: () => null,
|
|
54
|
-
}));
|
|
55
|
-
|
|
56
|
-
jest.mock('../../../lib/utils', () => ({
|
|
57
|
-
cn: (...parts: Array<string | false | null | undefined>) =>
|
|
58
|
-
parts.filter(Boolean).join(' '),
|
|
59
|
-
}));
|
|
60
|
-
|
|
61
|
-
import { ReactionPicker } from './ReactionPicker';
|
|
62
|
-
|
|
63
|
-
type TreeNode = {
|
|
64
|
-
type?: string;
|
|
65
|
-
props?: Record<string, unknown> | null;
|
|
66
|
-
children?: (TreeNode | string | null)[];
|
|
67
|
-
};
|
|
47
|
+
const { ReactionPicker } = require('./ReactionPicker');
|
|
68
48
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
return out;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** Depth-first walk over the render tree, visiting every element node. */
|
|
80
|
-
function walk(node: unknown, visit: (n: TreeNode) => void): void {
|
|
81
|
-
if (node === null || typeof node !== 'object') return;
|
|
82
|
-
const n = node as TreeNode;
|
|
83
|
-
visit(n);
|
|
84
|
-
for (const c of n.children || []) {
|
|
85
|
-
if (typeof c !== 'string' && c !== null) walk(c, visit);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/** The Pressable whose only text content is the given emoji. */
|
|
90
|
-
function emojiPressable(json: unknown, emoji: string): TreeNode | undefined {
|
|
91
|
-
let found: TreeNode | undefined;
|
|
92
|
-
walk(json, (n) => {
|
|
93
|
-
if (found || n.type !== 'Pressable') return;
|
|
94
|
-
if (collectText(n).join('') === emoji) found = n;
|
|
95
|
-
});
|
|
96
|
-
return found;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const renderPicker = (props?: {
|
|
100
|
-
myReactions?: string[];
|
|
101
|
-
onToggle?: (reaction: string) => void;
|
|
102
|
-
onClose?: () => void;
|
|
103
|
-
}) => {
|
|
104
|
-
const onToggle = props?.onToggle ?? jest.fn();
|
|
105
|
-
const onClose = props?.onClose ?? jest.fn();
|
|
106
|
-
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
49
|
+
const render = (
|
|
50
|
+
myReactions: string[],
|
|
51
|
+
reactions: readonly string[],
|
|
52
|
+
onToggle: (reaction: string) => void
|
|
53
|
+
) => {
|
|
54
|
+
let tree!: ReturnType<typeof ReactTestRenderer.create>;
|
|
107
55
|
ReactTestRenderer.act(() => {
|
|
108
56
|
tree = ReactTestRenderer.create(
|
|
109
|
-
|
|
110
|
-
myReactions
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
57
|
+
React.createElement(ReactionPicker, {
|
|
58
|
+
myReactions,
|
|
59
|
+
reactions,
|
|
60
|
+
onToggle,
|
|
61
|
+
})
|
|
114
62
|
);
|
|
115
63
|
});
|
|
116
|
-
return
|
|
64
|
+
return tree;
|
|
117
65
|
};
|
|
118
66
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const { tree } = renderPicker({ myReactions: ['❤️'] });
|
|
135
|
-
const highlighted: string[] = [];
|
|
136
|
-
walk(tree.toJSON(), (n) => {
|
|
137
|
-
const className = n.props?.className;
|
|
138
|
-
if (typeof className === 'string' && className.includes('bg-border')) {
|
|
139
|
-
highlighted.push(...collectText(n));
|
|
140
|
-
}
|
|
67
|
+
describe('ReactionPicker (native) orphans', () => {
|
|
68
|
+
it('renders the orphan (dimmed flag) after the divider', () => {
|
|
69
|
+
const tree = render(['🐰'], ['👍'], () => {});
|
|
70
|
+
const dividers = tree.root.findAllByType('DIVIDER');
|
|
71
|
+
const orphans = tree.root.findAllByType('RB_ORPHAN');
|
|
72
|
+
expect(dividers.length).toBe(1);
|
|
73
|
+
expect(orphans.length).toBe(1);
|
|
74
|
+
// The divider precedes the orphan in render order.
|
|
75
|
+
const all = tree.root.findAll(() => true);
|
|
76
|
+
const dividerIdx = all.findIndex((n) => n.type === 'DIVIDER');
|
|
77
|
+
const orphanIdx = all.findIndex((n) => n.type === 'RB_ORPHAN');
|
|
78
|
+
expect(dividerIdx).toBeGreaterThanOrEqual(0);
|
|
79
|
+
expect(dividerIdx).toBeLessThan(orphanIdx);
|
|
80
|
+
// The orphan row carries the emoji it retracts.
|
|
81
|
+
expect(orphans[0].children).toContain('🐰');
|
|
141
82
|
});
|
|
142
|
-
expect(highlighted).toEqual(['❤️']);
|
|
143
|
-
tree.unmount();
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
test('gives each emoji button an accessibility label with the reaction name', () => {
|
|
147
|
-
const { tree } = renderPicker();
|
|
148
|
-
for (const emoji of REACTION_TYPES) {
|
|
149
|
-
const button = emojiPressable(tree.toJSON(), emoji);
|
|
150
|
-
expect(button).toBeTruthy();
|
|
151
|
-
expect(button?.props?.accessibilityLabel).toBe(emoji);
|
|
152
|
-
}
|
|
153
|
-
tree.unmount();
|
|
154
|
-
});
|
|
155
83
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
(
|
|
84
|
+
it('retracts when the orphan is tapped', () => {
|
|
85
|
+
let toggled: string | undefined;
|
|
86
|
+
const tree = render(['👍', '🐰'], ['👍'], (r) => {
|
|
87
|
+
toggled = r;
|
|
88
|
+
});
|
|
89
|
+
const orphan = tree.root.findAllByType('RB_ORPHAN')[0];
|
|
90
|
+
expect(orphan.children).toContain('🐰');
|
|
91
|
+
// The orphan button is wired to retract its own emoji.
|
|
92
|
+
ReactTestRenderer.act(() => {
|
|
93
|
+
orphan.props.onPress();
|
|
94
|
+
});
|
|
95
|
+
expect(toggled).toBe('🐰');
|
|
163
96
|
});
|
|
164
|
-
expect(onToggle).toHaveBeenCalledTimes(1);
|
|
165
|
-
expect(onToggle).toHaveBeenCalledWith('😂');
|
|
166
|
-
tree.unmount();
|
|
167
|
-
});
|
|
168
97
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
let closed = false;
|
|
174
|
-
walk(tree.toJSON(), (n) => {
|
|
175
|
-
if (n.props?.accessibilityLabel === CLOSE_LABEL && n.props?.onPress) {
|
|
176
|
-
closed = true;
|
|
177
|
-
ReactTestRenderer.act(() => (n.props.onPress as () => void)());
|
|
178
|
-
}
|
|
98
|
+
it('renders no orphan section when every attached reaction is allowed', () => {
|
|
99
|
+
const tree = render(['👍', '🎉'], ['👍', '🎉'], () => {});
|
|
100
|
+
expect(tree.root.findAllByType('RB_ORPHAN').length).toBe(0);
|
|
101
|
+
expect(tree.root.findAllByType('DIVIDER').length).toBe(0);
|
|
179
102
|
});
|
|
180
|
-
expect(closed).toBe(true);
|
|
181
|
-
expect(onClose).toHaveBeenCalledTimes(1);
|
|
182
|
-
expect(onToggle).not.toHaveBeenCalled();
|
|
183
|
-
tree.unmount();
|
|
184
103
|
});
|