@openpeepshq/rn-components 0.20.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/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/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/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
|
@@ -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
|
+
});
|
|
@@ -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,7 +1,10 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
2
|
import { Pressable, View } from 'react-native';
|
|
3
3
|
import type { CategoryNode } from '@openpeepshq/common/lib';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
RESOURCE_CATEGORY_NAME_MAX_LENGTH,
|
|
6
|
+
categoryPathKey,
|
|
7
|
+
} from '@openpeepshq/common/lib';
|
|
5
8
|
import { Input } from '../ui/input';
|
|
6
9
|
import { ThemedText } from '../ui/themed-text';
|
|
7
10
|
import { useTranslation } from 'react-i18next';
|
|
@@ -76,6 +79,7 @@ export const CategoryPathPicker = ({
|
|
|
76
79
|
<Input
|
|
77
80
|
value={level}
|
|
78
81
|
onChangeText={setLevel}
|
|
82
|
+
maxLength={RESOURCE_CATEGORY_NAME_MAX_LENGTH}
|
|
79
83
|
placeholder={t('resources.form.addLevel', {
|
|
80
84
|
defaultValue: 'Add a folder',
|
|
81
85
|
})}
|
|
@@ -83,7 +87,9 @@ export const CategoryPathPicker = ({
|
|
|
83
87
|
<Pressable
|
|
84
88
|
className="border-border rounded-md border bg-background px-3 py-1.5"
|
|
85
89
|
onPress={() => {
|
|
86
|
-
const name = level
|
|
90
|
+
const name = level
|
|
91
|
+
.trim()
|
|
92
|
+
.slice(0, RESOURCE_CATEGORY_NAME_MAX_LENGTH);
|
|
87
93
|
if (!name) return;
|
|
88
94
|
onChange([...path, name]);
|
|
89
95
|
setLevel('');
|
|
@@ -96,8 +96,16 @@ jest.mock('../custom/common', () => ({
|
|
|
96
96
|
}));
|
|
97
97
|
|
|
98
98
|
jest.mock('../ui/themed-text', () => ({
|
|
99
|
-
ThemedText: (props: {
|
|
100
|
-
|
|
99
|
+
ThemedText: (props: {
|
|
100
|
+
children?: unknown;
|
|
101
|
+
className?: string;
|
|
102
|
+
numberOfLines?: number;
|
|
103
|
+
}) =>
|
|
104
|
+
React.createElement(
|
|
105
|
+
'ThemedText',
|
|
106
|
+
{ className: props.className, numberOfLines: props.numberOfLines },
|
|
107
|
+
props.children
|
|
108
|
+
),
|
|
101
109
|
}));
|
|
102
110
|
|
|
103
111
|
jest.mock('../post/VideoPlayOverlay', () => ({
|
|
@@ -188,19 +196,34 @@ const linkPost = resourcePost({
|
|
|
188
196
|
url: 'https://example.com/docs',
|
|
189
197
|
});
|
|
190
198
|
|
|
191
|
-
const renderCard = (
|
|
199
|
+
const renderCard = (
|
|
200
|
+
post: ResourceCardProps['post'],
|
|
201
|
+
layout: 'card' | 'list' = 'list'
|
|
202
|
+
) => {
|
|
192
203
|
let tree: ReturnType<typeof ReactTestRenderer.create>;
|
|
193
204
|
ReactTestRenderer.act(() => {
|
|
194
205
|
tree = ReactTestRenderer.create(
|
|
195
206
|
React.createElement(ResourceCard, {
|
|
196
207
|
post,
|
|
197
|
-
layout
|
|
208
|
+
layout,
|
|
198
209
|
})
|
|
199
210
|
);
|
|
200
211
|
});
|
|
201
212
|
return tree;
|
|
202
213
|
};
|
|
203
214
|
|
|
215
|
+
// A single unbroken word: on RN a Text won't shrink by default, so the
|
|
216
|
+
// category line needs `shrink` + `numberOfLines` to stay inside the card
|
|
217
|
+
// (issue #2174, mirrored from the web break-words fix).
|
|
218
|
+
const LONG_CATEGORY = 'a'.repeat(200);
|
|
219
|
+
|
|
220
|
+
const longCategoryPost = resourcePost({
|
|
221
|
+
title: 'Long path',
|
|
222
|
+
resourceKind: 'link',
|
|
223
|
+
url: 'https://example.com/docs',
|
|
224
|
+
categoryPath: ['Root', LONG_CATEGORY],
|
|
225
|
+
});
|
|
226
|
+
|
|
204
227
|
// The bookmark button is also a Pressable; it renders disabled for the
|
|
205
228
|
// anonymous profile the mock returns, so enabled Pressables are the
|
|
206
229
|
// card's actions only.
|
|
@@ -272,3 +295,24 @@ describe('ResourceCard list-layout actions', () => {
|
|
|
272
295
|
tree.unmount();
|
|
273
296
|
});
|
|
274
297
|
});
|
|
298
|
+
|
|
299
|
+
describe('ResourceCard long category path (issue #2174)', () => {
|
|
300
|
+
it.each(['card', 'list'] as const)(
|
|
301
|
+
'constrains the category line to two shrinkable lines in the %s layout',
|
|
302
|
+
(layout) => {
|
|
303
|
+
const tree = renderCard(longCategoryPost, layout);
|
|
304
|
+
|
|
305
|
+
const pathText = tree.root
|
|
306
|
+
.findAllByType('ThemedText')
|
|
307
|
+
.find(
|
|
308
|
+
(node: { props: { children?: unknown } }) =>
|
|
309
|
+
typeof node.props.children === 'string' &&
|
|
310
|
+
node.props.children.includes(LONG_CATEGORY)
|
|
311
|
+
);
|
|
312
|
+
expect(pathText).toBeTruthy();
|
|
313
|
+
expect(pathText!.props.className).toContain('shrink');
|
|
314
|
+
expect(pathText!.props.numberOfLines).toBe(2);
|
|
315
|
+
tree.unmount();
|
|
316
|
+
}
|
|
317
|
+
);
|
|
318
|
+
});
|
|
@@ -211,7 +211,10 @@ export const ResourceCard = ({
|
|
|
211
211
|
{resource.title}
|
|
212
212
|
</ThemedText>
|
|
213
213
|
{resource.categoryPath?.length ? (
|
|
214
|
-
<ThemedText
|
|
214
|
+
<ThemedText
|
|
215
|
+
className="shrink text-xs text-muted-foreground"
|
|
216
|
+
numberOfLines={2}
|
|
217
|
+
>
|
|
215
218
|
{resource.categoryPath.join(' / ')}
|
|
216
219
|
</ThemedText>
|
|
217
220
|
) : null}
|
|
@@ -330,7 +333,10 @@ export const ResourceCard = ({
|
|
|
330
333
|
{resource.title}
|
|
331
334
|
</ThemedText>
|
|
332
335
|
{resource.categoryPath?.length ? (
|
|
333
|
-
<ThemedText
|
|
336
|
+
<ThemedText
|
|
337
|
+
className="shrink text-xs text-muted-foreground"
|
|
338
|
+
numberOfLines={2}
|
|
339
|
+
>
|
|
334
340
|
{resource.categoryPath.join(' / ')}
|
|
335
341
|
</ThemedText>
|
|
336
342
|
) : null}
|
|
@@ -62,6 +62,7 @@ jest.mock('@openpeepshq/common/lib', () => ({
|
|
|
62
62
|
// Mirrored from platform/common/src/lib/resources.ts — the built
|
|
63
63
|
// package ships ESM which Jest's node transform doesn't cover.
|
|
64
64
|
categoryPathKey: (path: readonly string[]): string => JSON.stringify(path),
|
|
65
|
+
RESOURCE_CATEGORY_NAME_MAX_LENGTH: 120,
|
|
65
66
|
RESOURCE_KINDS: ['video', 'file', 'gallery', 'audio', 'link'],
|
|
66
67
|
}));
|
|
67
68
|
|
|
@@ -79,8 +80,16 @@ jest.mock('../ui/loading-spinner', () => ({
|
|
|
79
80
|
}));
|
|
80
81
|
|
|
81
82
|
jest.mock('../ui/themed-text', () => ({
|
|
82
|
-
ThemedText: (props: {
|
|
83
|
-
|
|
83
|
+
ThemedText: (props: {
|
|
84
|
+
children?: unknown;
|
|
85
|
+
className?: string;
|
|
86
|
+
numberOfLines?: number;
|
|
87
|
+
}) =>
|
|
88
|
+
React.createElement(
|
|
89
|
+
'ThemedText',
|
|
90
|
+
{ className: props.className, numberOfLines: props.numberOfLines },
|
|
91
|
+
props.children
|
|
92
|
+
),
|
|
84
93
|
}));
|
|
85
94
|
|
|
86
95
|
jest.mock('../icons', () => ({
|
|
@@ -258,6 +267,35 @@ describe('ResourceLibrary folder tree collision (issue #2148)', () => {
|
|
|
258
267
|
});
|
|
259
268
|
});
|
|
260
269
|
|
|
270
|
+
describe('ResourceLibrary breadcrumb long path (issue #2174)', () => {
|
|
271
|
+
it('constrains the breadcrumb to a single shrinkable line', () => {
|
|
272
|
+
mockTranslations = {};
|
|
273
|
+
// A non-empty pathPrefix so the breadcrumb path span renders.
|
|
274
|
+
mockLibrary = {
|
|
275
|
+
...libraryFor([slashPost]),
|
|
276
|
+
pathPrefix: ['[TEST] A/B'],
|
|
277
|
+
hierarchy: false,
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
const tree = render(
|
|
281
|
+
React.createElement(ResourceLibrary, {
|
|
282
|
+
groupId: 'g1',
|
|
283
|
+
} as ResourceLibraryProps)
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
const crumb = tree.root
|
|
287
|
+
.findAllByType('ThemedText')
|
|
288
|
+
.find(
|
|
289
|
+
(node: { props: { children?: unknown } }) =>
|
|
290
|
+
typeof node.props.children === 'string' &&
|
|
291
|
+
node.props.children.includes('[TEST] A/B')
|
|
292
|
+
);
|
|
293
|
+
expect(crumb).toBeTruthy();
|
|
294
|
+
expect(crumb!.props.className).toContain('shrink');
|
|
295
|
+
expect(crumb!.props.numberOfLines).toBe(1);
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
|
|
261
299
|
describe('CategoryPathPicker RN parity', () => {
|
|
262
300
|
beforeEach(() => {
|
|
263
301
|
mockTranslations = {};
|
|
@@ -74,9 +74,9 @@ const Tree = ({
|
|
|
74
74
|
}`}
|
|
75
75
|
/>
|
|
76
76
|
</Pressable>
|
|
77
|
-
<Pressable onPress={() => onSelect(node.path)}>
|
|
77
|
+
<Pressable className="flex-1" onPress={() => onSelect(node.path)}>
|
|
78
78
|
<ThemedText
|
|
79
|
-
className={`text-sm ${
|
|
79
|
+
className={`shrink text-sm ${
|
|
80
80
|
isSelected
|
|
81
81
|
? 'font-semibold text-foreground'
|
|
82
82
|
: 'text-muted-foreground'
|
|
@@ -268,12 +268,17 @@ export const ResourceLibrary = ({ groupId }: ResourceLibraryProps) => {
|
|
|
268
268
|
</Pressable>
|
|
269
269
|
{library.pathPrefix.length > 0 ? (
|
|
270
270
|
<>
|
|
271
|
-
<ThemedText className="text-sm text-muted-foreground">
|
|
271
|
+
<ThemedText className="shrink-0 text-sm text-muted-foreground">
|
|
272
272
|
/
|
|
273
273
|
</ThemedText>
|
|
274
|
-
<
|
|
275
|
-
|
|
276
|
-
|
|
274
|
+
<View className="flex-1">
|
|
275
|
+
<ThemedText
|
|
276
|
+
className="shrink text-sm text-muted-foreground"
|
|
277
|
+
numberOfLines={1}
|
|
278
|
+
>
|
|
279
|
+
{library.pathPrefix.join(' / ')}
|
|
280
|
+
</ThemedText>
|
|
281
|
+
</View>
|
|
277
282
|
</>
|
|
278
283
|
) : null}
|
|
279
284
|
<Pressable
|