@openpeepshq/rn-components 0.14.0 → 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 +4 -3
- package/src/components/buttonOverflow.test.tsx +463 -0
- package/src/components/conversations/ConversationParticipantsModal.tsx +1 -6
- package/src/components/groups/GroupCard.tsx +26 -23
- package/src/components/groups/JoinGroupButton.tsx +7 -2
- package/src/components/jams/JamCapacityGate.tsx +9 -1
- 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/JamFooter.tsx +26 -22
- package/src/components/jams/JamParticipantConference.tsx +7 -4
- package/src/components/jams/JamPeopleDrawer.test.tsx +216 -0
- package/src/components/jams/JamPeopleDrawer.tsx +51 -5
- package/src/components/jams/JamRequestJoin.tsx +30 -3
- package/src/components/jams/JamRoomIndicators.test.tsx +190 -38
- package/src/components/jams/JamRoomIndicators.tsx +62 -20
- package/src/components/jams/LeaveCloseButton.tsx +5 -1
- 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/post/types/Event.tsx +6 -2
- package/src/components/profile/Avatar.test.tsx +147 -0
- package/src/components/profile/Avatar.tsx +30 -1
- 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/components/profile/ProfileWithActionCard.tsx +14 -6
- package/src/lib/post.ts +0 -128
- 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/pages/posts/New.carryover.test.tsx +245 -0
- package/src/pages/posts/New.tsx +18 -2
- package/src/pages/posts/Reply.tsx +17 -2
- package/src/stores/useLocalPostStore.ts +7 -4
- package/src/theme/useThemeOpacity.test.ts +70 -0
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression coverage for #1799 (native composer) — the poll <-> note type
|
|
3
|
+
* switch must carry the typed text over *and* persist the converted draft to
|
|
4
|
+
* the app-lifetime local post store, so the carry-over (including the
|
|
5
|
+
* `questionDraft` stash that lets a later note -> poll restore the original
|
|
6
|
+
* poll) survives a screen unmount/remount.
|
|
7
|
+
*
|
|
8
|
+
* The native `NewPost` is a large composite, so every external import is
|
|
9
|
+
* mocked (node jest env, no native modules) — mirroring FullEvent.test.tsx.
|
|
10
|
+
* Only `handleSelectComposerType` is exercised; the surrounding form / footer
|
|
11
|
+
* / picker UI render inert mocks. The shared `toNote`/`toQuestion`/
|
|
12
|
+
* `isSwitchablePostData` helpers are loaded from `@openpeepshq/react`'s
|
|
13
|
+
* real source so the conversion logic under test is the production one.
|
|
14
|
+
*/
|
|
15
|
+
import { type ReactNode } from 'react';
|
|
16
|
+
import ReactTestRenderer from 'react-test-renderer';
|
|
17
|
+
|
|
18
|
+
const React = require('react');
|
|
19
|
+
|
|
20
|
+
// Shared helper (the production conversion logic) resolved from the real
|
|
21
|
+
// react package source. The jest moduleNameMapper only pins the package
|
|
22
|
+
// *root* import to contentLength; this explicit subpath keeps real toNote /
|
|
23
|
+
// toQuestion / isSwitchablePostData in the test.
|
|
24
|
+
const mockSharedPost = require('../../../../react/src/lib/post');
|
|
25
|
+
|
|
26
|
+
// --- react-native: host elements render as plain host tags ----------------
|
|
27
|
+
jest.mock('react-native', () => {
|
|
28
|
+
const make = (tag: string) => (props: { children?: ReactNode }) =>
|
|
29
|
+
React.createElement(tag, null, props.children);
|
|
30
|
+
return { View: make('View'), Text: make('Text') };
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// --- i18n: resolve keys to their defaultValue -----------------------------
|
|
34
|
+
jest.mock('react-i18next', () => ({
|
|
35
|
+
useTranslation: () => ({
|
|
36
|
+
t: (_key: string, opts?: { defaultValue?: string; number?: number }) =>
|
|
37
|
+
opts?.defaultValue ?? _key,
|
|
38
|
+
}),
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
// --- shared @openpeepshq/react: real conversion helpers, inert context ----
|
|
42
|
+
jest.mock('@openpeepshq/react', () => ({
|
|
43
|
+
isSwitchablePostData: mockSharedPost.isSwitchablePostData,
|
|
44
|
+
toNote: mockSharedPost.toNote,
|
|
45
|
+
toQuestion: mockSharedPost.toQuestion,
|
|
46
|
+
useOpenpeeps: () => ({
|
|
47
|
+
currentProfile: { id: 'me', roles: [] },
|
|
48
|
+
openpeepsApi: {
|
|
49
|
+
createPostAction: () => jest.fn(),
|
|
50
|
+
admin: { announcePostAction: () => jest.fn() },
|
|
51
|
+
joinGroupAction: () => jest.fn(),
|
|
52
|
+
useServerInfo: () => ({ data: { publicContent: true } }),
|
|
53
|
+
},
|
|
54
|
+
}),
|
|
55
|
+
}));
|
|
56
|
+
|
|
57
|
+
// --- common: the jest config pins the root import to contentLength.ts, which
|
|
58
|
+
// lacks these runtime helpers, so the page's named imports resolve here. --
|
|
59
|
+
jest.mock('@openpeepshq/common', () => ({
|
|
60
|
+
POLL_DEFAULT_EXPIRY_MS: 30 * 24 * 60 * 60 * 1000,
|
|
61
|
+
canAnnouncePosts: () => false,
|
|
62
|
+
isCommunityWideVisibility: () => true,
|
|
63
|
+
pollOptionsWithinLimit: () => true,
|
|
64
|
+
canSubmitPostContent: () => true,
|
|
65
|
+
resolvePollOptionContents: (opts: string[]) => opts,
|
|
66
|
+
visibleTextLength: (c?: string) => (c ?? '').length,
|
|
67
|
+
}));
|
|
68
|
+
|
|
69
|
+
// --- navigation: types are type-only, but the stack barrel is stubbed ------
|
|
70
|
+
jest.mock('@react-navigation/native', () => ({}));
|
|
71
|
+
jest.mock('@react-navigation/native-stack', () => ({}));
|
|
72
|
+
|
|
73
|
+
// --- local react-native deps ----------------------------------------------
|
|
74
|
+
jest.mock('react-native-toast-message', () => {
|
|
75
|
+
const Toast = { show: jest.fn() };
|
|
76
|
+
return { __esModule: true, default: Toast };
|
|
77
|
+
});
|
|
78
|
+
jest.mock('@gorhom/bottom-sheet', () => ({
|
|
79
|
+
BottomSheetModal: () => null,
|
|
80
|
+
}));
|
|
81
|
+
jest.mock('react-native-keyboard-aware-scroll-view', () => ({
|
|
82
|
+
KeyboardAwareScrollView: ({ children }: { children?: ReactNode }) =>
|
|
83
|
+
React.createElement('View', null, children),
|
|
84
|
+
}));
|
|
85
|
+
|
|
86
|
+
// --- react-hook-form: inert form, capturing reset() calls -----------------
|
|
87
|
+
let formResetCalls: unknown[][] = [];
|
|
88
|
+
jest.mock('react-hook-form', () => ({
|
|
89
|
+
useForm: () => ({
|
|
90
|
+
reset: (v?: unknown) => {
|
|
91
|
+
formResetCalls.push([v]);
|
|
92
|
+
},
|
|
93
|
+
}),
|
|
94
|
+
}));
|
|
95
|
+
|
|
96
|
+
// --- media permissions: always allowed (picker paths are inert) -----------
|
|
97
|
+
jest.mock('../../lib/media-permissions', () => ({
|
|
98
|
+
checkMediaPermissions: () => Promise.resolve(true),
|
|
99
|
+
}));
|
|
100
|
+
|
|
101
|
+
// --- layout + themed view: render inert ------------------------------------
|
|
102
|
+
jest.mock('../../components/layout', () => ({
|
|
103
|
+
HeaderActionButton: () => null,
|
|
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
|
+
|
|
111
|
+
// --- picker sheets + article form: render inert ----------------------------
|
|
112
|
+
jest.mock('../../components/custom/index', () => ({
|
|
113
|
+
ImagePickerSheet: () => null,
|
|
114
|
+
AudioPickerSheet: () => null,
|
|
115
|
+
DocumentPickerSheet: () => null,
|
|
116
|
+
}));
|
|
117
|
+
jest.mock('../../components/post/index', () => ({
|
|
118
|
+
ArticleForm: () => null,
|
|
119
|
+
}));
|
|
120
|
+
|
|
121
|
+
// --- composer children: PostForm inert, PostTypeSwitcher forwards onSelect -
|
|
122
|
+
let switcherOnSelect: ((type: 'note' | 'question') => void) | undefined;
|
|
123
|
+
jest.mock('../../components/post/post-form/PostForm', () => ({
|
|
124
|
+
PostForm: () => null,
|
|
125
|
+
}));
|
|
126
|
+
jest.mock('../../components/post/post-form/PostTypeSwitcher', () => ({
|
|
127
|
+
PostTypeSwitcher: (props: {
|
|
128
|
+
type: string;
|
|
129
|
+
onSelect: (type: 'note' | 'question') => void;
|
|
130
|
+
}) => {
|
|
131
|
+
switcherOnSelect = props.onSelect;
|
|
132
|
+
return React.createElement('View', null);
|
|
133
|
+
},
|
|
134
|
+
}));
|
|
135
|
+
jest.mock('../../components/post/post-form/Footer', () => ({
|
|
136
|
+
// Renders the `typeSwitcher` slot so PostTypeSwitcher mounts and captures its
|
|
137
|
+
// onSelect (New.tsx passes the switcher as a prop, not a child).
|
|
138
|
+
Footer: (props: { typeSwitcher?: ReactNode }) =>
|
|
139
|
+
React.createElement('View', null, props.typeSwitcher),
|
|
140
|
+
}));
|
|
141
|
+
|
|
142
|
+
import { useLocalPostStore } from '../../stores/useLocalPostStore';
|
|
143
|
+
import { NewPost } from './New';
|
|
144
|
+
|
|
145
|
+
const NOTE_DRAFT = {
|
|
146
|
+
type: 'note',
|
|
147
|
+
visibility: 'public' as const,
|
|
148
|
+
data: { type: 'note' as const, content: '[TEST] note text before poll' },
|
|
149
|
+
mentions: [],
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const QUESTION_DRAFT = {
|
|
153
|
+
type: 'question',
|
|
154
|
+
visibility: 'public' as const,
|
|
155
|
+
data: {
|
|
156
|
+
type: 'question' as const,
|
|
157
|
+
content: '[TEST] poll question',
|
|
158
|
+
options: [
|
|
159
|
+
{ type: 'note' as const, content: 'Option A' },
|
|
160
|
+
{ type: 'note' as const, content: 'Option B' },
|
|
161
|
+
],
|
|
162
|
+
expiresAt: '2026-12-31T18:00:00.000Z',
|
|
163
|
+
},
|
|
164
|
+
mentions: [],
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
function render(): ReactTestRenderer.ReactTestRenderer {
|
|
168
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
169
|
+
ReactTestRenderer.act(() => {
|
|
170
|
+
tree = ReactTestRenderer.create(
|
|
171
|
+
<NewPost route={{ params: {} }} navigation={{}} />
|
|
172
|
+
);
|
|
173
|
+
});
|
|
174
|
+
return tree;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function clickSwitchTo(type: 'note' | 'question'): void {
|
|
178
|
+
expect(switcherOnSelect).toBeDefined();
|
|
179
|
+
ReactTestRenderer.act(() => {
|
|
180
|
+
switcherOnSelect!(type);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
beforeEach(() => {
|
|
185
|
+
(
|
|
186
|
+
globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }
|
|
187
|
+
).IS_REACT_ACT_ENVIRONMENT = true;
|
|
188
|
+
useLocalPostStore.getState().resetPostData();
|
|
189
|
+
useLocalPostStore.setState({
|
|
190
|
+
postData: QUESTION_DRAFT,
|
|
191
|
+
replyData: {},
|
|
192
|
+
});
|
|
193
|
+
formResetCalls = [];
|
|
194
|
+
switcherOnSelect = undefined;
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test('poll -> note persists a note draft carrying the questionDraft stash', () => {
|
|
198
|
+
render();
|
|
199
|
+
clickSwitchTo('note');
|
|
200
|
+
|
|
201
|
+
// The converted draft is written to the app-lifetime local post store — the
|
|
202
|
+
// remount-restore path the screen comments rely on.
|
|
203
|
+
const stored = useLocalPostStore.getState().postData;
|
|
204
|
+
expect(stored.data).toMatchObject({
|
|
205
|
+
type: 'note',
|
|
206
|
+
content: '[TEST] poll question',
|
|
207
|
+
});
|
|
208
|
+
// The stash carries the poll's structural fields so a later note -> poll
|
|
209
|
+
// restores them instead of rebuilding a blank poll.
|
|
210
|
+
expect(stored.questionDraft).toMatchObject({
|
|
211
|
+
options: [
|
|
212
|
+
{ type: 'note', content: 'Option A' },
|
|
213
|
+
{ type: 'note', content: 'Option B' },
|
|
214
|
+
],
|
|
215
|
+
expiresAt: '2026-12-31T18:00:00.000Z',
|
|
216
|
+
});
|
|
217
|
+
// The form is reset to the same converted draft (the handler passes one
|
|
218
|
+
// object to both form.reset and setPostData).
|
|
219
|
+
expect(formResetCalls.length).toBeGreaterThan(0);
|
|
220
|
+
const formNote = formResetCalls
|
|
221
|
+
.map((c) => c[0])
|
|
222
|
+
.find((p) => (p as { data?: { type?: string } })?.data?.type === 'note');
|
|
223
|
+
expect(formNote).toBe(stored);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test('note -> poll converts the note into a poll and drops the questionDraft stash', () => {
|
|
227
|
+
useLocalPostStore.setState({
|
|
228
|
+
postData: NOTE_DRAFT,
|
|
229
|
+
replyData: {},
|
|
230
|
+
});
|
|
231
|
+
render();
|
|
232
|
+
clickSwitchTo('question');
|
|
233
|
+
|
|
234
|
+
const stored = useLocalPostStore.getState().postData;
|
|
235
|
+
expect(stored.data).toMatchObject({
|
|
236
|
+
type: 'question',
|
|
237
|
+
content: '[TEST] note text before poll',
|
|
238
|
+
options: [
|
|
239
|
+
{ type: 'note', content: '' },
|
|
240
|
+
{ type: 'note', content: '' },
|
|
241
|
+
],
|
|
242
|
+
});
|
|
243
|
+
// A note -> poll conversion has no stash to carry, so no questionDraft.
|
|
244
|
+
expect(stored.questionDraft).toBeUndefined();
|
|
245
|
+
});
|
package/src/pages/posts/New.tsx
CHANGED
|
@@ -11,7 +11,12 @@ import {
|
|
|
11
11
|
MainStackParamList,
|
|
12
12
|
TabStackParamList,
|
|
13
13
|
} from '../../components/navigation/types/index';
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
isSwitchablePostData,
|
|
16
|
+
toNote,
|
|
17
|
+
toQuestion,
|
|
18
|
+
useOpenpeeps,
|
|
19
|
+
} from '@openpeepshq/react';
|
|
15
20
|
import {
|
|
16
21
|
AudioPickerSheet,
|
|
17
22
|
ImagePickerSheet,
|
|
@@ -40,7 +45,7 @@ import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view
|
|
|
40
45
|
import { Footer } from '../../components/post/post-form/Footer';
|
|
41
46
|
import { PostTypeSwitcher } from '../../components/post/post-form/PostTypeSwitcher';
|
|
42
47
|
import { BottomSheetModal } from '@gorhom/bottom-sheet';
|
|
43
|
-
import { hasProcessingAttachments
|
|
48
|
+
import { hasProcessingAttachments } from '../../lib/post';
|
|
44
49
|
import { useForm } from 'react-hook-form';
|
|
45
50
|
|
|
46
51
|
import { ArticleForm } from '../../components/post/index';
|
|
@@ -234,9 +239,20 @@ export const NewPost = ({ route, navigation }: PostProps) => {
|
|
|
234
239
|
if (postData.data.type === next) {
|
|
235
240
|
return;
|
|
236
241
|
}
|
|
242
|
+
if (!isSwitchablePostData(postData)) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
237
245
|
const newPostData =
|
|
238
246
|
next === 'question' ? toQuestion(postData) : toNote(postData);
|
|
239
247
|
form.reset(newPostData);
|
|
248
|
+
// Persisting the converted draft to the (module-scoped, app-lifetime)
|
|
249
|
+
// local post store is what makes the carry-over survive a screen
|
|
250
|
+
// unmount/remount: a fresh `NewPost` mount re-seeds its form from
|
|
251
|
+
// `useLocalPostStore.getState().postData`, so the converted note body /
|
|
252
|
+
// poll question (and, for a poll, its stashed `questionDraft` fields)
|
|
253
|
+
// are restored on return. A full app restart clears the store, so a
|
|
254
|
+
// draft only survives within a running app — matching the web, whose
|
|
255
|
+
// draft stores are in-memory too.
|
|
240
256
|
setPostData(newPostData);
|
|
241
257
|
},
|
|
242
258
|
[postData, form, setPostData]
|
|
@@ -5,7 +5,13 @@ import React, {
|
|
|
5
5
|
useRef,
|
|
6
6
|
useState,
|
|
7
7
|
} from 'react';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
apiErrorMessage,
|
|
10
|
+
isSwitchablePostData,
|
|
11
|
+
toNote,
|
|
12
|
+
toQuestion,
|
|
13
|
+
useOpenpeeps,
|
|
14
|
+
} from '@openpeepshq/react';
|
|
9
15
|
import {
|
|
10
16
|
AudioPickerSheet,
|
|
11
17
|
DocumentPickerSheet,
|
|
@@ -40,7 +46,7 @@ import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view
|
|
|
40
46
|
import { Footer } from '../../components/post/post-form/Footer';
|
|
41
47
|
import { PostTypeSwitcher } from '../../components/post/post-form/PostTypeSwitcher';
|
|
42
48
|
import { useForm } from 'react-hook-form';
|
|
43
|
-
import { hasProcessingAttachments
|
|
49
|
+
import { hasProcessingAttachments } from '../../lib/post';
|
|
44
50
|
import { CompactReplyParent } from '../../components/post/CompactReplyParent';
|
|
45
51
|
|
|
46
52
|
import { ReplyModal } from '../../components/post/index';
|
|
@@ -230,9 +236,18 @@ export const ReplyPost = ({ route, navigation }: PostProps) => {
|
|
|
230
236
|
if (!postData || postData.data.type === next) {
|
|
231
237
|
return;
|
|
232
238
|
}
|
|
239
|
+
if (!isSwitchablePostData(postData)) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
233
242
|
const newPostData =
|
|
234
243
|
next === 'question' ? toQuestion(postData) : toNote(postData);
|
|
235
244
|
form.reset(newPostData);
|
|
245
|
+
// Persisting the converted draft to the (module-scoped, app-lifetime)
|
|
246
|
+
// `replyData[id]` store slot is what makes the carry-over survive the
|
|
247
|
+
// reply screen unmounting/remounting: a fresh `ReplyPost` mount
|
|
248
|
+
// re-seeds its form from `useLocalPostStore(...).replyData[id]`, so the
|
|
249
|
+
// converted note body / poll question (and, for a poll, its stashed
|
|
250
|
+
// `questionDraft` fields) are restored on return.
|
|
236
251
|
setPostData(newPostData);
|
|
237
252
|
},
|
|
238
253
|
[postData, form, setPostData]
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
POLL_DEFAULT_EXPIRY_MS,
|
|
3
|
+
PostCreationData,
|
|
4
|
+
PostType,
|
|
5
|
+
PostDataUnion,
|
|
6
|
+
} from '@openpeepshq/common';
|
|
2
7
|
import { create } from 'zustand';
|
|
3
8
|
|
|
4
9
|
const defaultPostData = (type: PostType): PostDataUnion => {
|
|
@@ -8,9 +13,7 @@ const defaultPostData = (type: PostType): PostDataUnion => {
|
|
|
8
13
|
type: 'question',
|
|
9
14
|
content: '',
|
|
10
15
|
options: [],
|
|
11
|
-
expiresAt: new Date(
|
|
12
|
-
Date.now() + 1000 * 60 * 60 * 24 * 30
|
|
13
|
-
).toISOString(),
|
|
16
|
+
expiresAt: new Date(Date.now() + POLL_DEFAULT_EXPIRY_MS).toISOString(),
|
|
14
17
|
};
|
|
15
18
|
case 'event':
|
|
16
19
|
return {
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract test for the real (unmocked) useThemeOpacity hook (issue #1666
|
|
3
|
+
* review S5).
|
|
4
|
+
*
|
|
5
|
+
* The picker-row tint tests in ProfileSelector.test.tsx assert against a
|
|
6
|
+
* MOCKED useThemeOpacity whose values are copied from theme/defaults.ts. If
|
|
7
|
+
* the real hook's signature or the token shape ever changes, that mock would
|
|
8
|
+
* silently drift and the mocked tests would keep passing. This suite pins
|
|
9
|
+
* the real hook directly: it must resolve `background(name, opacity)` to the
|
|
10
|
+
* documented `rgba(...)` shape by feeding the token hex into the real
|
|
11
|
+
* hexWithOpacity color math.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const React = require('react');
|
|
15
|
+
const ReactTestRenderer = require('react-test-renderer');
|
|
16
|
+
|
|
17
|
+
jest.mock('./OpenPeepsThemeProvider', () => ({
|
|
18
|
+
// Mirrors the context shape the real hook reads. Values come from
|
|
19
|
+
// theme/defaults.ts (the default light theme) so the assertions are pinned
|
|
20
|
+
// to the documented palette.
|
|
21
|
+
useOpenPeepsTheme: () => ({
|
|
22
|
+
colors: {
|
|
23
|
+
primary: '#16161a',
|
|
24
|
+
secondary: '#f4f4f5',
|
|
25
|
+
},
|
|
26
|
+
}),
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
import { useThemeOpacity } from './useThemeOpacity';
|
|
30
|
+
|
|
31
|
+
const UseThemeOpacityProbe = () => {
|
|
32
|
+
const opacity = useThemeOpacity();
|
|
33
|
+
return React.createElement('useThemeOpacityProbe', {
|
|
34
|
+
background: opacity.background,
|
|
35
|
+
border: opacity.border,
|
|
36
|
+
text: opacity.text,
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const renderProbe = () => {
|
|
41
|
+
let tree: ReturnType<typeof ReactTestRenderer.create>;
|
|
42
|
+
ReactTestRenderer.act(() => {
|
|
43
|
+
tree = ReactTestRenderer.create(React.createElement(UseThemeOpacityProbe));
|
|
44
|
+
});
|
|
45
|
+
return tree.root.findByType('useThemeOpacityProbe').props as {
|
|
46
|
+
background: (name: string, opacity: number) => Record<string, unknown>;
|
|
47
|
+
border: (name: string, opacity: number) => Record<string, unknown>;
|
|
48
|
+
text: (name: string, opacity: number) => Record<string, unknown>;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
describe('useThemeOpacity (real hook, issue #1666 review S5)', () => {
|
|
53
|
+
it('resolves background(primary, opacity) to the documented rgba shape', () => {
|
|
54
|
+
const { background } = renderProbe();
|
|
55
|
+
expect(background('primary', 0.15)).toEqual({
|
|
56
|
+
backgroundColor: 'rgba(22, 22, 26, 0.15)',
|
|
57
|
+
});
|
|
58
|
+
expect(background('secondary', 0.4)).toEqual({
|
|
59
|
+
backgroundColor: 'rgba(244, 244, 245, 0.4)',
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('exposes border/text variants on the same hex', () => {
|
|
64
|
+
const { border, text } = renderProbe();
|
|
65
|
+
expect(border('primary', 0.5)).toEqual({
|
|
66
|
+
borderColor: 'rgba(22, 22, 26, 0.5)',
|
|
67
|
+
});
|
|
68
|
+
expect(text('primary', 1)).toEqual({ color: 'rgba(22, 22, 26, 1)' });
|
|
69
|
+
});
|
|
70
|
+
});
|