@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.
Files changed (30) hide show
  1. package/package.json +4 -5
  2. package/src/components/conversations/ConversationMessageBubble.test.tsx +158 -0
  3. package/src/components/conversations/ConversationMessageBubble.tsx +43 -25
  4. package/src/components/jams/JamCallParticipant.tsx +84 -16
  5. package/src/components/jams/JamChatMessage.test.tsx +139 -0
  6. package/src/components/jams/JamChatMessage.tsx +13 -0
  7. package/src/components/jams/JamPeopleDrawer.test.tsx +77 -3
  8. package/src/components/jams/JamPeopleDrawer.tsx +94 -3
  9. package/src/components/jams/JamReactionMenu.tsx +10 -31
  10. package/src/components/jams/JamRoom.tsx +15 -0
  11. package/src/components/markdown/OpenpeepsMarkdown.tsx +10 -3
  12. package/src/components/markdown/theme.test.ts +78 -0
  13. package/src/components/markdown/theme.ts +30 -12
  14. package/src/components/post/CompactReplyParent.test.tsx +337 -0
  15. package/src/components/post/CompactReplyParent.tsx +21 -5
  16. package/src/components/post/TruncatedMarkdown.test.tsx +201 -0
  17. package/src/components/post/TruncatedMarkdown.tsx +98 -10
  18. package/src/components/post/pieces/PostActions.test.tsx +27 -19
  19. package/src/components/post/pieces/PostActions.tsx +7 -11
  20. package/src/components/post/pieces/ReactionButton.tsx +41 -0
  21. package/src/components/post/pieces/ReactionPicker.test.tsx +80 -161
  22. package/src/components/post/pieces/ReactionPicker.tsx +32 -33
  23. package/src/components/post/pieces/index.ts +1 -0
  24. package/src/components/preview-link/local/WelcomePreview.tsx +1 -0
  25. package/src/components/resources/CategoryPathPicker.tsx +8 -2
  26. package/src/components/resources/ResourceCard.test.tsx +48 -4
  27. package/src/components/resources/ResourceCard.tsx +8 -2
  28. package/src/components/resources/ResourceLibrary.test.tsx +40 -2
  29. package/src/components/resources/ResourceLibrary.tsx +11 -6
  30. package/src/lib/moduleResolverRootGuard.test.ts +281 -0
