@oxy.so/services 14.15.1 → 14.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/lib/commonjs/index.js +18 -0
  2. package/lib/commonjs/index.js.map +1 -1
  3. package/lib/commonjs/ui/components/setupFlow/OxySetupFlow.js +272 -0
  4. package/lib/commonjs/ui/components/setupFlow/OxySetupFlow.js.map +1 -0
  5. package/lib/commonjs/ui/components/setupFlow/oxySignInStep.js +34 -0
  6. package/lib/commonjs/ui/components/setupFlow/oxySignInStep.js.map +1 -0
  7. package/lib/commonjs/ui/components/signIn/OxyAuthScreen.js +21 -7
  8. package/lib/commonjs/ui/components/signIn/OxyAuthScreen.js.map +1 -1
  9. package/lib/commonjs/ui/components/signIn/OxySignInPanel.js +27 -2
  10. package/lib/commonjs/ui/components/signIn/OxySignInPanel.js.map +1 -1
  11. package/lib/commonjs/ui/components/signIn/OxySignUpPanel.js +3 -1
  12. package/lib/commonjs/ui/components/signIn/OxySignUpPanel.js.map +1 -1
  13. package/lib/commonjs/ui/components/signIn/ReauthStep.js +21 -0
  14. package/lib/commonjs/ui/components/signIn/ReauthStep.js.map +1 -1
  15. package/lib/commonjs/ui/context/OxyContext.js +18 -5
  16. package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
  17. package/lib/commonjs/ui/session/deviceCredentialTracker.js +4 -2
  18. package/lib/commonjs/ui/session/deviceCredentialTracker.js.map +1 -1
  19. package/lib/commonjs/ui/session/setupSignIn.js +6 -0
  20. package/lib/commonjs/ui/session/setupSignIn.js.map +1 -0
  21. package/lib/module/index.js +5 -1
  22. package/lib/module/index.js.map +1 -1
  23. package/lib/module/ui/components/setupFlow/OxySetupFlow.js +269 -0
  24. package/lib/module/ui/components/setupFlow/OxySetupFlow.js.map +1 -0
  25. package/lib/module/ui/components/setupFlow/oxySignInStep.js +29 -0
  26. package/lib/module/ui/components/setupFlow/oxySignInStep.js.map +1 -0
  27. package/lib/module/ui/components/signIn/OxyAuthScreen.js +22 -8
  28. package/lib/module/ui/components/signIn/OxyAuthScreen.js.map +1 -1
  29. package/lib/module/ui/components/signIn/OxySignInPanel.js +27 -2
  30. package/lib/module/ui/components/signIn/OxySignInPanel.js.map +1 -1
  31. package/lib/module/ui/components/signIn/OxySignUpPanel.js +3 -1
  32. package/lib/module/ui/components/signIn/OxySignUpPanel.js.map +1 -1
  33. package/lib/module/ui/components/signIn/ReauthStep.js +22 -1
  34. package/lib/module/ui/components/signIn/ReauthStep.js.map +1 -1
  35. package/lib/module/ui/context/OxyContext.js +18 -5
  36. package/lib/module/ui/context/OxyContext.js.map +1 -1
  37. package/lib/module/ui/session/deviceCredentialTracker.js +4 -2
  38. package/lib/module/ui/session/deviceCredentialTracker.js.map +1 -1
  39. package/lib/module/ui/session/setupSignIn.js +4 -0
  40. package/lib/module/ui/session/setupSignIn.js.map +1 -0
  41. package/lib/typescript/commonjs/index.d.ts +5 -0
  42. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  43. package/lib/typescript/commonjs/ui/components/setupFlow/OxySetupFlow.d.ts +88 -0
  44. package/lib/typescript/commonjs/ui/components/setupFlow/OxySetupFlow.d.ts.map +1 -0
  45. package/lib/typescript/commonjs/ui/components/setupFlow/oxySignInStep.d.ts +23 -0
  46. package/lib/typescript/commonjs/ui/components/setupFlow/oxySignInStep.d.ts.map +1 -0
  47. package/lib/typescript/commonjs/ui/components/signIn/OxyAuthScreen.d.ts +12 -3
  48. package/lib/typescript/commonjs/ui/components/signIn/OxyAuthScreen.d.ts.map +1 -1
  49. package/lib/typescript/commonjs/ui/components/signIn/OxySignInPanel.d.ts.map +1 -1
  50. package/lib/typescript/commonjs/ui/components/signIn/ReauthStep.d.ts +2 -1
  51. package/lib/typescript/commonjs/ui/components/signIn/ReauthStep.d.ts.map +1 -1
  52. package/lib/typescript/commonjs/ui/context/OxyContext.d.ts.map +1 -1
  53. package/lib/typescript/commonjs/ui/context/oxyContextTypes.d.ts +10 -3
  54. package/lib/typescript/commonjs/ui/context/oxyContextTypes.d.ts.map +1 -1
  55. package/lib/typescript/commonjs/ui/icons/Ionicons.d.ts +1 -1
  56. package/lib/typescript/commonjs/ui/icons/MaterialCommunityIcons.d.ts +1 -1
  57. package/lib/typescript/commonjs/ui/session/deviceCredentialTracker.d.ts +3 -12
  58. package/lib/typescript/commonjs/ui/session/deviceCredentialTracker.d.ts.map +1 -1
  59. package/lib/typescript/commonjs/ui/session/setupSignIn.d.ts +38 -0
  60. package/lib/typescript/commonjs/ui/session/setupSignIn.d.ts.map +1 -0
  61. package/lib/typescript/commonjs/ui/types/navigation.d.ts +7 -3
  62. package/lib/typescript/commonjs/ui/types/navigation.d.ts.map +1 -1
  63. package/lib/typescript/module/index.d.ts +5 -0
  64. package/lib/typescript/module/index.d.ts.map +1 -1
  65. package/lib/typescript/module/ui/components/setupFlow/OxySetupFlow.d.ts +88 -0
  66. package/lib/typescript/module/ui/components/setupFlow/OxySetupFlow.d.ts.map +1 -0
  67. package/lib/typescript/module/ui/components/setupFlow/oxySignInStep.d.ts +23 -0
  68. package/lib/typescript/module/ui/components/setupFlow/oxySignInStep.d.ts.map +1 -0
  69. package/lib/typescript/module/ui/components/signIn/OxyAuthScreen.d.ts +12 -3
  70. package/lib/typescript/module/ui/components/signIn/OxyAuthScreen.d.ts.map +1 -1
  71. package/lib/typescript/module/ui/components/signIn/OxySignInPanel.d.ts.map +1 -1
  72. package/lib/typescript/module/ui/components/signIn/ReauthStep.d.ts +2 -1
  73. package/lib/typescript/module/ui/components/signIn/ReauthStep.d.ts.map +1 -1
  74. package/lib/typescript/module/ui/context/OxyContext.d.ts.map +1 -1
  75. package/lib/typescript/module/ui/context/oxyContextTypes.d.ts +10 -3
  76. package/lib/typescript/module/ui/context/oxyContextTypes.d.ts.map +1 -1
  77. package/lib/typescript/module/ui/icons/Ionicons.d.ts +1 -1
  78. package/lib/typescript/module/ui/icons/MaterialCommunityIcons.d.ts +1 -1
  79. package/lib/typescript/module/ui/session/deviceCredentialTracker.d.ts +3 -12
  80. package/lib/typescript/module/ui/session/deviceCredentialTracker.d.ts.map +1 -1
  81. package/lib/typescript/module/ui/session/setupSignIn.d.ts +38 -0
  82. package/lib/typescript/module/ui/session/setupSignIn.d.ts.map +1 -0
  83. package/lib/typescript/module/ui/types/navigation.d.ts +7 -3
  84. package/lib/typescript/module/ui/types/navigation.d.ts.map +1 -1
  85. package/package.json +4 -4
  86. package/src/index.ts +17 -0
  87. package/src/ui/components/setupFlow/OxySetupFlow.tsx +339 -0
  88. package/src/ui/components/setupFlow/__tests__/OxySetupFlow.test.tsx +312 -0
  89. package/src/ui/components/setupFlow/oxySignInStep.tsx +32 -0
  90. package/src/ui/components/signIn/OxyAuthScreen.tsx +30 -7
  91. package/src/ui/components/signIn/OxySignInPanel.tsx +22 -2
  92. package/src/ui/components/signIn/OxySignUpPanel.tsx +1 -1
  93. package/src/ui/components/signIn/ReauthStep.tsx +26 -1
  94. package/src/ui/context/OxyContext.tsx +26 -5
  95. package/src/ui/context/oxyContextTypes.ts +11 -3
  96. package/src/ui/session/deviceCredentialTracker.ts +10 -5
  97. package/src/ui/session/setupSignIn.ts +41 -0
  98. package/src/ui/types/navigation.ts +7 -3
