@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.
Files changed (43) hide show
  1. package/package.json +4 -3
  2. package/src/components/buttonOverflow.test.tsx +463 -0
  3. package/src/components/conversations/ConversationParticipantsModal.tsx +1 -6
  4. package/src/components/groups/GroupCard.tsx +26 -23
  5. package/src/components/groups/JoinGroupButton.tsx +7 -2
  6. package/src/components/jams/JamCapacityGate.tsx +9 -1
  7. package/src/components/jams/JamChatDrawer.test.tsx +263 -0
  8. package/src/components/jams/JamChatDrawer.tsx +117 -52
  9. package/src/components/jams/JamConference.tsx +5 -0
  10. package/src/components/jams/JamFooter.tsx +26 -22
  11. package/src/components/jams/JamParticipantConference.tsx +7 -4
  12. package/src/components/jams/JamPeopleDrawer.test.tsx +216 -0
  13. package/src/components/jams/JamPeopleDrawer.tsx +51 -5
  14. package/src/components/jams/JamRequestJoin.tsx +30 -3
  15. package/src/components/jams/JamRoomIndicators.test.tsx +190 -38
  16. package/src/components/jams/JamRoomIndicators.tsx +62 -20
  17. package/src/components/jams/LeaveCloseButton.tsx +5 -1
  18. package/src/components/jams/useTrackSubscriptionBump.test.ts +294 -0
  19. package/src/components/jams/useTrackSubscriptionBump.ts +44 -0
  20. package/src/components/post/feed/events/EventsCalendar.test.tsx +33 -18
  21. package/src/components/post/pieces/ShareMenu.test.tsx +217 -0
  22. package/src/components/post/pieces/ShareMenu.tsx +107 -61
  23. package/src/components/post/post-form/VisibilitySheet.test.tsx +153 -0
  24. package/src/components/post/post-form/VisibilitySheet.tsx +6 -5
  25. package/src/components/post/types/Event.tsx +6 -2
  26. package/src/components/profile/Avatar.test.tsx +147 -0
  27. package/src/components/profile/Avatar.tsx +30 -1
  28. package/src/components/profile/ProfileCard.test.tsx +165 -8
  29. package/src/components/profile/ProfileCard.tsx +63 -10
  30. package/src/components/profile/ProfileSelector.test.tsx +147 -5
  31. package/src/components/profile/ProfileSelector.tsx +64 -18
  32. package/src/components/profile/ProfileWithActionCard.tsx +14 -6
  33. package/src/lib/post.ts +0 -128
  34. package/src/pages/conversations/New.test.tsx +340 -0
  35. package/src/pages/conversations/New.tsx +35 -30
  36. package/src/pages/events/Index.tsx +4 -1
  37. package/src/pages/events/My.tsx +1 -1
  38. package/src/pages/groups/Show.tsx +1 -1
  39. package/src/pages/posts/New.carryover.test.tsx +245 -0
  40. package/src/pages/posts/New.tsx +18 -2
  41. package/src/pages/posts/Reply.tsx +17 -2
  42. package/src/stores/useLocalPostStore.ts +7 -4
  43. package/src/theme/useThemeOpacity.test.ts +70 -0
