@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.
- package/.ai/guidelines/core.md +1 -1
- package/CHANGELOG.md +393 -0
- package/dist/Accordion.d.ts.map +1 -1
- package/dist/Accordion.js +3 -3
- package/dist/Accordion.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/Box.d.ts.map +1 -1
- package/dist/Box.js +38 -2
- package/dist/Box.js.map +1 -1
- package/dist/Card.js +2 -2
- package/dist/Card.js.map +1 -1
- package/dist/Common.d.ts +120 -7
- 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/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/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/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/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 +11 -0
- package/dist/SplitPage.d.ts.map +1 -1
- package/dist/SplitPage.js +11 -5
- package/dist/SplitPage.js.map +1 -1
- package/dist/SplitPage.native.d.ts.map +1 -1
- package/dist/SplitPage.native.js +3 -1
- package/dist/SplitPage.native.js.map +1 -1
- 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/TextField.d.ts.map +1 -1
- package/dist/TextField.js +44 -10
- package/dist/TextField.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 +19 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -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/package.json +3 -2
- package/src/Accordion.test.tsx +5 -0
- package/src/Accordion.tsx +3 -8
- package/src/AreaChart.test.tsx +15 -0
- package/src/Avatar.test.tsx +8 -0
- package/src/Avatar.tsx +2 -0
- package/src/BarChart.test.tsx +15 -0
- package/src/Box.test.tsx +61 -1
- package/src/Box.tsx +44 -2
- package/src/Card.tsx +2 -2
- package/src/Common.ts +134 -7
- 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/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/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/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/SocialLoginButton.test.tsx +14 -0
- package/src/SocialLoginButton.tsx +51 -7
- package/src/SplitPage.native.tsx +3 -1
- package/src/SplitPage.tsx +11 -5
- package/src/SyncStatusBanner.test.tsx +61 -4
- package/src/SyncStatusBanner.tsx +29 -3
- 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__/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__/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/fieldElements/FieldError.tsx +1 -0
- package/src/fieldElements/__snapshots__/FieldError.test.tsx.snap +2 -0
- package/src/index.tsx +42 -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
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {describe, expect, it} from "bun:test";
|
|
2
|
+
|
|
3
|
+
import {getSocialProviderName} from "../SocialLoginButton";
|
|
4
|
+
import {getLoginMethodLabels, maskEmail} from "./loginMethods";
|
|
5
|
+
|
|
6
|
+
describe("getSocialProviderName", () => {
|
|
7
|
+
it("names the branded providers", () => {
|
|
8
|
+
expect(getSocialProviderName("github")).toBe("GitHub");
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("returns undefined for other ids, including Object.prototype keys", () => {
|
|
12
|
+
expect(getSocialProviderName("mock-oidc")).toBeUndefined();
|
|
13
|
+
expect(getSocialProviderName("__proto__")).toBeUndefined();
|
|
14
|
+
expect(getSocialProviderName("constructor")).toBeUndefined();
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe("getLoginMethodLabels", () => {
|
|
19
|
+
it("names email, passkeys, branded and generic providers", () => {
|
|
20
|
+
expect(getLoginMethodLabels({method: "email"})).toEqual({name: "email", phrase: "email"});
|
|
21
|
+
expect(getLoginMethodLabels({method: "passkey"})).toEqual({
|
|
22
|
+
name: "passkey",
|
|
23
|
+
phrase: "a passkey",
|
|
24
|
+
});
|
|
25
|
+
expect(getLoginMethodLabels({method: "google"})).toEqual({name: "Google", phrase: "Google"});
|
|
26
|
+
expect(
|
|
27
|
+
getLoginMethodLabels({
|
|
28
|
+
genericProviders: [
|
|
29
|
+
{id: "mock-oidc", label: "Mock OIDC", onPress: async (): Promise<void> => {}},
|
|
30
|
+
],
|
|
31
|
+
method: "mock-oidc",
|
|
32
|
+
})
|
|
33
|
+
).toEqual({name: "Mock OIDC", phrase: "Mock OIDC"});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("names a method that matches an Object.prototype key by its id", () => {
|
|
37
|
+
expect(getLoginMethodLabels({method: "__proto__"})).toEqual({
|
|
38
|
+
name: "__proto__",
|
|
39
|
+
phrase: "__proto__",
|
|
40
|
+
});
|
|
41
|
+
expect(getLoginMethodLabels({method: "constructor"})).toEqual({
|
|
42
|
+
name: "constructor",
|
|
43
|
+
phrase: "constructor",
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe("maskEmail", () => {
|
|
49
|
+
it("keeps the first character of the name and the host", () => {
|
|
50
|
+
expect(maskEmail("josh@nang.io")).toBe("j***@n***.io");
|
|
51
|
+
expect(maskEmail("not-an-email")).toBe("not-an-email");
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {getSocialProviderName} from "../SocialLoginButton";
|
|
2
|
+
import type {GenericOAuthProviderConfig} from "../signUp/signUpTypes";
|
|
3
|
+
|
|
4
|
+
/** Ways to name a sign-in method in the login screen's copy. */
|
|
5
|
+
export interface LoginMethodLabels {
|
|
6
|
+
/** Noun form, e.g. "GitHub", "email", "passkey": "Forget this {name} account". */
|
|
7
|
+
name: string;
|
|
8
|
+
/** Form used after "with", e.g. "GitHub", "email", "a passkey": "Continue with {phrase}". */
|
|
9
|
+
phrase: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Names a sign-in method: a branded provider's name, a generic provider's label, "email",
|
|
14
|
+
* "passkey", or the raw id as a last resort.
|
|
15
|
+
*/
|
|
16
|
+
export const getLoginMethodLabels = ({
|
|
17
|
+
method,
|
|
18
|
+
genericProviders = [],
|
|
19
|
+
}: {
|
|
20
|
+
method: string;
|
|
21
|
+
genericProviders?: GenericOAuthProviderConfig[];
|
|
22
|
+
}): LoginMethodLabels => {
|
|
23
|
+
if (method === "email") {
|
|
24
|
+
return {name: "email", phrase: "email"};
|
|
25
|
+
}
|
|
26
|
+
if (method === "passkey") {
|
|
27
|
+
return {name: "passkey", phrase: "a passkey"};
|
|
28
|
+
}
|
|
29
|
+
const generic = genericProviders.find((provider) => provider.id === method);
|
|
30
|
+
const name = generic?.label ?? getSocialProviderName(method) ?? method;
|
|
31
|
+
return {name, phrase: name};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Masks an email for display: `josh@nang.io` becomes `j***@n***.io`. Returns the input when it
|
|
36
|
+
* is not an email.
|
|
37
|
+
*/
|
|
38
|
+
export const maskEmail = (email: string): string => {
|
|
39
|
+
const at = email.indexOf("@");
|
|
40
|
+
if (at <= 0 || at === email.length - 1) {
|
|
41
|
+
return email;
|
|
42
|
+
}
|
|
43
|
+
const local = email.slice(0, at);
|
|
44
|
+
const domain = email.slice(at + 1);
|
|
45
|
+
const dot = domain.lastIndexOf(".");
|
|
46
|
+
const host = dot === -1 ? domain : domain.slice(0, dot);
|
|
47
|
+
const tld = dot === -1 ? "" : domain.slice(dot);
|
|
48
|
+
return `${local.charAt(0)}***@${host.charAt(0)}***${tld}`;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/** Appends the last-used marker to an accessible name, e.g. "Continue with GitHub, last used". */
|
|
52
|
+
export const withLastUsedLabel = ({
|
|
53
|
+
label,
|
|
54
|
+
lastUsedLabel,
|
|
55
|
+
}: {
|
|
56
|
+
label: string;
|
|
57
|
+
lastUsedLabel: string;
|
|
58
|
+
}): string => {
|
|
59
|
+
return `${label}, ${lastUsedLabel.toLocaleLowerCase()}`;
|
|
60
|
+
};
|
package/src/login/loginTypes.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {ReactNode} from "react";
|
|
2
2
|
|
|
3
|
-
import type {OAuthProviderConfig} from "../signUp/signUpTypes";
|
|
3
|
+
import type {GenericOAuthProviderConfig, OAuthProviderConfig} from "../signUp/signUpTypes";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Configuration for a login form field.
|
|
@@ -17,7 +17,50 @@ export interface LoginFieldConfig {
|
|
|
17
17
|
/** Whether the field is required. */
|
|
18
18
|
required?: boolean;
|
|
19
19
|
/** Auto-complete hint for the field. */
|
|
20
|
-
autoComplete?: "current-password" | "on" | "off" | "username";
|
|
20
|
+
autoComplete?: "current-password" | "email" | "new-password" | "on" | "off" | "username";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* An account the login screen can offer as a one-tap "Continue" card: a session already signed
|
|
25
|
+
* in on this device, or an account remembered from an earlier sign-in. Identity fields are
|
|
26
|
+
* optional because apps remember only the method by default.
|
|
27
|
+
*/
|
|
28
|
+
export interface LoginAccountOption {
|
|
29
|
+
/** Stable id: the session token or user id for a session, the remembered entry id otherwise. */
|
|
30
|
+
id: string;
|
|
31
|
+
/** Display name, when known. */
|
|
32
|
+
name?: string;
|
|
33
|
+
/** Email address, when known. */
|
|
34
|
+
email?: string;
|
|
35
|
+
/** Avatar image URL, when known. */
|
|
36
|
+
image?: string;
|
|
37
|
+
/** How the account signs in: a provider id, `"email"`, or `"passkey"`. */
|
|
38
|
+
method: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Where a "Continue" card came from: a signed-in device session or a remembered account. */
|
|
42
|
+
export type LoginAccountSource = "session" | "remembered";
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A message shown under the heading, such as guidance after an `account_not_linked` error.
|
|
46
|
+
* Info notices can be dismissed. A wrong password is not a notice: it is `passwordError`.
|
|
47
|
+
*/
|
|
48
|
+
export interface LoginNotice {
|
|
49
|
+
/** Visual tone of the notice. */
|
|
50
|
+
tone: "info" | "warning" | "error";
|
|
51
|
+
/** Optional bold line above `text`. */
|
|
52
|
+
title?: string;
|
|
53
|
+
/** Message text. */
|
|
54
|
+
text: string;
|
|
55
|
+
/** Label for an optional action button under the text. */
|
|
56
|
+
actionLabel?: string;
|
|
57
|
+
/** Callback for the action button. */
|
|
58
|
+
onAction?: () => void | Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Sign-in method the action should bring forward: `"email"` focuses the email field, any other
|
|
61
|
+
* id expands the method list. The screen does this before calling `onAction`.
|
|
62
|
+
*/
|
|
63
|
+
focusMethod?: string;
|
|
21
64
|
}
|
|
22
65
|
|
|
23
66
|
/**
|
|
@@ -32,13 +75,28 @@ export interface LoginScreenProps {
|
|
|
32
75
|
oauthProviders?: OAuthProviderConfig[];
|
|
33
76
|
/** Custom logo or banner to display above the form. */
|
|
34
77
|
logo?: ReactNode;
|
|
35
|
-
/**
|
|
78
|
+
/**
|
|
79
|
+
* Title text for the login form. Defaults to "Welcome back" when accounts are offered and
|
|
80
|
+
* "Sign in" otherwise.
|
|
81
|
+
*/
|
|
36
82
|
title?: string;
|
|
83
|
+
/**
|
|
84
|
+
* Line under the title. Defaults to "Pick up where you left off." when accounts are offered and
|
|
85
|
+
* "Choose how you want to sign in." otherwise.
|
|
86
|
+
*/
|
|
87
|
+
subtitle?: string;
|
|
37
88
|
/** Whether the form is in a loading state. */
|
|
38
89
|
loading?: boolean;
|
|
39
|
-
/** Error message
|
|
90
|
+
/** Error message shown in a banner under the heading. A `notice` wins when both are set. */
|
|
40
91
|
error?: string;
|
|
41
|
-
/**
|
|
92
|
+
/**
|
|
93
|
+
* Wrong-password message shown under the password field, not in the banner.
|
|
94
|
+
*/
|
|
95
|
+
passwordError?: string;
|
|
96
|
+
/**
|
|
97
|
+
* Text of the "Create an account" link in the footer.
|
|
98
|
+
* @default "Create an account"
|
|
99
|
+
*/
|
|
42
100
|
signUpLinkText?: string;
|
|
43
101
|
/** Callback triggered when the sign-up link is pressed. */
|
|
44
102
|
onSignUpPress?: () => void;
|
|
@@ -48,6 +106,151 @@ export interface LoginScreenProps {
|
|
|
48
106
|
onForgotPasswordPress?: () => void;
|
|
49
107
|
/** Alias for `onForgotPasswordPress`. */
|
|
50
108
|
onForgotPassword?: () => void;
|
|
109
|
+
/**
|
|
110
|
+
* Sign-in providers without a branded button (for example a generic OIDC provider). They
|
|
111
|
+
* render after `oauthProviders` with the testID `${testID}-oauth-${id}`.
|
|
112
|
+
*/
|
|
113
|
+
genericProviders?: GenericOAuthProviderConfig[];
|
|
114
|
+
/**
|
|
115
|
+
* The method this device signed in with last: a provider id (`"google"`, `"github"`,
|
|
116
|
+
* `"mock-oidc"`, ...), `"email"`, or `"passkey"`. That method gets a "Last used" pill
|
|
117
|
+
* (testID `${testID}-last-used-${method}`). A provider moves to the front of the provider
|
|
118
|
+
* list, and a passkey leads the method stack. Methods stay above the email form. A method the
|
|
119
|
+
* screen does not offer is ignored.
|
|
120
|
+
*/
|
|
121
|
+
lastUsedMethod?: string;
|
|
122
|
+
/** Text of the last-used badge. Defaults to "Last used". */
|
|
123
|
+
lastUsedLabel?: string;
|
|
124
|
+
/**
|
|
125
|
+
* Sessions already signed in on this device. Each renders a "Continue" card that switches to
|
|
126
|
+
* it in one tap. Requires `onContinue`.
|
|
127
|
+
*/
|
|
128
|
+
currentSessions?: LoginAccountOption[];
|
|
129
|
+
/**
|
|
130
|
+
* Accounts remembered on this device. Each renders a row in the continue-as list that
|
|
131
|
+
* re-authenticates with the remembered method. `onForget` reveals Remove in the list's Edit
|
|
132
|
+
* mode. Requires `onContinue`.
|
|
133
|
+
*/
|
|
134
|
+
rememberedAccounts?: LoginAccountOption[];
|
|
135
|
+
/**
|
|
136
|
+
* Called when a "Continue" card is pressed. Cards are numbered sessions first, then remembered
|
|
137
|
+
* accounts (testID `${testID}-continue-${index}`).
|
|
138
|
+
*/
|
|
139
|
+
onContinue?: (account: LoginAccountOption, source: LoginAccountSource) => void | Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Called when a remembered account's Remove button is pressed in Edit mode
|
|
142
|
+
* (testID `${testID}-forget-${index}`). Sessions are never forgettable here.
|
|
143
|
+
*/
|
|
144
|
+
onForget?: (account: LoginAccountOption) => void | Promise<void>;
|
|
145
|
+
/**
|
|
146
|
+
* Replaces the screen body with the password step for this email account. Set by the controller
|
|
147
|
+
* when a continue-as row has a usable email. Requires `onCancelContinue` to return.
|
|
148
|
+
*/
|
|
149
|
+
continuingAccount?: LoginAccountOption;
|
|
150
|
+
/** Leaves the password step and returns to the account list. */
|
|
151
|
+
onCancelContinue?: () => void;
|
|
152
|
+
/**
|
|
153
|
+
* Opens the screen with the other sign-in methods expanded. Returning users start collapsed
|
|
154
|
+
* behind "Sign in another way".
|
|
155
|
+
*/
|
|
156
|
+
initialMethodsExpanded?: boolean;
|
|
157
|
+
/** Opens the account list in Edit mode, where remembered accounts can be removed. */
|
|
158
|
+
initialAccountsEditing?: boolean;
|
|
159
|
+
/**
|
|
160
|
+
* Shows a "Sign in with a passkey" button (testID `${testID}-passkey-button`) that calls this.
|
|
161
|
+
*/
|
|
162
|
+
onPasskeyPress?: () => void | Promise<void>;
|
|
163
|
+
/** Text of the passkey button. Defaults to "Sign in with a passkey". */
|
|
164
|
+
passkeyButtonText?: string;
|
|
165
|
+
/**
|
|
166
|
+
* On web, sets the email field's `autocomplete` to `"username webauthn"` so the browser offers
|
|
167
|
+
* saved passkeys in the field's autofill (conditional mediation). Ignored on native.
|
|
168
|
+
*/
|
|
169
|
+
passkeyAutofill?: boolean;
|
|
170
|
+
/**
|
|
171
|
+
* Values the form starts with, keyed by field name, such as `{email: "jane@example.com"}`.
|
|
172
|
+
* When a new object is passed later, its fields replace what is in the form and the other
|
|
173
|
+
* fields keep what the user typed, so a "Continue" card can prefill the email.
|
|
174
|
+
*/
|
|
175
|
+
initialValues?: Record<string, string>;
|
|
176
|
+
/** A message under the heading (testID `${testID}-notice`). */
|
|
177
|
+
notice?: LoginNotice;
|
|
51
178
|
/** Test ID for the root element. */
|
|
52
179
|
testID?: string;
|
|
53
180
|
}
|
|
181
|
+
|
|
182
|
+
/** Which kind of second factor a two-factor challenge submits. */
|
|
183
|
+
export type TwoFactorCodeKind = "totp" | "backup";
|
|
184
|
+
|
|
185
|
+
/** What {@link TwoFactorChallengeScreenProps.onSubmit} receives. */
|
|
186
|
+
export interface TwoFactorChallengeSubmission {
|
|
187
|
+
/** The code as entered: six digits for `totp`, a trimmed backup code for `backup`. */
|
|
188
|
+
code: string;
|
|
189
|
+
/** `totp` for an authenticator app code, `backup` for a one-time backup code. */
|
|
190
|
+
kind: TwoFactorCodeKind;
|
|
191
|
+
/** True when the user checked "Don't ask again on this device". Always false without `trustDeviceDays`. */
|
|
192
|
+
trustDevice: boolean;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Props for the TwoFactorChallengeScreen component.
|
|
197
|
+
*/
|
|
198
|
+
export interface TwoFactorChallengeScreenProps {
|
|
199
|
+
/** Called with the code, its kind, and the trust-device choice. A TOTP code submits itself once complete. */
|
|
200
|
+
onSubmit: (values: TwoFactorChallengeSubmission) => void | Promise<void>;
|
|
201
|
+
/** Disables the form and shows a spinner on the submit button. */
|
|
202
|
+
loading?: boolean;
|
|
203
|
+
/** Error text, such as an invalid code, shown with `role="alert"`. A new error clears the entered code. */
|
|
204
|
+
error?: string;
|
|
205
|
+
/**
|
|
206
|
+
* Shows a "Don't ask again on this device for N days" checkbox. Leave unset to hide it. Better
|
|
207
|
+
* Auth trusts a device for 30 days by default.
|
|
208
|
+
*/
|
|
209
|
+
trustDeviceDays?: number;
|
|
210
|
+
/** Shows a back link and a footer link (text via `cancelText`), for example back to sign-in. */
|
|
211
|
+
onCancel?: () => void;
|
|
212
|
+
/**
|
|
213
|
+
* Text for the footer link.
|
|
214
|
+
* @default "Sign in a different way"
|
|
215
|
+
*/
|
|
216
|
+
cancelText?: string;
|
|
217
|
+
/**
|
|
218
|
+
* Heading text. Defaults to "Enter your code" for an authenticator code and "Use a backup code"
|
|
219
|
+
* for a backup code.
|
|
220
|
+
*/
|
|
221
|
+
title?: string;
|
|
222
|
+
/**
|
|
223
|
+
* Account the code is for, usually an email. The authenticator subtitle names it. The screen
|
|
224
|
+
* masks an email address.
|
|
225
|
+
*/
|
|
226
|
+
accountLabel?: string;
|
|
227
|
+
/** Optional logo above the heading. */
|
|
228
|
+
logo?: ReactNode;
|
|
229
|
+
/**
|
|
230
|
+
* Digits in an authenticator code.
|
|
231
|
+
* @default 6
|
|
232
|
+
*/
|
|
233
|
+
codeLength?: number;
|
|
234
|
+
/**
|
|
235
|
+
* The mode the screen opens in.
|
|
236
|
+
* @default "totp"
|
|
237
|
+
*/
|
|
238
|
+
initialKind?: TwoFactorCodeKind;
|
|
239
|
+
/**
|
|
240
|
+
* Whether "Trust this device" starts checked. Defaults to checked for an authenticator code
|
|
241
|
+
* and unchecked for a backup code. Set `false` to start unchecked.
|
|
242
|
+
*/
|
|
243
|
+
initialTrustDevice?: boolean;
|
|
244
|
+
/**
|
|
245
|
+
* Focuses the first code cell when the screen mounts. Turn it off when the screen is not the
|
|
246
|
+
* page's main task (a preview or gallery), since focusing scrolls the page to the cells. A
|
|
247
|
+
* rejected code still returns focus to the first cell.
|
|
248
|
+
* @default true
|
|
249
|
+
*/
|
|
250
|
+
autoFocus?: boolean;
|
|
251
|
+
/**
|
|
252
|
+
* Root testID; child testIDs are derived from it.
|
|
253
|
+
* @default "two-factor-challenge"
|
|
254
|
+
*/
|
|
255
|
+
testID?: string;
|
|
256
|
+
}
|
|
@@ -1,14 +1,27 @@
|
|
|
1
|
-
import {describe, expect, it, mock} from "bun:test";
|
|
1
|
+
import {beforeEach, describe, expect, it, type Mock, mock} from "bun:test";
|
|
2
|
+
import * as Print from "expo-print";
|
|
3
|
+
import {DateTime} from "luxon";
|
|
2
4
|
import {Platform} from "react-native";
|
|
3
5
|
|
|
4
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
buildConsentPdfHtml,
|
|
8
|
+
type PdfTemplateData,
|
|
9
|
+
printConsentHtml,
|
|
10
|
+
sharePdfFromHtml,
|
|
11
|
+
} from "./pdfHtmlTemplate";
|
|
5
12
|
|
|
6
|
-
|
|
13
|
+
// expo-print is mocked once in the bun preload (src/bunSetup.ts).
|
|
14
|
+
const printAsync = Print.printAsync as unknown as Mock<typeof Print.printAsync>;
|
|
15
|
+
const printToFileAsync = Print.printToFileAsync as unknown as Mock<typeof Print.printToFileAsync>;
|
|
7
16
|
const shareAsync = mock(() => Promise.resolve());
|
|
8
17
|
|
|
9
|
-
mock.module("expo-print", () => ({printToFileAsync}));
|
|
10
18
|
mock.module("expo-sharing", () => ({shareAsync}));
|
|
11
19
|
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
printAsync.mockClear();
|
|
22
|
+
printToFileAsync.mockClear();
|
|
23
|
+
});
|
|
24
|
+
|
|
12
25
|
const baseData: PdfTemplateData = {
|
|
13
26
|
fields: [
|
|
14
27
|
{label: "Full Name", value: "Jane <Doe>"},
|
|
@@ -92,6 +105,232 @@ describe("buildConsentPdfHtml", () => {
|
|
|
92
105
|
});
|
|
93
106
|
});
|
|
94
107
|
|
|
108
|
+
describe("buildConsentPdfHtml provisional signature", () => {
|
|
109
|
+
const signedAt = "2026-10-20T15:30:00.000Z";
|
|
110
|
+
const voidedAt = "2026-10-21T09:00:00.000Z";
|
|
111
|
+
const full = (iso: string): string =>
|
|
112
|
+
DateTime.fromISO(iso).toLocaleString(DateTime.DATETIME_FULL);
|
|
113
|
+
|
|
114
|
+
it("renders the signer and date", () => {
|
|
115
|
+
const html = buildConsentPdfHtml({
|
|
116
|
+
...baseData,
|
|
117
|
+
provisionalSignature: {signedAt, signedByName: "Dana <Rivera>"},
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
expect(html).toContain("<h2>Provisional signature</h2>");
|
|
121
|
+
expect(html).toContain('<td class="field-value">Dana <Rivera></td>');
|
|
122
|
+
expect(html).toContain(`<td class="field-value">${full(signedAt)}</td>`);
|
|
123
|
+
expect(html).not.toContain("Note:");
|
|
124
|
+
expect(html).not.toContain("Signer IP:");
|
|
125
|
+
expect(html).not.toContain("Voided");
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("renders the escaped note, signer IP, and void date when given", () => {
|
|
129
|
+
const html = buildConsentPdfHtml({
|
|
130
|
+
...baseData,
|
|
131
|
+
provisionalSignature: {
|
|
132
|
+
note: 'Guardian said "yes" <by phone>',
|
|
133
|
+
signedAt,
|
|
134
|
+
signedByName: "Dana Rivera",
|
|
135
|
+
signerIp: "10.0.0.7",
|
|
136
|
+
voidedAt,
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
expect(html).toContain('<td class="field-label">Note:</td>');
|
|
141
|
+
expect(html).toContain(
|
|
142
|
+
'<td class="field-value">Guardian said "yes" <by phone></td>'
|
|
143
|
+
);
|
|
144
|
+
expect(html).toContain('<td class="field-value">10.0.0.7</td>');
|
|
145
|
+
expect(html).toContain(`<div class="voided">Voided ${full(voidedAt)}</div>`);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("prints a date that is not ISO as written", () => {
|
|
149
|
+
const html = buildConsentPdfHtml({
|
|
150
|
+
...baseData,
|
|
151
|
+
provisionalSignature: {signedAt: "Oct 20, 2026", signedByName: "Dana Rivera"},
|
|
152
|
+
});
|
|
153
|
+
expect(html).toContain('<td class="field-value">Oct 20, 2026</td>');
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("omits the date row when the signing date is unknown", () => {
|
|
157
|
+
const html = buildConsentPdfHtml({
|
|
158
|
+
...baseData,
|
|
159
|
+
provisionalSignature: {signedAt: "", signedByName: "Dana Rivera"},
|
|
160
|
+
});
|
|
161
|
+
expect(html).toContain("<h2>Provisional signature</h2>");
|
|
162
|
+
expect(html).not.toContain("Signed at:");
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("renders nothing extra without a provisional signature", () => {
|
|
166
|
+
expect(buildConsentPdfHtml(baseData)).not.toContain("Provisional signature");
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
interface FakeIframe {
|
|
171
|
+
attributes: Record<string, string>;
|
|
172
|
+
contentWindow: {
|
|
173
|
+
addEventListener: (event: string, listener: () => void) => void;
|
|
174
|
+
focus: ReturnType<typeof mock>;
|
|
175
|
+
print: ReturnType<typeof mock>;
|
|
176
|
+
};
|
|
177
|
+
onload: (() => void) | null;
|
|
178
|
+
removed: boolean;
|
|
179
|
+
remove: () => void;
|
|
180
|
+
setAttribute: (name: string, value: string) => void;
|
|
181
|
+
srcdoc: string;
|
|
182
|
+
style: Record<string, string>;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** A minimal DOM: appending the iframe loads it, like a browser does with `srcdoc`. */
|
|
186
|
+
const installFakeDocument = (): {iframes: FakeIframe[]; restore: () => void} => {
|
|
187
|
+
const iframes: FakeIframe[] = [];
|
|
188
|
+
const g = globalThis as unknown as {document?: unknown};
|
|
189
|
+
const originalDocument = g.document;
|
|
190
|
+
g.document = {
|
|
191
|
+
body: {
|
|
192
|
+
appendChild: (iframe: FakeIframe) => {
|
|
193
|
+
iframe.onload?.();
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
createElement: (tag: string) => {
|
|
197
|
+
expect(tag).toBe("iframe");
|
|
198
|
+
const listeners: Record<string, () => void> = {};
|
|
199
|
+
const iframe: FakeIframe = {
|
|
200
|
+
attributes: {},
|
|
201
|
+
contentWindow: {
|
|
202
|
+
addEventListener: (event, listener) => {
|
|
203
|
+
listeners[event] = listener;
|
|
204
|
+
},
|
|
205
|
+
focus: mock(() => {}),
|
|
206
|
+
print: mock(() => {
|
|
207
|
+
listeners.afterprint?.();
|
|
208
|
+
}),
|
|
209
|
+
},
|
|
210
|
+
onload: null,
|
|
211
|
+
remove: () => {
|
|
212
|
+
iframe.removed = true;
|
|
213
|
+
},
|
|
214
|
+
removed: false,
|
|
215
|
+
setAttribute: (name, value) => {
|
|
216
|
+
iframe.attributes[name] = value;
|
|
217
|
+
},
|
|
218
|
+
srcdoc: "",
|
|
219
|
+
style: {},
|
|
220
|
+
};
|
|
221
|
+
iframes.push(iframe);
|
|
222
|
+
return iframe;
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
return {
|
|
226
|
+
iframes,
|
|
227
|
+
restore: () => {
|
|
228
|
+
g.document = originalDocument;
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
describe("printConsentHtml", () => {
|
|
234
|
+
it("opens the native print dialog with the HTML on native", async () => {
|
|
235
|
+
printAsync.mockClear();
|
|
236
|
+
await printConsentHtml({html: "<p>consent</p>"});
|
|
237
|
+
expect(printAsync).toHaveBeenCalledWith({html: "<p>consent</p>"});
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it("prints from a hidden iframe on web and removes it afterwards", async () => {
|
|
241
|
+
const originalOS = Platform.OS;
|
|
242
|
+
Platform.OS = "web";
|
|
243
|
+
const {iframes, restore} = installFakeDocument();
|
|
244
|
+
printAsync.mockClear();
|
|
245
|
+
try {
|
|
246
|
+
await printConsentHtml({html: "<p>consent</p>"});
|
|
247
|
+
} finally {
|
|
248
|
+
Platform.OS = originalOS;
|
|
249
|
+
restore();
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
expect(iframes).toHaveLength(1);
|
|
253
|
+
expect(iframes[0].srcdoc).toBe("<p>consent</p>");
|
|
254
|
+
expect(iframes[0].attributes["aria-hidden"]).toBe("true");
|
|
255
|
+
expect(iframes[0].style.visibility).toBe("hidden");
|
|
256
|
+
expect(iframes[0].contentWindow.print).toHaveBeenCalledTimes(1);
|
|
257
|
+
expect(iframes[0].removed).toBe(true);
|
|
258
|
+
expect(printAsync).not.toHaveBeenCalled();
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it("removes the iframe and rejects when printing throws on web", async () => {
|
|
262
|
+
const originalOS = Platform.OS;
|
|
263
|
+
Platform.OS = "web";
|
|
264
|
+
const {iframes, restore} = installFakeDocument();
|
|
265
|
+
const failure = new Error("print blocked");
|
|
266
|
+
const g = globalThis as unknown as {document: {createElement: (tag: string) => FakeIframe}};
|
|
267
|
+
const createElement = g.document.createElement;
|
|
268
|
+
g.document.createElement = (tag: string): FakeIframe => {
|
|
269
|
+
const iframe = createElement(tag);
|
|
270
|
+
iframe.contentWindow.print = mock(() => {
|
|
271
|
+
throw failure;
|
|
272
|
+
});
|
|
273
|
+
return iframe;
|
|
274
|
+
};
|
|
275
|
+
try {
|
|
276
|
+
await expect(printConsentHtml({html: "<p>consent</p>"})).rejects.toBe(failure);
|
|
277
|
+
} finally {
|
|
278
|
+
Platform.OS = originalOS;
|
|
279
|
+
restore();
|
|
280
|
+
}
|
|
281
|
+
expect(iframes[0].removed).toBe(true);
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
describe("printConsentHtml when afterprint never fires", () => {
|
|
286
|
+
it("removes the previous print frame before printing again", async () => {
|
|
287
|
+
const originalOS = Platform.OS;
|
|
288
|
+
Platform.OS = "web";
|
|
289
|
+
const {iframes, restore} = installFakeDocument();
|
|
290
|
+
const g = globalThis as unknown as {document: {createElement: (tag: string) => FakeIframe}};
|
|
291
|
+
const createElement = g.document.createElement;
|
|
292
|
+
g.document.createElement = (tag: string): FakeIframe => {
|
|
293
|
+
const iframe = createElement(tag);
|
|
294
|
+
iframe.contentWindow.print = mock(() => {});
|
|
295
|
+
return iframe;
|
|
296
|
+
};
|
|
297
|
+
try {
|
|
298
|
+
await printConsentHtml({html: "<p>first</p>"});
|
|
299
|
+
expect(iframes[0].removed).toBe(false);
|
|
300
|
+
await printConsentHtml({html: "<p>second</p>"});
|
|
301
|
+
} finally {
|
|
302
|
+
Platform.OS = originalOS;
|
|
303
|
+
restore();
|
|
304
|
+
}
|
|
305
|
+
expect(iframes[0].removed).toBe(true);
|
|
306
|
+
expect(iframes[1].srcdoc).toBe("<p>second</p>");
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
describe("printConsentHtml without a frame window", () => {
|
|
311
|
+
it("removes the iframe and rejects", async () => {
|
|
312
|
+
const originalOS = Platform.OS;
|
|
313
|
+
Platform.OS = "web";
|
|
314
|
+
const {iframes, restore} = installFakeDocument();
|
|
315
|
+
const g = globalThis as unknown as {document: {createElement: (tag: string) => FakeIframe}};
|
|
316
|
+
const createElement = g.document.createElement;
|
|
317
|
+
g.document.createElement = (tag: string): FakeIframe => {
|
|
318
|
+
const iframe = createElement(tag);
|
|
319
|
+
(iframe as unknown as {contentWindow: null}).contentWindow = null;
|
|
320
|
+
return iframe;
|
|
321
|
+
};
|
|
322
|
+
try {
|
|
323
|
+
await expect(printConsentHtml({html: "<p>consent</p>"})).rejects.toThrow(
|
|
324
|
+
"Print frame did not load"
|
|
325
|
+
);
|
|
326
|
+
} finally {
|
|
327
|
+
Platform.OS = originalOS;
|
|
328
|
+
restore();
|
|
329
|
+
}
|
|
330
|
+
expect(iframes[0].removed).toBe(true);
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
|
|
95
334
|
describe("sharePdfFromHtml", () => {
|
|
96
335
|
it("throws on web", async () => {
|
|
97
336
|
const originalOS = Platform.OS;
|