@openpeepshq/rn-components 0.14.1 → 0.15.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/buttonOverflow.test.tsx +8 -0
- package/src/components/conversations/ConversationParticipantsModal.tsx +1 -6
- package/src/components/jams/JamChatDrawer.test.tsx +263 -0
- package/src/components/jams/JamChatDrawer.tsx +117 -52
- package/src/components/jams/JamConference.tsx +5 -0
- package/src/components/jams/JamParticipantConference.tsx +7 -4
- package/src/components/jams/JamPeopleDrawer.test.tsx +216 -0
- package/src/components/jams/JamPeopleDrawer.tsx +32 -2
- package/src/components/jams/JamRoomIndicators.test.tsx +190 -38
- package/src/components/jams/JamRoomIndicators.tsx +62 -20
- package/src/components/jams/useTrackSubscriptionBump.test.ts +294 -0
- package/src/components/jams/useTrackSubscriptionBump.ts +44 -0
- package/src/components/post/feed/events/EventsCalendar.test.tsx +33 -18
- package/src/components/post/pieces/ShareMenu.test.tsx +217 -0
- package/src/components/post/pieces/ShareMenu.tsx +107 -61
- package/src/components/post/post-form/VisibilitySheet.test.tsx +153 -0
- package/src/components/post/post-form/VisibilitySheet.tsx +6 -5
- package/src/components/profile/Avatar.test.tsx +147 -0
- package/src/components/profile/Avatar.tsx +26 -0
- package/src/components/profile/ProfileCard.test.tsx +165 -8
- package/src/components/profile/ProfileCard.tsx +63 -10
- package/src/components/profile/ProfileSelector.test.tsx +147 -5
- package/src/components/profile/ProfileSelector.tsx +64 -18
- package/src/pages/conversations/New.test.tsx +340 -0
- package/src/pages/conversations/New.tsx +35 -30
- package/src/pages/events/Index.tsx +4 -1
- package/src/pages/events/My.tsx +1 -1
- package/src/pages/groups/Show.tsx +1 -1
- package/src/theme/useThemeOpacity.test.ts +70 -0
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Regression tests for the ProfileSelector sheet title
|
|
2
|
+
* Regression tests for the ProfileSelector sheet title, picker-row tint,
|
|
3
|
+
* selection a11y and id-based selection (issue #1666).
|
|
3
4
|
*
|
|
4
5
|
* The sheet used to hard-code the English string "Add members", so every
|
|
5
6
|
* caller that omitted `title` (jam moderators, group members, event
|
|
6
7
|
* moderators) rendered untranslated copy, and the audience picker could be
|
|
7
8
|
* re-titled to a non-matching string. Web defaults to
|
|
8
9
|
* `profile.selector.title` ("Select profiles"); RN must match.
|
|
10
|
+
*
|
|
11
|
+
* The picker rows also carried no visual selection state, so testers could
|
|
12
|
+
* not see which profiles were picked. NativeWind v4 cannot apply the `/N`
|
|
13
|
+
* opacity modifier to a CSS-variable color, so the tint is built inline via
|
|
14
|
+
* `useThemeOpacity` (`rgba` style) — asserted here as the resolved style
|
|
15
|
+
* value. The tint must use a token that actually contrasts on the sheet:
|
|
16
|
+
* `secondary` is a near-white neutral in the RN palette (web's is the brand
|
|
17
|
+
* teal), so a `secondary` wash is invisible; the selected row uses `primary`
|
|
18
|
+
* at low opacity. The mocked hook is keyed by token so a regression back to
|
|
19
|
+
* `secondary` fails here.
|
|
9
20
|
*/
|
|
10
21
|
|
|
11
22
|
const React = require('react');
|
|
12
23
|
const ReactTestRenderer = require('react-test-renderer');
|
|
13
24
|
|
|
14
|
-
const mockT = (key: string) => MESSAGES[key] ?? key;
|
|
15
|
-
|
|
16
25
|
const MESSAGES: Record<string, string> = {
|
|
17
26
|
'profile.selector.title': 'Select profiles',
|
|
27
|
+
// Deliberately NOT the literal ', selected' the old code hard-coded, so
|
|
28
|
+
// this suite fails if the label regresses to a hard-coded English
|
|
29
|
+
// fragment instead of resolving the locale key (issue #1666 review S1).
|
|
30
|
+
'profile.selector.rowSelected': '{{name}} (selected)',
|
|
18
31
|
'profile.search.placeholder': 'Search profiles',
|
|
19
32
|
'profile.search.noResults': 'No results found',
|
|
20
33
|
'common.members.addSuccess': 'Added',
|
|
@@ -23,11 +36,19 @@ const MESSAGES: Record<string, string> = {
|
|
|
23
36
|
'common.actions.add': 'Add',
|
|
24
37
|
};
|
|
25
38
|
|
|
39
|
+
// Mirrors i18next's default interpolation so the row-label regression test
|
|
40
|
+
// can assert the composed, localized screen-reader string (issue #1666
|
|
41
|
+
// review S1).
|
|
42
|
+
const mockT = (key: string, opts?: { name?: string }) =>
|
|
43
|
+
(MESSAGES[key] ?? key).replace('{{name}}', opts?.name ?? '');
|
|
44
|
+
|
|
26
45
|
jest.mock('react-native', () => ({
|
|
27
46
|
View: (props: { children?: unknown }) =>
|
|
28
47
|
React.createElement('View', null, props.children),
|
|
29
48
|
ScrollView: (props: { children?: unknown }) =>
|
|
30
49
|
React.createElement('ScrollView', null, props.children),
|
|
50
|
+
Pressable: (props: Record<string, unknown>) =>
|
|
51
|
+
React.createElement('Pressable', props, props.children),
|
|
31
52
|
ActivityIndicator: () => null,
|
|
32
53
|
}));
|
|
33
54
|
|
|
@@ -48,6 +69,12 @@ jest.mock('@openpeepshq/react', () => ({
|
|
|
48
69
|
|
|
49
70
|
const PROFILES: unknown[] = [];
|
|
50
71
|
|
|
72
|
+
// Two profile objects; PROFILES[0] is passed as the sheet's initial selection
|
|
73
|
+
// so the tint test can compare a selected row against an unselected one.
|
|
74
|
+
const ada = { id: 'p1', handle: 'ada', displayName: 'Ada' };
|
|
75
|
+
const alan = { id: 'p2', handle: 'alan', displayName: 'Alan' };
|
|
76
|
+
PROFILES.push(ada, alan);
|
|
77
|
+
|
|
51
78
|
jest.mock('../../lib/utils', () => ({
|
|
52
79
|
profileMatchesQuery: () => true,
|
|
53
80
|
}));
|
|
@@ -74,13 +101,29 @@ jest.mock('../custom/modals/common', () => ({
|
|
|
74
101
|
|
|
75
102
|
jest.mock('react-native-toast-message', () => ({ show: jest.fn() }));
|
|
76
103
|
|
|
104
|
+
jest.mock('../../theme/useThemeOpacity', () => ({
|
|
105
|
+
// Mirrors the real hook's shape. Values come from theme/defaults.ts so the
|
|
106
|
+
// tint style is asserted deterministically; keyed by token so a regression
|
|
107
|
+
// back to the invisible `secondary` wash fails (issue #1666 review S1).
|
|
108
|
+
useThemeOpacity: () => ({
|
|
109
|
+
background: (name: string, opacity: number) => ({
|
|
110
|
+
backgroundColor:
|
|
111
|
+
name === 'primary'
|
|
112
|
+
? `rgba(22, 22, 26, ${opacity})`
|
|
113
|
+
: `rgba(244, 244, 245, ${opacity})`,
|
|
114
|
+
}),
|
|
115
|
+
}),
|
|
116
|
+
}));
|
|
117
|
+
|
|
77
118
|
jest.mock('../../lib/bottom-sheet-ref', () => ({
|
|
78
119
|
bottomSheetClose: jest.fn(),
|
|
79
120
|
}));
|
|
80
121
|
|
|
81
122
|
jest.mock('./ProfileCard', () => ({
|
|
82
|
-
MiniProfileCard: () =>
|
|
83
|
-
|
|
123
|
+
MiniProfileCard: (props: Record<string, unknown>) =>
|
|
124
|
+
React.createElement('MiniProfileCard', props),
|
|
125
|
+
ProfileCard: (props: Record<string, unknown>) =>
|
|
126
|
+
React.createElement('ProfileCard', props),
|
|
84
127
|
}));
|
|
85
128
|
|
|
86
129
|
import type { ProfilePickerSheetProps } from './ProfileSelector';
|
|
@@ -113,3 +156,102 @@ describe('ProfileSelector sheet title (issue #1666)', () => {
|
|
|
113
156
|
expect(titleText(tree)).toBe('Add members to Test Group');
|
|
114
157
|
});
|
|
115
158
|
});
|
|
159
|
+
|
|
160
|
+
describe('ProfileSelector selected-row tint (issue #1666)', () => {
|
|
161
|
+
it('tints the selected row with primary at low opacity and leaves the unselected ones clear', () => {
|
|
162
|
+
const tree = renderSelector({
|
|
163
|
+
initialProfiles: [PROFILES[0]] as never,
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const rows = tree.root.findAllByType('Pressable');
|
|
167
|
+
expect(rows.length).toBeGreaterThanOrEqual(2);
|
|
168
|
+
const selected = rows.find(
|
|
169
|
+
(node: { props: { accessibilityState?: { selected?: boolean } } }) =>
|
|
170
|
+
node.props.accessibilityState?.selected === true
|
|
171
|
+
);
|
|
172
|
+
expect(selected).toBeDefined();
|
|
173
|
+
expect(selected.props.style).toEqual({
|
|
174
|
+
backgroundColor: 'rgba(22, 22, 26, 0.15)',
|
|
175
|
+
});
|
|
176
|
+
const unselected = rows.find(
|
|
177
|
+
(node: { props: { accessibilityState?: { selected?: boolean } } }) =>
|
|
178
|
+
node.props.accessibilityState?.selected === false
|
|
179
|
+
);
|
|
180
|
+
expect(unselected).toBeDefined();
|
|
181
|
+
expect(unselected.props.style).toBeUndefined();
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('marks the rows as accessible buttons with a selected state (web parity)', () => {
|
|
185
|
+
const tree = renderSelector({
|
|
186
|
+
initialProfiles: [PROFILES[0]] as never,
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// Only the selectable rows carry `accessibilityState`; the selected-chip
|
|
190
|
+
// remove buttons (also Pressable) do not, so scope to the rows.
|
|
191
|
+
const rows = tree.root
|
|
192
|
+
.findAllByType('Pressable')
|
|
193
|
+
.filter(
|
|
194
|
+
(node: { props: { accessibilityState?: unknown } }) =>
|
|
195
|
+
node.props.accessibilityState !== undefined
|
|
196
|
+
);
|
|
197
|
+
const selected = rows.filter(
|
|
198
|
+
(node: { props: { accessibilityState?: { selected?: boolean } } }) =>
|
|
199
|
+
node.props.accessibilityState?.selected === true
|
|
200
|
+
);
|
|
201
|
+
const unselected = rows.filter(
|
|
202
|
+
(node: { props: { accessibilityState?: { selected?: boolean } } }) =>
|
|
203
|
+
node.props.accessibilityState?.selected === false
|
|
204
|
+
);
|
|
205
|
+
expect(selected.length).toBe(1);
|
|
206
|
+
expect(unselected.length).toBeGreaterThan(0);
|
|
207
|
+
for (const row of rows) {
|
|
208
|
+
expect(row.props.accessibilityRole).toBe('button');
|
|
209
|
+
expect(typeof row.props.accessibilityLabel).toBe('string');
|
|
210
|
+
expect(row.props.accessibilityLabel.length).toBeGreaterThan(0);
|
|
211
|
+
}
|
|
212
|
+
expect(selected[0].props.accessibilityLabel).toContain('selected');
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('builds the selected-row label from the profile.selector.rowSelected locale key (issue #1666 review S1)', () => {
|
|
216
|
+
// The label must come from a t() key, not a hard-coded English fragment:
|
|
217
|
+
// the mock t() resolves the key and interpolates {{name}}, so a
|
|
218
|
+
// regression to a literal ", selected" concatenation would skip the key
|
|
219
|
+
// entirely and leave the label with no interpolation.
|
|
220
|
+
const tree = renderSelector({
|
|
221
|
+
initialProfiles: [PROFILES[0]] as never,
|
|
222
|
+
});
|
|
223
|
+
const rows = tree.root
|
|
224
|
+
.findAllByType('Pressable')
|
|
225
|
+
.filter(
|
|
226
|
+
(node: { props: { accessibilityState?: unknown } }) =>
|
|
227
|
+
node.props.accessibilityState !== undefined
|
|
228
|
+
);
|
|
229
|
+
const selected = rows.find(
|
|
230
|
+
(node: { props: { accessibilityState?: { selected?: boolean } } }) =>
|
|
231
|
+
node.props.accessibilityState?.selected === true
|
|
232
|
+
);
|
|
233
|
+
const unselected = rows.find(
|
|
234
|
+
(node: { props: { accessibilityState?: { selected?: boolean } } }) =>
|
|
235
|
+
node.props.accessibilityState?.selected === false
|
|
236
|
+
);
|
|
237
|
+
expect(selected.props.accessibilityLabel).toBe('Ada (selected)');
|
|
238
|
+
expect(unselected.props.accessibilityLabel).toBe('Alan');
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
describe('ProfileSelector id-based selection (issue #1666 review S3)', () => {
|
|
243
|
+
it('keeps the selection when the caller re-seeds with a fresh object of the same id', () => {
|
|
244
|
+
// A re-mounted sheet (or upstream object churn) seeds `initialProfiles`
|
|
245
|
+
// with a new object; reference equality would drop the selection, so the
|
|
246
|
+
// row must still render selected for the matching id.
|
|
247
|
+
const freshAda = { id: 'p1', handle: 'ada', displayName: 'Ada' };
|
|
248
|
+
const tree = renderSelector({ initialProfiles: [freshAda] as never });
|
|
249
|
+
|
|
250
|
+
const rows = tree.root.findAllByType('Pressable');
|
|
251
|
+
const selected = rows.filter(
|
|
252
|
+
(node: { props: { accessibilityState?: { selected?: boolean } } }) =>
|
|
253
|
+
node.props.accessibilityState?.selected === true
|
|
254
|
+
);
|
|
255
|
+
expect(selected.length).toBe(1);
|
|
256
|
+
});
|
|
257
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { forwardRef, useEffect, useState } from 'react';
|
|
2
|
-
import { View, ScrollView, ActivityIndicator } from 'react-native';
|
|
2
|
+
import { View, ScrollView, ActivityIndicator, Pressable } from 'react-native';
|
|
3
3
|
import { BottomSheetModal } from '@gorhom/bottom-sheet';
|
|
4
4
|
import { ThemedText } from '../ui/themed-text';
|
|
5
5
|
import { PublicProfile } from '@openpeepshq/common';
|
|
@@ -11,6 +11,7 @@ import { BaseSheet, SheetFooter } from '../custom/modals/common';
|
|
|
11
11
|
import Toast from 'react-native-toast-message';
|
|
12
12
|
import { MiniProfileCard, ProfileCard } from './ProfileCard';
|
|
13
13
|
import { useTranslation } from 'react-i18next';
|
|
14
|
+
import { useThemeOpacity } from '../../theme/useThemeOpacity';
|
|
14
15
|
import { bottomSheetClose } from '../../lib/bottom-sheet-ref';
|
|
15
16
|
|
|
16
17
|
interface ProfilePickerSheetProps {
|
|
@@ -87,10 +88,23 @@ export const ProfileSelector = forwardRef<
|
|
|
87
88
|
}
|
|
88
89
|
}, [searchQuery, profiles, currentProfile, profilesToExclude]);
|
|
89
90
|
|
|
91
|
+
// NativeWind v4 can't apply `/N` opacity to CSS-variable colors, so the
|
|
92
|
+
// selected-row tint is built inline from the theme color (issue #1666).
|
|
93
|
+
// `secondary` is a near-white neutral in the RN palette (unlike web's
|
|
94
|
+
// teal), so a `secondary` wash is invisible on a white sheet; the tint
|
|
95
|
+
// uses `primary` at low opacity, matching web's brand-accent selection.
|
|
96
|
+
const { background: tintBackground } = useThemeOpacity();
|
|
97
|
+
|
|
98
|
+
// Compare by id, not object reference: callers re-seed `initialProfiles`
|
|
99
|
+
// with fresh objects on every present, so reference equality would drop
|
|
100
|
+
// the selection (issue #1666 review).
|
|
101
|
+
const isSelected = (profile: PublicProfile) =>
|
|
102
|
+
selectedProfiles.some((p) => p.id === profile.id);
|
|
103
|
+
|
|
90
104
|
const handleSelectProfile = (profile: PublicProfile) => {
|
|
91
105
|
setSelectedProfiles((prev) =>
|
|
92
|
-
prev.
|
|
93
|
-
? prev.filter((p) => p !== profile)
|
|
106
|
+
prev.some((p) => p.id === profile.id)
|
|
107
|
+
? prev.filter((p) => p.id !== profile.id)
|
|
94
108
|
: [...prev, profile]
|
|
95
109
|
);
|
|
96
110
|
if (single) {
|
|
@@ -164,21 +178,53 @@ export const ProfileSelector = forwardRef<
|
|
|
164
178
|
</View>
|
|
165
179
|
)}
|
|
166
180
|
|
|
167
|
-
{filteredProfiles?.map((profile) =>
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
181
|
+
{filteredProfiles?.map((profile) => {
|
|
182
|
+
const selected = isSelected(profile);
|
|
183
|
+
// Screen-reader copy is user-facing copy: compose the label
|
|
184
|
+
// from a locale key instead of a hard-coded English fragment
|
|
185
|
+
// (issue #1666 review S1).
|
|
186
|
+
const rowLabel = selected
|
|
187
|
+
? t('profile.selector.rowSelected', {
|
|
188
|
+
name: profile.displayName || `@${profile.handle}`,
|
|
189
|
+
})
|
|
190
|
+
: profile.displayName || `@${profile.handle}`;
|
|
191
|
+
// Two overlapping press surfaces, on purpose: the full row is a
|
|
192
|
+
// `Pressable` (the a11y element), but the left avatar+name column
|
|
193
|
+
// is also `ProfileCard`'s inner `TouchableWithoutFeedback`. RN
|
|
194
|
+
// hands a tap to the first responder that claims it, so a tap on
|
|
195
|
+
// the left column hits the inner touchable and a tap on the right
|
|
196
|
+
// (check-icon) region hits this Pressable — both call
|
|
197
|
+
// `handleSelectProfile`, so exactly one toggle per tap. Do not
|
|
198
|
+
// "simplify" away the inner touchable: it is the only tap target
|
|
199
|
+
// over the card itself, and dropping it would strand the right
|
|
200
|
+
// half of the row (issue #1666 review S3).
|
|
201
|
+
return (
|
|
202
|
+
<Pressable
|
|
203
|
+
key={profile.id}
|
|
204
|
+
className="rounded-md"
|
|
205
|
+
style={
|
|
206
|
+
selected ? tintBackground('primary', 0.15) : undefined
|
|
207
|
+
}
|
|
208
|
+
accessibilityRole="button"
|
|
209
|
+
accessibilityLabel={rowLabel}
|
|
210
|
+
accessibilityState={{ selected }}
|
|
211
|
+
onPress={() => handleSelectProfile(profile)}
|
|
212
|
+
>
|
|
213
|
+
<ProfileCard
|
|
214
|
+
profile={profile}
|
|
215
|
+
actionType="select"
|
|
216
|
+
handleSelectProfile={() => handleSelectProfile(profile)}
|
|
217
|
+
rightComponent={
|
|
218
|
+
selected ? (
|
|
219
|
+
<View className="items-center justify-center pr-1">
|
|
220
|
+
<CheckIcon size={16} className="text-primary" />
|
|
221
|
+
</View>
|
|
222
|
+
) : null
|
|
223
|
+
}
|
|
224
|
+
/>
|
|
225
|
+
</Pressable>
|
|
226
|
+
);
|
|
227
|
+
})}
|
|
182
228
|
|
|
183
229
|
{filteredProfiles?.length === 0 && (
|
|
184
230
|
<ThemedText className="text-center text-muted-foreground">
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression tests for the NewConversation candidate rows
|
|
3
|
+
* (issue #1666 review S3, round-10 review S1).
|
|
4
|
+
*
|
|
5
|
+
* The row list is refiltered on every search keystroke, so keying rows by
|
|
6
|
+
* array index remounts them across filter boundaries (state loss, wasted
|
|
7
|
+
* work). The sibling selected-chips block keys by `profile.id`; the rows
|
|
8
|
+
* must do the same.
|
|
9
|
+
*
|
|
10
|
+
* The candidate rows are also the one picker surface rendered as *bare*
|
|
11
|
+
* `ProfileCard` rows — no accessible wrapper. They must carry their own
|
|
12
|
+
* screen-reader identity (role/label/state), or the whole DM picker is
|
|
13
|
+
* invisible to screen readers (round-10 review S1).
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const React = require('react');
|
|
17
|
+
const ReactTestRenderer = require('react-test-renderer');
|
|
18
|
+
|
|
19
|
+
const MESSAGES: Record<string, string> = {
|
|
20
|
+
// Mirrors ProfileSelector.test — deliberately not the raw key, so a
|
|
21
|
+
// regression that skips the t() lookup (or the interpolation) fails.
|
|
22
|
+
'profile.selector.rowSelected': '{{name}} (selected)',
|
|
23
|
+
// Pluralized selection-count caption (plan step 4). Distinct per plural so a
|
|
24
|
+
// regression that drops the count or the plural form fails (round-11 S3).
|
|
25
|
+
'conversations.createNew.selectedCount_one': '{{count}} selected',
|
|
26
|
+
'conversations.createNew.selectedCount_other': '{{count}} selected',
|
|
27
|
+
// Plan step 4 page-header title and search placeholder (round-12 S1/S2).
|
|
28
|
+
// Pinned to the en.json values so a regression to a different key or a
|
|
29
|
+
// hard-coded string fails.
|
|
30
|
+
'conversations.createNew.title': 'New Conversation',
|
|
31
|
+
'conversations.createNew.searchPlaceholder': 'Search for people',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const mockT = (key: string, opts?: { name?: string; count?: number }) => {
|
|
35
|
+
// Emulate i18next pluralization: a `count` option resolves `key` to
|
|
36
|
+
// `key_one` / `key_other` (used by the selection-count caption).
|
|
37
|
+
const count = opts?.count;
|
|
38
|
+
const pluralKey =
|
|
39
|
+
typeof count === 'number' ? `${key}_${count === 1 ? 'one' : 'other'}` : key;
|
|
40
|
+
return (MESSAGES[pluralKey] ?? key)
|
|
41
|
+
.replace('{{name}}', opts?.name ?? '')
|
|
42
|
+
.replace('{{count}}', String(count ?? ''));
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const ada = { id: 'p1', handle: 'ada', displayName: 'Ada' };
|
|
46
|
+
const alan = { id: 'p2', handle: 'alan', displayName: 'Alan' };
|
|
47
|
+
const PROFILES = [ada, alan];
|
|
48
|
+
|
|
49
|
+
// The store mock returns this array by reference, so the a11y test mutates
|
|
50
|
+
// it in place (reassigning the outer variable would not propagate — the
|
|
51
|
+
// factory captured the array once at first import).
|
|
52
|
+
const memberStore: unknown[] = [];
|
|
53
|
+
|
|
54
|
+
jest.mock('react-native', () => ({
|
|
55
|
+
View: (props: { children?: unknown }) =>
|
|
56
|
+
React.createElement('View', null, props.children),
|
|
57
|
+
ActivityIndicator: () => null,
|
|
58
|
+
}));
|
|
59
|
+
|
|
60
|
+
jest.mock('react-i18next', () => ({
|
|
61
|
+
useTranslation: () => ({ t: mockT }),
|
|
62
|
+
}));
|
|
63
|
+
|
|
64
|
+
jest.mock('react-native-keyboard-aware-scroll-view', () => ({
|
|
65
|
+
KeyboardAwareScrollView: (props: { children?: unknown }) =>
|
|
66
|
+
React.createElement('KeyboardAwareScrollView', null, props.children),
|
|
67
|
+
}));
|
|
68
|
+
|
|
69
|
+
jest.mock('@openpeepshq/react', () => ({
|
|
70
|
+
useOpenpeeps: () => ({
|
|
71
|
+
openpeepsApi: {
|
|
72
|
+
useProfiles: () => ({ data: PROFILES, isLoading: false }),
|
|
73
|
+
},
|
|
74
|
+
currentProfile: null,
|
|
75
|
+
}),
|
|
76
|
+
}));
|
|
77
|
+
|
|
78
|
+
jest.mock('@openpeepshq/common/lib', () => ({
|
|
79
|
+
blockedPairIds: () => [],
|
|
80
|
+
}));
|
|
81
|
+
|
|
82
|
+
jest.mock('../../lib/utils', () => ({
|
|
83
|
+
profileMatchesQuery: () => true,
|
|
84
|
+
}));
|
|
85
|
+
|
|
86
|
+
jest.mock('../../components/ui/themed-view', () => ({
|
|
87
|
+
ThemedView: (props: { children?: unknown }) =>
|
|
88
|
+
React.createElement('ThemedView', null, props.children),
|
|
89
|
+
}));
|
|
90
|
+
|
|
91
|
+
jest.mock('../../components/ui/themed-text', () => ({
|
|
92
|
+
ThemedText: (props: { children?: unknown }) =>
|
|
93
|
+
React.createElement('ThemedText', null, props.children),
|
|
94
|
+
}));
|
|
95
|
+
|
|
96
|
+
jest.mock('../../components/ui/input', () => ({
|
|
97
|
+
// Passes props through (like the other stubs) so the search Input's
|
|
98
|
+
// placeholder is assertable (round-12 S2).
|
|
99
|
+
Input: (props: Record<string, unknown>) =>
|
|
100
|
+
React.createElement('Input', props),
|
|
101
|
+
}));
|
|
102
|
+
|
|
103
|
+
jest.mock('../../components/icons/index', () => ({
|
|
104
|
+
CheckIcon: () => React.createElement('CheckIcon'),
|
|
105
|
+
}));
|
|
106
|
+
|
|
107
|
+
// Shared jest.fn (not a fresh one per call) so the page-header assertion can
|
|
108
|
+
// read the captured title (round-12 S1).
|
|
109
|
+
const setPageHeaderSpy = jest.fn();
|
|
110
|
+
|
|
111
|
+
jest.mock('../../components/layout', () => ({
|
|
112
|
+
HeaderActionButton: () => null,
|
|
113
|
+
useSetPageHeader: (...args: unknown[]) => setPageHeaderSpy(...args),
|
|
114
|
+
}));
|
|
115
|
+
|
|
116
|
+
jest.mock('../../components/custom/common/index', () => ({
|
|
117
|
+
EmptyStateContainer: () => null,
|
|
118
|
+
}));
|
|
119
|
+
|
|
120
|
+
jest.mock('../../stores/useNewConversationStore', () => ({
|
|
121
|
+
useNewConversationStore: () => ({
|
|
122
|
+
members: memberStore,
|
|
123
|
+
setMember: jest.fn(),
|
|
124
|
+
removeMember: jest.fn(),
|
|
125
|
+
}),
|
|
126
|
+
}));
|
|
127
|
+
|
|
128
|
+
jest.mock('../../components/profile/index', () => ({
|
|
129
|
+
ProfileCard: (props: Record<string, unknown>) =>
|
|
130
|
+
React.createElement('ProfileCard', props),
|
|
131
|
+
MiniProfileCard: (props: Record<string, unknown>) =>
|
|
132
|
+
React.createElement('MiniProfileCard', props),
|
|
133
|
+
}));
|
|
134
|
+
|
|
135
|
+
import { NewConversation } from './New';
|
|
136
|
+
|
|
137
|
+
const renderPage = () => {
|
|
138
|
+
let tree: ReturnType<typeof ReactTestRenderer.create>;
|
|
139
|
+
ReactTestRenderer.act(() => {
|
|
140
|
+
tree = ReactTestRenderer.create(
|
|
141
|
+
React.createElement(NewConversation, {
|
|
142
|
+
navigation: { navigate: jest.fn() },
|
|
143
|
+
} as never)
|
|
144
|
+
);
|
|
145
|
+
});
|
|
146
|
+
return tree;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const rowsOf = (tree: ReturnType<typeof ReactTestRenderer.create>) =>
|
|
150
|
+
tree.root.findAll(
|
|
151
|
+
(node: { type?: { name?: string } }) =>
|
|
152
|
+
typeof node.type === 'function' && node.type.name === 'ProfileCard'
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
describe('NewConversation row keying (issue #1666 review S3)', () => {
|
|
156
|
+
it('keys the profile rows by profile.id, not array index', () => {
|
|
157
|
+
let tree: ReturnType<typeof ReactTestRenderer.create>;
|
|
158
|
+
ReactTestRenderer.act(() => {
|
|
159
|
+
tree = ReactTestRenderer.create(
|
|
160
|
+
React.createElement(NewConversation, {
|
|
161
|
+
navigation: { navigate: jest.fn() },
|
|
162
|
+
} as never)
|
|
163
|
+
);
|
|
164
|
+
});
|
|
165
|
+
// React strips keys from the public TestInstance / toJSON output; the
|
|
166
|
+
// key only lives on the fiber, so read it from there. Match the mock
|
|
167
|
+
// component itself (the object-literal shorthand names it
|
|
168
|
+
// `ProfileCard`), not the string-typed element it returns. With the
|
|
169
|
+
// fixed `key={profile.id}` this is the profile id; the old
|
|
170
|
+
// `key={index}` would yield "0"/"1" and fail.
|
|
171
|
+
const rowKeys = tree.root
|
|
172
|
+
.findAll(
|
|
173
|
+
(node: { type?: { name?: string } }) =>
|
|
174
|
+
typeof node.type === 'function' && node.type.name === 'ProfileCard'
|
|
175
|
+
)
|
|
176
|
+
.map(
|
|
177
|
+
(node: { _currentFiber: () => { key: string } }) =>
|
|
178
|
+
node._currentFiber().key
|
|
179
|
+
);
|
|
180
|
+
expect(rowKeys).toEqual(['p1', 'p2']);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('gives the bare candidate rows their own screen-reader identity (issue #1666 round-10 S1)', () => {
|
|
184
|
+
// The rows are not wrapped in an accessible element, so the a11y must
|
|
185
|
+
// reach the ProfileCard itself. Mark one profile selected (in place —
|
|
186
|
+
// the store mock holds the array by reference) and assert each row
|
|
187
|
+
// carries a button role, a non-empty localized label, and a selected
|
|
188
|
+
// state that matches its membership.
|
|
189
|
+
memberStore.push(ada);
|
|
190
|
+
try {
|
|
191
|
+
let tree: ReturnType<typeof ReactTestRenderer.create>;
|
|
192
|
+
ReactTestRenderer.act(() => {
|
|
193
|
+
tree = ReactTestRenderer.create(
|
|
194
|
+
React.createElement(NewConversation, {
|
|
195
|
+
navigation: { navigate: jest.fn() },
|
|
196
|
+
} as never)
|
|
197
|
+
);
|
|
198
|
+
});
|
|
199
|
+
const rows = tree.root.findAll(
|
|
200
|
+
(node: { type?: { name?: string } }) =>
|
|
201
|
+
typeof node.type === 'function' && node.type.name === 'ProfileCard'
|
|
202
|
+
);
|
|
203
|
+
expect(rows).toHaveLength(2);
|
|
204
|
+
for (const row of rows) {
|
|
205
|
+
expect(row.props.accessibilityRole).toBe('button');
|
|
206
|
+
expect(typeof row.props.accessibilityLabel).toBe('string');
|
|
207
|
+
expect(row.props.accessibilityLabel.length).toBeGreaterThan(0);
|
|
208
|
+
expect(typeof row.props.accessibilityState?.selected).toBe('boolean');
|
|
209
|
+
}
|
|
210
|
+
// The selected row composes its label through the locale key with the
|
|
211
|
+
// profile name interpolated; the unselected row uses the plain name.
|
|
212
|
+
const selected = rows.find(
|
|
213
|
+
(node: { props: { accessibilityState?: { selected?: boolean } } }) =>
|
|
214
|
+
node.props.accessibilityState?.selected === true
|
|
215
|
+
);
|
|
216
|
+
const unselected = rows.find(
|
|
217
|
+
(node: { props: { accessibilityState?: { selected?: boolean } } }) =>
|
|
218
|
+
node.props.accessibilityState?.selected === false
|
|
219
|
+
);
|
|
220
|
+
expect(selected?.props.accessibilityLabel).toBe('Ada (selected)');
|
|
221
|
+
expect(unselected?.props.accessibilityLabel).toBe('Alan');
|
|
222
|
+
} finally {
|
|
223
|
+
memberStore.length = 0;
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
// The caption is the page's only `ThemedText` (every other string goes
|
|
229
|
+
// through a mocked component), so the first ThemedText is the selection-count
|
|
230
|
+
// caption when it renders at all.
|
|
231
|
+
const caption = (tree: ReturnType<typeof ReactTestRenderer.create>) =>
|
|
232
|
+
tree.root.findAllByType('ThemedText')[0]?.props.children;
|
|
233
|
+
|
|
234
|
+
describe('NewConversation selection-count caption (issue #1666 round-11 S3)', () => {
|
|
235
|
+
it('renders the localized selectedCount caption with the count interpolated', () => {
|
|
236
|
+
// The mock t() resolves the plural key and interpolates {{count}}, so a
|
|
237
|
+
// regression that drops the count (or skips the t() lookup and renders
|
|
238
|
+
// the raw key) fails here.
|
|
239
|
+
memberStore.push(ada, alan);
|
|
240
|
+
try {
|
|
241
|
+
expect(caption(renderPage())).toBe('2 selected');
|
|
242
|
+
} finally {
|
|
243
|
+
memberStore.length = 0;
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it('resolves the singular plural form for exactly one selection', () => {
|
|
248
|
+
memberStore.push(ada);
|
|
249
|
+
try {
|
|
250
|
+
expect(caption(renderPage())).toBe('1 selected');
|
|
251
|
+
} finally {
|
|
252
|
+
memberStore.length = 0;
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it('renders no caption when nothing is selected', () => {
|
|
257
|
+
const tree = renderPage();
|
|
258
|
+
expect(caption(tree)).toBeUndefined();
|
|
259
|
+
expect(tree.root.findAllByType('ThemedText')).toHaveLength(0);
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
describe('NewConversation candidate-row label strings (issue #1666 round-11 S4)', () => {
|
|
264
|
+
const labelOf = (
|
|
265
|
+
rows: Array<{
|
|
266
|
+
props: {
|
|
267
|
+
accessibilityState?: { selected?: boolean };
|
|
268
|
+
accessibilityLabel?: string;
|
|
269
|
+
};
|
|
270
|
+
}>,
|
|
271
|
+
selected: boolean
|
|
272
|
+
) =>
|
|
273
|
+
rows.find((row) => row.props.accessibilityState?.selected === selected)
|
|
274
|
+
?.props.accessibilityLabel;
|
|
275
|
+
|
|
276
|
+
it('composes the exact localized screen-reader string, selected and unselected', () => {
|
|
277
|
+
// Pinned via the key-resolution mock (mirrors ProfileSelector.test): the
|
|
278
|
+
// selected label is the resolved profile.selector.rowSelected string with
|
|
279
|
+
// the name interpolated, the unselected label is the plain name — so a
|
|
280
|
+
// regression to a hard-coded English fragment or a missing t() lookup fails.
|
|
281
|
+
memberStore.push(ada);
|
|
282
|
+
try {
|
|
283
|
+
const rows = rowsOf(renderPage());
|
|
284
|
+
expect(labelOf(rows, true)).toBe('Ada (selected)');
|
|
285
|
+
expect(labelOf(rows, false)).toBe('Alan');
|
|
286
|
+
} finally {
|
|
287
|
+
memberStore.length = 0;
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it('falls back to the handle when a profile has no display name', () => {
|
|
292
|
+
// New.tsx composes `displayName || \`@${handle}\`` for both the plain and
|
|
293
|
+
// the selected label; a profile with no displayName must yield the handle
|
|
294
|
+
// in both states.
|
|
295
|
+
const carl = { id: 'p3', handle: 'carl' };
|
|
296
|
+
PROFILES.push(carl);
|
|
297
|
+
memberStore.push(carl);
|
|
298
|
+
try {
|
|
299
|
+
const findRow = (tree: ReturnType<typeof ReactTestRenderer.create>) =>
|
|
300
|
+
rowsOf(tree).find(
|
|
301
|
+
(row) =>
|
|
302
|
+
(row.props as { profile: { handle: string } }).profile.handle ===
|
|
303
|
+
'carl'
|
|
304
|
+
);
|
|
305
|
+
// Selected: label is the localized key with the handle interpolated.
|
|
306
|
+
expect(findRow(renderPage())?.props.accessibilityLabel).toBe(
|
|
307
|
+
'@carl (selected)'
|
|
308
|
+
);
|
|
309
|
+
// Unselected (no one selected): the row falls back to the plain handle.
|
|
310
|
+
memberStore.length = 0;
|
|
311
|
+
const plainRow = findRow(renderPage());
|
|
312
|
+
expect(plainRow?.props.accessibilityState?.selected).toBe(false);
|
|
313
|
+
expect(plainRow?.props.accessibilityLabel).toBe('@carl');
|
|
314
|
+
} finally {
|
|
315
|
+
memberStore.length = 0;
|
|
316
|
+
PROFILES.pop();
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
describe('NewConversation page chrome (issue #1666 round-12 S1/S2)', () => {
|
|
322
|
+
it('sets the page header title via conversations.createNew.title (plan step 4)', () => {
|
|
323
|
+
// The captured title is the resolved locale value; the old header used
|
|
324
|
+
// the nonexistent conversations.selectMembers key, which silently fell
|
|
325
|
+
// back to its defaultValue — a regression to that key (or any other)
|
|
326
|
+
// fails on the resolved string.
|
|
327
|
+
renderPage();
|
|
328
|
+
expect(setPageHeaderSpy).toHaveBeenCalled();
|
|
329
|
+
expect(setPageHeaderSpy.mock.calls.at(-1)?.[0]).toBe('New Conversation');
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it('passes the localized search placeholder to the search Input (plan step 4)', () => {
|
|
333
|
+
// The Input stub passes props through, so the rendered Input carries the
|
|
334
|
+
// resolved placeholder; a regression to the old hard-coded
|
|
335
|
+
// "Enter name or handle" fails.
|
|
336
|
+
const tree = renderPage();
|
|
337
|
+
const input = tree.root.findAllByType('Input')[0];
|
|
338
|
+
expect(input?.props.placeholder).toBe('Search for people');
|
|
339
|
+
});
|
|
340
|
+
});
|