@terreno/ui 57.18.0 → 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.
- package/.ai/guidelines/core.md +1 -1
- package/CHANGELOG.md +2074 -0
- package/dist/Accordion.d.ts.map +1 -1
- package/dist/Accordion.js +3 -3
- package/dist/Accordion.js.map +1 -1
- package/dist/AreaChart.d.ts.map +1 -1
- package/dist/AreaChart.js +2 -2
- package/dist/AreaChart.js.map +1 -1
- package/dist/Avatar.d.ts.map +1 -1
- package/dist/Avatar.js +3 -1
- package/dist/Avatar.js.map +1 -1
- package/dist/BarChart.d.ts.map +1 -1
- package/dist/BarChart.js +2 -2
- package/dist/BarChart.js.map +1 -1
- package/dist/Box.d.ts.map +1 -1
- package/dist/Box.js +66 -8
- package/dist/Box.js.map +1 -1
- package/dist/Card.d.ts.map +1 -1
- package/dist/Card.js +5 -4
- package/dist/Card.js.map +1 -1
- package/dist/ChartCard.d.ts.map +1 -1
- package/dist/ChartCard.js +4 -2
- package/dist/ChartCard.js.map +1 -1
- package/dist/Common.d.ts +240 -14
- package/dist/Common.d.ts.map +1 -1
- package/dist/Common.js.map +1 -1
- package/dist/ConsentFormScreen.d.ts +1 -1
- package/dist/ConsentFormScreen.d.ts.map +1 -1
- package/dist/ConsentFormScreen.js +13 -4
- package/dist/ConsentFormScreen.js.map +1 -1
- package/dist/DateTimeField.d.ts.map +1 -1
- package/dist/DateTimeField.js +5 -3
- package/dist/DateTimeField.js.map +1 -1
- package/dist/DonutChart.d.ts.map +1 -1
- package/dist/DonutChart.js +2 -2
- package/dist/DonutChart.js.map +1 -1
- package/dist/Field.d.ts.map +1 -1
- package/dist/Field.js +2 -0
- package/dist/Field.js.map +1 -1
- package/dist/FormContainer.d.ts +68 -0
- package/dist/FormContainer.d.ts.map +1 -0
- package/dist/FormContainer.js +79 -0
- package/dist/FormContainer.js.map +1 -0
- package/dist/GPTChat.d.ts.map +1 -1
- package/dist/GPTChat.js +2 -1
- package/dist/GPTChat.js.map +1 -1
- package/dist/Heading.d.ts +1 -1
- package/dist/Heading.d.ts.map +1 -1
- package/dist/Heading.js +5 -2
- package/dist/Heading.js.map +1 -1
- package/dist/Icon.d.ts +4 -0
- package/dist/Icon.d.ts.map +1 -1
- package/dist/Icon.js +43 -2
- package/dist/Icon.js.map +1 -1
- package/dist/LabeledCheckBox.d.ts +22 -0
- package/dist/LabeledCheckBox.d.ts.map +1 -0
- package/dist/LabeledCheckBox.js +30 -0
- package/dist/LabeledCheckBox.js.map +1 -0
- package/dist/LineChart.d.ts.map +1 -1
- package/dist/LineChart.js +2 -2
- package/dist/LineChart.js.map +1 -1
- package/dist/ListDetailLayout.d.ts +36 -0
- package/dist/ListDetailLayout.d.ts.map +1 -0
- package/dist/ListDetailLayout.js +153 -0
- package/dist/ListDetailLayout.js.map +1 -0
- package/dist/MarkdownEditor.d.ts.map +1 -1
- package/dist/MarkdownEditor.js +2 -1
- package/dist/MarkdownEditor.js.map +1 -1
- package/dist/MediaQuery.d.ts +1 -1
- package/dist/MediaQuery.d.ts.map +1 -1
- package/dist/MediaQuery.js +1 -1
- package/dist/MediaQuery.js.map +1 -1
- package/dist/OtpField.d.ts +60 -0
- package/dist/OtpField.d.ts.map +1 -0
- package/dist/OtpField.js +154 -0
- package/dist/OtpField.js.map +1 -0
- package/dist/Page.d.ts +1 -0
- package/dist/Page.d.ts.map +1 -1
- package/dist/Page.js +10 -1
- package/dist/Page.js.map +1 -1
- package/dist/ProvisionalConsentSigner.d.ts +21 -0
- package/dist/ProvisionalConsentSigner.d.ts.map +1 -0
- package/dist/ProvisionalConsentSigner.js +199 -0
- package/dist/ProvisionalConsentSigner.js.map +1 -0
- package/dist/ResponsiveBreakpoint.d.ts +5 -0
- package/dist/ResponsiveBreakpoint.d.ts.map +1 -1
- package/dist/ResponsiveBreakpoint.js +7 -0
- package/dist/ResponsiveBreakpoint.js.map +1 -1
- package/dist/Scorecard.d.ts.map +1 -1
- package/dist/Scorecard.js +5 -2
- package/dist/Scorecard.js.map +1 -1
- package/dist/Skeleton.d.ts +39 -0
- package/dist/Skeleton.d.ts.map +1 -0
- package/dist/Skeleton.js +195 -0
- package/dist/Skeleton.js.map +1 -0
- package/dist/SocialLoginButton.d.ts +10 -0
- package/dist/SocialLoginButton.d.ts.map +1 -1
- package/dist/SocialLoginButton.js +26 -8
- package/dist/SocialLoginButton.js.map +1 -1
- package/dist/SplitPage.d.ts +12 -1
- package/dist/SplitPage.d.ts.map +1 -1
- package/dist/SplitPage.js +14 -7
- package/dist/SplitPage.js.map +1 -1
- package/dist/SplitPage.native.d.ts +1 -1
- package/dist/SplitPage.native.d.ts.map +1 -1
- package/dist/SplitPage.native.js +6 -3
- package/dist/SplitPage.native.js.map +1 -1
- package/dist/SplitPageLoading.d.ts +14 -0
- package/dist/SplitPageLoading.d.ts.map +1 -0
- package/dist/SplitPageLoading.js +19 -0
- package/dist/SplitPageLoading.js.map +1 -0
- package/dist/SyncStatusBanner.d.ts +7 -1
- package/dist/SyncStatusBanner.d.ts.map +1 -1
- package/dist/SyncStatusBanner.js +20 -4
- package/dist/SyncStatusBanner.js.map +1 -1
- package/dist/Text.d.ts +3 -1
- package/dist/Text.d.ts.map +1 -1
- package/dist/Text.js +2 -0
- package/dist/Text.js.map +1 -1
- package/dist/TextField.d.ts.map +1 -1
- package/dist/TextField.js +44 -10
- package/dist/TextField.js.map +1 -1
- package/dist/charts/ChartFrame.d.ts +2 -2
- package/dist/charts/ChartFrame.d.ts.map +1 -1
- package/dist/charts/ChartFrame.js +9 -2
- package/dist/charts/ChartFrame.js.map +1 -1
- package/dist/fieldElements/FieldError.d.ts.map +1 -1
- package/dist/fieldElements/FieldError.js +1 -1
- package/dist/fieldElements/FieldError.js.map +1 -1
- package/dist/index.d.ts +21 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts +3 -0
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts.map +1 -1
- package/dist/lazyBoundaries/heavyOptionalExports.js +2 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
- package/dist/login/LastUsedBadge.d.ts +14 -0
- package/dist/login/LastUsedBadge.d.ts.map +1 -0
- package/dist/login/LastUsedBadge.js +23 -0
- package/dist/login/LastUsedBadge.js.map +1 -0
- package/dist/login/LoginAccountCard.d.ts +38 -0
- package/dist/login/LoginAccountCard.d.ts.map +1 -0
- package/dist/login/LoginAccountCard.js +72 -0
- package/dist/login/LoginAccountCard.js.map +1 -0
- package/dist/login/LoginAccountList.d.ts +33 -0
- package/dist/login/LoginAccountList.d.ts.map +1 -0
- package/dist/login/LoginAccountList.js +30 -0
- package/dist/login/LoginAccountList.js.map +1 -0
- package/dist/login/LoginScreen.d.ts +4 -4
- package/dist/login/LoginScreen.d.ts.map +1 -1
- package/dist/login/LoginScreen.js +294 -13
- package/dist/login/LoginScreen.js.map +1 -1
- package/dist/login/OutlinePill.d.ts +28 -0
- package/dist/login/OutlinePill.d.ts.map +1 -0
- package/dist/login/OutlinePill.js +48 -0
- package/dist/login/OutlinePill.js.map +1 -0
- package/dist/login/TwoFactorChallengeScreen.d.ts +26 -0
- package/dist/login/TwoFactorChallengeScreen.d.ts.map +1 -0
- package/dist/login/TwoFactorChallengeScreen.js +139 -0
- package/dist/login/TwoFactorChallengeScreen.js.map +1 -0
- package/dist/login/loginMethods.d.ts +27 -0
- package/dist/login/loginMethods.d.ts.map +1 -0
- package/dist/login/loginMethods.js +37 -0
- package/dist/login/loginMethods.js.map +1 -0
- package/dist/login/loginTypes.d.ts +202 -5
- package/dist/login/loginTypes.d.ts.map +1 -1
- package/dist/pdfHtmlTemplate.d.ts +17 -0
- package/dist/pdfHtmlTemplate.d.ts.map +1 -1
- package/dist/pdfHtmlTemplate.js +78 -0
- package/dist/pdfHtmlTemplate.js.map +1 -1
- package/dist/security/AccountSecurityScreen.d.ts +10 -0
- package/dist/security/AccountSecurityScreen.d.ts.map +1 -0
- package/dist/security/AccountSecurityScreen.js +50 -0
- package/dist/security/AccountSecurityScreen.js.map +1 -0
- package/dist/security/LinkedAccountsCard.d.ts +32 -0
- package/dist/security/LinkedAccountsCard.d.ts.map +1 -0
- package/dist/security/LinkedAccountsCard.js +145 -0
- package/dist/security/LinkedAccountsCard.js.map +1 -0
- package/dist/security/PasskeysCard.d.ts +39 -0
- package/dist/security/PasskeysCard.d.ts.map +1 -0
- package/dist/security/PasskeysCard.js +168 -0
- package/dist/security/PasskeysCard.js.map +1 -0
- package/dist/security/PasswordCard.d.ts +32 -0
- package/dist/security/PasswordCard.d.ts.map +1 -0
- package/dist/security/PasswordCard.js +198 -0
- package/dist/security/PasswordCard.js.map +1 -0
- package/dist/security/SessionsCard.d.ts +39 -0
- package/dist/security/SessionsCard.d.ts.map +1 -0
- package/dist/security/SessionsCard.js +168 -0
- package/dist/security/SessionsCard.js.map +1 -0
- package/dist/security/TwoFactorSettingsCard.d.ts +55 -0
- package/dist/security/TwoFactorSettingsCard.d.ts.map +1 -0
- package/dist/security/TwoFactorSettingsCard.js +458 -0
- package/dist/security/TwoFactorSettingsCard.js.map +1 -0
- package/dist/security/securityMethods.d.ts +40 -0
- package/dist/security/securityMethods.d.ts.map +1 -0
- package/dist/security/securityMethods.js +66 -0
- package/dist/security/securityMethods.js.map +1 -0
- package/dist/security/securityTypes.d.ts +467 -0
- package/dist/security/securityTypes.d.ts.map +1 -0
- package/dist/security/securityTypes.js +2 -0
- package/dist/security/securityTypes.js.map +1 -0
- package/dist/security/userAgent.d.ts +26 -0
- package/dist/security/userAgent.d.ts.map +1 -0
- package/dist/security/userAgent.js +80 -0
- package/dist/security/userAgent.js.map +1 -0
- package/dist/signUp/OAuthButtons.d.ts +28 -5
- package/dist/signUp/OAuthButtons.d.ts.map +1 -1
- package/dist/signUp/OAuthButtons.js +44 -5
- package/dist/signUp/OAuthButtons.js.map +1 -1
- package/dist/signUp/SignUpScreen.d.ts.map +1 -1
- package/dist/signUp/SignUpScreen.js +50 -5
- package/dist/signUp/SignUpScreen.js.map +1 -1
- package/dist/signUp/signUpTypes.d.ts +21 -1
- package/dist/signUp/signUpTypes.d.ts.map +1 -1
- package/dist/useConsentForms.d.ts +9 -0
- package/dist/useConsentForms.d.ts.map +1 -1
- package/dist/useConsentForms.js +18 -0
- package/dist/useConsentForms.js.map +1 -1
- package/dist/useProvisionalConsent.d.ts +124 -0
- package/dist/useProvisionalConsent.d.ts.map +1 -0
- package/dist/useProvisionalConsent.js +79 -0
- package/dist/useProvisionalConsent.js.map +1 -0
- package/dist/withLoading.d.ts +20 -0
- package/dist/withLoading.d.ts.map +1 -0
- package/dist/withLoading.js +24 -0
- package/dist/withLoading.js.map +1 -0
- package/package.json +4 -2
- package/src/Accordion.test.tsx +5 -0
- package/src/Accordion.tsx +3 -8
- package/src/AreaChart.test.tsx +15 -0
- package/src/AreaChart.tsx +6 -0
- package/src/Avatar.test.tsx +8 -0
- package/src/Avatar.tsx +2 -0
- package/src/BarChart.test.tsx +15 -0
- package/src/BarChart.tsx +6 -0
- package/src/Box.test.tsx +131 -1
- package/src/Box.tsx +77 -8
- package/src/Card.test.tsx +48 -0
- package/src/Card.tsx +13 -2
- package/src/ChartCard.test.tsx +30 -0
- package/src/ChartCard.tsx +18 -1
- package/src/Common.ts +263 -14
- package/src/ConsentFormScreen.test.tsx +84 -0
- package/src/ConsentFormScreen.tsx +28 -4
- package/src/DateTimeField.tsx +5 -3
- package/src/DonutChart.test.tsx +15 -0
- package/src/DonutChart.tsx +6 -0
- package/src/Field.tsx +2 -0
- package/src/FilePickerButton.test.tsx +35 -0
- package/src/FormContainer.test.tsx +242 -0
- package/src/FormContainer.tsx +177 -0
- package/src/GPTChat.test.tsx +16 -0
- package/src/GPTChat.tsx +8 -2
- package/src/Heading.test.tsx +14 -0
- package/src/Heading.tsx +6 -1
- package/src/Icon.test.tsx +52 -1
- package/src/Icon.tsx +92 -3
- package/src/IconButton.test.tsx +85 -0
- package/src/LabeledCheckBox.test.tsx +45 -0
- package/src/LabeledCheckBox.tsx +89 -0
- package/src/LineChart.test.tsx +18 -0
- package/src/LineChart.tsx +6 -0
- package/src/ListDetailLayout.tsx +247 -0
- package/src/MarkdownEditor.tsx +2 -1
- package/src/MediaQuery.ts +1 -0
- package/src/OtpField.test.tsx +280 -0
- package/src/OtpField.tsx +307 -0
- package/src/Page.test.tsx +38 -0
- package/src/Page.tsx +38 -19
- package/src/ProvisionalConsentSigner.test.tsx +625 -0
- package/src/ProvisionalConsentSigner.tsx +423 -0
- package/src/ResponsiveBreakpoint.test.tsx +7 -0
- package/src/ResponsiveBreakpoint.tsx +14 -0
- package/src/RootImportRegression.test.tsx +3 -0
- package/src/Scorecard.test.tsx +11 -0
- package/src/Scorecard.tsx +21 -0
- package/src/Skeleton.test.tsx +262 -0
- package/src/Skeleton.tsx +430 -0
- package/src/SocialLoginButton.test.tsx +14 -0
- package/src/SocialLoginButton.tsx +51 -7
- package/src/SplitPage.native.tsx +16 -3
- package/src/SplitPage.tsx +29 -12
- package/src/SplitPageLoading.test.tsx +51 -0
- package/src/SplitPageLoading.tsx +53 -0
- package/src/SyncStatusBanner.test.tsx +61 -4
- package/src/SyncStatusBanner.tsx +29 -3
- package/src/Text.tsx +4 -1
- package/src/TextField.test.tsx +150 -0
- package/src/TextField.tsx +66 -8
- package/src/__snapshots__/AddressField.test.tsx.snap +12 -0
- package/src/__snapshots__/AiSuggestionBox.test.tsx.snap +15 -0
- package/src/__snapshots__/Avatar.test.tsx.snap +1 -0
- package/src/__snapshots__/CustomSelectField.test.tsx.snap +3 -0
- package/src/__snapshots__/EmailField.test.tsx.snap +6 -0
- package/src/__snapshots__/Field.test.tsx.snap +37 -0
- package/src/__snapshots__/HeightField.test.tsx.snap +2 -0
- package/src/__snapshots__/MobileAddressAutoComplete.test.tsx.snap +3 -0
- package/src/__snapshots__/NumberField.test.tsx.snap +3 -0
- package/src/__snapshots__/Page.test.tsx.snap +28 -5
- package/src/__snapshots__/PhoneNumberField.test.tsx.snap +12 -0
- package/src/__snapshots__/Slider.test.tsx.snap +1 -0
- package/src/__snapshots__/SocialLoginButton.test.tsx.snap +43 -22
- package/src/__snapshots__/SplitPage.test.tsx.snap +16 -0
- package/src/__snapshots__/TapToEdit.test.tsx.snap +3 -0
- package/src/__snapshots__/TextArea.test.tsx.snap +17 -1
- package/src/__snapshots__/TextField.test.tsx.snap +19 -2
- package/src/__snapshots__/TypedSignatureField.test.tsx.snap +3 -0
- package/src/__snapshots__/UnifiedAddressAutoComplete.test.tsx.snap +18 -0
- package/src/__snapshots__/WebAddressAutocomplete.test.tsx.snap +12 -0
- package/src/bunSetup.ts +13 -1
- package/src/charts/ChartFrame.tsx +19 -8
- package/src/fieldElements/FieldError.tsx +1 -0
- package/src/fieldElements/__snapshots__/FieldError.test.tsx.snap +2 -0
- package/src/index.tsx +44 -1
- package/src/isolated/ListDetailLayout.isolated.tsx +634 -0
- package/src/lazyBoundaries/heavyOptionalExports.tsx +7 -0
- package/src/login/LastUsedBadge.tsx +40 -0
- package/src/login/LoginAccountCard.tsx +205 -0
- package/src/login/LoginAccountList.tsx +115 -0
- package/src/login/LoginScreen.test.tsx +837 -1
- package/src/login/LoginScreen.tsx +674 -91
- package/src/login/OutlinePill.tsx +110 -0
- package/src/login/TwoFactorChallengeScreen.test.tsx +376 -0
- package/src/login/TwoFactorChallengeScreen.tsx +307 -0
- package/src/login/__snapshots__/LoginScreen.test.tsx.snap +1454 -334
- package/src/login/loginMethods.test.ts +53 -0
- package/src/login/loginMethods.ts +60 -0
- package/src/login/loginTypes.ts +208 -5
- package/src/pdfHtmlTemplate.test.ts +243 -4
- package/src/pdfHtmlTemplate.ts +93 -0
- package/src/security/AccountSecurityScreen.test.tsx +262 -0
- package/src/security/AccountSecurityScreen.tsx +156 -0
- package/src/security/LinkedAccountsCard.test.tsx +371 -0
- package/src/security/LinkedAccountsCard.tsx +297 -0
- package/src/security/PasskeysCard.test.tsx +378 -0
- package/src/security/PasskeysCard.tsx +371 -0
- package/src/security/PasswordCard.test.tsx +445 -0
- package/src/security/PasswordCard.tsx +342 -0
- package/src/security/SessionsCard.test.tsx +349 -0
- package/src/security/SessionsCard.tsx +362 -0
- package/src/security/TwoFactorSettingsCard.test.tsx +700 -0
- package/src/security/TwoFactorSettingsCard.tsx +872 -0
- package/src/security/securityMethods.test.ts +101 -0
- package/src/security/securityMethods.ts +104 -0
- package/src/security/securityTypes.ts +480 -0
- package/src/security/userAgent.test.ts +119 -0
- package/src/security/userAgent.ts +102 -0
- package/src/signUp/OAuthButtons.test.tsx +27 -0
- package/src/signUp/OAuthButtons.tsx +153 -19
- package/src/signUp/SignUpScreen.test.tsx +170 -1
- package/src/signUp/SignUpScreen.tsx +87 -25
- package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +22 -11
- package/src/signUp/signUpTypes.ts +23 -1
- package/src/useConsentForms.test.ts +37 -1
- package/src/useConsentForms.ts +25 -0
- package/src/useProvisionalConsent.test.ts +256 -0
- package/src/useProvisionalConsent.ts +218 -0
- package/src/withLoading.test.tsx +61 -0
- package/src/withLoading.tsx +50 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type {FC, ReactNode} from "react";
|
|
2
|
+
import {ActivityIndicator, Text as NativeText, Pressable, View} from "react-native";
|
|
3
|
+
|
|
4
|
+
import {useTheme} from "../Theme";
|
|
5
|
+
import {LastUsedPill} from "./LastUsedBadge";
|
|
6
|
+
|
|
7
|
+
interface OutlinePillProps {
|
|
8
|
+
/** Visible label, centered in the pill. */
|
|
9
|
+
text: string;
|
|
10
|
+
/** Icon pinned to the left edge. */
|
|
11
|
+
icon?: ReactNode;
|
|
12
|
+
/** Called when the pill is pressed. */
|
|
13
|
+
onPress: () => void | Promise<void>;
|
|
14
|
+
/** Disables the pill. */
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
/** Shows a spinner and disables the pill. */
|
|
17
|
+
loading?: boolean;
|
|
18
|
+
/** Accessible name. Defaults to `text`. */
|
|
19
|
+
accessibilityLabel?: string;
|
|
20
|
+
/** Test ID of the pressable. */
|
|
21
|
+
testID?: string;
|
|
22
|
+
/** When set, highlights the pill and shows this last-used label inside it. */
|
|
23
|
+
lastUsedLabel?: string;
|
|
24
|
+
/** Test ID of the last-used pill. */
|
|
25
|
+
lastUsedTestID?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A full-width sign-in method pill: neutral outline, icon pinned left, label centered.
|
|
30
|
+
* A last-used method gets the secondary fill and an inline pill.
|
|
31
|
+
*/
|
|
32
|
+
export const OutlinePill: FC<OutlinePillProps> = ({
|
|
33
|
+
text,
|
|
34
|
+
icon,
|
|
35
|
+
onPress,
|
|
36
|
+
disabled = false,
|
|
37
|
+
loading = false,
|
|
38
|
+
accessibilityLabel,
|
|
39
|
+
testID,
|
|
40
|
+
lastUsedLabel,
|
|
41
|
+
lastUsedTestID,
|
|
42
|
+
}) => {
|
|
43
|
+
const {theme} = useTheme();
|
|
44
|
+
if (!theme) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const isDisabled = disabled || loading;
|
|
48
|
+
const isLastUsed = Boolean(lastUsedLabel);
|
|
49
|
+
const textColor = isDisabled ? theme.text.secondaryLight : theme.text.primary;
|
|
50
|
+
return (
|
|
51
|
+
<Pressable
|
|
52
|
+
accessibilityRole="button"
|
|
53
|
+
accessibilityState={{disabled: isDisabled}}
|
|
54
|
+
aria-label={accessibilityLabel ?? text}
|
|
55
|
+
disabled={isDisabled}
|
|
56
|
+
onPress={() => {
|
|
57
|
+
void onPress();
|
|
58
|
+
}}
|
|
59
|
+
style={{
|
|
60
|
+
alignItems: "center",
|
|
61
|
+
backgroundColor: isDisabled
|
|
62
|
+
? theme.surface.disabled
|
|
63
|
+
: isLastUsed
|
|
64
|
+
? theme.surface.secondaryExtraLight
|
|
65
|
+
: theme.surface.base,
|
|
66
|
+
borderColor: isLastUsed ? theme.surface.secondaryLight : theme.border.default,
|
|
67
|
+
borderRadius: theme.radius.rounded,
|
|
68
|
+
borderWidth: isLastUsed ? 2 : 1,
|
|
69
|
+
flexDirection: "row",
|
|
70
|
+
minHeight: 48,
|
|
71
|
+
opacity: isDisabled ? 0.6 : 1,
|
|
72
|
+
paddingLeft: 16,
|
|
73
|
+
paddingRight: 12,
|
|
74
|
+
paddingVertical: 8,
|
|
75
|
+
width: "100%",
|
|
76
|
+
}}
|
|
77
|
+
testID={testID}
|
|
78
|
+
>
|
|
79
|
+
<View style={{alignItems: "center", justifyContent: "center", width: 28}}>{icon}</View>
|
|
80
|
+
<View style={{alignItems: "center", flex: 1, minWidth: 0, paddingHorizontal: 4}}>
|
|
81
|
+
<NativeText
|
|
82
|
+
style={{
|
|
83
|
+
color: textColor,
|
|
84
|
+
fontSize: 16,
|
|
85
|
+
fontWeight: "700",
|
|
86
|
+
textAlign: "center",
|
|
87
|
+
width: "100%",
|
|
88
|
+
}}
|
|
89
|
+
>
|
|
90
|
+
{text}
|
|
91
|
+
</NativeText>
|
|
92
|
+
</View>
|
|
93
|
+
<View
|
|
94
|
+
style={{
|
|
95
|
+
alignItems: "flex-end",
|
|
96
|
+
justifyContent: "center",
|
|
97
|
+
minWidth: isLastUsed || loading ? undefined : 28,
|
|
98
|
+
}}
|
|
99
|
+
>
|
|
100
|
+
{loading ? <ActivityIndicator color={textColor} size="small" /> : null}
|
|
101
|
+
{isLastUsed && !loading ? (
|
|
102
|
+
<LastUsedPill
|
|
103
|
+
label={lastUsedLabel ?? ""}
|
|
104
|
+
testID={lastUsedTestID ?? `${testID}-last-used`}
|
|
105
|
+
/>
|
|
106
|
+
) : null}
|
|
107
|
+
</View>
|
|
108
|
+
</Pressable>
|
|
109
|
+
);
|
|
110
|
+
};
|
|
@@ -0,0 +1,376 @@
|
|
|
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
|
+
|
|
5
|
+
import {ThemeProvider} from "../Theme";
|
|
6
|
+
import {renderWithTheme} from "../test-utils";
|
|
7
|
+
import type {TwoFactorChallengeSubmission} from "./loginTypes";
|
|
8
|
+
import {TwoFactorChallengeScreen} from "./TwoFactorChallengeScreen";
|
|
9
|
+
|
|
10
|
+
const makeOnSubmit = () => mock((_values: TwoFactorChallengeSubmission) => Promise.resolve());
|
|
11
|
+
|
|
12
|
+
/** Renders with a node mock per code cell and records the cells focused (1-based), in order. */
|
|
13
|
+
const renderWithFocusSpy = (ui: ReactElement): ReturnType<typeof render> & {focused: number[]} => {
|
|
14
|
+
const focused: number[] = [];
|
|
15
|
+
const result = render(ui, {
|
|
16
|
+
createNodeMock: (element: ReactElement) => {
|
|
17
|
+
const cellTestID = (element.props as {testID?: string}).testID ?? "";
|
|
18
|
+
const match = /-otp-cell-(\d+)$/.exec(cellTestID);
|
|
19
|
+
return {
|
|
20
|
+
focus: () => {
|
|
21
|
+
if (match) {
|
|
22
|
+
focused.push(Number(match[1]));
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
wrapper: ThemeProvider,
|
|
28
|
+
});
|
|
29
|
+
return Object.assign(result, {focused});
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const pressButton = async (element: Parameters<typeof fireEvent.press>[0]): Promise<void> => {
|
|
33
|
+
await act(async () => {
|
|
34
|
+
fireEvent.press(element);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
describe("TwoFactorChallengeScreen", () => {
|
|
39
|
+
it("renders the root, title and TOTP cells", () => {
|
|
40
|
+
const {getByTestId, getByText, queryByTestId} = renderWithTheme(
|
|
41
|
+
<TwoFactorChallengeScreen onSubmit={makeOnSubmit()} />
|
|
42
|
+
);
|
|
43
|
+
expect(getByTestId("two-factor-challenge")).toBeTruthy();
|
|
44
|
+
expect(getByText("Enter your code")).toBeTruthy();
|
|
45
|
+
expect(getByTestId("two-factor-challenge-otp-cell-1")).toBeTruthy();
|
|
46
|
+
expect(getByTestId("two-factor-challenge-otp-cell-6")).toBeTruthy();
|
|
47
|
+
expect(queryByTestId("two-factor-challenge-backup-input")).toBeNull();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("auto-submits a completed TOTP code", async () => {
|
|
51
|
+
const onSubmit = makeOnSubmit();
|
|
52
|
+
const {getByTestId} = renderWithTheme(<TwoFactorChallengeScreen onSubmit={onSubmit} />);
|
|
53
|
+
await act(async () => {
|
|
54
|
+
fireEvent.changeText(getByTestId("two-factor-challenge-otp-cell-1"), "123456");
|
|
55
|
+
});
|
|
56
|
+
await waitFor(() => {
|
|
57
|
+
expect(onSubmit).toHaveBeenCalledWith({code: "123456", kind: "totp", trustDevice: false});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("keeps submit disabled until the TOTP code is complete", () => {
|
|
62
|
+
const {getByTestId} = renderWithTheme(<TwoFactorChallengeScreen onSubmit={makeOnSubmit()} />);
|
|
63
|
+
fireEvent.changeText(getByTestId("two-factor-challenge-otp-cell-1"), "1");
|
|
64
|
+
expect(getByTestId("two-factor-challenge-submit").props.accessibilityState?.disabled).toBe(
|
|
65
|
+
true
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("the backup toggle switches kind to backup and submits the trimmed code", async () => {
|
|
70
|
+
const onSubmit = makeOnSubmit();
|
|
71
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
72
|
+
<TwoFactorChallengeScreen onSubmit={onSubmit} />
|
|
73
|
+
);
|
|
74
|
+
await pressButton(getByTestId("two-factor-challenge-backup-toggle"));
|
|
75
|
+
await waitFor(() => {
|
|
76
|
+
expect(getByTestId("two-factor-challenge-backup-input")).toBeTruthy();
|
|
77
|
+
});
|
|
78
|
+
expect(queryByTestId("two-factor-challenge-otp-cell-1")).toBeNull();
|
|
79
|
+
// Backup codes are case-sensitive, so the field must not capitalize or autocorrect.
|
|
80
|
+
expect(getByTestId("two-factor-challenge-backup-input").props.autoCapitalize).toBe("none");
|
|
81
|
+
expect(getByTestId("two-factor-challenge-backup-input").props.autoCorrect).toBe(false);
|
|
82
|
+
|
|
83
|
+
fireEvent.changeText(getByTestId("two-factor-challenge-backup-input"), " abcde-12345 ");
|
|
84
|
+
await pressButton(getByTestId("two-factor-challenge-submit"));
|
|
85
|
+
await waitFor(() => {
|
|
86
|
+
expect(onSubmit).toHaveBeenCalledWith({
|
|
87
|
+
code: "abcde-12345",
|
|
88
|
+
kind: "backup",
|
|
89
|
+
trustDevice: false,
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("the backup toggle switches back to the authenticator code", async () => {
|
|
95
|
+
const {getByTestId, getByText} = renderWithTheme(
|
|
96
|
+
<TwoFactorChallengeScreen initialKind="backup" onSubmit={makeOnSubmit()} />
|
|
97
|
+
);
|
|
98
|
+
expect(getByText("Use your authenticator app")).toBeTruthy();
|
|
99
|
+
await pressButton(getByTestId("two-factor-challenge-backup-toggle"));
|
|
100
|
+
await waitFor(() => {
|
|
101
|
+
expect(getByTestId("two-factor-challenge-otp-cell-1")).toBeTruthy();
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("hides the trust-device checkbox without trustDeviceDays", () => {
|
|
106
|
+
const {queryByTestId} = renderWithTheme(<TwoFactorChallengeScreen onSubmit={makeOnSubmit()} />);
|
|
107
|
+
expect(queryByTestId("two-factor-challenge-trust-device")).toBeNull();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("starts the trust-device checkbox unchecked when initialTrustDevice is false", async () => {
|
|
111
|
+
const onSubmit = makeOnSubmit();
|
|
112
|
+
const {getByTestId} = renderWithTheme(
|
|
113
|
+
<TwoFactorChallengeScreen
|
|
114
|
+
initialTrustDevice={false}
|
|
115
|
+
onSubmit={onSubmit}
|
|
116
|
+
trustDeviceDays={30}
|
|
117
|
+
/>
|
|
118
|
+
);
|
|
119
|
+
expect(getByTestId("two-factor-challenge-trust-device").props["aria-checked"]).toBe(false);
|
|
120
|
+
await act(async () => {
|
|
121
|
+
fireEvent.changeText(getByTestId("two-factor-challenge-otp-cell-1"), "654321");
|
|
122
|
+
});
|
|
123
|
+
await waitFor(() => {
|
|
124
|
+
expect(onSubmit).toHaveBeenCalledWith({code: "654321", kind: "totp", trustDevice: false});
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("submits trustDevice when the checkbox is checked", async () => {
|
|
129
|
+
const onSubmit = makeOnSubmit();
|
|
130
|
+
const {getByTestId, getByText} = renderWithTheme(
|
|
131
|
+
<TwoFactorChallengeScreen onSubmit={onSubmit} trustDeviceDays={30} />
|
|
132
|
+
);
|
|
133
|
+
const checkbox = getByTestId("two-factor-challenge-trust-device");
|
|
134
|
+
expect(getByText("Trust this device")).toBeTruthy();
|
|
135
|
+
expect(checkbox.props.role).toBe("checkbox");
|
|
136
|
+
expect(checkbox.props["aria-checked"]).toBe(true);
|
|
137
|
+
|
|
138
|
+
await act(async () => {
|
|
139
|
+
fireEvent.changeText(getByTestId("two-factor-challenge-otp-cell-1"), "654321");
|
|
140
|
+
});
|
|
141
|
+
await waitFor(() => {
|
|
142
|
+
expect(onSubmit).toHaveBeenCalledWith({code: "654321", kind: "totp", trustDevice: true});
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("renders the error under two-factor-challenge-error as an alert", () => {
|
|
147
|
+
const {getByTestId, getByText} = renderWithTheme(
|
|
148
|
+
<TwoFactorChallengeScreen error="Invalid code" onSubmit={makeOnSubmit()} />
|
|
149
|
+
);
|
|
150
|
+
const error = getByTestId("two-factor-challenge-error");
|
|
151
|
+
expect(error.props.role).toBe("alert");
|
|
152
|
+
expect(getByText("Invalid code")).toBeTruthy();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("focuses the first code cell on mount by default", () => {
|
|
156
|
+
const {focused} = renderWithFocusSpy(<TwoFactorChallengeScreen onSubmit={makeOnSubmit()} />);
|
|
157
|
+
expect(focused).toEqual([1]);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("autoFocus={false} leaves focus alone on mount but refocuses after a rejected code", () => {
|
|
161
|
+
const onSubmit = makeOnSubmit();
|
|
162
|
+
const {focused, rerender} = renderWithFocusSpy(
|
|
163
|
+
<TwoFactorChallengeScreen autoFocus={false} onSubmit={onSubmit} />
|
|
164
|
+
);
|
|
165
|
+
expect(focused).toEqual([]);
|
|
166
|
+
rerender(
|
|
167
|
+
<TwoFactorChallengeScreen autoFocus={false} error="Invalid code" onSubmit={onSubmit} />
|
|
168
|
+
);
|
|
169
|
+
expect(focused).toEqual([1]);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("clears the entered code when a new error arrives", async () => {
|
|
173
|
+
const onSubmit = makeOnSubmit();
|
|
174
|
+
const {getByTestId, rerender} = renderWithTheme(
|
|
175
|
+
<TwoFactorChallengeScreen onSubmit={onSubmit} />
|
|
176
|
+
);
|
|
177
|
+
await act(async () => {
|
|
178
|
+
fireEvent.changeText(getByTestId("two-factor-challenge-otp-cell-1"), "123456");
|
|
179
|
+
});
|
|
180
|
+
expect(getByTestId("two-factor-challenge-otp-cell-6").props.value).toBe("6");
|
|
181
|
+
rerender(<TwoFactorChallengeScreen error="Invalid code" onSubmit={onSubmit} />);
|
|
182
|
+
await waitFor(() => {
|
|
183
|
+
expect(getByTestId("two-factor-challenge-otp-cell-1").props.value).toBe("");
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("does not submit when loading turns on after the code is entered", async () => {
|
|
188
|
+
const onSubmit = makeOnSubmit();
|
|
189
|
+
const {getByTestId, rerender} = renderWithTheme(
|
|
190
|
+
<TwoFactorChallengeScreen initialKind="backup" onSubmit={onSubmit} />
|
|
191
|
+
);
|
|
192
|
+
fireEvent.changeText(getByTestId("two-factor-challenge-backup-input"), "abcde-12345");
|
|
193
|
+
rerender(<TwoFactorChallengeScreen initialKind="backup" loading onSubmit={onSubmit} />);
|
|
194
|
+
await pressButton(getByTestId("two-factor-challenge-submit"));
|
|
195
|
+
await new Promise((resolve) => setTimeout(resolve, 600));
|
|
196
|
+
expect(onSubmit).not.toHaveBeenCalled();
|
|
197
|
+
|
|
198
|
+
// The same press goes through once loading ends, so the check above is not vacuous.
|
|
199
|
+
rerender(<TwoFactorChallengeScreen initialKind="backup" onSubmit={onSubmit} />);
|
|
200
|
+
await pressButton(getByTestId("two-factor-challenge-submit"));
|
|
201
|
+
await waitFor(() => {
|
|
202
|
+
expect(onSubmit).toHaveBeenCalledTimes(1);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("asks for one-time-code autofill and a numeric keyboard on the code cells", () => {
|
|
207
|
+
const {getByTestId} = renderWithTheme(<TwoFactorChallengeScreen onSubmit={makeOnSubmit()} />);
|
|
208
|
+
const cell = getByTestId("two-factor-challenge-otp-cell-1");
|
|
209
|
+
expect(cell.props.autoComplete).toBe("one-time-code");
|
|
210
|
+
expect(cell.props.textContentType).toBe("oneTimeCode");
|
|
211
|
+
expect(cell.props.keyboardType).toBe("number-pad");
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("submits a complete code on Enter, and ignores Enter on an incomplete one", async () => {
|
|
215
|
+
const onSubmit = makeOnSubmit();
|
|
216
|
+
const {getByTestId} = renderWithTheme(<TwoFactorChallengeScreen onSubmit={onSubmit} />);
|
|
217
|
+
await act(async () => {
|
|
218
|
+
fireEvent.changeText(getByTestId("two-factor-challenge-otp-cell-1"), "12345");
|
|
219
|
+
});
|
|
220
|
+
await act(async () => {
|
|
221
|
+
fireEvent(getByTestId("two-factor-challenge-otp-cell-6"), "submitEditing");
|
|
222
|
+
});
|
|
223
|
+
expect(onSubmit).not.toHaveBeenCalled();
|
|
224
|
+
|
|
225
|
+
// The last digit auto-submits; Enter on the completed code submits it again.
|
|
226
|
+
await act(async () => {
|
|
227
|
+
fireEvent.changeText(getByTestId("two-factor-challenge-otp-cell-6"), "6");
|
|
228
|
+
});
|
|
229
|
+
expect(onSubmit).toHaveBeenCalledTimes(1);
|
|
230
|
+
await act(async () => {
|
|
231
|
+
fireEvent(getByTestId("two-factor-challenge-otp-cell-6"), "submitEditing");
|
|
232
|
+
});
|
|
233
|
+
expect(onSubmit).toHaveBeenCalledTimes(2);
|
|
234
|
+
expect(onSubmit).toHaveBeenLastCalledWith({code: "123456", kind: "totp", trustDevice: false});
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it("submits the backup code on Enter", async () => {
|
|
238
|
+
const onSubmit = makeOnSubmit();
|
|
239
|
+
const {getByTestId} = renderWithTheme(
|
|
240
|
+
<TwoFactorChallengeScreen initialKind="backup" onSubmit={onSubmit} />
|
|
241
|
+
);
|
|
242
|
+
fireEvent.changeText(getByTestId("two-factor-challenge-backup-input"), "abcde-12345");
|
|
243
|
+
await act(async () => {
|
|
244
|
+
fireEvent(getByTestId("two-factor-challenge-backup-input"), "submitEditing");
|
|
245
|
+
});
|
|
246
|
+
expect(onSubmit).toHaveBeenCalledWith({
|
|
247
|
+
code: "abcde-12345",
|
|
248
|
+
kind: "backup",
|
|
249
|
+
trustDevice: false,
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it("submits once when Verify is pressed while the auto-submit is in flight", async () => {
|
|
254
|
+
let resolveSubmit: () => void = () => {};
|
|
255
|
+
const onSubmit = mock(
|
|
256
|
+
(_values: TwoFactorChallengeSubmission) =>
|
|
257
|
+
new Promise<void>((resolve) => {
|
|
258
|
+
resolveSubmit = resolve;
|
|
259
|
+
})
|
|
260
|
+
);
|
|
261
|
+
const {getByTestId} = renderWithTheme(<TwoFactorChallengeScreen onSubmit={onSubmit} />);
|
|
262
|
+
await act(async () => {
|
|
263
|
+
fireEvent.changeText(getByTestId("two-factor-challenge-otp-cell-1"), "123456");
|
|
264
|
+
});
|
|
265
|
+
await pressButton(getByTestId("two-factor-challenge-submit"));
|
|
266
|
+
await new Promise((resolve) => setTimeout(resolve, 600));
|
|
267
|
+
expect(onSubmit).toHaveBeenCalledTimes(1);
|
|
268
|
+
await act(async () => {
|
|
269
|
+
resolveSubmit();
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it("catches a rejected onSubmit and clears the code", async () => {
|
|
274
|
+
const warn = spyOn(console, "warn").mockImplementation(() => {});
|
|
275
|
+
const onSubmit = mock((_values: TwoFactorChallengeSubmission) =>
|
|
276
|
+
Promise.reject(new Error("network"))
|
|
277
|
+
);
|
|
278
|
+
const {getByTestId} = renderWithTheme(<TwoFactorChallengeScreen onSubmit={onSubmit} />);
|
|
279
|
+
await act(async () => {
|
|
280
|
+
fireEvent.changeText(getByTestId("two-factor-challenge-otp-cell-1"), "123456");
|
|
281
|
+
});
|
|
282
|
+
await waitFor(() => {
|
|
283
|
+
expect(getByTestId("two-factor-challenge-otp-cell-1").props.value).toBe("");
|
|
284
|
+
});
|
|
285
|
+
expect(warn).toHaveBeenCalled();
|
|
286
|
+
warn.mockRestore();
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it("clears the code again when the same error comes back after loading", async () => {
|
|
290
|
+
const onSubmit = makeOnSubmit();
|
|
291
|
+
const {getByTestId, rerender} = renderWithTheme(
|
|
292
|
+
<TwoFactorChallengeScreen error="Invalid code" initialKind="backup" onSubmit={onSubmit} />
|
|
293
|
+
);
|
|
294
|
+
fireEvent.changeText(getByTestId("two-factor-challenge-backup-input"), "abcde-12345");
|
|
295
|
+
rerender(
|
|
296
|
+
<TwoFactorChallengeScreen
|
|
297
|
+
error="Invalid code"
|
|
298
|
+
initialKind="backup"
|
|
299
|
+
loading
|
|
300
|
+
onSubmit={onSubmit}
|
|
301
|
+
/>
|
|
302
|
+
);
|
|
303
|
+
expect(getByTestId("two-factor-challenge-backup-input").props.value).toBe("abcde-12345");
|
|
304
|
+
rerender(
|
|
305
|
+
<TwoFactorChallengeScreen error="Invalid code" initialKind="backup" onSubmit={onSubmit} />
|
|
306
|
+
);
|
|
307
|
+
await waitFor(() => {
|
|
308
|
+
expect(getByTestId("two-factor-challenge-backup-input").props.value).toBe("");
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it("clears the code again when a submission settles with the same error", async () => {
|
|
313
|
+
const onSubmit = makeOnSubmit();
|
|
314
|
+
const {getByTestId} = renderWithTheme(
|
|
315
|
+
<TwoFactorChallengeScreen error="Invalid code" onSubmit={onSubmit} />
|
|
316
|
+
);
|
|
317
|
+
await act(async () => {
|
|
318
|
+
fireEvent.changeText(getByTestId("two-factor-challenge-otp-cell-1"), "123456");
|
|
319
|
+
});
|
|
320
|
+
await waitFor(() => {
|
|
321
|
+
expect(onSubmit).toHaveBeenCalledTimes(1);
|
|
322
|
+
});
|
|
323
|
+
await waitFor(() => {
|
|
324
|
+
expect(getByTestId("two-factor-challenge-otp-cell-1").props.value).toBe("");
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it("toggles the trust-device checkbox with the Space key", () => {
|
|
329
|
+
const preventDefault = mock(() => {});
|
|
330
|
+
const {getByTestId} = renderWithTheme(
|
|
331
|
+
<TwoFactorChallengeScreen onSubmit={makeOnSubmit()} trustDeviceDays={30} />
|
|
332
|
+
);
|
|
333
|
+
fireEvent(getByTestId("two-factor-challenge-trust-device"), "keyDown", {
|
|
334
|
+
key: " ",
|
|
335
|
+
preventDefault,
|
|
336
|
+
});
|
|
337
|
+
expect(getByTestId("two-factor-challenge-trust-device").props["aria-checked"]).toBe(false);
|
|
338
|
+
expect(preventDefault).toHaveBeenCalled();
|
|
339
|
+
fireEvent(getByTestId("two-factor-challenge-trust-device"), "keyDown", {
|
|
340
|
+
nativeEvent: {key: "Enter"},
|
|
341
|
+
});
|
|
342
|
+
expect(getByTestId("two-factor-challenge-trust-device").props["aria-checked"]).toBe(false);
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
it("names the backup input Backup code", async () => {
|
|
346
|
+
const {getByTestId} = renderWithTheme(
|
|
347
|
+
<TwoFactorChallengeScreen initialKind="backup" onSubmit={makeOnSubmit()} />
|
|
348
|
+
);
|
|
349
|
+
expect(getByTestId("two-factor-challenge-backup-input").props["aria-label"]).toBe(
|
|
350
|
+
"Backup code"
|
|
351
|
+
);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
it("shows the cancel link only with onCancel and calls it", async () => {
|
|
355
|
+
const onCancel = mock(() => {});
|
|
356
|
+
const {getByTestId, getByText, rerender, queryByTestId} = renderWithTheme(
|
|
357
|
+
<TwoFactorChallengeScreen onSubmit={makeOnSubmit()} />
|
|
358
|
+
);
|
|
359
|
+
expect(queryByTestId("two-factor-challenge-cancel")).toBeNull();
|
|
360
|
+
rerender(<TwoFactorChallengeScreen onCancel={onCancel} onSubmit={makeOnSubmit()} />);
|
|
361
|
+
expect(getByText("Sign in a different way")).toBeTruthy();
|
|
362
|
+
await pressButton(getByTestId("two-factor-challenge-cancel"));
|
|
363
|
+
await waitFor(() => {
|
|
364
|
+
expect(onCancel).toHaveBeenCalledTimes(1);
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it("uses a custom code length", () => {
|
|
369
|
+
const {getByTestId, getByText, queryByTestId} = renderWithTheme(
|
|
370
|
+
<TwoFactorChallengeScreen codeLength={8} onSubmit={makeOnSubmit()} />
|
|
371
|
+
);
|
|
372
|
+
expect(getByTestId("two-factor-challenge-otp-cell-8")).toBeTruthy();
|
|
373
|
+
expect(queryByTestId("two-factor-challenge-otp-cell-9")).toBeNull();
|
|
374
|
+
expect(getByText("Open your authenticator app and enter the 8-digit code.")).toBeTruthy();
|
|
375
|
+
});
|
|
376
|
+
});
|