@@ -0,0 +1,337 @@
1
+ /**
2
+ * Layout contract for the RN `CompactReplyParent` strip (issue #2074): the
3
+ * author name/handle line renders first and can never be clipped. The strip
4
+ * keeps its `max-h-20` cap but aligns its row content to the start so any
5
+ * residual overflow clips at the bottom instead of the top. The note/question
6
+ * bodies stay clamped to one line via `maxLines={1}`. A visual-attachment
7
+ * thumbnail renders beside the pinned author line, and the hidden/deleted
8
+ * tombstone branches render the placeholder instead of the author line.
9
+ */
10
+
11
+ const React = require('react');
12
+ const ReactTestRenderer = require('react-test-renderer');
13
+
14
+ jest.mock('react-native', () => ({
15
+ Pressable: (props: {
16
+ children?: unknown;
17
+ className?: string;
18
+ onPress?: () => void;
19
+ accessibilityLabel?: string;
20
+ }) =>
21
+ React.createElement(
22
+ 'Pressable',
23
+ {
24
+ className: props.className,
25
+ onPress: props.onPress,
26
+ accessibilityLabel: props.accessibilityLabel,
27
+ },
28
+ props.children
29
+ ),
30
+ View: (props: { className?: string; children?: unknown }) =>
31
+ React.createElement('View', { className: props.className }, props.children),
32
+ }));
33
+
34
+ jest.mock('react-i18next', () => ({
35
+ useTranslation: () => ({
36
+ t: (key: string, opts?: Record<string, string | number>) =>
37
+ (key.startsWith('posts.compact.pollOptions')
38
+ ? `${opts?.count} options`
39
+ : key
40
+ ).replace(/\{\{(\w+)\}\}/g, (_m: string, name: string) =>
41
+ String(opts?.[name] ?? '')
42
+ ),
43
+ }),
44
+ }));
45
+
46
+ jest.mock('@react-navigation/native', () => ({
47
+ useNavigation: () => ({ navigate: jest.fn() }),
48
+ }));
49
+
50
+ jest.mock('@openpeepshq/common', () => ({
51
+ formatEventWhen: () => '',
52
+ isHiddenPost: (post: { hidden?: boolean }) => !!post.hidden,
53
+ }));
54
+
55
+ jest.mock('../profile/index', () => ({
56
+ ProfileAvatar: () => null,
57
+ }));
58
+
59
+ jest.mock('../icons/index', () => ({
60
+ CalendarIcon: () => null,
61
+ PaperclipIcon: () => null,
62
+ PlayIcon: () => null,
63
+ }));
64
+
65
+ jest.mock('../ui/themed-text', () => ({
66
+ ThemedText: (props: Record<string, unknown>) =>
67
+ React.createElement(
68
+ 'ThemedText',
69
+ { numberOfLines: props.numberOfLines },
70
+ props.children
71
+ ),
72
+ }));
73
+
74
+ jest.mock('../ui/themed-view', () => ({
75
+ ThemedView: (props: Record<string, unknown>) =>
76
+ React.createElement(
77
+ 'ThemedView',
78
+ { className: props.className },
79
+ props.children
80
+ ),
81
+ }));
82
+
83
+ jest.mock('../ui/svg-image', () => ({
84
+ SvgImage: (props: { uri?: string }) =>
85
+ React.createElement('SvgImage', { uri: props.uri }),
86
+ }));
87
+
88
+ jest.mock('./TruncatedMarkdown', () => ({
89
+ TruncatedMarkdown: (props: {
90
+ maxLines?: number;
91
+ maxChars?: number;
92
+ className?: string;
93
+ }) =>
94
+ React.createElement('Excerpt', {
95
+ maxLines: props.maxLines,
96
+ maxChars: props.maxChars,
97
+ className: props.className,
98
+ }),
99
+ }));
100
+
101
+ import type { ReactElement } from 'react';
102
+ import { CompactReplyParent } from './CompactReplyParent';
103
+
104
+ const makePost = (data: Record<string, unknown>) =>
105
+ ({
106
+ id: 'post-1',
107
+ type: 'note',
108
+ profile: {
109
+ id: 'bob',
110
+ displayName: 'A Very Long Display Name',
111
+ handle: 'some-long-handle-1234',
112
+ },
113
+ data: { type: 'note', content: 'hello' },
114
+ ...data,
115
+ }) as never;
116
+
117
+ const render = (element: ReactElement) => {
118
+ let tree!: ReactTestRenderer.ReactTestRenderer;
119
+ ReactTestRenderer.act(() => {
120
+ tree = ReactTestRenderer.create(element);
121
+ });
122
+ return tree;
123
+ };
124
+
125
+ /** Flattened pre-order of the test tree: node types and string children. */
126
+ const flatten = (
127
+ node:
128
+ | ReactTestRenderer.ReactTestRendererJSON
129
+ | ReactTestRenderer.ReactTestRendererJSON[]
130
+ | string
131
+ | null
132
+ ): string[] => {
133
+ if (node == null) return [];
134
+ if (typeof node === 'string') return [node];
135
+ const list = Array.isArray(node) ? node : [node];
136
+ return list.flatMap((n) =>
137
+ typeof n === 'string' ? [n] : [n.type as string, ...flatten(n.children)]
138
+ );
139
+ };
140
+
141
+ /** All string text of a rendered JSON subtree. */
142
+ const jsonText = (
143
+ node:
144
+ | ReactTestRenderer.ReactTestRendererJSON
145
+ | ReactTestRenderer.ReactTestRendererJSON[]
146
+ | string
147
+ | null
148
+ ): string => {
149
+ if (node == null) return '';
150
+ if (typeof node === 'string') return node;
151
+ const list = Array.isArray(node) ? node : [node];
152
+ return list
153
+ .map((n) => (typeof n === 'string' ? n : jsonText(n.children)))
154
+ .join('');
155
+ };
156
+
157
+ /** All JSON nodes of a rendered tree, pre-order. */
158
+ const allNodes = (
159
+ node:
160
+ | ReactTestRenderer.ReactTestRendererJSON
161
+ | ReactTestRenderer.ReactTestRendererJSON[]
162
+ | string
163
+ | null
164
+ ): ReactTestRenderer.ReactTestRendererJSON[] => {
165
+ if (node == null || typeof node === 'string') return [];
166
+ const list = Array.isArray(node) ? node : [node];
167
+ return list.flatMap((n) => [n, ...allNodes(n.children)]);
168
+ };
169
+
170
+ test('the strip container caps height, keeps overflow hidden and aligns content to the start', () => {
171
+ const tree = render(<CompactReplyParent post={makePost({})} />);
172
+ const pressable = tree.root.find((n) => n.type === 'Pressable');
173
+ const cls = pressable.props.className as string;
174
+ expect(cls).toContain('max-h-20');
175
+ expect(cls).toContain('overflow-hidden');
176
+ expect(cls).toContain('items-start');
177
+ expect(cls).not.toContain('items-center');
178
+ ReactTestRenderer.act(() => tree.unmount());
179
+ });
180
+
181
+ test('the author line renders before the one-line body excerpt', () => {
182
+ const tree = render(
183
+ <CompactReplyParent
184
+ post={makePost({
185
+ data: { type: 'note', content: 'a reply body' },
186
+ })}
187
+ />
188
+ );
189
+ const order = flatten(tree.toJSON());
190
+ const nameIdx = order.indexOf('A Very Long Display Name');
191
+ const bodyIdx = order.indexOf('Excerpt');
192
+ expect(nameIdx).toBeGreaterThanOrEqual(0);
193
+ expect(bodyIdx).toBeGreaterThanOrEqual(0);
194
+ expect(nameIdx).toBeLessThan(bodyIdx);
195
+ ReactTestRenderer.act(() => tree.unmount());
196
+ });
197
+
198
+ test('the author line is clamped to one line so it can never wrap and clip', () => {
199
+ const tree = render(
200
+ <CompactReplyParent
201
+ post={makePost({
202
+ data: { type: 'note', content: 'a reply body' },
203
+ })}
204
+ />
205
+ );
206
+ // The single-line header clamp: without it a long name+handle would wrap
207
+ // and the wrapped line is exactly what the strip cap would clip. The author
208
+ // row is the ThemedText carrying the display name (and handle), so assert
209
+ // that row is the single-line one.
210
+ const authorRow = allNodes(tree.toJSON()).find(
211
+ (n) =>
212
+ n.type === 'ThemedText' &&
213
+ n.props.numberOfLines === 1 &&
214
+ jsonText(n.children).includes('A Very Long Display Name')
215
+ );
216
+ expect(authorRow).toBeTruthy();
217
+ ReactTestRenderer.act(() => tree.unmount());
218
+ });
219
+
220
+ test('the note body excerpt is clamped to one line at the sm size', () => {
221
+ const tree = render(
222
+ <CompactReplyParent
223
+ post={makePost({
224
+ data: { type: 'note', content: 'a reply body' },
225
+ })}
226
+ />
227
+ );
228
+ const json = JSON.stringify(tree.toJSON());
229
+ expect(json).toContain('Excerpt');
230
+ // maxLines={1} must reach the excerpt (previously dropped on RN).
231
+ expect(json).toContain('"maxLines":1');
232
+ expect(json).toContain('"maxChars":80');
233
+ expect(json).toContain('text-sm text-muted-foreground');
234
+ ReactTestRenderer.act(() => tree.unmount());
235
+ });
236
+
237
+ test('a block-hidden reply tombstone renders the hidden placeholder, not the reply content', () => {
238
+ // A hidden post (toHiddenPost) reaches the strip the same way a deleted one
239
+ // does, but with `hidden: true` and no `deletedAt`. The web twin branches on
240
+ // `isHiddenPost` and renders `posts.hiddenMessage`; RN must mirror that
241
+ // instead of showing a bare name row with an empty body.
242
+ const tree = render(
243
+ <CompactReplyParent
244
+ post={makePost({
245
+ hidden: true,
246
+ data: { type: 'note', content: 'secret reply body' },
247
+ })}
248
+ />
249
+ );
250
+ const text = jsonText(tree.toJSON());
251
+ // The i18n mock returns keys verbatim, so the placeholder is the key itself.
252
+ expect(text).toContain('posts.hiddenMessage');
253
+ // None of the reply content renders: no body excerpt, no name row.
254
+ const json = JSON.stringify(tree.toJSON());
255
+ expect(json).not.toContain('Excerpt');
256
+ expect(text).not.toContain('A Very Long Display Name');
257
+ expect(text).not.toContain('secret reply body');
258
+ // The deleted placeholder must not render either (hidden is the first branch).
259
+ expect(text).not.toContain('posts.compact.deleted');
260
+ ReactTestRenderer.act(() => tree.unmount());
261
+ });
262
+
263
+ test('a deleted reply renders the deleted placeholder, not the hidden message', () => {
264
+ // Reverse of the hidden-tombstone test: with `hidden` unset the second
265
+ // branch must win, so a future swap of the two ternary arms (or of the
266
+ // `isHiddenPost`/`deletedAt` checks) renders reply content for deleted
267
+ // posts and this fails.
268
+ const tree = render(
269
+ <CompactReplyParent
270
+ post={makePost({
271
+ deletedAt: '2026-11-01T00:00:00.000Z',
272
+ data: { type: 'note', content: 'deleted reply body' },
273
+ })}
274
+ />
275
+ );
276
+ const text = jsonText(tree.toJSON());
277
+ // Keyed on the i18n mock's verbatim key echo — do not simplify the mock to
278
+ // a no-op, it would silently weaken these assertions.
279
+ expect(text).toContain('posts.compact.deleted');
280
+ // None of the reply content renders: no body excerpt, no name row.
281
+ const json = JSON.stringify(tree.toJSON());
282
+ expect(json).not.toContain('Excerpt');
283
+ expect(text).not.toContain('A Very Long Display Name');
284
+ expect(text).not.toContain('deleted reply body');
285
+ // The hidden placeholder must not leak into the deleted branch.
286
+ expect(text).not.toContain('posts.hiddenMessage');
287
+ ReactTestRenderer.act(() => tree.unmount());
288
+ });
289
+
290
+ test('a question post with an image attachment keeps the author line and the compact thumb', () => {
291
+ // The `question` arm of `compactThumb` is one of several (note/question/
292
+ // link/article) that feed the 64×64 thumbnail beside the pinned author line.
293
+ // Pinning it here keeps that branch↔thumbnail pairing from drifting the same
294
+ // way the author line did: a post that should carry a thumb rendering without
295
+ // one (or the thumb detached from its author line) fails this.
296
+ const tree = render(
297
+ <CompactReplyParent
298
+ post={makePost({
299
+ type: 'question',
300
+ data: {
301
+ type: 'question',
302
+ content: 'Which option wins?',
303
+ options: [{ id: 'a' }, { id: 'b' }],
304
+ attachments: [
305
+ {
306
+ type: 'image',
307
+ url: 'https://example.com/poll.png',
308
+ previewUrl: 'https://example.com/poll-preview.png',
309
+ meta: { mimetype: 'image/png' },
310
+ },
311
+ ],
312
+ },
313
+ })}
314
+ />
315
+ );
316
+ const order = flatten(tree.toJSON());
317
+ // The author line still renders for the question branch.
318
+ const nameIdx = order.indexOf('A Very Long Display Name');
319
+ expect(nameIdx).toBeGreaterThanOrEqual(0);
320
+ // Exactly one 64×64 (size-16) thumbnail container renders, and it points
321
+ // at the attachment's preview URL (not the full-size URL).
322
+ const thumbViews = allNodes(tree.toJSON()).filter(
323
+ (n) =>
324
+ n.type === 'View' &&
325
+ typeof n.props?.className === 'string' &&
326
+ n.props.className.includes('size-16')
327
+ );
328
+ expect(thumbViews).toHaveLength(1);
329
+ const svgImage = allNodes(tree.toJSON()).find((n) => n.type === 'SvgImage');
330
+ expect(svgImage).toBeTruthy();
331
+ expect(svgImage?.props.uri).toBe('https://example.com/poll-preview.png');
332
+ // The question body still renders its one-line excerpt + poll-option count.
333
+ const json = JSON.stringify(tree.toJSON());
334
+ expect(json).toContain('Excerpt');
335
+ expect(order).toContain('2 options');
336
+ ReactTestRenderer.act(() => tree.unmount());
337
+ });
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  formatEventWhen,
3
+ isHiddenPost,
3
4
  type Article,
