@terreno/ui 57.19.2 → 57.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.
Files changed (295) hide show
  1. package/.ai/guidelines/core.md +1 -1
  2. package/CHANGELOG.md +393 -0
  3. package/dist/Accordion.d.ts.map +1 -1
  4. package/dist/Accordion.js +3 -3
  5. package/dist/Accordion.js.map +1 -1
  6. package/dist/Avatar.d.ts.map +1 -1
  7. package/dist/Avatar.js +3 -1
  8. package/dist/Avatar.js.map +1 -1
  9. package/dist/Box.d.ts.map +1 -1
  10. package/dist/Box.js +38 -2
  11. package/dist/Box.js.map +1 -1
  12. package/dist/Card.js +2 -2
  13. package/dist/Card.js.map +1 -1
  14. package/dist/Common.d.ts +120 -7
  15. package/dist/Common.d.ts.map +1 -1
  16. package/dist/Common.js.map +1 -1
  17. package/dist/ConsentFormScreen.d.ts +1 -1
  18. package/dist/ConsentFormScreen.d.ts.map +1 -1
  19. package/dist/ConsentFormScreen.js +13 -4
  20. package/dist/ConsentFormScreen.js.map +1 -1
  21. package/dist/DateTimeField.d.ts.map +1 -1
  22. package/dist/DateTimeField.js +5 -3
  23. package/dist/DateTimeField.js.map +1 -1
  24. package/dist/Field.d.ts.map +1 -1
  25. package/dist/Field.js +2 -0
  26. package/dist/Field.js.map +1 -1
  27. package/dist/FormContainer.d.ts +68 -0
  28. package/dist/FormContainer.d.ts.map +1 -0
  29. package/dist/FormContainer.js +79 -0
  30. package/dist/FormContainer.js.map +1 -0
  31. package/dist/GPTChat.d.ts.map +1 -1
  32. package/dist/GPTChat.js +2 -1
  33. package/dist/GPTChat.js.map +1 -1
  34. package/dist/Heading.d.ts +1 -1
  35. package/dist/Heading.d.ts.map +1 -1
  36. package/dist/Heading.js +5 -2
  37. package/dist/Heading.js.map +1 -1
  38. package/dist/Icon.d.ts +4 -0
  39. package/dist/Icon.d.ts.map +1 -1
  40. package/dist/Icon.js +43 -2
  41. package/dist/Icon.js.map +1 -1
  42. package/dist/LabeledCheckBox.d.ts +22 -0
  43. package/dist/LabeledCheckBox.d.ts.map +1 -0
  44. package/dist/LabeledCheckBox.js +30 -0
  45. package/dist/LabeledCheckBox.js.map +1 -0
  46. package/dist/ListDetailLayout.d.ts +36 -0
  47. package/dist/ListDetailLayout.d.ts.map +1 -0
  48. package/dist/ListDetailLayout.js +153 -0
  49. package/dist/ListDetailLayout.js.map +1 -0
  50. package/dist/MarkdownEditor.d.ts.map +1 -1
  51. package/dist/MarkdownEditor.js +2 -1
  52. package/dist/MarkdownEditor.js.map +1 -1
  53. package/dist/MediaQuery.d.ts +1 -1
  54. package/dist/MediaQuery.d.ts.map +1 -1
  55. package/dist/MediaQuery.js +1 -1
  56. package/dist/MediaQuery.js.map +1 -1
  57. package/dist/OtpField.d.ts +60 -0
  58. package/dist/OtpField.d.ts.map +1 -0
  59. package/dist/OtpField.js +154 -0
  60. package/dist/OtpField.js.map +1 -0
  61. package/dist/ProvisionalConsentSigner.d.ts +21 -0
  62. package/dist/ProvisionalConsentSigner.d.ts.map +1 -0
  63. package/dist/ProvisionalConsentSigner.js +199 -0
  64. package/dist/ProvisionalConsentSigner.js.map +1 -0
  65. package/dist/ResponsiveBreakpoint.d.ts +5 -0
  66. package/dist/ResponsiveBreakpoint.d.ts.map +1 -1
  67. package/dist/ResponsiveBreakpoint.js +7 -0
  68. package/dist/ResponsiveBreakpoint.js.map +1 -1
  69. package/dist/SocialLoginButton.d.ts +10 -0
  70. package/dist/SocialLoginButton.d.ts.map +1 -1
  71. package/dist/SocialLoginButton.js +26 -8
  72. package/dist/SocialLoginButton.js.map +1 -1
  73. package/dist/SplitPage.d.ts +11 -0
  74. package/dist/SplitPage.d.ts.map +1 -1
  75. package/dist/SplitPage.js +11 -5
  76. package/dist/SplitPage.js.map +1 -1
  77. package/dist/SplitPage.native.d.ts.map +1 -1
  78. package/dist/SplitPage.native.js +3 -1
  79. package/dist/SplitPage.native.js.map +1 -1
  80. package/dist/SyncStatusBanner.d.ts +7 -1
  81. package/dist/SyncStatusBanner.d.ts.map +1 -1
  82. package/dist/SyncStatusBanner.js +20 -4
  83. package/dist/SyncStatusBanner.js.map +1 -1
  84. package/dist/TextField.d.ts.map +1 -1
  85. package/dist/TextField.js +44 -10
  86. package/dist/TextField.js.map +1 -1
  87. package/dist/fieldElements/FieldError.d.ts.map +1 -1
  88. package/dist/fieldElements/FieldError.js +1 -1
  89. package/dist/fieldElements/FieldError.js.map +1 -1
  90. package/dist/index.d.ts +19 -3
  91. package/dist/index.d.ts.map +1 -1
  92. package/dist/index.js +14 -1
  93. package/dist/index.js.map +1 -1
  94. package/dist/lazyBoundaries/heavyOptionalExports.d.ts +3 -0
  95. package/dist/lazyBoundaries/heavyOptionalExports.d.ts.map +1 -1
  96. package/dist/lazyBoundaries/heavyOptionalExports.js +2 -0
  97. package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
  98. package/dist/login/LastUsedBadge.d.ts +14 -0
  99. package/dist/login/LastUsedBadge.d.ts.map +1 -0
  100. package/dist/login/LastUsedBadge.js +23 -0
  101. package/dist/login/LastUsedBadge.js.map +1 -0
  102. package/dist/login/LoginAccountCard.d.ts +38 -0
  103. package/dist/login/LoginAccountCard.d.ts.map +1 -0
  104. package/dist/login/LoginAccountCard.js +72 -0
  105. package/dist/login/LoginAccountCard.js.map +1 -0
  106. package/dist/login/LoginAccountList.d.ts +33 -0
  107. package/dist/login/LoginAccountList.d.ts.map +1 -0
  108. package/dist/login/LoginAccountList.js +30 -0
  109. package/dist/login/LoginAccountList.js.map +1 -0
  110. package/dist/login/LoginScreen.d.ts +4 -4
  111. package/dist/login/LoginScreen.d.ts.map +1 -1
  112. package/dist/login/LoginScreen.js +294 -13
  113. package/dist/login/LoginScreen.js.map +1 -1
  114. package/dist/login/OutlinePill.d.ts +28 -0
  115. package/dist/login/OutlinePill.d.ts.map +1 -0
  116. package/dist/login/OutlinePill.js +48 -0
  117. package/dist/login/OutlinePill.js.map +1 -0
  118. package/dist/login/TwoFactorChallengeScreen.d.ts +26 -0
  119. package/dist/login/TwoFactorChallengeScreen.d.ts.map +1 -0
  120. package/dist/login/TwoFactorChallengeScreen.js +139 -0
  121. package/dist/login/TwoFactorChallengeScreen.js.map +1 -0
  122. package/dist/login/loginMethods.d.ts +27 -0
  123. package/dist/login/loginMethods.d.ts.map +1 -0
  124. package/dist/login/loginMethods.js +37 -0
  125. package/dist/login/loginMethods.js.map +1 -0
  126. package/dist/login/loginTypes.d.ts +202 -5
  127. package/dist/login/loginTypes.d.ts.map +1 -1
  128. package/dist/pdfHtmlTemplate.d.ts +17 -0
  129. package/dist/pdfHtmlTemplate.d.ts.map +1 -1
  130. package/dist/pdfHtmlTemplate.js +78 -0
  131. package/dist/pdfHtmlTemplate.js.map +1 -1
  132. package/dist/security/AccountSecurityScreen.d.ts +10 -0
  133. package/dist/security/AccountSecurityScreen.d.ts.map +1 -0
  134. package/dist/security/AccountSecurityScreen.js +50 -0
  135. package/dist/security/AccountSecurityScreen.js.map +1 -0
  136. package/dist/security/LinkedAccountsCard.d.ts +32 -0
  137. package/dist/security/LinkedAccountsCard.d.ts.map +1 -0
  138. package/dist/security/LinkedAccountsCard.js +145 -0
  139. package/dist/security/LinkedAccountsCard.js.map +1 -0
  140. package/dist/security/PasskeysCard.d.ts +39 -0
  141. package/dist/security/PasskeysCard.d.ts.map +1 -0
  142. package/dist/security/PasskeysCard.js +168 -0
  143. package/dist/security/PasskeysCard.js.map +1 -0
  144. package/dist/security/PasswordCard.d.ts +32 -0
  145. package/dist/security/PasswordCard.d.ts.map +1 -0
  146. package/dist/security/PasswordCard.js +198 -0
  147. package/dist/security/PasswordCard.js.map +1 -0
  148. package/dist/security/SessionsCard.d.ts +39 -0
  149. package/dist/security/SessionsCard.d.ts.map +1 -0
  150. package/dist/security/SessionsCard.js +168 -0
  151. package/dist/security/SessionsCard.js.map +1 -0
  152. package/dist/security/TwoFactorSettingsCard.d.ts +55 -0
  153. package/dist/security/TwoFactorSettingsCard.d.ts.map +1 -0
  154. package/dist/security/TwoFactorSettingsCard.js +458 -0
  155. package/dist/security/TwoFactorSettingsCard.js.map +1 -0
  156. package/dist/security/securityMethods.d.ts +40 -0
  157. package/dist/security/securityMethods.d.ts.map +1 -0
  158. package/dist/security/securityMethods.js +66 -0
  159. package/dist/security/securityMethods.js.map +1 -0
  160. package/dist/security/securityTypes.d.ts +467 -0
  161. package/dist/security/securityTypes.d.ts.map +1 -0
  162. package/dist/security/securityTypes.js +2 -0
  163. package/dist/security/securityTypes.js.map +1 -0
  164. package/dist/security/userAgent.d.ts +26 -0
  165. package/dist/security/userAgent.d.ts.map +1 -0
  166. package/dist/security/userAgent.js +80 -0
  167. package/dist/security/userAgent.js.map +1 -0
  168. package/dist/signUp/OAuthButtons.d.ts +28 -5
  169. package/dist/signUp/OAuthButtons.d.ts.map +1 -1
  170. package/dist/signUp/OAuthButtons.js +44 -5
  171. package/dist/signUp/OAuthButtons.js.map +1 -1
  172. package/dist/signUp/SignUpScreen.d.ts.map +1 -1
  173. package/dist/signUp/SignUpScreen.js +50 -5
  174. package/dist/signUp/SignUpScreen.js.map +1 -1
  175. package/dist/signUp/signUpTypes.d.ts +21 -1
  176. package/dist/signUp/signUpTypes.d.ts.map +1 -1
  177. package/dist/useConsentForms.d.ts +9 -0
  178. package/dist/useConsentForms.d.ts.map +1 -1
  179. package/dist/useConsentForms.js +18 -0
  180. package/dist/useConsentForms.js.map +1 -1
  181. package/dist/useProvisionalConsent.d.ts +124 -0
  182. package/dist/useProvisionalConsent.d.ts.map +1 -0
  183. package/dist/useProvisionalConsent.js +79 -0
  184. package/dist/useProvisionalConsent.js.map +1 -0
  185. package/package.json +3 -2
  186. package/src/Accordion.test.tsx +5 -0
  187. package/src/Accordion.tsx +3 -8
  188. package/src/AreaChart.test.tsx +15 -0
  189. package/src/Avatar.test.tsx +8 -0
  190. package/src/Avatar.tsx +2 -0
  191. package/src/BarChart.test.tsx +15 -0
  192. package/src/Box.test.tsx +61 -1
  193. package/src/Box.tsx +44 -2
  194. package/src/Card.tsx +2 -2
  195. package/src/Common.ts +134 -7
  196. package/src/ConsentFormScreen.test.tsx +84 -0
  197. package/src/ConsentFormScreen.tsx +28 -4
  198. package/src/DateTimeField.tsx +5 -3
  199. package/src/DonutChart.test.tsx +15 -0
  200. package/src/Field.tsx +2 -0
  201. package/src/FilePickerButton.test.tsx +35 -0
  202. package/src/FormContainer.test.tsx +242 -0
  203. package/src/FormContainer.tsx +177 -0
  204. package/src/GPTChat.test.tsx +16 -0
  205. package/src/GPTChat.tsx +8 -2
  206. package/src/Heading.test.tsx +14 -0
  207. package/src/Heading.tsx +6 -1
  208. package/src/Icon.test.tsx +52 -1
  209. package/src/Icon.tsx +92 -3
  210. package/src/IconButton.test.tsx +85 -0
  211. package/src/LabeledCheckBox.test.tsx +45 -0
  212. package/src/LabeledCheckBox.tsx +89 -0
  213. package/src/ListDetailLayout.tsx +247 -0
  214. package/src/MarkdownEditor.tsx +2 -1
  215. package/src/MediaQuery.ts +1 -0
  216. package/src/OtpField.test.tsx +280 -0
  217. package/src/OtpField.tsx +307 -0
  218. package/src/ProvisionalConsentSigner.test.tsx +625 -0
  219. package/src/ProvisionalConsentSigner.tsx +423 -0
  220. package/src/ResponsiveBreakpoint.test.tsx +7 -0
  221. package/src/ResponsiveBreakpoint.tsx +14 -0
  222. package/src/RootImportRegression.test.tsx +3 -0
  223. package/src/SocialLoginButton.test.tsx +14 -0
  224. package/src/SocialLoginButton.tsx +51 -7
  225. package/src/SplitPage.native.tsx +3 -1
  226. package/src/SplitPage.tsx +11 -5
  227. package/src/SyncStatusBanner.test.tsx +61 -4
  228. package/src/SyncStatusBanner.tsx +29 -3
  229. package/src/TextField.test.tsx +150 -0
  230. package/src/TextField.tsx +66 -8
  231. package/src/__snapshots__/AddressField.test.tsx.snap +12 -0
  232. package/src/__snapshots__/AiSuggestionBox.test.tsx.snap +15 -0
  233. package/src/__snapshots__/Avatar.test.tsx.snap +1 -0
  234. package/src/__snapshots__/CustomSelectField.test.tsx.snap +3 -0
  235. package/src/__snapshots__/EmailField.test.tsx.snap +6 -0
  236. package/src/__snapshots__/Field.test.tsx.snap +37 -0
  237. package/src/__snapshots__/HeightField.test.tsx.snap +2 -0
  238. package/src/__snapshots__/MobileAddressAutoComplete.test.tsx.snap +3 -0
  239. package/src/__snapshots__/NumberField.test.tsx.snap +3 -0
  240. package/src/__snapshots__/PhoneNumberField.test.tsx.snap +12 -0
  241. package/src/__snapshots__/Slider.test.tsx.snap +1 -0
  242. package/src/__snapshots__/SocialLoginButton.test.tsx.snap +43 -22
  243. package/src/__snapshots__/TapToEdit.test.tsx.snap +3 -0
  244. package/src/__snapshots__/TextArea.test.tsx.snap +17 -1
  245. package/src/__snapshots__/TextField.test.tsx.snap +19 -2
  246. package/src/__snapshots__/TypedSignatureField.test.tsx.snap +3 -0
  247. package/src/__snapshots__/UnifiedAddressAutoComplete.test.tsx.snap +18 -0
  248. package/src/__snapshots__/WebAddressAutocomplete.test.tsx.snap +12 -0
  249. package/src/bunSetup.ts +13 -1
  250. package/src/fieldElements/FieldError.tsx +1 -0
  251. package/src/fieldElements/__snapshots__/FieldError.test.tsx.snap +2 -0
  252. package/src/index.tsx +42 -1
  253. package/src/isolated/ListDetailLayout.isolated.tsx +634 -0
  254. package/src/lazyBoundaries/heavyOptionalExports.tsx +7 -0
  255. package/src/login/LastUsedBadge.tsx +40 -0
  256. package/src/login/LoginAccountCard.tsx +205 -0
  257. package/src/login/LoginAccountList.tsx +115 -0
  258. package/src/login/LoginScreen.test.tsx +837 -1
  259. package/src/login/LoginScreen.tsx +674 -91
  260. package/src/login/OutlinePill.tsx +110 -0
  261. package/src/login/TwoFactorChallengeScreen.test.tsx +376 -0
  262. package/src/login/TwoFactorChallengeScreen.tsx +307 -0
  263. package/src/login/__snapshots__/LoginScreen.test.tsx.snap +1454 -334
  264. package/src/login/loginMethods.test.ts +53 -0
  265. package/src/login/loginMethods.ts +60 -0
  266. package/src/login/loginTypes.ts +208 -5
  267. package/src/pdfHtmlTemplate.test.ts +243 -4
  268. package/src/pdfHtmlTemplate.ts +93 -0
  269. package/src/security/AccountSecurityScreen.test.tsx +262 -0
  270. package/src/security/AccountSecurityScreen.tsx +156 -0
  271. package/src/security/LinkedAccountsCard.test.tsx +371 -0
  272. package/src/security/LinkedAccountsCard.tsx +297 -0
  273. package/src/security/PasskeysCard.test.tsx +378 -0
  274. package/src/security/PasskeysCard.tsx +371 -0
  275. package/src/security/PasswordCard.test.tsx +445 -0
  276. package/src/security/PasswordCard.tsx +342 -0
  277. package/src/security/SessionsCard.test.tsx +349 -0
  278. package/src/security/SessionsCard.tsx +362 -0
  279. package/src/security/TwoFactorSettingsCard.test.tsx +700 -0
  280. package/src/security/TwoFactorSettingsCard.tsx +872 -0
  281. package/src/security/securityMethods.test.ts +101 -0
  282. package/src/security/securityMethods.ts +104 -0
  283. package/src/security/securityTypes.ts +480 -0
  284. package/src/security/userAgent.test.ts +119 -0
  285. package/src/security/userAgent.ts +102 -0
  286. package/src/signUp/OAuthButtons.test.tsx +27 -0
  287. package/src/signUp/OAuthButtons.tsx +153 -19
  288. package/src/signUp/SignUpScreen.test.tsx +170 -1
  289. package/src/signUp/SignUpScreen.tsx +87 -25
  290. package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +22 -11
  291. package/src/signUp/signUpTypes.ts +23 -1
  292. package/src/useConsentForms.test.ts +37 -1
  293. package/src/useConsentForms.ts +25 -0
  294. package/src/useProvisionalConsent.test.ts +256 -0
  295. package/src/useProvisionalConsent.ts +218 -0
