@openpeepshq/rn-components 0.18.0 → 0.19.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpeepshq/rn-components",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "description": "React Native community screens and shared UI (extracted from the Black Ambition app) for the OpenPeeps stack.",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./src/index.ts",
@@ -142,9 +142,9 @@
142
142
  "timezones-list": "^3.1.0",
143
143
  "validator": "^13.15.23",
144
144
  "zustand": "^5.0.3",
145
- "@openpeepshq/react": "^0.19.0",
146
- "@openpeepshq/common": "^0.12.0",
147
- "@openpeepshq/fetch-client": "^0.2.1"
145
+ "@openpeepshq/fetch-client": "^0.2.1",
146
+ "@openpeepshq/common": "^0.13.0",
147
+ "@openpeepshq/react": "^0.20.0"
148
148
  },
149
149
  "devDependencies": {
150
150
  "@babel/core": "^7.26.7",
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Regression tests for the GroupAvatar loading-gap fix (issue #1666, round-4
3
+ * review item 2).
4
+ *
5
+ * A group avatar that is still downloading — or permanently, when the media
6
+ * cache cannot produce the file — must keep the slot filled with the same
7
+ * sized initials tile as a no-avatar group, instead of leaving an empty box
8
+ * that reads as a misaligned avatar. The image branch renders the tile
9
+ * behind the image (tile first in tree order), so the guarantee is uniform
10
+ * with ProfileAvatar.
11
+ */
12
+
13
+ const React = require('react');
14
+ const ReactTestRenderer = require('react-test-renderer');
15
+
16
+ // Mocked element types, shared with the jest.mock factories below so tests can
17
+ // assert tree order by reference instead of by string name. The tile's style
18
+ // (backgroundColor / fontSize) is forwarded so the underlay's actual styling
19
+ // can be pinned, not just its presence and tree position.
20
+ const MockView = (props: {
21
+ children?: unknown;
22
+ className?: string;
23
+ style?: unknown;
24
+ }) =>
25
+ React.createElement(
26
+ 'View',
27
+ { className: props.className, style: props.style },
28
+ props.children
29
+ );
30
+ const MockText = (props: {
31
+ children?: unknown;
32
+ className?: string;
33
+ style?: unknown;
34
+ }) =>
35
+ React.createElement(
36
+ 'Text',
37
+ { className: props.className, style: props.style },
38
+ props.children
39
+ );
40
+ const MockAvatar = (props: { children?: unknown; className?: string }) =>
41
+ React.createElement('Avatar', { className: props.className }, props.children);
42
+ const MockAvatarImage = (props: { source?: unknown; className?: string }) =>
43
+ React.createElement('AvatarImage', { source: props.source });
44
+
45
+ jest.mock('react-native', () => ({
46
+ View: MockView,
47
+ Text: MockText,
48
+ }));
49
+
50
+ jest.mock('@openpeepshq/common', () => ({
51
+ // Only the runtime helper is needed; `Group` is a type-only import.
52
+ getGroupAvatar: (
53
+ group: { avatar?: string | null } | null | undefined,
54
+ _config: unknown
55
+ ) => group?.avatar,
56
+ }));
57
+
58
+ jest.mock('@openpeepshq/react', () => ({
59
+ useOpenpeeps: () => ({
60
+ openpeepsApi: { useServerInfo: () => ({ data: { communityConfig: {} } }) },
61
+ }),
62
+ // Real source for the initials fallback (first + last name initial).
63
+ getInitials: require('../../../../react/src/lib/initialsAvatar').getInitials,
64
+ hueFromHandle: () => 180,
65
+ initialsBackground: () => 'rgb(20, 20, 20)',
66
+ }));
67
+
68
+ jest.mock('../../theme/OpenPeepsThemeProvider', () => ({
69
+ useOpenPeepsTheme: () => ({ isDark: false }),
70
+ }));
71
+
72
+ jest.mock('../ui/avatar', () => ({
73
+ Avatar: MockAvatar,
74
+ AvatarImage: MockAvatarImage,
75
+ }));
76
+
77
+ jest.mock('../../lib/utils', () => ({
78
+ cn: (...parts: Array<string | undefined>) => parts.filter(Boolean).join(' '),
79
+ }));
80
+
81
+ import type { Group } from '@openpeepshq/common';
82
+ import { GroupAvatar } from './GroupAvatar';
83
+
84
+ const baseGroup = {
85
+ id: 'g1',
86
+ handle: 'ada-group',
87
+ displayName: 'Ada Group',
88
+ } as unknown as Group;
89
+
90
+ const renderGroupAvatar = (group: Group, className?: string) => {
91
+ let tree: ReturnType<typeof ReactTestRenderer.create>;
92
+ ReactTestRenderer.act(() => {
93
+ tree = ReactTestRenderer.create(
94
+ React.createElement(GroupAvatar, { group, className })
95
+ );
96
+ });
97
+ return tree;
98
+ };
99
+
100
+ const initialsText = (tree: ReturnType<typeof ReactTestRenderer.create>) =>
101
+ tree.root
102
+ .findAllByType(MockText)
103
+ .map((node: { props: { children?: unknown } }) => node.props.children)
104
+ .find((child) => typeof child === 'string');
105
+
106
+ // The underlay tile is the View carrying the initialsBackground color.
107
+ const findTile = (tree: ReturnType<typeof ReactTestRenderer.create>) =>
108
+ tree.root
109
+ .findAllByType(MockView)
110
+ .find(
111
+ (node: { props: { style?: { backgroundColor?: string } } }) =>
112
+ typeof node.props.style?.backgroundColor === 'string'
113
+ );
114
+
115
+ // The tile's single child is the initials Text (not an array).
116
+ const tileFontSize = (tree: ReturnType<typeof ReactTestRenderer.create>) => {
117
+ const child = findTile(tree)?.props?.children;
118
+ return (Array.isArray(child) ? child[0] : child)?.props?.style?.fontSize;
119
+ };
120
+
121
+ describe('GroupAvatar loading-gap fix (issue #1666 round-4 review item 2)', () => {
122
+ it('renders the initials tile behind the image while the group avatar is still loading', () => {
123
+ const tree = renderGroupAvatar({
124
+ ...baseGroup,
125
+ avatar: 'https://cdn.example/groups/ada-group.png',
126
+ });
127
+ const avatar = tree.root.findByType('Avatar');
128
+ expect(initialsText(tree)).toBe('AG');
129
+ expect(avatar.findAllByType(MockAvatarImage)).toHaveLength(1);
130
+ const childTypes = avatar.children.map(
131
+ (child: { type?: unknown }) => child.type
132
+ );
133
+ expect(childTypes[0]).toBe(MockView);
134
+ expect(childTypes[childTypes.length - 1]).toBe(MockAvatarImage);
135
+ });
136
+
137
+ it('renders the initials tile standalone when the group has no avatar', () => {
138
+ const tree = renderGroupAvatar(baseGroup);
139
+ const avatar = tree.root.findByType('Avatar');
140
+ expect(initialsText(tree)).toBe('AG');
141
+ expect(avatar.findAllByType(MockAvatarImage)).toHaveLength(0);
142
+ const childTypes = avatar.children.map(
143
+ (child: { type?: unknown }) => child.type
144
+ );
145
+ expect(childTypes).toEqual([MockView]);
146
+ });
147
+
148
+ it('pins the underlay style: tile background from initialsBackground and size-derived fontSize (issue #1666 round-20 #1/#3)', () => {
149
+ // Default (no size class) → 64dp box → fontSize 24; background is the
150
+ // real initialsBackground output for the mocked hue.
151
+ const tree = renderGroupAvatar(baseGroup);
152
+ expect(findTile(tree)?.props.style?.backgroundColor).toBe(
153
+ 'rgb(20, 20, 20)'
154
+ );
155
+ expect(tileFontSize(tree)).toBe(24);
156
+ });
157
+
158
+ it('scales the tile fontSize with the requested size, including non-bucket sizes (issue #1666 round-20 #3)', () => {
159
+ // size-8 → 32dp → 12 (was the 14px bucket before round-20 #4), size-24 →
160
+ // 96dp → 36, w-12 h-12 → 48dp → 18, and a non-bucket size-14 → 56dp → 21.
161
+ expect(tileFontSize(renderGroupAvatar(baseGroup, 'size-8'))).toBe(12);
162
+ expect(tileFontSize(renderGroupAvatar(baseGroup, 'size-24'))).toBe(36);
163
+ expect(tileFontSize(renderGroupAvatar(baseGroup, 'w-12 h-12'))).toBe(18);
164
+ expect(tileFontSize(renderGroupAvatar(baseGroup, 'size-14'))).toBe(21);
165
+ });
166
+ });
@@ -11,6 +11,11 @@ import { useOpenPeepsTheme } from '../../theme/OpenPeepsThemeProvider';
11
11
  import { Avatar, AvatarImage } from '../ui/avatar';
12
12
  import { cn } from '../../lib/utils';
13
13
 
14
+ /** Tailwind spacing unit in dp (size-N / w-N → N × 4). */
15
+ const TAILWIND_UNIT = 4;
16
+ /** Initials scale with the avatar instead of preset buckets. */
17
+ const FONT_RATIO = 0.375;
18
+
14
19
  export const GroupAvatar = ({
15
20
  group,
16
21
  className,
@@ -22,19 +27,46 @@ export const GroupAvatar = ({
22
27
  const { isDark } = useOpenPeepsTheme();
23
28
  const { data: server } = openpeepsApi.useServerInfo();
24
29
 
25
- const isSmall = className?.includes('size-8');
26
- const sizeClass = isSmall ? 'h-8 w-8' : 'h-16 w-16';
27
30
  const roundedClass = 'rounded-full';
28
31
 
32
+ // The requested size (size-N / w-N / h-N) drives the initials font size
33
+ // directly, matching ProfileAvatar: every size renders proportionally
34
+ // scaled fallback content instead of preset buckets, so a group tile and a
35
+ // profile tile of the same size read the same next to each other.
36
+ const sizeMatch = (className ?? '').match(
37
+ /(?:^|\s)(?:size-|w-|h-)(\d+)(?=\s|$)/
38
+ );
39
+ const px = sizeMatch ? Number(sizeMatch[1]) * TAILWIND_UNIT : 64;
40
+ const fontSize = Math.max(10, Math.round(px * FONT_RATIO));
41
+ const sizeClass = sizeMatch ? '' : 'h-16 w-16';
42
+
29
43
  const avatarUri =
30
44
  server && group
31
45
  ? getGroupAvatar(group, server.communityConfig)
32
46
  : group?.avatar;
33
47
 
34
48
  const hue = hueFromHandle(group?.handle ?? '');
35
- const backgroundColor = avatarUri
36
- ? undefined
37
- : initialsBackground(hue, isDark);
49
+ const backgroundColor = initialsBackground(hue, isDark);
50
+
51
+ // The initials tile is the underlay behind the image branch (absolutely
52
+ // positioned to fill the avatar box): while the group avatar is still
53
+ // downloading — or permanently, when the media cache cannot produce the
54
+ // file — it is the visible content, and it doubles as the standalone
55
+ // content for no-avatar groups. Either way the slot carries sized,
56
+ // centered content (issue #1666).
57
+ const initialsTile = (
58
+ <View
59
+ className={cn(
60
+ 'absolute inset-0 flex items-center justify-center',
61
+ roundedClass
62
+ )}
63
+ style={{ backgroundColor }}
64
+ >
65
+ <Text className="text-foreground font-medium" style={{ fontSize }}>
66
+ {getInitials(group?.displayName, group?.handle)}
67
+ </Text>
68
+ </View>
69
+ );
38
70
 
39
71
  return (
40
72
  <Avatar
@@ -47,26 +79,16 @@ export const GroupAvatar = ({
47
79
  )}
48
80
  >
49
81
  {avatarUri ? (
50
- <AvatarImage
51
- source={{ uri: avatarUri }}
52
- className={cn('h-full w-full', roundedClass)}
53
- resizeMode="cover"
54
- />
82
+ <>
83
+ {initialsTile}
84
+ <AvatarImage
85
+ source={{ uri: avatarUri }}
86
+ className={cn('h-full w-full', roundedClass)}
87
+ resizeMode="cover"
88
+ />
89
+ </>
55
90
  ) : (
56
- <View
57
- className={cn(
58
- 'flex h-full w-full items-center justify-center',
59
- roundedClass
60
- )}
61
- style={{ backgroundColor }}
62
- >
63
- <Text
64
- className="text-foreground font-medium"
65
- style={{ fontSize: isSmall ? 14 : 24 }}
66
- >
67
- {getInitials(group?.displayName, group?.handle)}
68
- </Text>
69
- </View>
91
+ initialsTile
70
92
  )}
71
93
  </Avatar>
72
94
  );
@@ -344,7 +344,12 @@ export const EventForm = ({
344
344
 
345
345
  <SectionTitle>{t('events.form.location')}</SectionTitle>
346
346
 
347
- <EventTypeSwitcher event={event} isEdit={isEdit} onChange={setEvent} />
347
+ <EventTypeSwitcher
348
+ event={event}
349
+ isEdit={isEdit}
350
+ onChange={setEvent}
351
+ visibility={postData.visibility}
352
+ />
348
353
 
349
354
  <SectionTitle>{t('events.form.people')}</SectionTitle>
350
355
 
@@ -0,0 +1,247 @@
1
+ /**
2
+ * RN parity for the community-jam "notify everyone" opt-in (issue #1621): the
3
+ * native event form must render the opt-in checkbox only when the profile can
4
+ * announce posts (`core-posts-announce`) AND the post visibility is
5
+ * community-wide, mirroring
6
+ * platform/react/src/components/post/post-form/EventTypeSwitcher.tsx.
7
+ *
8
+ * react-native, the UI primitives and the shared `@openpeepshq/react` hooks are
9
+ * stubbed; the two gate predicates come from `@openpeepshq/common` with the
10
+ * exact semantics of `canAnnouncePosts` / `isCommunityWideVisibility`, fed by
11
+ * `state`, so the test pins the gate without depending on the workspace
12
+ * symlink target carrying the role surface.
13
+ *
14
+ * Unlike counting `Checkbox` renders, the tests identify each checkbox by the
15
+ * handler its `onCheckedChange` is wired to. The `@openpeepshq/react` mock
16
+ * mirrors the real `useEventTypeSwitcher` contract: `setWaitingRoom` /
17
+ * `setNotifyEveryone` each spread `event` and write the matching `jam` field,
18
+ * then call the component's `onChange`. So the notify checkbox is recognized by
19
+ * `onCheckedChange === setNotifyEveryone` (not by a render count that the
20
+ * always-present waiting-room checkbox would inflate), and firing it is asserted
21
+ * to drive `onChange` with `jam.notifyEveryone: true`.
22
+ */
23
+
24
+ const React = require('react');
25
+ const ReactTestRenderer = require('react-test-renderer');
26
+
27
+ (
28
+ globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }
29
+ ).IS_REACT_ACT_ENVIRONMENT = true;
30
+
31
+ // Shared `useAuthData` mock surface (same module the web parity test drives
32
+ // against `IdentityContext`), so the profile the tree sees is identical on
33
+ // both platforms.
34
+ const {
35
+ authDataState,
36
+ makeAuthDataValue,
37
+ } = require('../../../../../react/src/test/support/mockAuth');
38
+
39
+ type CheckboxProps = {
40
+ checked?: boolean;
41
+ disabled?: boolean;
42
+ onCheckedChange?: (value: boolean) => void;
43
+ };
44
+
45
+ // Every Checkbox the tree renders, in order, with the props it was handed.
46
+ let checkboxes: CheckboxProps[] = [];
47
+ // Handler identities handed to the component this render, used to tell the
48
+ // notify checkbox apart from the always-present waiting-room checkbox.
49
+ let setWaitingRoom: ((value: boolean) => void) | undefined;
50
+ let setNotifyEveryone: ((value: boolean) => void) | undefined;
51
+
52
+ jest.mock('react-native', () => ({
53
+ View: (props: { children?: unknown }) =>
54
+ React.createElement('View', null, props.children),
55
+ Pressable: (props: { children?: unknown }) =>
56
+ React.createElement('Pressable', null, props.children),
57
+ }));
58
+
59
+ jest.mock('react-i18next', () => ({
60
+ useTranslation: () => ({ t: (key: string) => key }),
61
+ }));
62
+
63
+ // Mirrored from platform/common/src/lib — the package entry the test would
64
+ // otherwise load through the workspace symlink may not carry the role surface.
65
+ jest.mock('@openpeepshq/common', () => ({
66
+ canAnnouncePosts: (roles: { capabilities?: { add?: string[] } }[] = []) =>
67
+ roles.some((r) =>
68
+ (r.capabilities?.add ?? []).includes('core-posts-announce')
69
+ ),
70
+ isCommunityWideVisibility: (visibility?: string) =>
71
+ visibility === 'public' || visibility === 'local',
72
+ }));
73
+
74
+ jest.mock('@openpeepshq/react', () => ({
75
+ useAuthData: makeAuthDataValue,
76
+ useEventTypeSwitcher: (args: {
77
+ event: { jam?: Record<string, unknown> };
78
+ onChange: (event: unknown) => void;
79
+ }) => {
80
+ // Mirror the real hook (platform/react useEventTypeSwitcher): both setters
81
+ // spread the current event, write their jam field, and call onChange.
82
+ setWaitingRoom = (value: boolean) =>
83
+ args.onChange({
84
+ ...args.event,
85
+ jam: { ...args.event.jam, waitingRoom: value },
86
+ });
87
+ setNotifyEveryone = (value: boolean) =>
88
+ args.onChange({
89
+ ...args.event,
90
+ jam: { ...args.event.jam, notifyEveryone: value },
91
+ });
92
+ return {
93
+ eventFormat: 'jam',
94
+ formats: [{ value: 'jam', label: 'events.form.jamFormat' }],
95
+ livekitEnabled: true,
96
+ switchFormat: () => undefined,
97
+ moderatorProfiles: [],
98
+ setModerators: () => undefined,
99
+ setWaitingRoom,
100
+ setNotifyEveryone,
101
+ setUrl: () => undefined,
102
+ setPhysicalLocation: () => undefined,
103
+ };
104
+ },
105
+ useLocationSearch: () => ({
106
+ text: '',
107
+ setText: () => undefined,
108
+ suggestions: [],
109
+ clearSuggestions: () => undefined,
110
+ search: () => undefined,
111
+ }),
112
+ }));
113
+
114
+ jest.mock('../../ui/checkbox', () => ({
115
+ Checkbox: (props: CheckboxProps) => {
116
+ checkboxes.push(props);
117
+ return React.createElement('Checkbox', props);
118
+ },
119
+ }));
120
+ jest.mock('../../ui/input', () => ({
121
+ Input: () => React.createElement('Input'),
122
+ }));
123
+ jest.mock('../../ui/label', () => ({
124
+ Label: ({ children }: { children?: unknown }) =>
125
+ React.createElement('Label', null, children),
126
+ }));
127
+ jest.mock('../../ui/radio-group', () => ({
128
+ RadioGroup: ({ children }: { children?: unknown }) =>
129
+ React.createElement('RadioGroup', null, children),
130
+ RadioGroupItem: (props: Record<string, unknown>) =>
131
+ React.createElement('RadioGroupItem', props),
132
+ }));
133
+ jest.mock('../../ui/themed-text', () => ({
134
+ ThemedText: ({ children }: { children?: unknown }) =>
135
+ React.createElement('ThemedText', null, children),
136
+ }));
137
+ jest.mock('../../../lib/constants', () => ({ BASE_URL: 'http://localhost' }));
138
+ jest.mock('../../profile/ProfilesInput', () => ({
139
+ ProfilesInput: () => React.createElement('ProfilesInput'),
140
+ }));
141
+
142
+ const { EventTypeSwitcher } = require('./EventTypeSwitcher');
143
+
144
+ const event = { type: 'event', name: 'Standup', jam: {} };
145
+
146
+ // Renders the tree (driving the gate) and returns every checkbox it produced,
147
+ // so callers can pick the one wired to the setter they care about.
148
+ const render = (visibility?: string, onChange?: (event: unknown) => void) => {
149
+ checkboxes = [];
150
+ setWaitingRoom = undefined;
151
+ setNotifyEveryone = undefined;
152
+ ReactTestRenderer.act(() => {
153
+ ReactTestRenderer.create(
154
+ React.createElement(EventTypeSwitcher, {
155
+ event,
156
+ onChange: onChange ?? (() => undefined),
157
+ visibility,
158
+ })
159
+ );
160
+ });
161
+ return checkboxes;
162
+ };
163
+
164
+ // True only when the tree renders exactly one checkbox and it is the
165
+ // waiting-room one — i.e. the notify opt-in is absent (the `>= 2` count the
166
+ // old render-count assertions relied on would be satisfied by a future third
167
+ // toggle; identity is not).
168
+ const waitingRoomOnly = (boxes: CheckboxProps[]) =>
169
+ boxes.length === 1 && boxes[0].onCheckedChange === setWaitingRoom;
170
+
171
+ const notifyCheckbox = (boxes: CheckboxProps[]) =>
172
+ boxes.find((b) => b.onCheckedChange === setNotifyEveryone);
173
+
174
+ describe('RN EventTypeSwitcher community jam broadcast opt-in', () => {
175
+ beforeEach(() => {
176
+ authDataState.roles = [];
177
+ });
178
+
179
+ it('shows the opt-in for a public jam when the role can announce posts', () => {
180
+ authDataState.roles = [{ capabilities: { add: ['core-posts-announce'] } }];
181
+ const boxes = render('public');
182
+ expect(boxes).toHaveLength(2);
183
+ expect(notifyCheckbox(boxes)).toBeDefined();
184
+ });
185
+
186
+ it('shows the opt-in for a local jam with the announce role', () => {
187
+ authDataState.roles = [{ capabilities: { add: ['core-posts-announce'] } }];
188
+ const boxes = render('local');
189
+ expect(boxes).toHaveLength(2);
190
+ expect(notifyCheckbox(boxes)).toBeDefined();
191
+ });
192
+
193
+ it('keeps the waiting-room checkbox as the only checkbox for a group jam', () => {
194
+ authDataState.roles = [{ capabilities: { add: ['core-posts-announce'] } }];
195
+ expect(waitingRoomOnly(render('group'))).toBe(true);
196
+ });
197
+
198
+ it('keeps the waiting-room checkbox as the only checkbox for a direct jam', () => {
199
+ authDataState.roles = [{ capabilities: { add: ['core-posts-announce'] } }];
200
+ expect(waitingRoomOnly(render('direct'))).toBe(true);
201
+ });
202
+
203
+ it('keeps the waiting-room checkbox as the only checkbox without the announce role', () => {
204
+ authDataState.roles = [{ capabilities: { add: ['core-posts-create'] } }];
205
+ expect(waitingRoomOnly(render('public'))).toBe(true);
206
+ });
207
+
208
+ it('keeps the waiting-room checkbox as the only checkbox when no visibility is supplied', () => {
209
+ authDataState.roles = [{ capabilities: { add: ['core-posts-announce'] } }];
210
+ expect(waitingRoomOnly(render(undefined))).toBe(true);
211
+ });
212
+
213
+ it('drives onChange with jam.notifyEveryone: true when the opt-in is toggled on', () => {
214
+ authDataState.roles = [{ capabilities: { add: ['core-posts-announce'] } }];
215
+ const onChange = jest.fn();
216
+ const boxes = render('public', onChange);
217
+ const notify = notifyCheckbox(boxes);
218
+ expect(notify).toBeDefined();
219
+ expect(notify!.checked).toBe(false);
220
+
221
+ notify!.onCheckedChange!(true);
222
+
223
+ expect(onChange).toHaveBeenCalledTimes(1);
224
+ expect(onChange).toHaveBeenCalledWith(
225
+ expect.objectContaining({
226
+ jam: expect.objectContaining({ notifyEveryone: true }),
227
+ })
228
+ );
229
+ });
230
+
231
+ it('drives onChange with jam.waitingRoom: true when the waiting-room toggle is toggled', () => {
232
+ authDataState.roles = [{ capabilities: { add: ['core-posts-announce'] } }];
233
+ const onChange = jest.fn();
234
+ const boxes = render('public', onChange);
235
+ const waitingRoom = boxes.find((b) => b.onCheckedChange === setWaitingRoom);
236
+ expect(waitingRoom).toBeDefined();
237
+
238
+ waitingRoom!.onCheckedChange!(true);
239
+
240
+ expect(onChange).toHaveBeenCalledTimes(1);
241
+ expect(onChange).toHaveBeenCalledWith(
242
+ expect.objectContaining({
243
+ jam: expect.objectContaining({ waitingRoom: true }),
244
+ })
245
+ );
246
+ });
247
+ });
@@ -2,7 +2,15 @@ import React from 'react';
2
2
  import { Pressable, View } from 'react-native';
3
3
  import { useTranslation } from 'react-i18next';
4
4
  import type { Event, Location } from '@openpeepshq/common';
5
- import { useEventTypeSwitcher, useLocationSearch } from '@openpeepshq/react';
5
+ import {
6
+ canAnnouncePosts,
7
+ isCommunityWideVisibility,
8
+ } from '@openpeepshq/common';
9
+ import {
10
+ useAuthData,
11
+ useEventTypeSwitcher,
12
+ useLocationSearch,
13
+ } from '@openpeepshq/react';
6
14
  import { Checkbox } from '../../ui/checkbox';
7
15
  import { Input } from '../../ui/input';
8
16
  import { Label } from '../../ui/label';
@@ -17,6 +25,8 @@ export interface EventTypeSwitcherProps {
17
25
  event: Event;
18
26
  isEdit?: boolean;
19
27
  onChange: (event: Event) => void;
28
+ /** Post visibility; gates the community-wide "notify everyone" opt-in. */
29
+ visibility?: string;
20
30
  }
21
31
 
22
32
  const SimpleLocationInput = ({
@@ -67,8 +77,13 @@ export const EventTypeSwitcher = ({
67
77
  event,
68
78
  isEdit = false,
69
79
  onChange,
80
+ visibility,
70
81
  }: EventTypeSwitcherProps) => {
71
82
  const { t } = useTranslation();
83
+ const authData = useAuthData();
84
+ const canNotify =
85
+ canAnnouncePosts(authData.profile?.roles) &&
86
+ isCommunityWideVisibility(visibility);
72
87
  const {
73
88
  eventFormat,
74
89
  formats,
@@ -77,6 +92,7 @@ export const EventTypeSwitcher = ({
77
92
  moderatorProfiles,
78
93
  setModerators,
79
94
  setWaitingRoom,
95
+ setNotifyEveryone,
80
96
  setUrl,
81
97
  setPhysicalLocation,
82
98
  } = useEventTypeSwitcher({ event, isEdit, onChange, origin: BASE_URL ?? '' });
@@ -157,6 +173,25 @@ export const EventTypeSwitcher = ({
157
173
  {t('events.form.jamWaitingRoom')}
158
174
  </ThemedText>
159
175
  </View>
176
+ {canNotify ? (
177
+ <View className="gap-1">
178
+ <View className="flex-row items-start gap-2">
179
+ <View className="pt-0.5">
180
+ <Checkbox
181
+ checked={event.jam?.notifyEveryone ?? false}
182
+ disabled={!livekitEnabled}
183
+ onCheckedChange={setNotifyEveryone}
184
+ />
185
+ </View>
186
+ <ThemedText className="text-sm">
187
+ {t('events.form.jamNotifyEveryone')}
188
+ </ThemedText>
189
+ </View>
190
+ <ThemedText className="text-xs text-muted-foreground pl-6">
191
+ {t('events.form.jamNotifyEveryoneDescription')}
192
+ </ThemedText>
193
+ </View>
194
+ ) : null}
160
195
  </>
161
196
  ) : null}
162
197
  </View>
@@ -15,11 +15,43 @@
15
15
  const React = require('react');
16
16
  const ReactTestRenderer = require('react-test-renderer');
17
17
 
18
+ // Mocked element types, shared with the jest.mock factories below so tests can
19
+ // assert tree order by reference instead of by string name. The tile's style
20
+ // (backgroundColor / fontSize) is forwarded so the underlay's actual styling
21
+ // can be pinned, not just its presence and tree position.
22
+ const MockView = (props: {
23
+ children?: unknown;
24
+ className?: string;
25
+ style?: unknown;
26
+ }) =>
27
+ React.createElement(
28
+ 'View',
29
+ { className: props.className, style: props.style },
30
+ props.children
31
+ );
32
+ const MockText = (props: {
33
+ children?: unknown;
34
+ className?: string;
35
+ style?: unknown;
36
+ }) =>
37
+ React.createElement(
38
+ 'Text',
39
+ { className: props.className, style: props.style },
40
+ props.children
41
+ );
42
+ const MockAvatar = (props: { children?: unknown; className?: string }) =>
43
+ React.createElement('Avatar', { className: props.className }, props.children);
44
+ const MockAvatarImage = (props: { source?: unknown; className?: string }) =>
45
+ React.createElement('AvatarImage', { source: props.source });
46
+ const MockSvgImage = (props: { uri?: string; className?: string }) =>
47
+ React.createElement('SvgImage', {
48
+ uri: props.uri,
49
+ className: props.className,
50
+ });
51
+
18
52
  jest.mock('react-native', () => ({
19
- View: (props: { children?: unknown; className?: string }) =>
20
- React.createElement('View', { className: props.className }, props.children),
21
- Text: (props: { children?: unknown; className?: string }) =>
22
- React.createElement('Text', { className: props.className }, props.children),
53
+ View: MockView,
54
+ Text: MockText,
23
55
  }));
24
56
 
25
57
  jest.mock('react-i18next', () => ({
@@ -47,23 +79,13 @@ jest.mock('../../theme/OpenPeepsThemeProvider', () => ({
47
79
  }));
48
80
 
49
81
  jest.mock('../ui/avatar', () => ({
50
- Avatar: (props: { children?: unknown; className?: string }) =>
51
- React.createElement(
52
- 'Avatar',
53
- { className: props.className },
54
- props.children
55
- ),
82
+ Avatar: MockAvatar,
56
83
  AvatarFallback: () => null,
57
- AvatarImage: (props: { source?: unknown; className?: string }) =>
58
- React.createElement('AvatarImage', { source: props.source }),
84
+ AvatarImage: MockAvatarImage,
59
85
  }));
60
86
 
61
87
  jest.mock('../ui/svg-image', () => ({
62
- SvgImage: (props: { uri?: string; className?: string }) =>
63
- React.createElement('SvgImage', {
64
- uri: props.uri,
65
- className: props.className,
66
- }),
88
+ SvgImage: MockSvgImage,
67
89
  }));
68
90
 
69
91
  jest.mock('../icons/index', () => ({
@@ -144,4 +166,67 @@ describe('ProfileAvatar SVG path selection (issue #1666 round-2 plan step 2)', (
144
166
  .find((child) => typeof child === 'string');
145
167
  expect(initials).toBe('AL');
146
168
  });
169
+
170
+ it('renders the initials tile under the SVG image (issue #1666 round-3)', () => {
171
+ // Both children must render simultaneously, with the tile first in tree
172
+ // order so a loaded SvgImage paints over it (a re-order, or a condition
173
+ // that hides the image, must fail this test).
174
+ const tree = renderAvatar({
175
+ ...baseProfile,
176
+ avatar: 'https://cdn.example/avatars/ada.svg',
177
+ });
178
+ const avatar = tree.root.findByType('Avatar');
179
+ const initials = tree.root
180
+ .findAllByType('Text')
181
+ .map((node: { props: { children?: unknown } }) => node.props.children)
182
+ .find((child) => typeof child === 'string');
183
+ expect(initials).toBe('AL');
184
+ expect(avatar.findAllByType(MockSvgImage)).toHaveLength(1);
185
+ const childTypes = avatar.children.map(
186
+ (child: { type?: unknown }) => child.type
187
+ );
188
+ expect(childTypes[0]).toBe(MockView);
189
+ expect(childTypes[childTypes.length - 1]).toBe(MockSvgImage);
190
+ });
191
+
192
+ it('renders the initials tile under the raster image (issue #1666 round-3)', () => {
193
+ // Both children must render simultaneously, with the tile first in tree
194
+ // order so a loaded AvatarImage paints over it (a re-order, or a
195
+ // condition that hides the image, must fail this test).
196
+ const tree = renderAvatar({
197
+ ...baseProfile,
198
+ avatar: 'https://cdn.example/avatars/ada.png',
199
+ });
200
+ const avatar = tree.root.findByType('Avatar');
201
+ const initials = tree.root
202
+ .findAllByType('Text')
203
+ .map((node: { props: { children?: unknown } }) => node.props.children)
204
+ .find((child) => typeof child === 'string');
205
+ expect(initials).toBe('AL');
206
+ expect(avatar.findAllByType(MockAvatarImage)).toHaveLength(1);
207
+ const childTypes = avatar.children.map(
208
+ (child: { type?: unknown }) => child.type
209
+ );
210
+ expect(childTypes[0]).toBe(MockView);
211
+ expect(childTypes[childTypes.length - 1]).toBe(MockAvatarImage);
212
+ });
213
+
214
+ it('pins the underlay style: tile background from initialsBackground and size-derived fontSize (issue #1666 round-20 #1)', () => {
215
+ // The loading-gap symptom is invisible-if-unstyled: a refactor that drops
216
+ // the tile's style must fail here. size-10 → 40dp → fontSize 15, and the
217
+ // background is the real initialsBackground output for the mocked hue.
218
+ const tree = renderAvatar({
219
+ ...baseProfile,
220
+ avatar: 'https://cdn.example/avatars/ada.png',
221
+ });
222
+ const tile = tree.root
223
+ .findAllByType(MockView)
224
+ .find((node) => typeof node.props.style?.backgroundColor === 'string');
225
+ expect(tile.props.style.backgroundColor).toBe('rgb(20, 20, 20)');
226
+ // The tile's single child is the initials Text (not an array).
227
+ const text = Array.isArray(tile.props.children)
228
+ ? tile.props.children[0]
229
+ : tile.props.children;
230
+ expect(text.props.style.fontSize).toBe(15);
231
+ });
147
232
  });
@@ -55,8 +55,27 @@ export const ProfileAvatar = ({
55
55
  !deleted && profile?.avatar ? { uri: svgCoverSrc(profile.avatar) } : null;
56
56
 
57
57
  const hue = hueFromHandle(profile?.handle ?? '');
58
- const backgroundColor =
59
- !deleted && !avatarSource ? initialsBackground(hue, isDark) : undefined;
58
+ const initialsBg = !deleted ? initialsBackground(hue, isDark) : undefined;
59
+
60
+ // The initials tile is the underlay behind both image branches (absolutely
61
+ // positioned to fill the avatar box): while a remote/SVG avatar is still
62
+ // downloading — or permanently, when the media cache cannot produce the
63
+ // file — it is the visible content, and it doubles as the standalone
64
+ // content for no-avatar profiles. Either way every row carries sized,
65
+ // centered content (issue #1666).
66
+ const initialsTile = (
67
+ <View
68
+ className={cn(
69
+ 'absolute inset-0 flex items-center justify-center',
70
+ roundedClass
71
+ )}
72
+ style={{ backgroundColor: initialsBg }}
73
+ >
74
+ <Text className="text-foreground font-medium" style={{ fontSize }}>
75
+ {getInitials(profile?.displayName, profile?.handle)}
76
+ </Text>
77
+ </View>
78
+ );
60
79
 
61
80
  const rootClassName = cn(
62
81
  'border border-muted-foreground overflow-hidden',
@@ -71,27 +90,26 @@ export const ProfileAvatar = ({
71
90
  className={rootClassName}
72
91
  style={{ width: px, height: px }}
73
92
  >
74
- <View
75
- className={cn(
76
- 'flex h-full w-full items-center justify-center',
77
- roundedClass
78
- )}
79
- style={{ backgroundColor }}
80
- >
81
- {deleted ? (
93
+ {deleted ? (
94
+ <View
95
+ className={cn(
96
+ 'flex h-full w-full items-center justify-center',
97
+ roundedClass
98
+ )}
99
+ >
82
100
  <UserXIcon size={iconSize} className="text-muted-foreground" />
83
- ) : (
84
- <Text className="text-foreground font-medium" style={{ fontSize }}>
85
- {getInitials(profile?.displayName, profile?.handle)}
86
- </Text>
87
- )}
88
- </View>
101
+ </View>
102
+ ) : (
103
+ initialsTile
104
+ )}
89
105
  </Avatar>
90
106
  );
91
107
  }
92
108
 
93
- // RN Image cannot decode SVG: render via SvgImage, which ignores the
94
- // #svgView fragment and applies cover natively via preserveAspectRatio.
109
+ // The image branches render the initials tile underneath the image: while
110
+ // the media cache is still downloading (or an SVG has not reached the
111
+ // decode-ready state) the avatar shows the same tile as no-avatar
112
+ // profiles, so rows always carry sized, centered content (issue #1666).
95
113
  if (isSvg) {
96
114
  return (
97
115
  <Avatar
@@ -99,6 +117,7 @@ export const ProfileAvatar = ({
99
117
  className={rootClassName}
100
118
  style={{ width: px, height: px }}
101
119
  >
120
+ {initialsTile}
102
121
  <SvgImage
103
122
  uri={avatarSource.uri}
104
123
  className={cn('h-full w-full', roundedClass)}
@@ -114,6 +133,7 @@ export const ProfileAvatar = ({
114
133
  className={rootClassName}
115
134
  style={{ width: px, height: px }}
116
135
  >
136
+ {initialsTile}
117
137
  <AvatarImage
118
138
  source={avatarSource}
119
139
  className={cn('h-full w-full', roundedClass)}
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Regression tests for `ui/avatar`'s paint-over guarantee (issue #1666,
3
+ * round-20 review item 2).
4
+ *
5
+ * The avatar underlays (ProfileAvatar / GroupAvatar initials tiles) rely on a
6
+ * *loaded* image covering them: `AvatarImage` must keep a full-size base
7
+ * `className` (`aspect-square h-full w-full`, merged with any passed
8
+ * `className` via the real `cn`/twMerge) and forward `style` to the primitive
9
+ * image. A regression that drops the size classes or `style` renders a loaded
10
+ * image at zero size — leaving only the underlay visible — which silently
11
+ * reintroduces the exact reported symptom. These tests fail on that.
12
+ *
13
+ * `./svg-image` is mocked to a marker so the SVG branch is deterministic
14
+ * (the real `SvgImage` only paints after an async file read); the size
15
+ * `className` under test is computed in `avatar.tsx` and asserted on the prop
16
+ * it passes down. The real `isSvgUrl` (Jest source convention) decides the
17
+ * SVG-vs-raster branch.
18
+ */
19
+
20
+ const React = require('react');
21
+ const ReactTestRenderer = require('react-test-renderer');
22
+
23
+ const MockPrimitiveImage = (props: {
24
+ source?: unknown;
25
+ className?: string;
26
+ style?: unknown;
27
+ }) =>
28
+ React.createElement('PrimitiveImage', {
29
+ source: props.source,
30
+ className: props.className,
31
+ style: props.style,
32
+ });
33
+ const MockSvgImage = (props: {
34
+ uri?: string;
35
+ className?: string;
36
+ resizeMode?: string;
37
+ }) =>
38
+ React.createElement('SvgImage', {
39
+ uri: props.uri,
40
+ className: props.className,
41
+ resizeMode: props.resizeMode,
42
+ });
43
+
44
+ jest.mock('react-native', () => ({ View: 'view', Image: 'image' }));
45
+ jest.mock('@rn-primitives/avatar', () => ({
46
+ Root: 'avatar-root',
47
+ Image: MockPrimitiveImage,
48
+ Fallback: 'avatar-fallback',
49
+ }));
50
+ jest.mock('../../hooks/use-cached-media-uri', () => ({
51
+ useCachedMediaUri: (uri?: string) =>
52
+ uri ? `file:///cache/${uri}` : undefined,
53
+ isLocalMediaUri: () => false,
54
+ }));
55
+ jest.mock('./svg-image', () => ({ SvgImage: MockSvgImage }));
56
+
57
+ // Real merge semantics: the real lib/utils drags in @openpeepshq/common (ESM
58
+ // dist) via its import graph, so recreate cn exactly (clsx + twMerge) here.
59
+ // That is what the assertions exercise — that the full-size base classes
60
+ // survive the real twMerge with the passed className.
61
+ const { clsx } = require('clsx');
62
+ const { twMerge } = require('tailwind-merge');
63
+ jest.mock('../../lib/utils', () => ({
64
+ cn: (...inputs: Array<string | undefined>) => twMerge(clsx(inputs)),
65
+ }));
66
+
67
+ // Real URL helper (mapped through the repo's Jest source convention for
68
+ // `@openpeepshq/react`) — the SVG-vs-raster branch is part of what is pinned.
69
+ jest.mock('@openpeepshq/react', () => ({
70
+ isSvgUrl: require('../../../../react/src/lib/svgCover').isSvgUrl,
71
+ }));
72
+
73
+ const { AvatarImage } = require('./avatar');
74
+
75
+ const renderImage = (props: {
76
+ source?: unknown;
77
+ className?: string;
78
+ style?: unknown;
79
+ }) => {
80
+ let tree: ReturnType<typeof ReactTestRenderer.create>;
81
+ ReactTestRenderer.act(() => {
82
+ tree = ReactTestRenderer.create(React.createElement(AvatarImage, props));
83
+ });
84
+ return tree;
85
+ };
86
+
87
+ describe('ui/avatar AvatarImage size/style pass-through (issue #1666 round-20 #2)', () => {
88
+ it('keeps the full-size base classes, merges the passed className, and forwards style (raster branch)', () => {
89
+ const tree = renderImage({
90
+ source: { uri: 'https://cdn.example/avatars/x.png' },
91
+ className: 'rounded-full',
92
+ style: { width: 40, height: 40 },
93
+ });
94
+ const image = tree.root.findByType('PrimitiveImage');
95
+ // The cached URI (useCachedMediaUri) is what a loaded image renders with.
96
+ expect(image.props.source).toEqual({
97
+ uri: 'file:///cache/https://cdn.example/avatars/x.png',
98
+ });
99
+ // style must reach the primitive image (dropping it regresses the underlay
100
+ // paint-over to a zero-size overlay).
101
+ expect(image.props.style).toEqual({ width: 40, height: 40 });
102
+ // The full-size base classes survive the real cn/twMerge merge with the
103
+ // passed className — nothing size-related is dropped.
104
+ expect(image.props.className).toContain('h-full');
105
+ expect(image.props.className).toContain('w-full');
106
+ expect(image.props.className).toContain('rounded-full');
107
+ expect(tree.root.findAllByType('SvgImage')).toHaveLength(0);
108
+ });
109
+
110
+ it('keeps the full-size base classes and merges the passed className (SVG branch)', () => {
111
+ const tree = renderImage({
112
+ source: { uri: 'https://cdn.example/avatars/x.svg' },
113
+ className: 'rounded-full',
114
+ });
115
+ const svgImage = tree.root.findByType('SvgImage');
116
+ expect(svgImage.props.uri).toBe('https://cdn.example/avatars/x.svg');
117
+ expect(svgImage.props.resizeMode).toBe('cover');
118
+ expect(svgImage.props.className).toContain('h-full');
119
+ expect(svgImage.props.className).toContain('w-full');
120
+ expect(svgImage.props.className).toContain('rounded-full');
121
+ expect(tree.root.findAllByType('PrimitiveImage')).toHaveLength(0);
122
+ });
123
+ });
@@ -0,0 +1,179 @@
1
+ /**
2
+ * RN parity for the community-jam "notify everyone" opt-in in the dedicated
3
+ * New Jam screen (issue #1621, round-13 review suggestion 1): the native
4
+ * `NewJam` screen — the primary jam-creation surface besides the generic event
5
+ * form — must offer the same broadcast opt-in `EventTypeSwitcher` already
6
+ * offers.
7
+ *
8
+ * The screen is a large composite, so every external import is mocked (node
9
+ * jest env, no native modules). The production surface under test is the
10
+ * screen's wiring: it must render the opt-in checkbox only when the shared
11
+ * `useCreateNewJamForm` hook reports `canNotify`, and firing it must call the
12
+ * hook's `setNotifyEveryone` (the checkbox is identified by its
13
+ * `onCheckedChange` identity, since the waiting-room checkbox is always
14
+ * present).
15
+ */
16
+ import { type ReactNode } from 'react';
17
+
18
+ const React = require('react');
19
+ const ReactTestRenderer = require('react-test-renderer');
20
+
21
+ (
22
+ globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }
23
+ ).IS_REACT_ACT_ENVIRONMENT = true;
24
+
25
+ type CheckboxProps = {
26
+ checked?: boolean;
27
+ disabled?: boolean;
28
+ onCheckedChange?: (value: boolean) => void;
29
+ };
30
+
31
+ let checkboxes: CheckboxProps[] = [];
32
+ // The shared hook's return surface, driven per test. The mock reads these at
33
+ // call time (inside a hoisted jest.mock factory), so mutating the object is
34
+ // what changes the render.
35
+ const form = {
36
+ canNotify: false,
37
+ notifyEveryone: false,
38
+ notifyCalls: [] as boolean[],
39
+ setNotifyEveryone: (value: boolean) => {
40
+ form.notifyEveryone = value;
41
+ form.notifyCalls.push(value);
42
+ },
43
+ };
44
+
45
+ jest.mock('react-native', () => {
46
+ const make = (tag: string) => (props: { children?: ReactNode }) =>
47
+ React.createElement(tag, props);
48
+ return { View: make('View'), Text: make('Text') };
49
+ });
50
+
51
+ jest.mock('react-i18next', () => ({
52
+ useTranslation: () => ({ t: (key: string) => key }),
53
+ }));
54
+
55
+ jest.mock('react-native-keyboard-aware-scroll-view', () => ({
56
+ KeyboardAwareScrollView: (props: { children?: ReactNode }) =>
57
+ React.createElement('KeyboardAwareScrollView', null, props.children),
58
+ }));
59
+
60
+ jest.mock('@openpeepshq/react', () => ({
61
+ useCreateNewJamForm: () => ({
62
+ me: undefined,
63
+ postData: { type: 'event', visibility: 'local', data: { type: 'event' } },
64
+ event: {
65
+ name: 'Test jam',
66
+ jam: { notifyEveryone: form.notifyEveryone },
67
+ },
68
+ isAdmin: false,
69
+ submitting: false,
70
+ error: null,
71
+ visibilityDescription: 'local',
72
+ selectedGroupName: undefined,
73
+ selectedModerators: [],
74
+ directAudience: [],
75
+ canNotify: form.canNotify,
76
+ patchEvent: () => undefined,
77
+ setWaitingRoom: () => undefined,
78
+ setNotifyEveryone: form.setNotifyEveryone,
79
+ handleModeratorsChange: () => undefined,
80
+ applyAudience: () => undefined,
81
+ handleCreate: () => undefined,
82
+ handleSchedule: () => undefined,
83
+ }),
84
+ }));
85
+
86
+ jest.mock('../../components/layout', () => ({
87
+ HeaderActionButton: () => React.createElement('HeaderActionButton'),
88
+ useSetPageHeader: () => undefined,
89
+ }));
90
+
91
+ jest.mock('../../components/ui/themed-view', () => ({
92
+ ThemedView: (props: { children?: ReactNode }) =>
93
+ React.createElement('ThemedView', null, props.children),
94
+ }));
95
+
96
+ jest.mock('../../components/icons/index', () => ({
97
+ EyeOnIcon: () => React.createElement('EyeOnIcon'),
98
+ }));
99
+
100
+ jest.mock('../../components/post/post-form/VisibilitySelector', () => ({
101
+ VisibilitySelector: () => React.createElement('VisibilitySelector'),
102
+ }));
103
+
104
+ jest.mock('../../components/profile/ProfilesInput', () => ({
105
+ ProfilesInput: () => React.createElement('ProfilesInput'),
106
+ }));
107
+
108
+ jest.mock('../../components/ui/button', () => ({
109
+ Button: ({ children }: { children?: ReactNode }) =>
110
+ React.createElement('Button', null, children),
111
+ }));
112
+
113
+ jest.mock('../../components/ui/checkbox', () => ({
114
+ Checkbox: (props: CheckboxProps) => {
115
+ checkboxes.push(props);
116
+ return React.createElement('Checkbox', props);
117
+ },
118
+ }));
119
+
120
+ jest.mock('../../components/ui/input', () => ({
121
+ Input: () => React.createElement('Input'),
122
+ }));
123
+
124
+ jest.mock('../../components/ui/label', () => ({
125
+ Label: ({ children }: { children?: unknown }) =>
126
+ React.createElement('Label', null, children),
127
+ }));
128
+
129
+ jest.mock('../../components/ui/themed-text', () => ({
130
+ ThemedText: ({ children }: { children?: unknown }) =>
131
+ React.createElement('ThemedText', null, children),
132
+ }));
133
+
134
+ const { NewJam } = require('./New');
135
+
136
+ // Renders the screen and returns every checkbox it produced.
137
+ const render = () => {
138
+ checkboxes = [];
139
+ ReactTestRenderer.act(() => {
140
+ ReactTestRenderer.create(
141
+ React.createElement(NewJam, { navigation: { goBack: () => undefined } })
142
+ );
143
+ });
144
+ };
145
+
146
+ const notifyCheckbox = () =>
147
+ checkboxes.find((b) => b.onCheckedChange === form.setNotifyEveryone);
148
+
149
+ describe('NewJam community jam broadcast opt-in (RN parity)', () => {
150
+ beforeEach(() => {
151
+ form.canNotify = false;
152
+ form.notifyEveryone = false;
153
+ form.notifyCalls = [];
154
+ });
155
+
156
+ it('shows the opt-in and drives setNotifyEveryone when the hook allows it', () => {
157
+ form.canNotify = true;
158
+ render();
159
+
160
+ const box = notifyCheckbox();
161
+ expect(box).toBeTruthy();
162
+ expect(box!.checked).toBe(false);
163
+
164
+ ReactTestRenderer.act(() => {
165
+ box!.onCheckedChange?.(true);
166
+ });
167
+ expect(form.notifyEveryone).toBe(true);
168
+ expect(form.notifyCalls).toEqual([true]);
169
+ });
170
+
171
+ it('hides the opt-in when the hook reports the creator may not broadcast', () => {
172
+ form.canNotify = false;
173
+ render();
174
+ // The waiting-room checkbox is always present, so exactly one checkbox
175
+ // renders (no opt-in) and none of them is wired to setNotifyEveryone.
176
+ expect(checkboxes.length).toBe(1);
177
+ expect(notifyCheckbox()).toBeFalsy();
178
+ });
179
+ });
@@ -26,8 +26,10 @@ export const NewJam: React.FC<NewJamProps> = ({ navigation }) => {
26
26
  submitting,
27
27
  error,
28
28
  selectedModerators,
29
+ canNotify,
29
30
  patchEvent,
30
31
  setWaitingRoom,
32
+ setNotifyEveryone,
31
33
  handleModeratorsChange,
32
34
  applyAudience,
33
35
  handleCreate,
@@ -95,6 +97,25 @@ export const NewJam: React.FC<NewJamProps> = ({ navigation }) => {
95
97
  </View>
96
98
  </View>
97
99
 
100
+ {canNotify ? (
101
+ <View className="gap-1">
102
+ <View className="flex-row items-start gap-2">
103
+ <View className="pt-0.5">
104
+ <Checkbox
105
+ checked={event.jam?.notifyEveryone ?? false}
106
+ onCheckedChange={setNotifyEveryone}
107
+ />
108
+ </View>
109
+ <ThemedText className="text-sm">
110
+ {t('events.form.jamNotifyEveryone')}
111
+ </ThemedText>
112
+ </View>
113
+ <ThemedText className="text-xs text-muted-foreground pl-6">
114
+ {t('events.form.jamNotifyEveryoneDescription')}
115
+ </ThemedText>
116
+ </View>
117
+ ) : null}
118
+
98
119
  <View className="gap-2">
99
120
  <Label nativeID="jam-moderators">
100
121
  {t('events.form.jamModerators')}