@@ -0,0 +1,339 @@
1
+ /**
2
+ * A platform's setup, in the SDK sign-in's own frame: the host's steps and the
3
+ * SDK's sign-in (`oxySignInStep`) one after another on one card, as macOS's
4
+ * Setup Assistant walks Welcome → Apple Account → … → Done (oxy ADR 0064,
5
+ * OxyOS ADR 0020).
6
+ *
7
+ * Controlled and presentational: the host owns which steps apply, which one is
8
+ * current and what every action does; this draws them.
9
+ *
10
+ * step the sign-in's shell (`OxyAuthScreen`): the step's icon or the Oxy
11
+ * mark (56), its title (48/800) and description (18), its content,
12
+ * blocks 24 apart, at most 448 wide. A step with an `aside` is the
13
+ * split card from `md` (`OxyAuthSplit`), asking its surface for 880
14
+ * as the sign-in's QR side does. A step without a title is drawn as
15
+ * its content brings it (the SDK sign-in brings its own screens).
16
+ * motion a step change is Bloom's `ScreenTransition` (forward from the
17
+ * right, back from the left; a cross-fade on the web), clipped to
18
+ * the card; nothing moves under reduced motion
19
+ * progress quiet, above the footer: decorative dots and "Step 2 of 5"
20
+ * footer Back leading (plain), then the secondary action and the primary
21
+ * (the solid default action) trailing — Tab order is visual order
22
+ *
23
+ * Accessibility: on a step change focus moves to the new step's title, or
24
+ * stays with its content when the step says so (`initialFocus: 'content'`: a
25
+ * field of its own takes it), and the change is said politely ("Create a PIN,
26
+ * step 3 of 5"). The dots are hidden from assistive technology; the count line
27
+ * and the announcement say where the step sits.
28
+ */
29
+
30
+ import type React from 'react';
31
+ import { useEffect, useLayoutEffect, useRef, useState } from 'react';
32
+ import { AccessibilityInfo, Platform, Text as RNText } from 'react-native';
33
+ import { View } from 'react-native-css/components';
34
+ import { Button } from '@oxy.so/bloom/button';
35
+ import { CarouselDots } from '@oxy.so/bloom/carousel';
36
+ import { useItemAccessibilityFocus, usePrefersReducedMotion } from '@oxy.so/bloom/hooks';
37
+ import { ScreenTransition } from '@oxy.so/bloom/motion';
38
+ import { useTheme } from '@oxy.so/bloom/theme';
39
+ import { Text } from '@oxy.so/bloom/typography';
40
+ import { useI18n } from '../../hooks/useI18n';
41
+ import { SurfaceFrameWidthContext, useSurfaceFrameWidth } from '../../hooks/useSurfaceFrameWidth';
42
+ import { OxyAuthScreen, OxyAuthScreenHeader, OxyAuthSplit } from '../signIn/OxyAuthScreen';
43
+
44
+ /** The split card's width, as the sign-in asks it for its QR side. */
45
+ const SPLIT_WIDTH = 880;
46
+
47
+ /** A footer action of a step. */
48
+ export interface OxySetupAction {
49
+ label: string;
50
+ onPress: () => void;
51
+ testID?: string;
52
+ }
53
+
54
+ /** The step's primary action: the default one, solid. */
55
+ export interface OxySetupPrimaryAction extends OxySetupAction {
56
+ /** Not available yet (a PIN not typed twice). */
57
+ disabled?: boolean;
58
+ /** Working: Bloom's spinner, presses refused, said busy; Back and the secondary wait with it. */
59
+ busy?: boolean;
60
+ }
61
+
62
+ /** One step of a setup. */
63
+ export interface OxySetupStep {
64
+ /** Stable: focus, the announcement and the transition key on it. */
65
+ id: string;
66
+ /** The step's one heading. Omit for content that brings its own (the SDK sign-in). */
67
+ title?: string;
68
+ description?: React.ReactNode;
69
+ /** Drawn in place of the Oxy mark above the title (the host's own step icon), at most 56 tall. */
70
+ icon?: React.ReactNode;
71
+ /** The step's body. */
72
+ content: React.ReactNode;
73
+ /** From `md`, the split card's right column (as the sign-in's QR side). */
74
+ aside?: React.ReactNode;
75
+ /**
76
+ * Where focus goes when the step becomes current: its title (`'heading'`, the
77
+ * default with a title), or left to its content (`'content'`, the default
78
+ * without one) — a step whose field takes focus itself (`autoFocus`).
79
+ */
80
+ initialFocus?: 'heading' | 'content';
81
+ primary?: OxySetupPrimaryAction;
82
+ /** "Not Now", "Set Up Later". */
83
+ secondary?: OxySetupAction;
84
+ }
85
+
86
+ export interface OxySetupFlowProps {
87
+ /** The accessible name of the whole setup ("Set up your account"). */
88
+ label: string;
89
+ /** In order; the host decides which apply. */
90
+ steps: readonly OxySetupStep[];
91
+ /** The current step's `id` (controlled). */
92
+ current: string;
93
+ /** Back is offered on the current step only when this is given. */
94
+ onBack?: () => void;
95
+ /** Default: the SDK's own "Back". */
96
+ backLabel?: string;
97
+ /** "Step 2 of 5" and the dots. Default `true`. */
98
+ showProgress?: boolean;
99
+ /**
100
+ * The card width (px) the current step asks, as `OxySurfaceFrame` reports it:
101
+ * 880 for a split step (the sign-in's, with the QR, from `md`), `null` for the
102
+ * card's own. A surface around the flow (`OxySurfaceFrame`, the account
103
+ * dialog) is asked too.
104
+ */
105
+ onMaxWidthChange?: (maxWidth: number | null) => void;
106
+ }
107
+
108
+ /** What one step change owes: the direction it travelled and what to say and focus. */
109
+ interface StepChange {
110
+ id: string;
111
+ /** 0 until the first change: appearing is not a change. */
112
+ count: number;
113
+ direction: 'forward' | 'backward';
114
+ announcement: string;
115
+ focusHeading: boolean;
116
+ }
117
+
118
+ /** Asks the surface for the split card's width while mounted. */
119
+ const SplitWidth: React.FC = () => {
120
+ useSurfaceFrameWidth(SPLIT_WIDTH);
121
+ return null;
122
+ };
123
+
124
+ const StepBody: React.FC<{
125
+ step: OxySetupStep;
126
+ titleRef: React.Ref<React.ComponentRef<typeof RNText>>;
127
+ }> = ({ step, titleRef }) => {
128
+ const header = step.title ? (
129
+ <OxyAuthScreenHeader
130
+ title={step.title}
131
+ description={step.description}
132
+ icon={step.icon}
133
+ titleRef={titleRef}
134
+ />
135
+ ) : null;
136
+ if (step.aside != null) {
137
+ return (
138
+ <>
139
+ <SplitWidth />
140
+ <OxyAuthSplit bare aside={step.aside}>
141
+ <OxyAuthScreen className="md:max-w-none">
142
+ {header}
143
+ {step.content}
144
+ </OxyAuthScreen>
145
+ </OxyAuthSplit>
146
+ </>
147
+ );
148
+ }
149
+ if (!header) return <>{step.content}</>;
150
+ return (
151
+ <OxyAuthScreen>
152
+ {header}
153
+ {step.content}
154
+ </OxyAuthScreen>
155
+ );
156
+ };
157
+
158
+ /** Off screen, still read: the web's polite announcement. */
159
+ const VISUALLY_HIDDEN = {
160
+ position: 'absolute',
161
+ width: 1,
162
+ height: 1,
163
+ margin: -1,
164
+ overflow: 'hidden',
165
+ opacity: 0,
166
+ } as const;
167
+
168
+ /** Says `text` once, politely, on a platform with an announcement API (not the web). */
169
+ function announce(text: string): void {
170
+ if (Platform.OS === 'ios') {
171
+ // iOS has no live regions; queued, the title the focus move reads goes first.
172
+ AccessibilityInfo.announceForAccessibilityWithOptions(text, { queue: true });
173
+ return;
174
+ }
175
+ AccessibilityInfo.announceForAccessibility(text);
176
+ }
177
+
178
+ export const OxySetupFlow: React.FC<OxySetupFlowProps> = ({
179
+ label,
180
+ steps,
181
+ current,
182
+ onBack,
183
+ backLabel,
184
+ showProgress = true,
185
+ onMaxWidthChange,
186
+ }) => {
187
+ const { t } = useI18n();
188
+ const theme = useTheme();
189
+ const reducedMotion = usePrefersReducedMotion();
190
+ const index = steps.findIndex((candidate) => candidate.id === current);
191
+ const step = index === -1 ? undefined : steps[index];
192
+ const total = steps.length;
193
+ const focusHeading = step?.title ? (step.initialFocus ?? 'heading') === 'heading' : false;
194
+ const announcement =
195
+ step?.title != null && step.title !== ''
196
+ ? t('common.stepAnnouncement', { title: step.title, step: index + 1, total })
197
+ : t('common.stepOf', { step: index + 1, total });
198
+
199
+ // A step change, derived during render: which way it went, and what it owes.
200
+ const [change, setChange] = useState<StepChange>({
201
+ id: current,
202
+ count: 0,
203
+ direction: 'forward',
204
+ announcement,
205
+ focusHeading,
206
+ });
207
+ if (change.id !== current) {
208
+ const from = steps.findIndex((candidate) => candidate.id === change.id);
209
+ setChange({
210
+ id: current,
211
+ count: change.count + 1,
212
+ direction: from !== -1 && index < from ? 'backward' : 'forward',
213
+ announcement,
214
+ focusHeading,
215
+ });
216
+ }
217
+
218
+ // The width the current step asks (the sign-in's split card, a step's aside),
219
+ // handed to the host and to any surface around the flow.
220
+ const [askedWidth, setAskedWidth] = useState<number | null>(null);
221
+ useSurfaceFrameWidth(askedWidth);
222
+ useLayoutEffect(() => {
223
+ if (!onMaxWidthChange) return;
224
+ onMaxWidthChange(askedWidth);
225
+ return () => onMaxWidthChange(null);
226
+ }, [onMaxWidthChange, askedWidth]);
227
+
228
+ // Screen-reader focus to the new title on native (Bloom's, which waits for
229
+ // the view to be laid out); the browser's focus on the web, below.
230
+ const focusTitle = useItemAccessibilityFocus(focusHeading && step ? step.id : null);
231
+ const webTitle = useRef<React.ComponentRef<typeof RNText> | null>(null);
232
+ const titleRef = (view: React.ComponentRef<typeof RNText> | null) => {
233
+ webTitle.current = view;
234
+ if (step) focusTitle(step.id, view);
235
+ };
236
+
237
+ useEffect(() => {
238
+ if (change.count === 0) return;
239
+ if (Platform.OS === 'web') {
240
+ // The pressed button may be gone with its step: focus goes to the new title.
241
+ if (change.focusHeading) webTitle.current?.focus?.();
242
+ return;
243
+ }
244
+ announce(change.announcement);
245
+ }, [change]);
246
+
247
+ if (!step) return null;
248
+
249
+ const busy = step.primary?.busy === true;
250
+ const wide = askedWidth !== null;
251
+ const body = <StepBody step={step} titleRef={titleRef} />;
252
+
253
+ return (
254
+ // A labelled region: the setup is a place a reader can name and jump to.
255
+ <View
256
+ role="region"
257
+ accessibilityLabel={label}
258
+ className={`w-full self-center gap-6 max-w-[448px] ${wide ? 'md:max-w-[880px]' : ''}`}
259
+ >
260
+ <SurfaceFrameWidthContext.Provider value={setAskedWidth}>
261
+ {/* Clipped, so a step slides in within the card; the 4px bleed keeps
262
+ the content's focus rings. */}
263
+ <View className="-m-1 overflow-hidden p-1">
264
+ {reducedMotion ? (
265
+ <View key={step.id} testID="oxy-setup-step">
266
+ {body}
267
+ </View>
268
+ ) : (
269
+ <ScreenTransition key={step.id} direction={change.direction} enabledWeb>
270
+ {body}
271
+ </ScreenTransition>
272
+ )}
273
+ </View>
274
+ </SurfaceFrameWidthContext.Provider>
275
+
276
+ {showProgress && total > 1 ? (
277
+ <View className="items-center gap-2">
278
+ <CarouselDots count={total} index={index} testID="oxy-setup-dots" />
279
+ <Text
280
+ variant="caption-1-medium"
281
+ style={{ color: theme.colors.textSecondary }}
282
+ testID="oxy-setup-progress"
283
+ >
284
+ {t('common.stepOf', { step: index + 1, total })}
285
+ </Text>
286
+ </View>
287
+ ) : null}
288
+
289
+ {onBack || step.secondary || step.primary ? (
290
+ <View className="w-full flex-row items-center gap-3">
291
+ {onBack ? (
292
+ <Button
293
+ appearance="plain"
294
+ tone="neutral"
295
+ size="lg"
296
+ onPress={onBack}
297
+ disabled={busy}
298
+ testID="oxy-setup-back"
299
+ >
300
+ {backLabel ?? t('common.actions.back')}
301
+ </Button>
302
+ ) : null}
303
+ <View className="flex-1" />
304
+ {step.secondary ? (
305
+ <Button
306
+ appearance="subtle"
307
+ tone="neutral"
308
+ size="lg"
309
+ onPress={step.secondary.onPress}
310
+ disabled={busy}
311
+ testID={step.secondary.testID ?? 'oxy-setup-secondary'}
312
+ >
313
+ {step.secondary.label}
314
+ </Button>
315
+ ) : null}
316
+ {step.primary ? (
317
+ <Button
318
+ appearance="solid"
319
+ tone="action"
320
+ size="lg"
321
+ onPress={step.primary.onPress}
322
+ disabled={step.primary.disabled}
323
+ loading={busy}
324
+ testID={step.primary.testID ?? 'oxy-setup-primary'}
325
+ >
326
+ {step.primary.label}
327
+ </Button>
328
+ ) : null}
329
+ </View>
330
+ ) : null}
331
+
332
+ {Platform.OS === 'web' ? (
333
+ <RNText aria-live="polite" style={VISUALLY_HIDDEN} testID="oxy-setup-announcement">
334
+ {change.count > 0 ? change.announcement : ''}
335
+ </RNText>
336
+ ) : null}
337
+ </View>
338
+ );
339
+ };
@@ -0,0 +1,312 @@
1
+ /**
2
+ * `OxySetupFlow` — a platform's setup in the sign-in's own frame (ADR 0064).
3
+ *
4
+ * The flow is controlled and presentational, so these render it with plain
5
+ * steps and assert what it draws and owes: the step's header and footer, Back
6
+ * only with `onBack`, the primary's disabled and busy states, the quiet
7
+ * progress, and on a step change the focus move and the polite announcement
8
+ * (the web's live region; native's announcement API). `oxySignInStep` is the
9
+ * SDK's chooser unchanged, here a stub that asks for the split card's width as
10
+ * the real one does: the flow must hand that width to the host and give it back.
11
+ */
12
+ import { act, fireEvent, render, screen } from '@testing-library/react';
13
+ import { AccessibilityInfo, Platform } from 'react-native';
14
+ import { OxySetupFlow, type OxySetupFlowProps, type OxySetupStep } from '../OxySetupFlow';
15
+ import { oxySignInStep } from '../oxySignInStep';
16
+
17
+ let mockReducedMotion = false;
18
+ jest.mock('@oxy.so/bloom/hooks', () => ({
19
+ ...jest.requireActual('@oxy.so/bloom/hooks'),
20
+ usePrefersReducedMotion: () => mockReducedMotion,
21
+ }));
22
+
23
+ // The SDK's chooser, as far as the flow can tell: on its split card (the QR
24
+ // side, from `md`) it asks its surface for 880 while mounted.
25
+ jest.mock('../../OxyAuthChooser', () => {
26
+ const { useSurfaceFrameWidth } = jest.requireActual('../../../hooks/useSurfaceFrameWidth');
27
+ return {
28
+ __esModule: true,
29
+ default: () => {
30
+ useSurfaceFrameWidth(880);
31
+ return 'The SDK sign-in';
32
+ },
33
+ };
34
+ });
35
+
36
+ const welcome: OxySetupStep = {
37
+ id: 'welcome',
38
+ title: 'Welcome',
39
+ description: 'Set up your computer with your Oxy account.',
40
+ content: null,
41
+ primary: { label: 'Continue', onPress: () => undefined },
42
+ };
43
+
44
+ const pin = (overrides: Partial<OxySetupStep> = {}): OxySetupStep => ({
45
+ id: 'create-pin',
46
+ title: 'Create a PIN',
47
+ description: 'You will use it to unlock this computer.',
48
+ content: <input aria-label="PIN" />,
49
+ primary: { label: 'Continue', onPress: () => undefined },
50
+ ...overrides,
51
+ });
52
+
53
+ const appearance: OxySetupStep = {
54
+ id: 'appearance',
55
+ title: 'Choose your look',
56
+ content: null,
57
+ primary: { label: 'Continue', onPress: () => undefined },
58
+ secondary: { label: 'Set Up Later', onPress: () => undefined },
59
+ };
60
+
61
+ const STEPS: OxySetupStep[] = [welcome, oxySignInStep(), pin(), appearance];
62
+
63
+ const flow = (props: Partial<OxySetupFlowProps> = {}) => (
64
+ <OxySetupFlow label="Set up your account" steps={STEPS} current="welcome" {...props} />
65
+ );
66
+
67
+ const originalOS = Platform.OS;
68
+
69
+ afterEach(() => {
70
+ Platform.OS = originalOS;
71
+ mockReducedMotion = false;
72
+ jest.restoreAllMocks();
73
+ });
74
+
75
+ describe('a step', () => {
76
+ it('draws its header in the sign-in frame, its icon in place of the mark, and its content', () => {
77
+ render(
78
+ flow({
79
+ steps: [pin({ icon: <span data-testid="pin-icon" /> }), appearance],
80
+ current: 'create-pin',
81
+ }),
82
+ );
83
+ expect(screen.getByLabelText('Set up your account')).toBeTruthy();
84
+ expect(screen.getByText('Create a PIN')).toBeTruthy();
85
+ expect(screen.getByText('You will use it to unlock this computer.')).toBeTruthy();
86
+ expect(screen.getByTestId('pin-icon')).toBeTruthy();
87
+ expect(screen.getByLabelText('PIN')).toBeTruthy();
88
+ });
89
+
90
+ it('draws a step with an aside as the split card and asks its surface for 880', () => {
91
+ const onMaxWidthChange = jest.fn();
92
+ const { rerender } = render(
93
+ flow({
94
+ steps: [welcome, pin({ aside: <span data-testid="pin-aside" /> })],
95
+ current: 'create-pin',
96
+ onMaxWidthChange,
97
+ }),
98
+ );
99
+ expect(screen.getByTestId('pin-aside')).toBeTruthy();
100
+ expect(onMaxWidthChange).toHaveBeenLastCalledWith(880);
101
+
102
+ rerender(
103
+ flow({
104
+ steps: [welcome, pin({ aside: <span data-testid="pin-aside" /> })],
105
+ current: 'welcome',
106
+ onMaxWidthChange,
107
+ }),
108
+ );
109
+ expect(onMaxWidthChange).toHaveBeenLastCalledWith(null);
110
+ });
111
+
112
+ it('renders nothing for a current id that is not one of its steps', () => {
113
+ const { container } = render(flow({ current: 'nowhere' }));
114
+ expect(container.textContent).toBe('');
115
+ });
116
+ });
117
+
118
+ describe('the footer', () => {
119
+ it('offers Back only when onBack is given, in the SDK’s own words by default', () => {
120
+ const { rerender } = render(flow({ current: 'create-pin' }));
121
+ expect(screen.queryByTestId('oxy-setup-back')).toBeNull();
122
+
123
+ const onBack = jest.fn();
124
+ rerender(flow({ current: 'create-pin', onBack }));
125
+ fireEvent.click(screen.getByText('Back'));
126
+ expect(onBack).toHaveBeenCalledTimes(1);
127
+
128
+ rerender(flow({ current: 'create-pin', onBack, backLabel: 'Previous' }));
129
+ expect(screen.getByTestId('oxy-setup-back').textContent).toBe('Previous');
130
+ });
131
+
132
+ it('draws Back, then the secondary and the primary, in that order', () => {
133
+ render(flow({ current: 'appearance', onBack: () => undefined }));
134
+ const order = screen
135
+ .getAllByRole('button')
136
+ .map((button) => button.getAttribute('data-testid'))
137
+ .filter((id) => id?.startsWith('oxy-setup-'));
138
+ expect(order).toEqual(['oxy-setup-back', 'oxy-setup-secondary', 'oxy-setup-primary']);
139
+ });
140
+
141
+ it('presses the primary and the secondary', () => {
142
+ const onPrimary = jest.fn();
143
+ const onSecondary = jest.fn();
144
+ render(
145
+ flow({
146
+ steps: [
147
+ {
148
+ ...appearance,
149
+ primary: { label: 'Continue', onPress: onPrimary, testID: 'look-continue' },
150
+ secondary: { label: 'Set Up Later', onPress: onSecondary },
151
+ },
152
+ ],
153
+ current: 'appearance',
154
+ }),
155
+ );
156
+ fireEvent.click(screen.getByTestId('look-continue'));
157
+ fireEvent.click(screen.getByText('Set Up Later'));
158
+ expect(onPrimary).toHaveBeenCalledTimes(1);
159
+ expect(onSecondary).toHaveBeenCalledTimes(1);
160
+ });
161
+
162
+ it('refuses a disabled primary', () => {
163
+ const onPress = jest.fn();
164
+ render(
165
+ flow({
166
+ steps: [pin({ primary: { label: 'Continue', onPress, disabled: true } })],
167
+ current: 'create-pin',
168
+ }),
169
+ );
170
+ const primary = screen.getByTestId('oxy-setup-primary') as HTMLButtonElement;
171
+ expect(primary.disabled).toBe(true);
172
+ fireEvent.click(primary);
173
+ expect(onPress).not.toHaveBeenCalled();
174
+ });
175
+
176
+ it('says a busy primary is busy, and holds Back and the secondary while it works', () => {
177
+ render(
178
+ flow({
179
+ steps: [
180
+ {
181
+ ...appearance,
182
+ primary: { label: 'Continue', onPress: () => undefined, busy: true },
183
+ },
184
+ ],
185
+ current: 'appearance',
186
+ onBack: () => undefined,
187
+ }),
188
+ );
189
+ const primary = screen.getByTestId('oxy-setup-primary');
190
+ expect(primary.getAttribute('aria-busy')).toBe('true');
191
+ expect((screen.getByTestId('oxy-setup-back') as HTMLButtonElement).disabled).toBe(true);
192
+ expect((screen.getByTestId('oxy-setup-secondary') as HTMLButtonElement).disabled).toBe(true);
193
+ });
194
+
195
+ it('draws no footer for a step without actions and no Back', () => {
196
+ render(flow({ current: 'oxy-sign-in' }));
197
+ expect(screen.queryByRole('button')).toBeNull();
198
+ });
199
+ });
200
+
201
+ describe('progress', () => {
202
+ it('says "Step N of M" under decorative dots hidden from assistive technology', () => {
203
+ render(flow({ current: 'create-pin' }));
204
+ expect(screen.getByTestId('oxy-setup-progress').textContent).toBe('Step 3 of 4');
205
+ const dots = screen.getByTestId('oxy-setup-dots');
206
+ expect(dots.getAttribute('aria-hidden')).toBe('true');
207
+ expect(dots.getAttribute('data-index')).toBe('2');
208
+ expect(dots.getAttribute('data-count')).toBe('4');
209
+ });
210
+
211
+ it('is left out with showProgress false', () => {
212
+ render(flow({ current: 'create-pin', showProgress: false }));
213
+ expect(screen.queryByTestId('oxy-setup-progress')).toBeNull();
214
+ expect(screen.queryByTestId('oxy-setup-dots')).toBeNull();
215
+ });
216
+ });
217
+
218
+ describe('a step change', () => {
219
+ it('moves focus to the new title and says the step politely; appearing says nothing', () => {
220
+ const { rerender } = render(flow({ current: 'welcome' }));
221
+ const live = screen.getByTestId('oxy-setup-announcement');
222
+ expect(live.getAttribute('aria-live')).toBe('polite');
223
+ expect(live.textContent).toBe('');
224
+ expect(document.activeElement).toBe(document.body);
225
+
226
+ rerender(flow({ current: 'appearance' }));
227
+ expect(document.activeElement).toBe(screen.getByText('Choose your look'));
228
+ expect(live.textContent).toBe('Choose your look, step 4 of 4');
229
+ });
230
+
231
+ it('leaves focus to a step whose content takes it', () => {
232
+ const { rerender } = render(
233
+ flow({ steps: [welcome, pin({ initialFocus: 'content' })], current: 'welcome' }),
234
+ );
235
+ rerender(flow({ steps: [welcome, pin({ initialFocus: 'content' })], current: 'create-pin' }));
236
+ expect(document.activeElement).not.toBe(screen.getByText('Create a PIN'));
237
+ expect(screen.getByTestId('oxy-setup-announcement').textContent).toBe(
238
+ 'Create a PIN, step 2 of 2',
239
+ );
240
+ });
241
+
242
+ it('says only where an untitled step sits (the SDK sign-in brings its own heading)', () => {
243
+ const { rerender } = render(flow({ current: 'welcome' }));
244
+ rerender(flow({ current: 'oxy-sign-in' }));
245
+ expect(screen.getByTestId('oxy-setup-announcement').textContent).toBe('Step 2 of 4');
246
+ });
247
+
248
+ it('announces through the platform on native, once per change', () => {
249
+ Platform.OS = 'android';
250
+ const announce = jest
251
+ .spyOn(AccessibilityInfo, 'announceForAccessibility')
252
+ .mockImplementation(() => undefined);
253
+ const { rerender } = render(flow({ current: 'welcome' }));
254
+ expect(announce).not.toHaveBeenCalled();
255
+ expect(screen.queryByTestId('oxy-setup-announcement')).toBeNull();
256
+
257
+ rerender(flow({ current: 'create-pin' }));
258
+ expect(announce).toHaveBeenCalledTimes(1);
259
+ expect(announce).toHaveBeenCalledWith('Create a PIN, step 3 of 4');
260
+ });
261
+
262
+ it('queues the announcement on iOS, after the title the focus move reads', () => {
263
+ Platform.OS = 'ios';
264
+ const queued = jest.fn();
265
+ Object.assign(AccessibilityInfo, { announceForAccessibilityWithOptions: queued });
266
+ const { rerender } = render(flow({ current: 'welcome' }));
267
+ rerender(flow({ current: 'create-pin' }));
268
+ expect(queued).toHaveBeenCalledWith('Create a PIN, step 3 of 4', { queue: true });
269
+ });
270
+
271
+ it('travels forward to a later step and backward to an earlier one', () => {
272
+ const { rerender } = render(flow({ current: 'welcome' }));
273
+ rerender(flow({ current: 'create-pin' }));
274
+ expect(screen.getByTestId('screen-transition').getAttribute('data-direction')).toBe('forward');
275
+ rerender(flow({ current: 'oxy-sign-in' }));
276
+ expect(screen.getByTestId('screen-transition').getAttribute('data-direction')).toBe('backward');
277
+ });
278
+
279
+ it('does not move under reduced motion', () => {
280
+ mockReducedMotion = true;
281
+ const { rerender } = render(flow({ current: 'welcome' }));
282
+ rerender(flow({ current: 'create-pin' }));
283
+ expect(screen.queryByTestId('screen-transition')).toBeNull();
284
+ expect(screen.getByTestId('oxy-setup-step')).toBeTruthy();
285
+ expect(screen.getByText('Create a PIN')).toBeTruthy();
286
+ });
287
+ });
288
+
289
+ describe('oxySignInStep', () => {
290
+ it('is the SDK chooser, untitled, leaving focus to its own screens', () => {
291
+ const step = oxySignInStep();
292
+ expect(step.id).toBe('oxy-sign-in');
293
+ expect(step.title).toBeUndefined();
294
+ expect(step.initialFocus).toBe('content');
295
+ expect(oxySignInStep({ id: 'account' }).id).toBe('account');
296
+ });
297
+
298
+ it('hands the chooser’s split-card width to the host, and gives it back after', () => {
299
+ const onMaxWidthChange = jest.fn();
300
+ const { rerender } = render(flow({ current: 'welcome', onMaxWidthChange }));
301
+ expect(onMaxWidthChange).toHaveBeenLastCalledWith(null);
302
+
303
+ rerender(flow({ current: 'oxy-sign-in', onMaxWidthChange }));
304
+ expect(screen.getByText('The SDK sign-in')).toBeTruthy();
305
+ expect(onMaxWidthChange).toHaveBeenLastCalledWith(880);
306
+
307
+ act(() => {
308
+ rerender(flow({ current: 'create-pin', onMaxWidthChange }));
309
+ });
310
+ expect(onMaxWidthChange).toHaveBeenLastCalledWith(null);
311
+ });
312
+ });
@@ -0,0 +1,32 @@
1
+ /**
2
+ * The SDK's sign-in as a step of a platform's setup (`OxySetupFlow`): the
3
+ * account dialog's own chooser (`OxyAuthChooser`), unchanged — the same sign-in
4
+ * (the Commons QR from `md`, the email's code or link, the password, the
5
+ * authenticator), sign-up and request views every Oxy app shows.
6
+ *
7
+ * The flow is its surface: the chooser asks it for the split card's 880 while
8
+ * its QR side shows and for the flow's own width after, as it asks the account
9
+ * dialog. The step draws no title (the chooser's screens bring their own) and
10
+ * leaves focus to them (the identifier field takes it on a computer).
11
+ *
12
+ * The host learns the sign-in where it always has: the credential a sign-in
13
+ * commits goes to `OxyProvider`'s `authStateStore` (`PlatformSetupAuthStateStore`,
14
+ * with `context.method` 'qr' or 'password' and the typed password), and
15
+ * `useOxy()` follows the signed-in account. Needs `OxyProvider` around the flow.
16
+ */
17
+
18
+ import OxyAuthChooser from '../OxyAuthChooser';
19
+ import type { OxySetupStep } from './OxySetupFlow';
20
+
21
+ export interface OxySignInStepOptions {
22
+ /** The step's `id`. Default `'oxy-sign-in'`. */
23
+ id?: string;
24
+ }
25
+
26
+ export function oxySignInStep(options: OxySignInStepOptions = {}): OxySetupStep {
27
+ return {
28
+ id: options.id ?? 'oxy-sign-in',
29
+ initialFocus: 'content',
30
+ content: <OxyAuthChooser />,
31
+ };
32
+ }