@openpeepshq/rn-components 0.15.0 → 0.16.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/icons/index.ts +2 -0
- package/src/components/navigation/nativeRouter.tsx +13 -3
- package/src/components/notifications/NotificationHeaderActions.test.tsx +285 -0
- package/src/components/notifications/NotificationHeaderActions.tsx +91 -4
- package/src/components/notifications/NotificationsList.test.tsx +109 -0
- package/src/components/notifications/NotificationsList.tsx +13 -3
- package/src/components/notifications/types/Reaction.tsx +6 -2
- package/src/components/post/pieces/PostActions.test.tsx +244 -0
- package/src/components/post/pieces/PostActions.tsx +74 -49
- package/src/components/post/pieces/ReactionPicker.test.tsx +184 -0
- package/src/components/post/pieces/ReactionPicker.tsx +58 -0
- package/src/components/post/pieces/index.ts +1 -0
- package/src/components/post/pieces/modals/ReactionsModal.tsx +1 -1
- package/src/pages/Notifications.tsx +3 -1
- package/src/pages/Welcome.test.tsx +166 -0
- package/src/pages/Welcome.tsx +50 -4
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression coverage for #1600 (RN parity) — the native Onboarding screen
|
|
3
|
+
* (the RN mirror of the web Welcome page) is guest-reachable, so a signed-out
|
|
4
|
+
* visitor must see the markdown welcome plus a Sign In CTA, NOT the signed-in
|
|
5
|
+
* setup checklist. The checklist is the only consumer of the disabled
|
|
6
|
+
* `usePostsByProfile('')` query, which never leaves `isPending` for a guest —
|
|
7
|
+
* rendering it would leave the checklist in a permanent loading spin (the bug
|
|
8
|
+
* fixed on the web side). Nothing else asserted that a guest opening this
|
|
9
|
+
* screen avoided that path.
|
|
10
|
+
*
|
|
11
|
+
* The node jest env has no native modules, so every external import is
|
|
12
|
+
* mocked (mirroring New.carryover.test.tsx); only the real `Welcome` under
|
|
13
|
+
* test renders, with its guest / signed-in branches driven by the mocked
|
|
14
|
+
* `useOpenpeeps`.
|
|
15
|
+
*/
|
|
16
|
+
import { type ReactNode } from 'react';
|
|
17
|
+
import ReactTestRenderer from 'react-test-renderer';
|
|
18
|
+
|
|
19
|
+
const React = require('react');
|
|
20
|
+
|
|
21
|
+
let mockCurrentProfile: {
|
|
22
|
+
id: string;
|
|
23
|
+
displayName?: string;
|
|
24
|
+
handle?: string;
|
|
25
|
+
} | null = null;
|
|
26
|
+
const mockNavigate = jest.fn();
|
|
27
|
+
|
|
28
|
+
// --- react-native: host elements render as plain host tags, props kept ----
|
|
29
|
+
jest.mock('react-native', () => {
|
|
30
|
+
const make = (tag: string) => (props: { children?: ReactNode }) =>
|
|
31
|
+
React.createElement(tag, props);
|
|
32
|
+
return {
|
|
33
|
+
View: make('View'),
|
|
34
|
+
Text: make('Text'),
|
|
35
|
+
ScrollView: make('ScrollView'),
|
|
36
|
+
TouchableOpacity: make('TouchableOpacity'),
|
|
37
|
+
Pressable: make('Pressable'),
|
|
38
|
+
ActivityIndicator: make('ActivityIndicator'),
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// --- shared @openpeepshq/react: drive the branch, capture navigation ------
|
|
43
|
+
jest.mock('@openpeepshq/react', () => ({
|
|
44
|
+
useOpenpeeps: () => ({
|
|
45
|
+
currentProfile: mockCurrentProfile,
|
|
46
|
+
currentAccount: { emailValidated: true },
|
|
47
|
+
openpeepsApi: {
|
|
48
|
+
useServerInfo: () => ({
|
|
49
|
+
data: {
|
|
50
|
+
communityConfig: {
|
|
51
|
+
info: { name: 'TestCo' },
|
|
52
|
+
content: { welcomePage: 'Welcome to TestCo' },
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
isLoading: false,
|
|
56
|
+
}),
|
|
57
|
+
// Disabled for guests (empty profile id) — mirrors the production
|
|
58
|
+
// wiring; only the render gate under test decides whether it is used.
|
|
59
|
+
usePostsByProfile: () => ({ data: { pages: [] }, isLoading: false }),
|
|
60
|
+
validationEmailAction: () => () => Promise.resolve({ success: true }),
|
|
61
|
+
},
|
|
62
|
+
}),
|
|
63
|
+
useRouter: () => ({ navigate: mockNavigate }),
|
|
64
|
+
}));
|
|
65
|
+
|
|
66
|
+
// --- i18n: resolve keys to their defaultValue, or a few known values ------
|
|
67
|
+
// (the guest row calls t(key) without a defaultValue, unlike the web page) --
|
|
68
|
+
jest.mock('react-i18next', () => ({
|
|
69
|
+
useTranslation: () => ({
|
|
70
|
+
t: (_key: string, opts?: { defaultValue?: string }) => {
|
|
71
|
+
const known: Record<string, string> = {
|
|
72
|
+
'welcome.guestSignIn':
|
|
73
|
+
'Sign in to complete your account setup and see the checklist.',
|
|
74
|
+
'auth.register.signIn': 'Sign In',
|
|
75
|
+
};
|
|
76
|
+
return opts?.defaultValue ?? known[_key] ?? _key;
|
|
77
|
+
},
|
|
78
|
+
}),
|
|
79
|
+
}));
|
|
80
|
+
|
|
81
|
+
// --- lucide icons: inert ---------------------------------------------------
|
|
82
|
+
jest.mock('lucide-react-native', () => {
|
|
83
|
+
const icon = (name: string) => () => React.createElement(name, null);
|
|
84
|
+
return {
|
|
85
|
+
UserCheckIcon: icon('UserCheckIcon'),
|
|
86
|
+
MailCheckIcon: icon('MailCheckIcon'),
|
|
87
|
+
SquareUserRoundIcon: icon('SquareUserRoundIcon'),
|
|
88
|
+
PencilIcon: icon('PencilIcon'),
|
|
89
|
+
ChevronRightIcon: icon('ChevronRightIcon'),
|
|
90
|
+
CheckIcon: icon('CheckIcon'),
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// --- local component deps: inert -------------------------------------------
|
|
95
|
+
jest.mock('react-native-toast-message', () => {
|
|
96
|
+
const Toast = { show: jest.fn() };
|
|
97
|
+
return { __esModule: true, default: Toast };
|
|
98
|
+
});
|
|
99
|
+
jest.mock('@react-navigation/native', () => ({
|
|
100
|
+
useNavigation: () => ({ navigate: jest.fn() }),
|
|
101
|
+
}));
|
|
102
|
+
jest.mock('@react-navigation/native-stack', () => ({}));
|
|
103
|
+
jest.mock('../components/layout', () => ({
|
|
104
|
+
useSetPageHeader: jest.fn(),
|
|
105
|
+
}));
|
|
106
|
+
jest.mock('../components/ui/themed-view', () => ({
|
|
107
|
+
ThemedView: ({ children }: { children?: ReactNode }) =>
|
|
108
|
+
React.createElement('View', null, children),
|
|
109
|
+
}));
|
|
110
|
+
jest.mock('../components/ui/themed-text', () => ({
|
|
111
|
+
ThemedText: ({ children }: { children?: ReactNode }) =>
|
|
112
|
+
React.createElement('Text', null, children),
|
|
113
|
+
}));
|
|
114
|
+
jest.mock('../components/markdown/index', () => ({
|
|
115
|
+
OpenpeepsMarkdown: ({ source }: { source: string }) =>
|
|
116
|
+
React.createElement('Markdown', null, source),
|
|
117
|
+
}));
|
|
118
|
+
jest.mock('../theme/useThemeOpacity', () => ({
|
|
119
|
+
useThemeOpacity: () => ({ background: () => 'rgba(0,0,0,0.1)' }),
|
|
120
|
+
}));
|
|
121
|
+
|
|
122
|
+
import { Welcome } from './Welcome';
|
|
123
|
+
|
|
124
|
+
describe('RN Welcome (Onboarding) guest parity', () => {
|
|
125
|
+
beforeEach(() => {
|
|
126
|
+
mockCurrentProfile = null;
|
|
127
|
+
mockNavigate.mockClear();
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('shows a Sign In CTA (and no checklist) for a signed-out visitor', () => {
|
|
131
|
+
let tree: ReturnType<typeof ReactTestRenderer.create>;
|
|
132
|
+
ReactTestRenderer.act(() => {
|
|
133
|
+
tree = ReactTestRenderer.create(React.createElement(Welcome));
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// The guest CTA is rendered …
|
|
137
|
+
const [cta] = tree.root.findAllByProps({
|
|
138
|
+
testID: 'welcome-guest-sign-in',
|
|
139
|
+
});
|
|
140
|
+
// … and pressing it routes to the auth screen.
|
|
141
|
+
cta.props.onPress();
|
|
142
|
+
expect(mockNavigate).toHaveBeenCalledWith({ type: 'auth', mode: 'login' });
|
|
143
|
+
|
|
144
|
+
const json = JSON.stringify(tree.toJSON());
|
|
145
|
+
// The signed-in checklist must be absent — it is the only consumer of
|
|
146
|
+
// the disabled posts query, so rendering it is exactly the spin
|
|
147
|
+
// regression this test guards.
|
|
148
|
+
expect(json).not.toContain('Complete account setup');
|
|
149
|
+
// … while the guest copy and the CTA label are present.
|
|
150
|
+
expect(json).toContain('Sign in to complete your account setup');
|
|
151
|
+
expect(json).toContain('Sign In');
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('shows the setup checklist (and no guest CTA) when signed in', () => {
|
|
155
|
+
mockCurrentProfile = { id: 'me', displayName: 'Me', handle: 'me' };
|
|
156
|
+
let tree: ReturnType<typeof ReactTestRenderer.create>;
|
|
157
|
+
ReactTestRenderer.act(() => {
|
|
158
|
+
tree = ReactTestRenderer.create(React.createElement(Welcome));
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
expect(
|
|
162
|
+
tree.root.findAllByProps({ testID: 'welcome-guest-sign-in' })
|
|
163
|
+
).toHaveLength(0);
|
|
164
|
+
expect(JSON.stringify(tree.toJSON())).toContain('Complete account setup');
|
|
165
|
+
});
|
|
166
|
+
});
|
package/src/pages/Welcome.tsx
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import React, { useCallback, useMemo } from 'react';
|
|
2
2
|
import { ThemedView } from '../components/ui/themed-view';
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import {
|
|
4
|
+
ActivityIndicator,
|
|
5
|
+
Pressable,
|
|
6
|
+
ScrollView,
|
|
7
|
+
TouchableOpacity,
|
|
8
|
+
View,
|
|
9
|
+
} from 'react-native';
|
|
10
|
+
import { useOpenpeeps, useRouter } from '@openpeepshq/react';
|
|
5
11
|
import { useSetPageHeader } from '../components/layout';
|
|
6
12
|
import {
|
|
7
13
|
UserCheckIcon,
|
|
@@ -42,6 +48,7 @@ type AccountSetupChecklistItem = {
|
|
|
42
48
|
|
|
43
49
|
export const Welcome = () => {
|
|
44
50
|
const { openpeepsApi, currentProfile, currentAccount } = useOpenpeeps();
|
|
51
|
+
const router = useRouter();
|
|
45
52
|
const { t } = useTranslation();
|
|
46
53
|
const { data: serverInfo, isLoading } = openpeepsApi.useServerInfo();
|
|
47
54
|
const { data: posts, isLoading: isPostLoading } =
|
|
@@ -125,16 +132,55 @@ export const Welcome = () => {
|
|
|
125
132
|
|
|
126
133
|
useSetPageHeader(t('navigation.welcome'));
|
|
127
134
|
|
|
135
|
+
// Guest mirror of web Welcome.tsx: a signed-out visitor on the guest-reachable
|
|
136
|
+
// Onboarding screen sees the markdown welcome plus a Sign In CTA instead of
|
|
137
|
+
// the signed-in checklist — the checklist's posts query is disabled without a
|
|
138
|
+
// profile id and would leave the checklist in a permanent loading spin.
|
|
139
|
+
if (!currentProfile) {
|
|
140
|
+
return (
|
|
141
|
+
<ThemedView className="flex-1">
|
|
142
|
+
<ScrollView className="p-4 w-full">
|
|
143
|
+
{isLoading && <ActivityIndicator size={'small'} />}
|
|
144
|
+
<ThemedView className="w-full mt-2">
|
|
145
|
+
<ThemedText className="text-3xl font-bold mb-2">
|
|
146
|
+
{t('welcome.heading', {
|
|
147
|
+
name: serverInfo?.communityConfig?.info?.name,
|
|
148
|
+
})}
|
|
149
|
+
</ThemedText>
|
|
150
|
+
<OpenpeepsMarkdown
|
|
151
|
+
source={serverInfo?.communityConfig?.content?.welcomePage || ''}
|
|
152
|
+
/>
|
|
153
|
+
</ThemedView>
|
|
154
|
+
<View className="mt-4">
|
|
155
|
+
<ThemedText className="text-base text-muted-foreground">
|
|
156
|
+
{t('welcome.guestSignIn')}
|
|
157
|
+
</ThemedText>
|
|
158
|
+
<Pressable
|
|
159
|
+
testID="welcome-guest-sign-in"
|
|
160
|
+
onPress={() => router.navigate({ type: 'auth', mode: 'login' })}
|
|
161
|
+
>
|
|
162
|
+
<ThemedText className="text-base font-medium text-primary">
|
|
163
|
+
{t('auth.register.signIn')}
|
|
164
|
+
</ThemedText>
|
|
165
|
+
</Pressable>
|
|
166
|
+
</View>
|
|
167
|
+
</ScrollView>
|
|
168
|
+
</ThemedView>
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
128
172
|
return (
|
|
129
173
|
<ThemedView className="flex-1">
|
|
130
174
|
<ScrollView className="p-4 w-full">
|
|
131
175
|
{isLoading && <ActivityIndicator size={'small'} />}
|
|
132
176
|
<ThemedView className="w-full mt-2">
|
|
133
177
|
<ThemedText className="text-3xl font-bold mb-2">
|
|
134
|
-
|
|
178
|
+
{t('welcome.heading', {
|
|
179
|
+
name: serverInfo?.communityConfig?.info?.name,
|
|
180
|
+
})}
|
|
135
181
|
</ThemedText>
|
|
136
182
|
<OpenpeepsMarkdown
|
|
137
|
-
source={serverInfo?.communityConfig
|
|
183
|
+
source={serverInfo?.communityConfig?.content?.welcomePage || ''}
|
|
138
184
|
/>
|
|
139
185
|
</ThemedView>
|
|
140
186
|
<ThemedText className="text-3xl font-bold my-4">
|