@@ -0,0 +1,216 @@
1
+ /**
2
+ * Web/native parity pin for the People-drawer `Observers` section (issue #163).
3
+ *
4
+ * The web side of the same section is pinned in
5
+ * `platform/react/.../JamRoomIndicators.test.tsx`; this file pins the React
6
+ * Native `JamPeopleDrawer` so the required parity (AGENTS.md) is enforced on
7
+ * both platforms: the hidden external-session count renders under its own
8
+ * `Observers` heading, placed below the "In jam" heading, and the whole
9
+ * section is hidden while no external sessions are connected.
10
+ *
11
+ * Only the RN surface, livekit and i18n are stubbed. `ThemedText` is the
12
+ * single text primitive the drawer renders through, so the mock records every
13
+ * rendered label in document order (`mockRenderedTexts`) — the assertions read
14
+ * that ordered log instead of walking the rendered tree.
15
+ */
16
+
17
+ const React = require('react');
18
+ const ReactTestRenderer = require('react-test-renderer');
19
+
20
+ // Every label the drawer renders through ThemedText, in document order.
21
+ const mockRenderedTexts: string[] = [];
22
+ let mockSessions = 0;
23
+ const mockParticipants: unknown[] = [];
24
+ let mockIsModerator = false;
25
+ let mockHasWaitingRoom = false;
26
+ let mockWaitingProfiles: unknown[] = [];
27
+
28
+ jest.mock('react-native', () => ({
29
+ View: (props: { children?: unknown }) =>
30
+ React.createElement('View', null, props.children),
31
+ ScrollView: (props: { children?: unknown }) =>
32
+ React.createElement('ScrollView', null, props.children),
33
+ Pressable: (props: { children?: unknown }) =>
34
+ React.createElement('Pressable', null, props.children),
35
+ Text: (props: { children?: unknown }) =>
36
+ React.createElement('Text', null, props.children),
37
+ }));
38
+
39
+ jest.mock('@livekit/react-native', () => ({
40
+ useParticipants: () => mockParticipants,
41
+ useRoomContext: () => ({}),
42
+ useLocalParticipant: () => ({ localParticipant: {} }),
43
+ }));
44
+
45
+ jest.mock('react-i18next', () => ({
46
+ useTranslation: () => ({
47
+ // Values mirror `platform/i18n/src/locales/en.json` (plural branches
48
+ // included) so the rendered copy pins the key/count usage.
49
+ t: (key: string, opts?: Record<string, unknown>) => {
50
+ if (key === 'jams.people.inJam') return 'In jam';
51
+ if (key === 'jams.people.observers') return 'Observers';
52
+ if (key === 'jams.people.inWaitingRoom') return 'Waiting room';
53
+ if (key === 'jams.people.noParticipants') return 'No participants found';
54
+ if (key === 'jams.drawer.peopleTitle') return 'People';
55
+ if (key === 'jams.drawer.close') return 'Close';
56
+ if (key === 'jams.drawer.searchPeoplePlaceholder') return 'Search';
57
+ if (key === 'jams.observers.count') {
58
+ const count = Number(opts?.count ?? 0);
59
+ return count === 1
60
+ ? '1 external observer'
61
+ : `${count} external observers`;
62
+ }
63
+ return key;
64
+ },
65
+ }),
66
+ }));
67
+
68
+ jest.mock('@openpeepshq/react', () => ({
69
+ useJamExternalSessions: () => mockSessions,
70
+ parseParticipantMetadata: () => ({ profile: null }),
71
+ useJamPeople: () => ({
72
+ isModerator: mockIsModerator,
73
+ hasWaitingRoom: mockHasWaitingRoom,
74
+ moderatorIds: [],
75
+ raisedHands: new Set<string>(),
76
+ query: '',
77
+ setQuery: () => {},
78
+ listedParticipants: mockParticipants,
79
+ waitingProfiles: mockWaitingProfiles,
80
+ admittingId: null,
81
+ admit: () => {},
82
+ }),
83
+ }));
84
+
85
+ jest.mock('@openpeepshq/common/lib', () => ({
86
+ profileName: () => 'profile',
87
+ waitingRoomEntryName: () => 'waiting',
88
+ }));
89
+
90
+ jest.mock('../icons/index', () => {
91
+ const make = (name: string) => (props: Record<string, unknown>) =>
92
+ React.createElement(name, props);
93
+ return {
94
+ AudioLinesIcon: make('AudioLinesIcon'),
95
+ EyeOnIcon: make('EyeOnIcon'),
96
+ HandIcon: make('HandIcon'),
97
+ MicIcon: make('MicIcon'),
98
+ MicOffIcon: make('MicOffIcon'),
99
+ SearchIcon: make('SearchIcon'),
100
+ UserRoundCheckIcon: make('UserRoundCheckIcon'),
101
+ WifiOffIcon: make('WifiOffIcon'),
102
+ };
103
+ });
104
+
105
+ jest.mock('../ui/button', () => ({
106
+ Button: (props: { children?: unknown }) =>
107
+ React.createElement('Button', null, props.children),
108
+ }));
109
+
110
+ jest.mock('../ui/input', () => ({
111
+ Input: (props: { children?: unknown }) =>
112
+ React.createElement('Input', null, props.children),
113
+ }));
114
+
115
+ jest.mock('../profile/Avatar', () => ({
116
+ ProfileAvatar: () => React.createElement('ProfileAvatar'),
117
+ }));
118
+
119
+ jest.mock('../../lib/utils', () => ({
120
+ cn: (...classes: unknown[]) => classes.filter(Boolean).join(' '),
121
+ }));
122
+
123
+ // The drawer shell adds only chrome (title + close); the Observers section
124
+ // lives in the ScrollView content, so a passthrough keeps the assertions on
125
+ // the content that matters.
126
+ jest.mock('./JamDrawer', () => ({
127
+ JamDrawer: (props: { children?: unknown }) =>
128
+ React.createElement('JamDrawer', null, props.children),
129
+ }));
130
+
131
+ jest.mock('./useParticipantConnection', () => ({
132
+ useConnectionLost: () => false,
133
+ useConnectionQuality: () => 1,
134
+ }));
135
+
136
+ jest.mock('../ui/themed-text', () => ({
137
+ ThemedText: (props: { children?: unknown; className?: string }) => {
138
+ const c = props.children;
139
+ if (typeof c === 'string' && c) mockRenderedTexts.push(c);
140
+ else if (Array.isArray(c)) {
141
+ for (const part of c) {
142
+ if (typeof part === 'string' && part) mockRenderedTexts.push(part);
143
+ }
144
+ }
145
+ return React.createElement('ThemedText', { className: props.className }, c);
146
+ },
147
+ }));
148
+
149
+ const { JamPeopleDrawer } = require('./JamPeopleDrawer');
150
+
151
+ const renderDrawer = (sessions: number, waitingRoom: boolean = false) => {
152
+ mockSessions = sessions;
153
+ mockIsModerator = waitingRoom;
154
+ mockHasWaitingRoom = waitingRoom;
155
+ mockWaitingProfiles = waitingRoom ? [{ id: 'w1' }] : [];
156
+ mockRenderedTexts.length = 0;
157
+ let tree!: ReactTestRenderer.ReactTestRenderer;
158
+ ReactTestRenderer.act(() => {
159
+ tree = ReactTestRenderer.create(
160
+ React.createElement(JamPeopleDrawer, { open: true, onClose: () => {} })
161
+ );
162
+ });
163
+ return tree;
164
+ };
165
+
166
+ describe('JamPeopleDrawer observers section (RN)', () => {
167
+ it('renders the external-session count under its own heading below "In jam"', () => {
168
+ renderDrawer(2);
169
+ const texts = mockRenderedTexts;
170
+
171
+ expect(texts).toContain('In jam');
172
+ expect(texts).toContain('Observers');
173
+ expect(texts).toContain('2 external observers');
174
+ // The Observers section sits below the "In jam" section (document order).
175
+ expect(texts.indexOf('In jam')).toBeLessThan(texts.indexOf('Observers'));
176
+ });
177
+
178
+ it('pins the Observers section between "In jam" and the waiting room', () => {
179
+ // The web twin asserts the Observers heading's document position after
180
+ // "In jam"; this pins the RN placement on both bounds (the lower bound
181
+ // needs the waiting room rendered) so the section cannot be moved past it
182
+ // — the web/native parity the earlier rounds established for this drawer.
183
+ renderDrawer(2, true);
184
+ const texts = mockRenderedTexts;
185
+
186
+ expect(texts).toContain('In jam');
187
+ expect(texts).toContain('Observers');
188
+ expect(texts).toContain('2 external observers');
189
+ expect(texts).toContain('Waiting room');
190
+ // The count row follows its own heading…
191
+ expect(texts.indexOf('Observers')).toBeLessThan(
192
+ texts.indexOf('2 external observers')
193
+ );
194
+ // …and the whole Observers section sits between "In jam" and the
195
+ // waiting room (document order), mirroring the web drawer.
196
+ expect(texts.indexOf('In jam')).toBeLessThan(texts.indexOf('Observers'));
197
+ expect(texts.indexOf('2 external observers')).toBeLessThan(
198
+ texts.indexOf('Waiting room')
199
+ );
200
+ });
201
+
202
+ it('renders the singular count for one connected session', () => {
203
+ renderDrawer(1);
204
+ expect(mockRenderedTexts).toContain('Observers');
205
+ expect(mockRenderedTexts).toContain('1 external observer');
206
+ });
207
+
208
+ it('hides the Observers section while "In jam" still renders', () => {
209
+ renderDrawer(0);
210
+ const texts = mockRenderedTexts;
211
+
212
+ expect(texts).toContain('In jam');
213
+ expect(texts).not.toContain('Observers');
214
+ expect(texts).not.toContain('external observer');
215
+ });
216
+ });
@@ -3,10 +3,16 @@ import { ScrollView, View } from 'react-native';
3
3
  import { useParticipants, useRoomContext } from '@livekit/react-native';