4
5
  type Event,
5
6
  type MediaAttachmentData,
@@ -139,7 +140,7 @@ const CompactTypeBody = ({ post }: { post: CompactPost }) => {
139
140
  maxBlocks={1}
140
141
  maxChars={80}
141
142
  maxLines={1}
142
- className="text-sm text-muted-foreground"
143
+ className="break-words text-sm text-muted-foreground"
143
144
  />
144
145
  {docName ? (
145
146
  <View className="flex-row items-center gap-1">
@@ -165,7 +166,7 @@ const CompactTypeBody = ({ post }: { post: CompactPost }) => {
165
166
  maxBlocks={1}
166
167
  maxChars={80}
167
168
  maxLines={1}
168
- className="text-sm text-muted-foreground"
169
+ className="break-words text-sm text-muted-foreground"
169
170
  />
170
171
  {optionCount > 0 ? (
171
172
  <ThemedText
@@ -238,21 +239,36 @@ export const CompactReplyParent = ({
238
239
  const name = post.profile.displayName || `@${post.profile.handle}`;
239
240
  const thumb = post.deletedAt ? null : compactThumb(post);
240
241
 
242
+ // Intentionally divergent from the web twin: web keeps `items-center` and
243
+ // vertically centers its (truly line-clamped) content in an inner
244
+ // `min-h-0 flex-col justify-center overflow-hidden` column; RN cannot
245
+ // line-clamp rendered markdown, so it starts the row at the top and lets
246
+ // any residual overflow clip at the bottom — the author line can never be
247
+ // cut. See the approved plan for issue #2074.
241
248
  return (
242
249
  <Pressable
243
250
  accessibilityLabel={t('posts.compact.viewPost', {
244
251
  defaultValue: 'View post',
245
252
  })}
246
253
  onPress={() => navigation.navigate('Post', { id: post.id })}
247
- className={`bg-muted mx-2 mb-2 max-h-20 flex-row items-center gap-2 overflow-hidden rounded-lg px-2 py-1.5 ${className ?? ''}`}
254
+ className={`bg-muted mx-2 mb-2 max-h-20 flex-row items-start gap-2 overflow-hidden rounded-lg px-2 py-1.5 ${className ?? ''}`}
248
255
  >
249
256
  <ProfileAvatar profile={post.profile} className="size-8" />
250
- {post.deletedAt ? (
257
+ {isHiddenPost(post) ? (
251
258
  <ThemedText
252
259
  className="flex-1 text-sm text-muted-foreground"
253
260
  numberOfLines={2}
254
261
  >
255
- {t('posts.compact.deleted')}
262
+ {t('posts.hiddenMessage', { defaultValue: 'Hidden message' })}
263
+ </ThemedText>
264
+ ) : post.deletedAt ? (
265
+ <ThemedText
266
+ className="flex-1 text-sm text-muted-foreground"
267
+ numberOfLines={2}
268
+ >
269
+ {t('posts.compact.deleted', {
270
+ defaultValue: 'This post has been deleted.',
271
+ })}
256
272
  </ThemedText>
257
273
  ) : (
258
274
  <>
@@ -0,0 +1,201 @@
1
+ /**
2
+ * Contract for the RN `TruncatedMarkdown` (issue #2074): `maxLines` and the
3
+ * sizing/color `className` are honored, not ignored.
4
+ *
5
+ * `maxLines` tightens the excerpt to a per-line char budget; `text-sm`/`text-xs`
6
+ * map to text metrics and `text-foreground`/`text-muted-foreground` to theme
7
+ * colors — all merged over the markdown theme (the base 16/24 `foreground`
8
+ * previously applied regardless). A caller-provided `snippet` is re-truncated to
9
+ * the same budget so it cannot exceed `maxLines`.
10
+ *
11
+ * The excerpt budget math runs through the REAL `truncateMarkdown` (the
12
+ * `@openpeepshq/common/lib` barrel can't load under Jest's node runtime, so it
13
+ * is re-exported here from the shared source) so the tests pin the
14
+ * user-visible clamp — not just the shape of the call to the helper.
15
+ */
16
+
17
+ const React = require('react');
18
+ const ReactTestRenderer = require('react-test-renderer');
19
+
20
+ jest.mock('react-native', () => ({
21
+ StyleSheet: {
22
+ flatten: (s: unknown) => (Array.isArray(s) ? Object.assign({}, ...s) : s),
23
+ },
24
+ }));
25
+
26
+ jest.mock('react-i18next', () => ({
27
+ useTranslation: () => ({ t: (key: string) => key }),
28
+ }));
29
+
30
+ jest.mock('../../theme/OpenPeepsThemeProvider', () => ({
31
+ useOpenPeepsTheme: () => ({
32
+ colors: {
33
+ 'foreground': '#18181b',
34
+ 'muted-foreground': '#71717a',
35
+ },
36
+ }),
37
+ }));
38
+
39
+ jest.mock('@openpeepshq/common/lib', () => ({
40
+ // Real implementation from the shared source (the built barrel is ESM and
41
+ // can't be parsed under Jest's node transform).
42
+ truncateMarkdown: require('../../../../common/src/lib/markdownHelpers')
43
+ .truncateMarkdown,
44
+ }));
45
+
46
+ const mockMarkdownCalls: { source?: string; baseTextStyle?: unknown }[] = [];
47
+
48
+ jest.mock('../markdown', () => ({
49
+ OpenpeepsMarkdown: (props: { source?: string; baseTextStyle?: unknown }) => {
50
+ mockMarkdownCalls.push({
51
+ source: props.source,
52
+ baseTextStyle: props.baseTextStyle,
53
+ });
54
+ return React.createElement('MarkdownExcerpt', { source: props.source });
55
+ },
56
+ }));
57
+
58
+ jest.mock('../markdown/MarkdownOverlay', () => ({
59
+ MarkdownOverlay: ({ children }: { children?: unknown }) =>
60
+ React.createElement('Overlay', null, children),
61
+ }));
62
+
63
+ import { TruncatedMarkdown } from './TruncatedMarkdown';
64
+
65
+ const render = (element: React.ReactElement) => {
66
+ let tree!: ReactTestRenderer.ReactTestRenderer;
67
+ ReactTestRenderer.act(() => {
68
+ tree = ReactTestRenderer.create(element);
69
+ });
70
+ return tree;
71
+ };
72
+
73
+ /** The excerpt actually handed to the markdown renderer (last render). */
74
+ const lastExcerpt = () => mockMarkdownCalls.at(-1)?.source ?? '';
75
+ /** The style override actually handed to the markdown renderer. */
76
+ const lastStyle = () => mockMarkdownCalls.at(-1)?.baseTextStyle;
77
+
78
+ const LONG = 'word '.repeat(30).trim(); // ~150 chars of short words
79
+
80
+ beforeEach(() => {
81
+ mockMarkdownCalls.length = 0;
82
+ });
83
+
84
+ test('maxLines={1} bounds the rendered excerpt to the one-line char budget', () => {
85
+ render(
86
+ <TruncatedMarkdown
87
+ source={LONG}
88
+ maxBlocks={1}
89
+ maxChars={80}
90
+ maxLines={1}
91
+ interactive={false}
92
+ className="text-sm text-muted-foreground"
93
+ />
94
+ );
95
+ // Budget = min(80, 1 * 40) = 40 → the real truncateMarkdown keeps the
96
+ // excerpt within that (plus one char for the ellipsis it appends).
97
+ expect(lastExcerpt().length).toBeLessThanOrEqual(41);
98
+ });
99
+
100
+ test('without maxLines the caller char budget applies and no override is set', () => {
101
+ render(<TruncatedMarkdown source={LONG} maxBlocks={2} maxChars={240} />);
102
+ // No maxLines → the full 240-char budget is used, not the per-line one.
103
+ expect(lastExcerpt().length).toBeGreaterThan(41);
104
+ expect(lastExcerpt().length).toBeLessThanOrEqual(241);
105
+ expect(lastStyle()).toBeUndefined();
106
+ });
107
+
108
+ test('a caller snippet is re-truncated to the maxLines budget, not used raw', () => {
109
+ const rawSnippet = 'snippet-word '.repeat(20).trim(); // ~240 chars, unbounded
110
+ render(
111
+ <TruncatedMarkdown
112
+ source={LONG}
113
+ snippet={rawSnippet}
114
+ maxBlocks={1}
115
+ maxChars={80}
116
+ maxLines={1}
117
+ interactive={false}
118
+ />
119
+ );
120
+ // The 240-char snippet must be squeezed to the 40-char one-line budget.
121
+ expect(lastExcerpt().length).toBeLessThanOrEqual(41);
122
+ });
123
+
124
+ test('a caller snippet without maxLines is used as-is, not re-truncated', () => {
125
+ const rawSnippet = 'snippet-word '.repeat(20).trim(); // ~240 chars
126
+ render(
127
+ <TruncatedMarkdown
128
+ source={LONG}
129
+ snippet={rawSnippet}
130
+ maxBlocks={1}
131
+ maxChars={80}
132
+ interactive={false}
133
+ />
134
+ );
135
+ // No maxLines → no per-line budget: the caller snippet is trusted verbatim,
136
+ // even though it far exceeds maxChars. Pinning this keeps any future
137
+ // "always clamp" change a conscious decision, not a silent behavior flip.
138
+ expect(lastExcerpt()).toBe(rawSnippet);
139
+ expect(lastExcerpt().length).toBeGreaterThan(80);
140
+ });
141
+
142
+ test('text-sm + text-muted-foreground map to sm metrics and the muted color', () => {
143
+ render(
144
+ <TruncatedMarkdown
145
+ source={LONG}
146
+ maxChars={80}
147
+ maxLines={1}
148
+ interactive={false}
149
+ className="text-sm text-muted-foreground"
150
+ />
151
+ );
152
+ expect(lastStyle()).toEqual({
153
+ fontSize: 14,
154
+ lineHeight: 20,
155
+ color: '#71717a',
156
+ });
157
+ });
158
+
159
+ test('interactive excerpt keeps the overlay trigger around the sized excerpt', () => {
160
+ const tree = render(
161
+ <TruncatedMarkdown
162
+ source={LONG}
163
+ maxChars={80}
164
+ maxLines={1}
165
+ className="text-sm text-muted-foreground"
166
+ />
167
+ );
168
+ const json = JSON.stringify(tree.toJSON());
169
+ expect(json).toContain('Overlay');
170
+ expect(json).toContain('MarkdownExcerpt');
171
+ expect(lastStyle()).toEqual({
172
+ fontSize: 14,
173
+ lineHeight: 20,
174
+ color: '#71717a',
175
+ });
176
+ ReactTestRenderer.act(() => tree.unmount());
177
+ });
178
+
179
+ test('protected inline links are kept whole, never severed by the budget', () => {
180
+ const SHORT = '[ok](https://x.com)';
181
+ const LONG_LINK =
182
+ '[a long protected link label](https://example.com/some/very/long/url)';
183
+ const source = `head ${SHORT} mid ${LONG_LINK}`;
184
+ render(
185
+ <TruncatedMarkdown
186
+ source={source}
187
+ maxBlocks={1}
188
+ maxChars={80}
189
+ maxLines={1}
190
+ interactive={false}
191
+ />
192
+ );
193
+ const excerpt = lastExcerpt();
194
+ expect(excerpt.length).toBeLessThanOrEqual(41);
195
+ // A protected span that fits in the remaining budget is kept whole…
196
+ expect(excerpt).toContain(SHORT);
197
+ // …and one that does not fit is omitted rather than severed mid-token.
198
+ expect(excerpt).not.toContain('a long protected');
199
+ expect(excerpt).not.toMatch(/\[[^\]]*$/); // no dangling `[label`
200
+ expect(excerpt).not.toMatch(/\]\([^)]*$/); // no dangling `](url`
201
+ });