@openpeepshq/rn-components 0.18.0 → 0.20.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.
@@ -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')}