@@ -17,6 +17,16 @@ interface PdfUserInfo {
17
17
  email?: string;
18
18
  }
19
19
 
20
+ /** A signature staff recorded on the user's behalf. Dates are ISO strings. */
21
+ export interface PdfProvisionalSignature {
22
+ signedAt: string;
23
+ signedByName: string;
24
+ /** The signer's note. Pass it only on admin printouts; the user never sees it. */
25
+ note?: string;
26
+ signerIp?: string;
27
+ voidedAt?: string;
28
+ }
29
+
20
30
  export interface PdfTemplateData {
21
31
  title: string;
22
32
  formTitle: string;
@@ -27,6 +37,7 @@ export interface PdfTemplateData {
27
37
  contentSnapshot?: string;
28
38
  responseId?: string;
29
39
  userInfo?: PdfUserInfo;
40
+ provisionalSignature?: PdfProvisionalSignature;
30
41
  }
31
42
 
32
43
  const escapeHtml = (text: string): string => {
@@ -44,6 +55,34 @@ const renderField = (field: PdfField): string => {
44
55
  </tr>`;
45
56
  };
46
57
 
58
+ /** Format an ISO date for print; anything that is not ISO prints as written. */
59
+ const formatPrintDate = (value: string): string => {
60
+ const date = DateTime.fromISO(value);
61
+ return date.isValid ? date.toLocaleString(DateTime.DATETIME_FULL) : value;
62
+ };
63
+
64
+ const renderProvisionalSignature = (signature?: PdfProvisionalSignature): string => {
65
+ if (!signature) {
66
+ return "";
67
+ }
68
+ const rows = [
69
+ renderField({label: "Signed by:", value: signature.signedByName}),
70
+ signature.signedAt
71
+ ? renderField({label: "Signed at:", value: formatPrintDate(signature.signedAt)})
72
+ : "",
73
+ signature.note ? renderField({label: "Note:", value: signature.note}) : "",
74
+ signature.signerIp ? renderField({label: "Signer IP:", value: signature.signerIp}) : "",
75
+ ].join("\n");
76
+ const voidedHtml = signature.voidedAt
77
+ ? `<div class="voided">Voided ${escapeHtml(formatPrintDate(signature.voidedAt))}</div>`
78
+ : "";
79
+ return `<div class="section">
80
+ <h2>Provisional signature</h2>
81
+ <table>${rows}</table>
82
+ ${voidedHtml}
83
+ </div>`;
84
+ };
85
+
47
86
  export const buildConsentPdfHtml = (data: PdfTemplateData): string => {
48
87
  const now = DateTime.now().toLocaleString(DateTime.DATETIME_FULL);
49
88
 
@@ -168,6 +207,11 @@ export const buildConsentPdfHtml = (data: PdfTemplateData): string => {
168
207
  .section {
169
208
  margin-bottom: 4mm;
170
209
  }
210
+ .voided {
211
+ font-weight: bold;
212
+ color: #a00000;
213
+ margin-top: 2mm;
214
+ }
171
215
  @page {
172
216
  size: A4;
173
217
  margin: 20mm;
@@ -187,6 +231,7 @@ export const buildConsentPdfHtml = (data: PdfTemplateData): string => {
187
231
  ${userInfoHtml}
188
232
  ${checkboxesHtml}
189
233
  ${auditTrailHtml}
234
+ ${renderProvisionalSignature(data.provisionalSignature)}
190
235
  ${signatureHtml}
191
236
  ${contentSnapshotHtml}
192
237
 
@@ -217,3 +262,51 @@ export const sharePdfFromHtml = async (options: {
217
262
  UTI: "com.adobe.pdf",
218
263
  });
219
264
  };
265
+
266
+ /** The last web print frame, removed before the next print in case `afterprint` never fired. */
267
+ let lastPrintFrame: HTMLIFrameElement | undefined;
268
+
269
+ /**
270
+ * Open the print dialog for consent HTML (for example from `buildConsentPdfHtml`). Native uses
271
+ * `expo-print`; web prints from a hidden iframe so the app page itself is not printed.
272
+ */
273
+ export const printConsentHtml = async ({html}: {html: string}): Promise<void> => {
274
+ if (Platform.OS !== "web") {
275
+ const Print = await import("expo-print");
276
+ await Print.printAsync({html});
277
+ return;
278
+ }
279
+
280
+ // Consent HTML can hold PHI, so never leave an old frame in the page.
281
+ lastPrintFrame?.remove();
282
+ await new Promise<void>((resolve, reject) => {
283
+ const iframe = document.createElement("iframe");
284
+ lastPrintFrame = iframe;
285
+ iframe.setAttribute("aria-hidden", "true");
286
+ iframe.style.position = "fixed";
287
+ iframe.style.width = "0";
288
+ iframe.style.height = "0";
289
+ iframe.style.border = "0";
290
+ iframe.style.visibility = "hidden";
291
+ iframe.onload = (): void => {
292
+ const frameWindow = iframe.contentWindow;
293
+ if (!frameWindow) {
294
+ iframe.remove();
295
+ reject(new Error("Print frame did not load"));
296
+ return;
297
+ }
298
+ // Some browsers return from print() before the dialog closes; remove the frame after.
299
+ frameWindow.addEventListener("afterprint", () => iframe.remove());
300
+ try {
301
+ frameWindow.focus();
302
+ frameWindow.print();
303
+ resolve();
304
+ } catch (error) {
305
+ iframe.remove();
306
+ reject(error);
307
+ }
308
+ };
309
+ iframe.srcdoc = html;
310
+ document.body.appendChild(iframe);
311
+ });
312
+ };
@@ -0,0 +1,262 @@
1
+ import {afterEach, describe, expect, it, mock} from "bun:test";
2
+ import {act, fireEvent} from "@testing-library/react-native";
3
+ import {type ScaledSize, ScrollView, StyleSheet, Text, useWindowDimensions} from "react-native";
4
+
5
+ import {renderWithTheme} from "../test-utils";
6
+ import {AccountSecurityScreen} from "./AccountSecurityScreen";
7
+ import type {AccountSecurityScreenProps} from "./securityTypes";
8
+
9
+ const NOW = new Date("2026-03-10T12:00:00.000Z");
10
+
11
+ const ALL_CARDS: AccountSecurityScreenProps = {
12
+ linkedAccounts: {
13
+ accounts: [{id: "acc-google", linkedAt: "2026-03-01T12:00:00.000Z", providerId: "google"}],
14
+ providers: [{id: "google"}, {id: "github"}],
15
+ },
16
+ passkeys: {passkeys: []},
17
+ password: {hasPassword: false, onSubmit: async (): Promise<void> => {}},
18
+ sessions: {
19
+ currentSessionId: "s-current",
20
+ now: NOW,
21
+ sessions: [{createdAt: "2026-03-01T12:00:00.000Z", id: "s-current"}],
22
+ },
23
+ twoFactor: {
24
+ enabled: false,
25
+ onStartEnroll: async (): Promise<{backupCodes: string[]; totpURI: string}> => ({
26
+ backupCodes: [],
27
+ totpURI: "",
28
+ }),
29
+ onVerify: async (): Promise<void> => {},
30
+ },
31
+ };
32
+
33
+ const CARD_TEST_IDS = [
34
+ "linked-accounts-card",
35
+ "password-card",
36
+ "passkeys-card",
37
+ "two-factor-settings-card",
38
+ "sessions-card",
39
+ ];
40
+
41
+ /** The testIDs of every card on screen, in render order. */
42
+ const getRenderedCardOrder = (root: unknown): string[] => {
43
+ const found: string[] = [];
44
+ const visit = (node: unknown): void => {
45
+ if (!node || typeof node !== "object") {
46
+ return;
47
+ }
48
+ if (Array.isArray(node)) {
49
+ node.forEach(visit);
50
+ return;
51
+ }
52
+ const element = node as {children?: unknown; props?: {testID?: string}};
53
+ const testID = element.props?.testID;
54
+ if (testID && CARD_TEST_IDS.includes(testID) && !found.includes(testID)) {
55
+ found.push(testID);
56
+ }
57
+ visit(element.children);
58
+ };
59
+ visit(root);
60
+ return found;
61
+ };
62
+
63
+ type MockableUseWindowDimensions = (() => ScaledSize) & {
64
+ mockImplementation: (impl: () => ScaledSize) => void;
65
+ };
66
+
67
+ /** bunSetup mocks useWindowDimensions at 375px wide; this changes the width for one test. */
68
+ const setWindowWidth = (width: number): void => {
69
+ (useWindowDimensions as MockableUseWindowDimensions).mockImplementation(() => ({
70
+ fontScale: 1,
71
+ height: 1000,
72
+ scale: 2,
73
+ width,
74
+ }));
75
+ };
76
+
77
+ /** The flattened style of the element with this testID. */
78
+ const getStyle = (element: {props: {style?: unknown}}): Record<string, unknown> => {
79
+ return (StyleSheet.flatten(element.props.style as never) ?? {}) as Record<string, unknown>;
80
+ };
81
+
82
+ /** The side padding a flattened style applies, whichever padding key Box used; 0 when none. */
83
+ const getSidePadding = (style: Record<string, unknown>): unknown => {
84
+ return style.paddingLeft ?? style.paddingHorizontal ?? style.padding ?? 0;
85
+ };
86
+
87
+ describe("AccountSecurityScreen", () => {
88
+ afterEach(() => {
89
+ setWindowWidth(375);
90
+ });
91
+
92
+ it("renders every card whose props are given, in order", () => {
93
+ const {getByTestId, toJSON} = renderWithTheme(<AccountSecurityScreen {...ALL_CARDS} />);
94
+ expect(getByTestId("account-security-screen")).toBeTruthy();
95
+ expect(getByTestId("account-security-screen-title").props.children).toBe("Security");
96
+ expect(getRenderedCardOrder(toJSON())).toEqual(CARD_TEST_IDS);
97
+ });
98
+
99
+ it("hides the passkey card when passkeys is undefined", () => {
100
+ const {queryByTestId, getByTestId} = renderWithTheme(
101
+ <AccountSecurityScreen {...ALL_CARDS} passkeys={undefined} />
102
+ );
103
+ expect(queryByTestId("passkeys-card")).toBeNull();
104
+ expect(getByTestId("linked-accounts-card")).toBeTruthy();
105
+ expect(getByTestId("sessions-card")).toBeTruthy();
106
+ });
107
+
108
+ it.each([
109
+ ["linkedAccounts", "linked-accounts-card"],
110
+ ["password", "password-card"],
111
+ ["twoFactor", "two-factor-settings-card"],
112
+ ["sessions", "sessions-card"],
113
+ ] as const)("hides its card when %s is undefined", (prop, cardTestID) => {
114
+ const {queryByTestId, toJSON} = renderWithTheme(
115
+ <AccountSecurityScreen {...ALL_CARDS} {...{[prop]: undefined}} />
116
+ );
117
+ expect(queryByTestId(cardTestID)).toBeNull();
118
+ expect(getRenderedCardOrder(toJSON())).toEqual(
119
+ CARD_TEST_IDS.filter((testID) => testID !== cardTestID)
120
+ );
121
+ });
122
+
123
+ it("groups linked accounts and password under sign-in methods only when either is given", () => {
124
+ const withBoth = renderWithTheme(<AccountSecurityScreen {...ALL_CARDS} />);
125
+ expect(withBoth.getByTestId("account-security-screen-sign-in-methods")).toBeTruthy();
126
+
127
+ const withNeither = renderWithTheme(
128
+ <AccountSecurityScreen passkeys={ALL_CARDS.passkeys} sessions={ALL_CARDS.sessions} />
129
+ );
130
+ expect(withNeither.queryByTestId("account-security-screen-sign-in-methods")).toBeNull();
131
+ });
132
+
133
+ it("shows an empty message when no card is enabled", () => {
134
+ const {getByTestId} = renderWithTheme(<AccountSecurityScreen />);
135
+ expect(getByTestId("account-security-screen-empty")).toBeTruthy();
136
+ });
137
+
138
+ it("shows a custom title, description, header, and trailing children", () => {
139
+ const {getByTestId, getByText} = renderWithTheme(
140
+ <AccountSecurityScreen
141
+ {...ALL_CARDS}
142
+ description="Manage how you sign in."
143
+ header={<Text testID="custom-header">Ada Lovelace</Text>}
144
+ title="Account security"
145
+ >
146
+ <Text testID="custom-card">Recovery email</Text>
147
+ </AccountSecurityScreen>
148
+ );
149
+ expect(getByTestId("account-security-screen-title").props.children).toBe("Account security");
150
+ expect(getByText("Manage how you sign in.")).toBeTruthy();
151
+ expect(getByTestId("custom-header")).toBeTruthy();
152
+ expect(getByTestId("custom-card")).toBeTruthy();
153
+ });
154
+
155
+ it("shows a loading state instead of the cards while loading", () => {
156
+ const {getByTestId, queryByTestId} = renderWithTheme(
157
+ <AccountSecurityScreen {...ALL_CARDS} isLoading />
158
+ );
159
+ const loading = getByTestId("account-security-screen-loading");
160
+ expect(loading.props.accessibilityLabel ?? loading.props["aria-label"]).toBe(
161
+ "Loading security settings"
162
+ );
163
+ for (const cardTestID of CARD_TEST_IDS) {
164
+ expect(queryByTestId(cardTestID)).toBeNull();
165
+ }
166
+ expect(getByTestId("account-security-screen-title")).toBeTruthy();
167
+ });
168
+
169
+ it("shows a page error with a retry button instead of the cards", async () => {
170
+ const onRetry = mock(() => {});
171
+ const {getByTestId, queryByTestId} = renderWithTheme(
172
+ <AccountSecurityScreen
173
+ {...ALL_CARDS}
174
+ error="Couldn't load your security settings."
175
+ onRetry={onRetry}
176
+ />
177
+ );
178
+ const error = getByTestId("account-security-screen-error");
179
+ expect(error.props.role).toBe("alert");
180
+ expect(getByTestId("account-security-screen-error-message").props.children).toBe(
181
+ "Couldn't load your security settings."
182
+ );
183
+ for (const cardTestID of CARD_TEST_IDS) {
184
+ expect(queryByTestId(cardTestID)).toBeNull();
185
+ }
186
+ await act(async () => {
187
+ fireEvent.press(getByTestId("account-security-screen-retry"));
188
+ });
189
+ expect(onRetry).toHaveBeenCalledTimes(1);
190
+ });
191
+
192
+ it("omits the retry button when onRetry is not given", () => {
193
+ const {getByTestId, queryByTestId} = renderWithTheme(
194
+ <AccountSecurityScreen error="Something went wrong." />
195
+ );
196
+ expect(getByTestId("account-security-screen-error")).toBeTruthy();
197
+ expect(queryByTestId("account-security-screen-retry")).toBeNull();
198
+ });
199
+
200
+ it("prefers the loading state over an error while a retry is in flight", () => {
201
+ const {getByTestId, queryByTestId} = renderWithTheme(
202
+ <AccountSecurityScreen error="Something went wrong." isLoading />
203
+ );
204
+ expect(getByTestId("account-security-screen-loading")).toBeTruthy();
205
+ expect(queryByTestId("account-security-screen-error")).toBeNull();
206
+ });
207
+
208
+ it("renders without a Page wrapper when withPage is false", () => {
209
+ const {getByTestId} = renderWithTheme(
210
+ <AccountSecurityScreen {...ALL_CARDS} testID="settings-security" withPage={false} />
211
+ );
212
+ expect(getByTestId("settings-security")).toBeTruthy();
213
+ expect(getByTestId("settings-security-title")).toBeTruthy();
214
+ expect(getByTestId("passkeys-card")).toBeTruthy();
215
+ });
216
+
217
+ it("exposes the title as a level 1 heading and card titles as level 2", () => {
218
+ const {getByTestId} = renderWithTheme(<AccountSecurityScreen {...ALL_CARDS} />);
219
+ const title = getByTestId("account-security-screen-title");
220
+ expect(title.props.role).toBe("heading");
221
+ expect(title.props["aria-level"]).toBe(1);
222
+ for (const cardTestID of CARD_TEST_IDS) {
223
+ const cardTitle = getByTestId(`${cardTestID}-title`);
224
+ expect(cardTitle.props.role).toBe("heading");
225
+ expect(cardTitle.props["aria-level"]).toBe(2);
226
+ }
227
+ });
228
+
229
+ it("scrolls inside its own Page by default", () => {
230
+ const {UNSAFE_queryAllByType} = renderWithTheme(<AccountSecurityScreen {...ALL_CARDS} />);
231
+ expect(UNSAFE_queryAllByType(ScrollView)).toHaveLength(1);
232
+ });
233
+
234
+ it("adds no scroll view with withPage false, leaving scrolling to the parent", () => {
235
+ const {UNSAFE_queryAllByType} = renderWithTheme(
236
+ <AccountSecurityScreen {...ALL_CARDS} withPage={false} />
237
+ );
238
+ expect(UNSAFE_queryAllByType(ScrollView)).toHaveLength(0);
239
+ });
240
+
241
+ it("drops side padding and insets its text on narrow windows, where cards run edge to edge", () => {
242
+ setWindowWidth(768);
243
+ const {getByTestId} = renderWithTheme(<AccountSecurityScreen {...ALL_CARDS} />);
244
+ expect(getSidePadding(getStyle(getByTestId("account-security-screen")))).toBe(0);
245
+ expect(getSidePadding(getStyle(getByTestId("account-security-screen-heading")))).toBe(16);
246
+ });
247
+
248
+ it("pads its sides on wide windows and does not inset its text", () => {
249
+ setWindowWidth(1024);
250
+ const {getByTestId} = renderWithTheme(<AccountSecurityScreen {...ALL_CARDS} />);
251
+ expect(getSidePadding(getStyle(getByTestId("account-security-screen")))).toBe(16);
252
+ expect(getSidePadding(getStyle(getByTestId("account-security-screen-heading")))).toBe(0);
253
+ });
254
+
255
+ it("leaves side padding to the parent on wide windows with withPage false", () => {
256
+ setWindowWidth(1024);
257
+ const {getByTestId} = renderWithTheme(
258
+ <AccountSecurityScreen {...ALL_CARDS} withPage={false} />
259
+ );
260
+ expect(getSidePadding(getStyle(getByTestId("account-security-screen")))).toBe(0);
261
+ });
262
+ });
@@ -0,0 +1,156 @@
1
+ import type {FC, ReactElement, ReactNode} from "react";
2
+ import {ActivityIndicator, useWindowDimensions, View} from "react-native";
3
+
4
+ import {Box} from "../Box";
5
+ import {Button} from "../Button";
6
+ import {Card} from "../Card";
7
+ import {Heading} from "../Heading";
8
+ import {isSupportedDesktopWidth} from "../MediaQuery";
9
+ import {Page} from "../Page";
10
+ import {Text} from "../Text";
11
+ import {useTheme} from "../Theme";
12
+ import {LinkedAccountsCard} from "./LinkedAccountsCard";
13
+ import {PasskeysCard} from "./PasskeysCard";
14
+ import {PasswordCard} from "./PasswordCard";
15
+ import {SessionsCard} from "./SessionsCard";
16
+ import type {AccountSecurityScreenProps} from "./securityTypes";
17
+ import {TwoFactorSettingsCard} from "./TwoFactorSettingsCard";
18
+
19
+ const LOADING_LABEL = "Loading security settings";
20
+
21
+ /**
22
+ * A security settings screen built from the account security cards: sign-in methods (linked
23
+ * accounts and password), passkeys, two-factor authentication, and sessions, in that order. Each
24
+ * card renders only when its props are given, so a feature the app turned off hides its card.
25
+ * Presentational: it shows what it is given and reports actions through each card's callbacks.
26
+ */
27
+ export const AccountSecurityScreen: FC<AccountSecurityScreenProps> = ({
28
+ linkedAccounts,
29
+ password,
30
+ passkeys,
31
+ twoFactor,
32
+ sessions,
33
+ title = "Security",
34
+ description,
35
+ header,
36
+ children,
37
+ isLoading = false,
38
+ error,
39
+ onRetry,
40
+ withPage = true,
41
+ maxWidth = 720,
42
+ testID = "account-security-screen",
43
+ }) => {
44
+ const {theme} = useTheme();
45
+ const {width: windowWidth} = useWindowDimensions();
46
+ // Below the desktop floor, cards run edge to edge, so the screen adds no side padding of its
47
+ // own and insets its text to line up with the cards' content instead.
48
+ const isFullBleed = !isSupportedDesktopWidth({width: windowWidth});
49
+ const textInset = isFullBleed ? 4 : 0;
50
+
51
+ const hasSignInMethods = Boolean(linkedAccounts) || Boolean(password);
52
+ const hasCards = hasSignInMethods || Boolean(passkeys) || Boolean(twoFactor) || Boolean(sessions);
53
+
54
+ const renderBody = (): ReactNode => {
55
+ if (isLoading) {
56
+ return (
57
+ <View
58
+ accessibilityLabel={LOADING_LABEL}
59
+ accessibilityRole="progressbar"
60
+ aria-busy
61
+ style={{alignItems: "center", gap: 8, paddingVertical: 48}}
62
+ testID={`${testID}-loading`}
63
+ >
64
+ {/* The ui Spinner waits 300ms before showing; a page load wants feedback at once. */}
65
+ <ActivityIndicator color={theme.primitives.neutral400} size="large" />
66
+ <Text color="secondaryLight">Loading your security settings…</Text>
67
+ </View>
68
+ );
69
+ }
70
+
71
+ if (error) {
72
+ return (
73
+ <Card>
74
+ <View role="alert" style={{gap: 16}} testID={`${testID}-error`}>
75
+ <Text color="error" testID={`${testID}-error-message`}>
76
+ {error}
77
+ </Text>
78
+ {Boolean(onRetry) && (
79
+ <Box alignItems="start">
80
+ <Button
81
+ iconName="arrows-rotate"
82
+ onClick={(): void => onRetry?.()}
83
+ testID={`${testID}-retry`}
84
+ text="Try again"
85
+ variant="secondary"
86
+ />
87
+ </Box>
88
+ )}
89
+ </View>
90
+ </Card>
91
+ );
92
+ }
93
+
94
+ if (!hasCards && !children) {
95
+ return (
96
+ <Box paddingX={textInset}>
97
+ <Text color="secondaryLight" testID={`${testID}-empty`}>
98
+ There are no security settings to manage.
99
+ </Text>
100
+ </Box>
101
+ );
102
+ }
103
+
104
+ return (
105
+ <>
106
+ {hasSignInMethods && (
107
+ <Box gap={4} testID={`${testID}-sign-in-methods`}>
108
+ {Boolean(linkedAccounts) && <LinkedAccountsCard {...linkedAccounts!} />}
109
+ {Boolean(password) && <PasswordCard {...password!} />}
110
+ </Box>
111
+ )}
112
+ {Boolean(passkeys) && <PasskeysCard {...passkeys!} />}
113
+ {Boolean(twoFactor) && <TwoFactorSettingsCard {...twoFactor!} />}
114
+ {Boolean(sessions) && <SessionsCard {...sessions!} />}
115
+ {children}
116
+ </>
117
+ );
118
+ };
119
+
120
+ const content: ReactElement = (
121
+ <Box
122
+ alignSelf="center"
123
+ gap={4}
124
+ maxWidth={maxWidth}
125
+ paddingX={withPage && !isFullBleed ? 4 : 0}
126
+ paddingY={4}
127
+ testID={testID}
128
+ width="100%"
129
+ >
130
+ <Box gap={1} paddingX={textInset} testID={`${testID}-heading`}>
131
+ <Heading level={1} size="lg" testID={`${testID}-title`}>
132
+ {title}
133
+ </Heading>
134
+ {Boolean(description) && (
135
+ <Text color="secondaryLight" testID={`${testID}-description`}>
136
+ {description}
137
+ </Text>
138
+ )}
139
+ </Box>
140
+ {Boolean(header) && <Box paddingX={textInset}>{header}</Box>}
141
+ {renderBody()}
142
+ </Box>
143
+ );
144
+
145
+ if (!withPage) {
146
+ return content;
147
+ }
148
+
149
+ return (
150
+ // The Page (and its ScrollView) spans the window so the whole width scrolls; the content Box
151
+ // above applies maxWidth.
152
+ <Page maxWidth="100%" navigation={undefined} padding={0}>
153
+ {content}
154
+ </Page>
155
+ );
156
+ };