4
4
  import type { Participant } from 'livekit-client';
5
5
  import { useTranslation } from 'react-i18next';
6
- import { profileName } from '@openpeepshq/common/lib';
7
- import { parseParticipantMetadata, useJamPeople } from '@openpeepshq/react';
6
+ import { profileName, waitingRoomEntryName } from '@openpeepshq/common/lib';
7
+ import type { JamWaitingProfile } from '@openpeepshq/common';
8
+ import {
9
+ parseParticipantMetadata,
10
+ useJamExternalSessions,
11
+ useJamPeople,
12
+ } from '@openpeepshq/react';
8
13
  import {
9
14
  AudioLinesIcon,
15
+ EyeOnIcon,
10
16
  HandIcon,
11
17
  MicIcon,
12
18
  MicOffIcon,
@@ -85,14 +91,37 @@ const JamParticipantRow = ({
85
91
  );
86
92
  };
87
93
 
94
+ /**
95
+ * "Observers" section: hidden external sessions (observer links,
96
+ * recording/RTMP egress) never appear as rows in "In jam", so their presence
97
+ * is reported as a labeled count. Persists after the banner is dismissed.
98
+ */
99
+ const JamObserversSection = ({ count }: { count: number }) => {
100
+ const { t } = useTranslation();
101
+ if (count <= 0) return null;
102
+ return (
103
+ <View>
104
+ <SectionHeading>{t('jams.people.observers')}</SectionHeading>
105
+ <View className="mt-1 flex-row items-center gap-2">
106
+ <EyeOnIcon size={16} className="shrink-0 text-muted-foreground" />
107
+ <ThemedText numberOfLines={1} className="shrink text-sm">
108
+ {t('jams.observers.count', { count })}
109
+ </ThemedText>
110
+ </View>
111
+ </View>
112
+ );
113
+ };
114
+
88
115
  /**
89
116
  * In-room participants list with mic / raised-hand / moderator indicators,
90
- * plus a moderator-only waiting-room admit section.
117
+ * plus a moderator-only waiting-room admit section and the hidden
118
+ * external-session count.
91
119
  */
92
120
  export const JamPeopleDrawer = ({ open, onClose }: JamPeopleDrawerProps) => {
93
121
  const { t } = useTranslation();
94
122
  const room = useRoomContext();
95
123
  const participants = useParticipants();
124
+ const externalSessions = useJamExternalSessions();
96
125
  const {
97
126
  isModerator,
98
127
  hasWaitingRoom,
@@ -148,6 +177,8 @@ export const JamPeopleDrawer = ({ open, onClose }: JamPeopleDrawerProps) => {
148
177
  </View>
149
178
  </View>
150
179
 
180
+ <JamObserversSection count={externalSessions} />
181
+
151
182
  {isModerator && hasWaitingRoom && waitingProfiles.length > 0 ? (
152
183
  <View>
153
184
  <SectionHeading>{t('jams.people.inWaitingRoom')}</SectionHeading>
@@ -158,9 +189,9 @@ export const JamPeopleDrawer = ({ open, onClose }: JamPeopleDrawerProps) => {
158
189
  className="flex-row items-center justify-between gap-2"
159
190
  >
160
191
  <View className="min-w-0 flex-1 flex-row items-center gap-2">
161
- <ProfileAvatar profile={profile} className="size-8" />
192
+ <WaitingRoomAvatar profile={profile} />
162
193
  <ThemedText numberOfLines={1} className="shrink text-sm">
163
- {profileName(profile)}
194
+ {waitingRoomEntryName(profile)}
164
195
  </ThemedText>
165
196
  </View>
166
197
  <Button
@@ -181,3 +212,18 @@ export const JamPeopleDrawer = ({ open, onClose }: JamPeopleDrawerProps) => {
181
212
  </JamDrawer>
182
213
  );
183
214
  };
215
+
216
+ /**
217
+ * Waiting-room entries carry only a display name (no avatar/handle), so the
218
+ * initials fallback renders a stable, honest placeholder.
219
+ */
220
+ function WaitingRoomAvatar({ profile }: { profile: JamWaitingProfile }) {
221
+ // Initials-avatar input: only the name matters, so narrow instead of
222
+ // widening a queue entry to a full Profile.
223
+ return (
224
+ <ProfileAvatar
225
+ profile={{ displayName: waitingRoomEntryName(profile) }}
226
+ className="size-8"
227
+ />
228
+ );
229
+ }
@@ -1,10 +1,12 @@
1
- import React, { useState } from 'react';
1
+ import React, { useCallback, useState } from 'react';
2
2
  import { View } from 'react-native';
3
3
  import { useTranslation } from 'react-i18next';
4
4
  import {
5
+ apiErrorMessage,
5
6
  type JamJoinParams,
6
7
  useJoinWaitingRoomToken,
7
8
  } from '@openpeepshq/react';
9
+ import type { SseError } from '@openpeepshq/fetch-client';
8
10
  import { Button } from '../ui/button';
9
11
  import { ThemedText } from '../ui/themed-text';
10
12
 
@@ -17,8 +19,33 @@ const JamWaitingRoomListener = ({
17
19
  }: {
18
20
  onJoin: JamRequestJoinProps['onJoin'];
19
21
  }) => {
20
- useJoinWaitingRoomToken(onJoin);
21
- return null;
22
+ const { t } = useTranslation();
23
+ const [error, setError] = useState<string | null>(null);
24
+
25
+ // The error state is not terminal: when the token is delivered (a fresh
26
+ // stream after a reconnection or a moderator admission), the stale error
27
+ // must not sit behind the recovered stream.
28
+ const joinAndClearError = useCallback(
29
+ (params: JamJoinParams) => {
30
+ setError(null);
31
+ onJoin(params);
32
+ },
33
+ [onJoin]
34
+ );
35
+
36
+ useJoinWaitingRoomToken(joinAndClearError, (e?: SseError) => {
37
+ // Reuse the shared key→message mapping (`errorKey ?? key`, translate
38
+ // `error.*` keys). The SSE path passes an empty fallback so a keyless,
39
+ // message-less error renders nothing rather than a generic "Error".
40
+ const message = apiErrorMessage(e, t, '');
41
+ setError(message.length > 0 ? message : null);
42
+ });
43
+
44
+ return error ? (
45
+ <ThemedText className="text-center text-sm text-destructive">
46
+ {error}
47
+ </ThemedText>
48
+ ) : null;
22
49
  };
23
50
 
24
51
  export const JamRequestJoin = ({ onJoin }: JamRequestJoinProps) => {
@@ -21,25 +21,48 @@ const ReactTestRenderer = require('react-test-renderer');
21
21
 
22
22
  const { mapColors } = require('../../theme/defaults');
23
23
 
24
- const mockViewProps: Array<{ style?: unknown; className?: string }> = [];
24
+ const mockViewProps: Array<{
25
+ style?: unknown;
26
+ className?: string;
27
+ pointerEvents?: string;
28
+ }> = [];
29
+ const mockPressableProps: Array<{
30
+ accessibilityLabel?: string;
31
+ onPress?: () => void;
32
+ }> = [];
25
33
  let mockQuality = 1; // livekit-client ConnectionQuality.Good
26
34
  let mockIsDark = false;
27
35
  let mockSessions = 0;
28
36
  let mockSafeAreaTop = 36; // a typical status-bar inset
37
+ let mockIsRecording = false;
29
38
 
30
39
  jest.mock('react-native', () => {
31
40
  const View = (props: {
32
41
  style?: unknown;
33
42
  className?: string;
43
+ pointerEvents?: string;
34
44
  children?: unknown;
35
45
  }) => {
36
- mockViewProps.push({ style: props.style, className: props.className });
46
+ mockViewProps.push({
47
+ style: props.style,
48
+ className: props.className,
49
+ pointerEvents: props.pointerEvents,
50
+ });
37
51
  return React.createElement('View', null, props.children);
38
52
  };
39
53
  const Text = (props: { children?: unknown }) =>
40
54
  React.createElement('Text', null, props.children);
41
- const Pressable = (props: { children?: unknown }) =>
42
- React.createElement('Pressable', null, props.children);
55
+ const Pressable = (props: {
56
+ accessibilityLabel?: string;
57
+ onPress?: () => void;
58
+ children?: unknown;
59
+ }) => {
60
+ mockPressableProps.push({
61
+ accessibilityLabel: props.accessibilityLabel,
62
+ onPress: props.onPress,
63
+ });
64
+ return React.createElement('Pressable', null, props.children);
65
+ };
43
66
  return { View, Text, Pressable };
44
67
  });
45
68
 
@@ -53,19 +76,26 @@ jest.mock('livekit-client', () => ({
53
76
 
54
77
  jest.mock('react-i18next', () => ({
55
78
  useTranslation: () => ({
56
- // Plural branches mirror `jams.observers.present` in en.json, so the
79
+ // Plural branches mirror `jams.observers.connected` in en.json, so the
57
80
  // rendered text pins both the key/count usage and the plural choice.
58
81
  t: (key: string, opts?: Record<string, unknown>) => {
59
- if (key === 'jams.observers.present') {
82
+ if (key === 'jams.observers.connected') {
60
83
  const count = Number(opts?.count ?? 0);
61
84
  const text =
62
85
  count === 1
63
- ? '{{count}} external session is connected to this jam'
64
- : '{{count}} external sessions are connected to this jam';
86
+ ? '{{count}} external observer is connected to this jam'
87
+ : '{{count}} external observers are connected to this jam';
65
88
  return text.replace(/\{\{(\w+)\}\}/g, (_m: string, n: string) =>
66
89
  String(opts?.[n] ?? '')
67
90
  );
68
91
  }
92
+ // The dismiss label resolves to the real shipped copy (require is used
93
+ // in-line because the jest.mock factory is hoisted above top-level consts),
94
+ // so a dropped `jams.observers.dismiss` key breaks the assertion below.
95
+ if (key === 'jams.observers.dismiss') {
96
+ return require('../../../../i18n/src/locales/en.json').jams.observers
97
+ .dismiss;
98
+ }
69
99
  return key.replace(/\{\{(\w+)\}\}/g, (_m: string, n: string) =>
70
100
  String(opts?.[n] ?? '')
71
101
  );
@@ -74,7 +104,7 @@ jest.mock('react-i18next', () => ({
74
104
  }));
75
105
 
76
106
  jest.mock('@openpeepshq/react', () => ({
77
- useJamRecordingState: () => ({ isRecording: false }),
107
+ useJamRecordingState: () => ({ isRecording: mockIsRecording }),
78
108
  useJamRecordingElapsed: () => null,
79
109
  useJamExternalSessions: () => mockSessions,
80
110
  }));
@@ -82,7 +112,6 @@ jest.mock('@openpeepshq/react', () => ({
82
112
  jest.mock('react-native-safe-area-context', () => ({
83
113
  useSafeAreaInsets: () => ({ top: mockSafeAreaTop, bottom: 0 }),
84
114
  }));
85
-
86
115
  jest.mock('../icons/index', () => ({
87
116
  CircleIcon: () => React.createElement('CircleIcon'),
88
117
  EyeOnIcon: () => React.createElement('EyeOnIcon'),
@@ -115,9 +144,17 @@ jest.mock('./useParticipantConnection', () => ({
115
144
 
116
145
  const {
117
146
  JamNetworkQuality,
118
- JamObserverIndicator,
147
+ JamObserverBanner,
148
+ JamRecordingIndicator,
149
+ JamsBannerStack,
119
150
  } = require('./JamRoomIndicators');
120
151
 
152
+ // Real shipped locale, so the dismiss-copy assertion pins the value the user
153
+ // actually sees rather than the raw key path (a dropped key breaks the test).
154
+ const en = require('../../../../i18n/src/locales/en.json') as {
155
+ jams: { observers: { dismiss: string } };
156
+ };
157
+
121
158
  const renderQuality = (quality: number, isDark: boolean) => {
122
159
  mockViewProps.length = 0;
123
160
  mockQuality = quality;
@@ -129,18 +166,21 @@ const renderQuality = (quality: number, isDark: boolean) => {
129
166
  return { tree, banner: mockViewProps[mockViewProps.length - 1] };
130
167
  };
131
168
 
132
- const renderObserverPill = (sessions: number, safeAreaTop: number) => {
169
+ const renderObserverBanner = (sessions: number, safeAreaTop: number) => {
133
170
  mockViewProps.length = 0;
171
+ mockPressableProps.length = 0;
134
172
  mockSessions = sessions;
135
173
  mockSafeAreaTop = safeAreaTop;
136
174
  let tree!: ReactTestRenderer.ReactTestRenderer;
137
175
  ReactTestRenderer.act(() => {
138
- tree = ReactTestRenderer.create(React.createElement(JamObserverIndicator));
176
+ tree = ReactTestRenderer.create(React.createElement(JamObserverBanner));
139
177
  });
140
178
  const texts = tree.root.findAllByType('ThemedText');
141
179
  return {
142
- pill: mockViewProps[mockViewProps.length - 1],
180
+ tree,
181
+ banner: mockViewProps[mockViewProps.length - 1],
143
182
  renderedText: texts.length ? texts[0].children.join('') : null,
183
+ dismiss: mockPressableProps[mockPressableProps.length - 1],
144
184
  };
145
185
  };
146
186
 
@@ -181,39 +221,151 @@ describe('JamNetworkQuality banner background', () => {
181
221
  });
182
222
  });
183
223
 
184
- describe('JamObserverIndicator pill', () => {
224
+ describe('JamObserverBanner', () => {
185
225
  it('renders nothing when no external sessions are connected', () => {
186
- const { pill, renderedText } = renderObserverPill(0, 36);
187
- expect(pill).toBeUndefined();
226
+ const { banner, renderedText } = renderObserverBanner(0, 36);
227
+ expect(banner).toBeUndefined();
188
228
  expect(renderedText).toBeNull();
189
229
  });
190
230
 
191
- it('renders the singular copy with the inline primary background and a safe-area-aware top when one session is connected', () => {
231
+ it('renders the singular copy with a lower-contrast surface background when one session is connected', () => {
192
232
  mockIsDark = false;
193
- const { pill, renderedText } = renderObserverPill(1, 36);
194
-
195
- expect(renderedText).toBe('1 external session is connected to this jam');
196
- expect(pill).toBeDefined();
197
- // The pill background is the real primary color at 0.9 opacity (inline
198
- // rgba, not a NativeWind `/90` class) and clears the safe-area top
199
- // inset plus a 16px margin; pinned against the shipped light primary
200
- // (#16161a).
201
- expect(pill!.style).toEqual([
202
- { top: 52, right: 16 },
203
- { backgroundColor: 'rgba(22, 22, 26, 0.9)' },
204
- ]);
205
- // Positioning lives in the inline style; the magic `top-14` class must
206
- // not come back.
207
- expect(pill!.className).not.toContain('top-14');
233
+ const { banner, renderedText } = renderObserverBanner(1, 36);
234
+
235
+ expect(renderedText).toBe('1 external observer is connected to this jam');
236
+ expect(banner).toBeDefined();
237
+ // The banner background is the real surface-2 color at 0.9 opacity
238
+ // (inline rgba, not a NativeWind `/90` class); pinned against the
239
+ // shipped light surface-2 (#e4e4e7). The style is a plain object (the
240
+ // component passes `style={background('surface-2', 0.9)}`, no
241
+ // positioning array — positioning lives on the shared `JamsBannerStack`,
242
+ // mirroring the stack-level sibling assertions below).
243
+ expect(banner!.style).toEqual({
244
+ backgroundColor: 'rgba(228, 228, 231, 0.9)',
245
+ });
246
+ expect(banner!.className).not.toContain('absolute');
247
+ expect(banner!.className).not.toContain('top-');
248
+ // The old high-saturation primary pill must not come back.
249
+ expect(banner!.style).not.toEqual(
250
+ expect.arrayContaining([
251
+ expect.objectContaining({
252
+ backgroundColor: 'rgba(22, 22, 26, 0.9)',
253
+ }),
254
+ ])
255
+ );
208
256
  });
209
257
 
210
258
  it('renders the plural copy when two sessions are connected', () => {
211
- const { renderedText } = renderObserverPill(2, 0);
212
- expect(renderedText).toBe('2 external sessions are connected to this jam');
259
+ const { renderedText } = renderObserverBanner(2, 0);
260
+ expect(renderedText).toBe('2 external observers are connected to this jam');
213
261
  });
214
262
 
215
- it('adapts the top offset to the device safe-area inset', () => {
216
- const { pill } = renderObserverPill(1, 59); // large status-bar inset
217
- expect((pill!.style as Array<{ top?: number }>)[0].top).toBe(59 + 16);
263
+ it('adapts the stack top offset to the device safe-area inset and keeps the banners from positioning themselves', () => {
264
+ mockViewProps.length = 0;
265
+ mockPressableProps.length = 0;
266
+ mockQuality = 2; // ConnectionQuality.Poor — both banners visible
267
+ mockIsDark = false;
268
+ mockSessions = 2;
269
+ mockSafeAreaTop = 59; // large status-bar inset
270
+ ReactTestRenderer.act(() => {
271
+ ReactTestRenderer.create(
272
+ React.createElement(
273
+ JamsBannerStack,
274
+ null,
275
+ React.createElement(JamNetworkQuality),
276
+ React.createElement(JamObserverBanner)
277
+ )
278
+ );
279
+ });
280
+
281
+ // First recorded View is the stack: it owns the safe-area top offset
282
+ // (inset + 16px, the original `top-4` below the safe area) and the
283
+ // edge-to-edge horizontal positioning — the banners inside it do not.
284
+ const [stack, network, observer] = mockViewProps;
285
+ expect(stack.style).toEqual({ top: 59 + 16 });
286
+ expect(stack.className).toContain('left-4');
287
+ expect(stack.className).toContain('right-4');
288
+ expect(network.style).toEqual({
289
+ backgroundColor: 'rgba(244, 244, 245, 0.9)',
290
+ });
291
+ expect(observer.style).toEqual({
292
+ backgroundColor: 'rgba(228, 228, 231, 0.9)',
293
+ });
294
+ for (const banner of [network, observer]) {
295
+ expect(banner.className).not.toContain('absolute');
296
+ expect(banner.className).not.toContain('top-');
297
+ }
298
+ });
299
+
300
+ it('keeps the recording pill top-left inside the shared stack without self-positioning', () => {
301
+ mockViewProps.length = 0;
302
+ mockIsRecording = true;
303
+ mockSafeAreaTop = 36;
304
+ ReactTestRenderer.act(() => {
305
+ ReactTestRenderer.create(
306
+ React.createElement(
307
+ JamsBannerStack,
308
+ null,
309
+ React.createElement(JamRecordingIndicator)
310
+ )
311
+ );
312
+ });
313
+ mockIsRecording = false;
314
+
315
+ // First recorded View is the stack (it owns the safe-area top offset)…
316
+ const [stack, pill] = mockViewProps;
317
+ expect(stack.style).toEqual({ top: 36 + 16 });
318
+ // …and the pill keeps its deliberate top-left placement *within* the
319
+ // stack, mirroring the web pill: `self-start` pulls it to the start edge,
320
+ // `ml-4` insets it.
321
+ expect(pill.className).toContain('self-start');
322
+ expect(pill.className).toContain('ml-4');
323
+ // It must NOT bring its own fixed/top positioning — the stack owns the top
324
+ // offset, and a stray `absolute`/`top-*` here would break the stacking.
325
+ expect(pill.className).not.toContain('absolute');
326
+ expect(pill.className).not.toContain('top-');
327
+ expect((pill.style as { top?: number }).top).toBeUndefined();
328
+ });
329
+
330
+ it('hides the banner for the session when the close button is pressed', () => {
331
+ const { tree, banner, dismiss } = renderObserverBanner(1, 36);
332
+ expect(banner).toBeDefined();
333
+ expect(dismiss).toBeDefined();
334
+ // The dismiss control is discoverable by the shipped locale copy, not just
335
+ // the raw key path — this would fail if `jams.observers.dismiss` were dropped.
336
+ expect(dismiss!.accessibilityLabel).toBe(en.jams.observers.dismiss);
337
+
338
+ ReactTestRenderer.act(() => {
339
+ dismiss!.onPress!();
340
+ });
341
+ // The sessions are still connected (mockSessions unchanged), but the
342
+ // dismissal state lives in the banner component, so the same tree
343
+ // renders nothing for the duration of the visit.
344
+ expect(mockSessions).toBe(1);
345
+ expect(tree.root.findAllByType('ThemedText')).toHaveLength(0);
346
+ });
347
+
348
+ it('keeps the banner hidden when the last session disconnects after dismissal', () => {
349
+ // Dedicated auto-hide branch: the `sessions <= 0` exit condition is
350
+ // exercised on the same instance that already dismissed (the block
351
+ // above pins the `dismissed` flag with sessions still > 0). The count
352
+ // dropping to zero while dismissed must not re-surface the banner —
353
+ // mirrored on the web twin, which commits the same re-render.
354
+ const { tree, dismiss } = renderObserverBanner(1, 36);
355
+ expect(dismiss).toBeDefined();
356
+
357
+ ReactTestRenderer.act(() => {
358
+ dismiss!.onPress!();
359
+ });
360
+
361
+ // The last session disconnects while the banner is already dismissed.
362
+ // `tree.update` re-renders the *same* component instance (the `dismissed`
363
+ // state is preserved), matching the web twin's post-dismiss `rerender`.
364
+ mockSessions = 0;
365
+ ReactTestRenderer.act(() => {
366
+ tree.update(React.createElement(JamObserverBanner));
367
+ });
368
+ expect(mockSessions).toBe(0);
369
+ expect(tree.root.findAllByType('ThemedText')).toHaveLength(0);
218
370
  });
219
371
  });