@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
@@ -0,0 +1,445 @@
1
+ import {describe, expect, it, mock, spyOn} from "bun:test";
2
+ import {act, fireEvent, render, waitFor} from "@testing-library/react-native";
3
+ import type {ReactElement} from "react";
4
+ import {ThemeProvider} from "../Theme";
5
+ import {renderWithTheme} from "../test-utils";
6
+ import {PasswordCard} from "./PasswordCard";
7
+ import type {PasswordCardSubmission} from "./securityTypes";
8
+
9
+ const makeOnSubmit = () => mock((_values: PasswordCardSubmission) => Promise.resolve());
10
+
11
+ const press = async (element: Parameters<typeof fireEvent.press>[0]): Promise<void> => {
12
+ await act(async () => {
13
+ fireEvent.press(element);
14
+ });
15
+ };
16
+
17
+ /** Renders with host-node mocks whose focus() records the focused input's testID. */
18
+ const renderTrackingFocus = (ui: ReactElement): ReturnType<typeof render> & {focused: string[]} => {
19
+ const focused: string[] = [];
20
+ const result = render(ui, {
21
+ createNodeMock: (element: ReactElement<{testID?: string}>) => ({
22
+ blur: (): void => {},
23
+ clear: (): void => {},
24
+ focus: (): void => {
25
+ focused.push(element.props.testID ?? "");
26
+ },
27
+ isFocused: (): boolean => false,
28
+ }),
29
+ wrapper: ThemeProvider,
30
+ });
31
+ return {...result, focused};
32
+ };
33
+
34
+ const setOS = (os: string): string => {
35
+ const reactNative = require("react-native") as {Platform: {OS: string}};
36
+ const originalOS = reactNative.Platform.OS;
37
+ reactNative.Platform.OS = os;
38
+ return originalOS;
39
+ };
40
+
41
+ describe("PasswordCard", () => {
42
+ describe("change mode", () => {
43
+ it("renders current, new and confirm fields and the sign-out checkbox", () => {
44
+ const {getByTestId} = renderWithTheme(<PasswordCard hasPassword onSubmit={makeOnSubmit()} />);
45
+ expect(getByTestId("password-card")).toBeTruthy();
46
+ expect(getByTestId("password-card-title").props.children).toBe("Change password");
47
+ expect(getByTestId("password-card-current")).toBeTruthy();
48
+ expect(getByTestId("password-card-new")).toBeTruthy();
49
+ expect(getByTestId("password-card-confirm")).toBeTruthy();
50
+ expect(getByTestId("password-card-revoke-other-sessions")).toBeTruthy();
51
+ expect(getByTestId("password-card-submit")).toBeTruthy();
52
+ });
53
+
54
+ it("hints current-password and new-password to password managers on web", () => {
55
+ const originalOS = setOS("web");
56
+ try {
57
+ const {getByTestId} = renderWithTheme(
58
+ <PasswordCard hasPassword onSubmit={makeOnSubmit()} />
59
+ );
60
+ expect(getByTestId("password-card-current").props.autoComplete).toBe("current-password");
61
+ expect(getByTestId("password-card-new").props.autoComplete).toBe("new-password");
62
+ expect(getByTestId("password-card-confirm").props.autoComplete).toBe("new-password");
63
+ } finally {
64
+ setOS(originalOS);
65
+ }
66
+ });
67
+
68
+ it("submits the current and new password with the sign-out choice", async () => {
69
+ const onSubmit = makeOnSubmit();
70
+ const {getByTestId} = renderWithTheme(<PasswordCard hasPassword onSubmit={onSubmit} />);
71
+ fireEvent.changeText(getByTestId("password-card-current"), "old-password");
72
+ fireEvent.changeText(getByTestId("password-card-new"), "new-password-1");
73
+ fireEvent.changeText(getByTestId("password-card-confirm"), "new-password-1");
74
+ await press(getByTestId("password-card-revoke-other-sessions"));
75
+ await press(getByTestId("password-card-submit"));
76
+ await waitFor(() => {
77
+ expect(onSubmit).toHaveBeenCalledWith({
78
+ currentPassword: "old-password",
79
+ mode: "change",
80
+ newPassword: "new-password-1",
81
+ revokeOtherSessions: true,
82
+ });
83
+ });
84
+ });
85
+
86
+ it("leaves revokeOtherSessions false by default", async () => {
87
+ const onSubmit = makeOnSubmit();
88
+ const {getByTestId} = renderWithTheme(<PasswordCard hasPassword onSubmit={onSubmit} />);
89
+ fireEvent.changeText(getByTestId("password-card-current"), "old-password");
90
+ fireEvent.changeText(getByTestId("password-card-new"), "new-password-1");
91
+ fireEvent.changeText(getByTestId("password-card-confirm"), "new-password-1");
92
+ await press(getByTestId("password-card-submit"));
93
+ await waitFor(() => {
94
+ expect(onSubmit).toHaveBeenCalledWith(
95
+ expect.objectContaining({revokeOtherSessions: false})
96
+ );
97
+ });
98
+ });
99
+
100
+ it("hides the sign-out checkbox with showRevokeOtherSessions={false}", () => {
101
+ const {queryByTestId} = renderWithTheme(
102
+ <PasswordCard hasPassword onSubmit={makeOnSubmit()} showRevokeOtherSessions={false} />
103
+ );
104
+ expect(queryByTestId("password-card-revoke-other-sessions")).toBeNull();
105
+ });
106
+
107
+ it("requires the current password", async () => {
108
+ const onSubmit = makeOnSubmit();
109
+ const {getByTestId, getByText} = renderWithTheme(
110
+ <PasswordCard hasPassword onSubmit={onSubmit} />
111
+ );
112
+ fireEvent.changeText(getByTestId("password-card-new"), "new-password-1");
113
+ fireEvent.changeText(getByTestId("password-card-confirm"), "new-password-1");
114
+ await press(getByTestId("password-card-submit"));
115
+ expect(getByText("Enter your current password.")).toBeTruthy();
116
+ expect(onSubmit).not.toHaveBeenCalled();
117
+ });
118
+ });
119
+
120
+ describe("set mode", () => {
121
+ it("renders only new and confirm fields for an OAuth-only user", () => {
122
+ const {getByTestId, getByText, queryByTestId} = renderWithTheme(
123
+ <PasswordCard hasPassword={false} onSubmit={makeOnSubmit()} />
124
+ );
125
+ expect(getByText("Set a password")).toBeTruthy();
126
+ expect(queryByTestId("password-card-current")).toBeNull();
127
+ expect(queryByTestId("password-card-revoke-other-sessions")).toBeNull();
128
+ expect(getByTestId("password-card-new")).toBeTruthy();
129
+ expect(getByTestId("password-card-confirm")).toBeTruthy();
130
+ });
131
+
132
+ it("submits mode set with the new password", async () => {
133
+ const onSubmit = makeOnSubmit();
134
+ const {getByTestId} = renderWithTheme(
135
+ <PasswordCard hasPassword={false} onSubmit={onSubmit} />
136
+ );
137
+ fireEvent.changeText(getByTestId("password-card-new"), "first-password");
138
+ fireEvent.changeText(getByTestId("password-card-confirm"), "first-password");
139
+ await press(getByTestId("password-card-submit"));
140
+ await waitFor(() => {
141
+ expect(onSubmit).toHaveBeenCalledWith({
142
+ mode: "set",
143
+ newPassword: "first-password",
144
+ revokeOtherSessions: false,
145
+ });
146
+ });
147
+ });
148
+
149
+ it("switches to change mode once the user has a password", () => {
150
+ const onSubmit = makeOnSubmit();
151
+ const {getByTestId, rerender} = renderWithTheme(
152
+ <PasswordCard hasPassword={false} onSubmit={onSubmit} />
153
+ );
154
+ fireEvent.changeText(getByTestId("password-card-new"), "first-password");
155
+ rerender(<PasswordCard hasPassword onSubmit={onSubmit} />);
156
+ expect(getByTestId("password-card-current")).toBeTruthy();
157
+ expect(getByTestId("password-card-new").props.value).toBe("");
158
+ });
159
+
160
+ it("keeps the set-password success message after switching to change mode", async () => {
161
+ const onSubmit = makeOnSubmit();
162
+ const {getByTestId, getByText, rerender} = renderWithTheme(
163
+ <PasswordCard hasPassword={false} onSubmit={onSubmit} />
164
+ );
165
+ fireEvent.changeText(getByTestId("password-card-new"), "first-password");
166
+ fireEvent.changeText(getByTestId("password-card-confirm"), "first-password");
167
+ await press(getByTestId("password-card-submit"));
168
+ await waitFor(() => {
169
+ expect(getByTestId("password-card-success")).toBeTruthy();
170
+ });
171
+ rerender(<PasswordCard hasPassword onSubmit={onSubmit} />);
172
+ expect(
173
+ getByText("Your password has been set. You can now sign in with your email.")
174
+ ).toBeTruthy();
175
+ });
176
+ });
177
+
178
+ describe("validation", () => {
179
+ it("shows an inline error when the confirmation does not match", async () => {
180
+ const onSubmit = makeOnSubmit();
181
+ const {getByTestId, getByText} = renderWithTheme(
182
+ <PasswordCard hasPassword={false} onSubmit={onSubmit} />
183
+ );
184
+ fireEvent.changeText(getByTestId("password-card-new"), "first-password");
185
+ fireEvent.changeText(getByTestId("password-card-confirm"), "other-password");
186
+ await press(getByTestId("password-card-submit"));
187
+ expect(getByText("Passwords don't match.")).toBeTruthy();
188
+ expect(onSubmit).not.toHaveBeenCalled();
189
+ });
190
+
191
+ it("shows an inline error when the new password is too short", async () => {
192
+ const onSubmit = makeOnSubmit();
193
+ const {getByTestId, getByText} = renderWithTheme(
194
+ <PasswordCard hasPassword={false} minLength={10} onSubmit={onSubmit} />
195
+ );
196
+ fireEvent.changeText(getByTestId("password-card-new"), "short");
197
+ fireEvent.changeText(getByTestId("password-card-confirm"), "short");
198
+ await press(getByTestId("password-card-submit"));
199
+ expect(getByText("Use at least 10 characters.")).toBeTruthy();
200
+ expect(onSubmit).not.toHaveBeenCalled();
201
+ });
202
+
203
+ it("clears a field's error when that field changes", async () => {
204
+ const {getByTestId, getByText, queryByText} = renderWithTheme(
205
+ <PasswordCard hasPassword={false} onSubmit={makeOnSubmit()} />
206
+ );
207
+ fireEvent.changeText(getByTestId("password-card-new"), "first-password");
208
+ fireEvent.changeText(getByTestId("password-card-confirm"), "other-password");
209
+ await press(getByTestId("password-card-submit"));
210
+ expect(getByText("Passwords don't match.")).toBeTruthy();
211
+ fireEvent.changeText(getByTestId("password-card-confirm"), "first-password");
212
+ expect(queryByText("Passwords don't match.")).toBeNull();
213
+ });
214
+ });
215
+
216
+ describe("keyboard and focus", () => {
217
+ it("moves focus to the next field on Enter in the current and new password fields", async () => {
218
+ const onSubmit = makeOnSubmit();
219
+ const {focused, getByTestId} = renderTrackingFocus(
220
+ <PasswordCard hasPassword onSubmit={onSubmit} />
221
+ );
222
+ expect(getByTestId("password-card-current").props.enterKeyHint).toBe("next");
223
+ expect(getByTestId("password-card-current").props.blurOnSubmit).toBe(false);
224
+ expect(getByTestId("password-card-new").props.enterKeyHint).toBe("next");
225
+ expect(getByTestId("password-card-confirm").props.enterKeyHint).toBe("done");
226
+ fireEvent.changeText(getByTestId("password-card-current"), "old-password");
227
+ fireEvent.changeText(getByTestId("password-card-new"), "new-password-1");
228
+ fireEvent.changeText(getByTestId("password-card-confirm"), "new-password-1");
229
+ await act(async () => {
230
+ fireEvent(getByTestId("password-card-current"), "submitEditing");
231
+ });
232
+ await act(async () => {
233
+ fireEvent(getByTestId("password-card-new"), "submitEditing");
234
+ });
235
+ expect(focused).toEqual(["password-card-new", "password-card-confirm"]);
236
+ expect(onSubmit).not.toHaveBeenCalled();
237
+ });
238
+
239
+ it("moves from the new password to the confirm field on Enter in set mode", async () => {
240
+ const {focused, getByTestId} = renderTrackingFocus(
241
+ <PasswordCard hasPassword={false} onSubmit={makeOnSubmit()} />
242
+ );
243
+ await act(async () => {
244
+ fireEvent(getByTestId("password-card-new"), "submitEditing");
245
+ });
246
+ expect(focused).toEqual(["password-card-confirm"]);
247
+ });
248
+
249
+ it("wraps the fields in a form on web with the account's username and submits through it", async () => {
250
+ const originalOS = setOS("web");
251
+ try {
252
+ const requestSubmit = mock(() => {});
253
+ const onSubmit = makeOnSubmit();
254
+ const {UNSAFE_getByType, getByTestId} = render(
255
+ <PasswordCard hasPassword onSubmit={onSubmit} username="ada@example.com" />,
256
+ {
257
+ createNodeMock: (element: ReactElement) =>
258
+ element.type === "form" ? {requestSubmit} : {focus: (): void => {}},
259
+ wrapper: ThemeProvider,
260
+ }
261
+ );
262
+ const form = UNSAFE_getByType("form" as never);
263
+ expect(form.props["data-testid"]).toBe("password-card-form");
264
+ expect(UNSAFE_getByType("input" as never).props.value).toBe("ada@example.com");
265
+ fireEvent.changeText(getByTestId("password-card-current"), "old-password");
266
+ fireEvent.changeText(getByTestId("password-card-new"), "new-password-1");
267
+ fireEvent.changeText(getByTestId("password-card-confirm"), "new-password-1");
268
+ await act(async () => {
269
+ fireEvent(getByTestId("password-card-confirm"), "submitEditing");
270
+ });
271
+ await press(getByTestId("password-card-submit"));
272
+ expect(requestSubmit).toHaveBeenCalledTimes(2);
273
+ expect(onSubmit).not.toHaveBeenCalled();
274
+ await act(async () => {
275
+ fireEvent(form, "submit", {preventDefault: () => {}});
276
+ });
277
+ expect(onSubmit).toHaveBeenCalledTimes(1);
278
+ } finally {
279
+ setOS(originalOS);
280
+ }
281
+ });
282
+
283
+ it("submits with Enter from the confirm field without pressing the button", async () => {
284
+ const onSubmit = makeOnSubmit();
285
+ const {getByTestId} = renderWithTheme(<PasswordCard hasPassword onSubmit={onSubmit} />);
286
+ fireEvent.changeText(getByTestId("password-card-current"), "old-password");
287
+ fireEvent.changeText(getByTestId("password-card-new"), "new-password-1");
288
+ fireEvent.changeText(getByTestId("password-card-confirm"), "new-password-1");
289
+ await act(async () => {
290
+ fireEvent(getByTestId("password-card-confirm"), "submitEditing");
291
+ });
292
+ await waitFor(() => {
293
+ expect(onSubmit).toHaveBeenCalledTimes(1);
294
+ });
295
+ expect(onSubmit).toHaveBeenCalledWith({
296
+ currentPassword: "old-password",
297
+ mode: "change",
298
+ newPassword: "new-password-1",
299
+ revokeOtherSessions: false,
300
+ });
301
+ });
302
+
303
+ it("focuses the current password field when it is the first invalid field", async () => {
304
+ const {focused, getByTestId} = renderTrackingFocus(
305
+ <PasswordCard hasPassword onSubmit={makeOnSubmit()} />
306
+ );
307
+ fireEvent.changeText(getByTestId("password-card-new"), "short");
308
+ await press(getByTestId("password-card-submit"));
309
+ expect(focused).toEqual(["password-card-current"]);
310
+ });
311
+
312
+ it("focuses the new password field when it is the first invalid field", async () => {
313
+ const {focused, getByTestId} = renderTrackingFocus(
314
+ <PasswordCard hasPassword onSubmit={makeOnSubmit()} />
315
+ );
316
+ fireEvent.changeText(getByTestId("password-card-current"), "old-password");
317
+ fireEvent.changeText(getByTestId("password-card-new"), "short");
318
+ fireEvent.changeText(getByTestId("password-card-confirm"), "short");
319
+ await press(getByTestId("password-card-submit"));
320
+ expect(focused).toEqual(["password-card-new"]);
321
+ });
322
+
323
+ it("focuses the confirm field when only the confirmation is wrong", async () => {
324
+ const onSubmit = makeOnSubmit();
325
+ const {focused, getByTestId} = renderTrackingFocus(
326
+ <PasswordCard hasPassword={false} onSubmit={onSubmit} />
327
+ );
328
+ fireEvent.changeText(getByTestId("password-card-new"), "first-password");
329
+ fireEvent.changeText(getByTestId("password-card-confirm"), "other-password");
330
+ await press(getByTestId("password-card-submit"));
331
+ expect(focused).toEqual(["password-card-confirm"]);
332
+ expect(onSubmit).not.toHaveBeenCalled();
333
+ });
334
+
335
+ it("announces failed validation with an alert that counts the invalid fields", async () => {
336
+ const {getByTestId, getByText, queryByTestId} = renderWithTheme(
337
+ <PasswordCard hasPassword onSubmit={makeOnSubmit()} />
338
+ );
339
+ fireEvent.changeText(getByTestId("password-card-new"), "short");
340
+ await press(getByTestId("password-card-submit"));
341
+ expect(getByTestId("password-card-validation-error").props.role).toBe("alert");
342
+ expect(getByText("Fix the 3 highlighted fields.")).toBeTruthy();
343
+
344
+ fireEvent.changeText(getByTestId("password-card-current"), "old-password");
345
+ fireEvent.changeText(getByTestId("password-card-new"), "new-password-1");
346
+ expect(getByText("Fix the highlighted field.")).toBeTruthy();
347
+ fireEvent.changeText(getByTestId("password-card-confirm"), "new-password-1");
348
+ expect(queryByTestId("password-card-validation-error")).toBeNull();
349
+ });
350
+ });
351
+
352
+ describe("submission results", () => {
353
+ it("submits once when pressed again before onSubmit settles", async () => {
354
+ let resolveSubmit: () => void = () => {};
355
+ const onSubmit = mock(
356
+ (_values: PasswordCardSubmission) =>
357
+ new Promise<void>((resolve) => {
358
+ resolveSubmit = resolve;
359
+ })
360
+ );
361
+ const {getByTestId} = renderWithTheme(
362
+ <PasswordCard hasPassword={false} onSubmit={onSubmit} />
363
+ );
364
+ fireEvent.changeText(getByTestId("password-card-new"), "first-password");
365
+ fireEvent.changeText(getByTestId("password-card-confirm"), "first-password");
366
+ await act(async () => {
367
+ fireEvent(getByTestId("password-card-confirm"), "submitEditing");
368
+ fireEvent(getByTestId("password-card-confirm"), "submitEditing");
369
+ });
370
+ await press(getByTestId("password-card-submit"));
371
+ expect(onSubmit).toHaveBeenCalledTimes(1);
372
+ await act(async () => {
373
+ resolveSubmit();
374
+ });
375
+ await waitFor(() => {
376
+ expect(getByTestId("password-card-success")).toBeTruthy();
377
+ });
378
+ expect(onSubmit).toHaveBeenCalledTimes(1);
379
+ });
380
+
381
+ it("shows a success message and clears the form after onSubmit resolves", async () => {
382
+ const {getByTestId} = renderWithTheme(
383
+ <PasswordCard hasPassword={false} onSubmit={makeOnSubmit()} />
384
+ );
385
+ fireEvent.changeText(getByTestId("password-card-new"), "first-password");
386
+ fireEvent.changeText(getByTestId("password-card-confirm"), "first-password");
387
+ await press(getByTestId("password-card-submit"));
388
+ await waitFor(() => {
389
+ expect(getByTestId("password-card-success")).toBeTruthy();
390
+ });
391
+ expect(getByTestId("password-card-new").props.value).toBe("");
392
+ expect(getByTestId("password-card-confirm").props.value).toBe("");
393
+ });
394
+
395
+ it("shows a rejection's message as an alert and keeps the form", async () => {
396
+ const warn = spyOn(console, "warn").mockImplementation(() => {});
397
+ const onSubmit = mock((_values: PasswordCardSubmission) =>
398
+ Promise.reject(new Error("Invalid password"))
399
+ );
400
+ const {getByTestId, getByText, queryByTestId} = renderWithTheme(
401
+ <PasswordCard hasPassword onSubmit={onSubmit} />
402
+ );
403
+ fireEvent.changeText(getByTestId("password-card-current"), "wrong-password");
404
+ fireEvent.changeText(getByTestId("password-card-new"), "new-password-1");
405
+ fireEvent.changeText(getByTestId("password-card-confirm"), "new-password-1");
406
+ await press(getByTestId("password-card-submit"));
407
+ await waitFor(() => {
408
+ expect(getByTestId("password-card-error")).toBeTruthy();
409
+ });
410
+ expect(getByTestId("password-card-error").props.role).toBe("alert");
411
+ expect(getByText("Invalid password")).toBeTruthy();
412
+ expect(queryByTestId("password-card-success")).toBeNull();
413
+ expect(getByTestId("password-card-new").props.value).toBe("new-password-1");
414
+ warn.mockRestore();
415
+ });
416
+
417
+ it("shows the error prop as an alert", () => {
418
+ const {getByTestId, getByText} = renderWithTheme(
419
+ <PasswordCard error="Current password is incorrect" hasPassword onSubmit={makeOnSubmit()} />
420
+ );
421
+ expect(getByTestId("password-card-error").props.role).toBe("alert");
422
+ expect(getByText("Current password is incorrect")).toBeTruthy();
423
+ });
424
+
425
+ it("does not submit while loading", async () => {
426
+ const onSubmit = makeOnSubmit();
427
+ const {getByTestId} = renderWithTheme(
428
+ <PasswordCard hasPassword={false} loading onSubmit={onSubmit} />
429
+ );
430
+ fireEvent.changeText(getByTestId("password-card-new"), "first-password");
431
+ fireEvent.changeText(getByTestId("password-card-confirm"), "first-password");
432
+ await press(getByTestId("password-card-submit"));
433
+ expect(onSubmit).not.toHaveBeenCalled();
434
+ });
435
+ });
436
+
437
+ it("labels each password input for screen readers", () => {
438
+ const {getByLabelText} = renderWithTheme(
439
+ <PasswordCard hasPassword onSubmit={makeOnSubmit()} />
440
+ );
441
+ expect(getByLabelText("Current password")).toBeTruthy();
442
+ expect(getByLabelText("New password")).toBeTruthy();
443
+ expect(getByLabelText("Confirm new password")).toBeTruthy();
444
+ });
445
+ });