Skip to content

Commit

Permalink
chore(ui-react-native): Add RN Authenticator fields validations (#4107)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioanabrooks committed Jul 17, 2023
1 parent 7ab4713 commit 6d14bf3
Show file tree
Hide file tree
Showing 31 changed files with 343 additions and 14 deletions.
6 changes: 6 additions & 0 deletions .changeset/rotten-lies-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@aws-amplify/ui-react-native': patch
'@aws-amplify/ui-react-core': patch
---

chore(ui-react-native): Add Authenticator fields validations
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ Scenario: Sign up with a new email & password
And I click the "Create Account" button
Then I see "Confirmation Code"

@react-native
Scenario: Sign up using invalid email
When I type a new "email" with value ''
Then I see "This field is required"
When I type a new "email" with value 'inv'
Then I see "Please enter a valid email"

@angular @react @vue
Scenario: Email field autocompletes username

Expand Down
21 changes: 14 additions & 7 deletions packages/react-core/src/Authenticator/hooks/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,21 @@ export type ConfirmSignInBaseProps<FieldType = {}> = {
challengeName: AuthChallengeName;
toSignIn: UseAuthenticator['toSignIn'];
} & CommonRouteProps &
ComponentSlots<FieldType>;
ComponentSlots<FieldType> &
ValidationProps;

export type ConfirmSignUpBaseProps<FieldType = {}> = {
codeDeliveryDetails: UseAuthenticator['codeDeliveryDetails'];
resendCode: UseAuthenticator['resendCode'];
} & CommonRouteProps &
ComponentSlots<FieldType>;
ComponentSlots<FieldType> &
ValidationProps;

export type ConfirmVerifyUserProps<FieldType = {}> = {
skipVerification: UseAuthenticator['skipVerification'];
} & CommonRouteProps &
ComponentSlots<FieldType>;
ComponentSlots<FieldType> &
ValidationProps;

export type ForceResetPasswordBaseProps<FieldType = {}> = {
toSignIn: UseAuthenticator['toSignIn'];
Expand All @@ -117,21 +120,24 @@ export type ForceResetPasswordBaseProps<FieldType = {}> = {
export type ResetPasswordBaseProps<FieldType = {}> = {
toSignIn: UseAuthenticator['toSignIn'];
} & CommonRouteProps &
ComponentSlots<FieldType>;
ComponentSlots<FieldType> &
ValidationProps;

export type SetupTOTPBaseProps<FieldType = {}> = {
toSignIn: UseAuthenticator['toSignIn'];
totpSecretCode: UseAuthenticator['totpSecretCode'];
} & CommonRouteProps &
ComponentSlots<FieldType>;
ComponentSlots<FieldType> &
ValidationProps;

export type SignInBaseProps<FieldType = {}> = {
hideSignUp?: boolean;
toFederatedSignIn: UseAuthenticator['toFederatedSignIn'];
toResetPassword: UseAuthenticator['toResetPassword'];
toSignUp: UseAuthenticator['toSignUp'];
} & CommonRouteProps &
ComponentSlots<FieldType>;
ComponentSlots<FieldType> &
ValidationProps;

export type SignUpBaseProps<FieldType = {}> = {
hideSignIn?: boolean;
Expand All @@ -144,7 +150,8 @@ export type SignUpBaseProps<FieldType = {}> = {
export type VerifyUserProps<FieldType = {}> = {
skipVerification: UseAuthenticator['skipVerification'];
} & CommonRouteProps &
ComponentSlots<FieldType>;
ComponentSlots<FieldType> &
ValidationProps;

export interface DefaultProps<FieldType = {}> {
ConfirmSignIn: ConfirmSignInBaseProps<FieldType>;
Expand Down
1 change: 1 addition & 0 deletions packages/react-native/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
preset: 'react-native',
modulePathIgnorePatterns: ['<rootDir>/dist/'],
collectCoverage: true,
collectCoverageFrom: [
'<rootDir>/src/**/*.{js,jsx,ts,tsx}',
'!<rootDir>/src/**/*{c,C}onstants.ts',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,21 @@ const ConfirmResetPassword = ({
hasValidationErrors,
isPending,
resendCode,
validationErrors,
...rest
}: DefaultConfirmResetPasswordProps): JSX.Element => {
const {
disableFormSubmit,
fields: fieldsWithHandlers,
fieldValidationErrors,
handleFormSubmit,
} = useFieldValues({
componentName: COMPONENT_NAME,
fields,
handleBlur,
handleChange,
handleSubmit,
validationErrors,
});

const disabled = hasValidationErrors || disableFormSubmit;
Expand Down Expand Up @@ -72,6 +75,7 @@ const ConfirmResetPassword = ({
headerText={headerText}
fields={fieldsWithHandlers}
isPending={isPending}
validationErrors={fieldValidationErrors}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,21 @@ const ConfirmSignIn = ({
handleSubmit,
isPending,
toSignIn,
validationErrors,
...rest
}: DefaultConfirmSignInProps): JSX.Element => {
const {
disableFormSubmit: disabled,
fields: fieldsWithHandlers,
fieldValidationErrors,
handleFormSubmit,
} = useFieldValues({
componentName: COMPONENT_NAME,
fields,
handleBlur,
handleChange,
handleSubmit,
validationErrors,
});

const headerText = getChallengeText(challengeName);
Expand Down Expand Up @@ -71,6 +74,7 @@ const ConfirmSignIn = ({
headerText={headerText}
fields={fieldsWithHandlers}
isPending={isPending}
validationErrors={fieldValidationErrors}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const props = {
handleBlur: jest.fn(),
handleChange: jest.fn(),
handleSubmit: jest.fn(),
hasValidationErrors: false,
Header: ConfirmSignIn.Header,
isPending: false,
toSignIn: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,21 @@ const ConfirmSignUp = ({
handleSubmit,
isPending,
resendCode,
validationErrors,
...rest
}: DefaultConfirmSignUpProps): JSX.Element => {
const {
disableFormSubmit: disabled,
fields: fieldsWithHandlers,
fieldValidationErrors,
handleFormSubmit,
} = useFieldValues({
componentName: COMPONENT_NAME,
fields,
handleBlur,
handleChange,
handleSubmit,
validationErrors,
});

const headerText = getDeliveryMethodText(codeDeliveryDetails);
Expand Down Expand Up @@ -74,6 +77,7 @@ const ConfirmSignUp = ({
headerText={headerText}
fields={fieldsWithHandlers}
isPending={isPending}
validationErrors={fieldValidationErrors}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const props = {
handleBlur: jest.fn(),
handleChange: jest.fn(),
handleSubmit: jest.fn(),
hasValidationErrors: false,
Header: ConfirmSignUp.Header,
isPending: false,
resendCode: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,21 @@ const ConfirmVerifyUser = ({
handleSubmit,
isPending,
skipVerification,
validationErrors,
...rest
}: DefaultConfirmVerifyUserProps): JSX.Element => {
const {
disableFormSubmit: disabled,
fields: fieldsWithHandlers,
fieldValidationErrors,
handleFormSubmit,
} = useFieldValues({
componentName: COMPONENT_NAME,
fields,
handleBlur,
handleChange,
handleSubmit,
validationErrors,
});

const headerText = getAccountRecoveryInfoText();
Expand Down Expand Up @@ -70,6 +73,7 @@ const ConfirmVerifyUser = ({
headerText={headerText}
fields={fieldsWithHandlers}
isPending={isPending}
validationErrors={fieldValidationErrors}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const props = {
handleBlur: jest.fn(),
handleChange: jest.fn(),
handleSubmit: jest.fn(),
hasValidationErrors: false,
Header: ConfirmVerifyUser.Header,
isPending: false,
skipVerification: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,21 @@ const ForceNewPassword = ({
hasValidationErrors,
isPending,
toSignIn,
validationErrors,
...rest
}: DefaultForceNewPasswordProps): JSX.Element => {
const {
disableFormSubmit,
fields: fieldsWithHandlers,
fieldValidationErrors,
handleFormSubmit,
} = useFieldValues({
componentName: COMPONENT_NAME,
fields,
handleBlur,
handleChange,
handleSubmit,
validationErrors,
});

const disabled = hasValidationErrors || disableFormSubmit;
Expand Down Expand Up @@ -70,6 +73,7 @@ const ForceNewPassword = ({
headerText={headerText}
fields={fieldsWithHandlers}
isPending={isPending}
validationErrors={fieldValidationErrors}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@ const ResetPassword = ({
handleSubmit,
isPending,
toSignIn,
validationErrors,
...rest
}: DefaultResetPasswordProps): JSX.Element => {
const {
disableFormSubmit: disabled,
fields: fieldsWithHandlers,
fieldValidationErrors,
handleFormSubmit,
} = useFieldValues({
componentName: COMPONENT_NAME,
fields,
handleBlur,
handleChange,
handleSubmit,
validationErrors,
});

const headerText = getResetYourPasswordText();
Expand Down Expand Up @@ -69,6 +72,7 @@ const ResetPassword = ({
headerText={headerText}
fields={fieldsWithHandlers}
isPending={isPending}
validationErrors={fieldValidationErrors}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const props = {
handleBlur: jest.fn(),
handleChange: jest.fn(),
handleSubmit: jest.fn(),
hasValidationErrors: false,
Header: ResetPassword.Header,
isPending: false,
toSignIn: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,21 @@ const SetupTOTP = ({
isPending,
toSignIn,
totpSecretCode,
validationErrors,
...rest
}: DefaultSetupTOTPProps): JSX.Element => {
const {
disableFormSubmit: disabled,
fields: fieldsWithHandlers,
fieldValidationErrors,
handleFormSubmit,
} = useFieldValues({
componentName: COMPONENT_NAME,
fields,
handleBlur,
handleChange,
handleSubmit,
validationErrors,
});

const headerText = getSetupTOTPText();
Expand Down Expand Up @@ -88,6 +91,7 @@ const SetupTOTP = ({
headerText={headerText}
fields={fieldsWithHandlers}
isPending={isPending}
validationErrors={fieldValidationErrors}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const props = {
handleBlur: jest.fn(),
handleChange: jest.fn(),
handleSubmit: jest.fn(),
hasValidationErrors: false,
isPending: false,
toSignIn,
totpSecretCode: "Let's keep it hush hush",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const SignIn = ({
hideSignUp,
toResetPassword,
toSignUp,
validationErrors,
...rest
}: DefaultSignInProps): JSX.Element => {
const {
Expand All @@ -33,13 +34,15 @@ const SignIn = ({
const {
disableFormSubmit: disabled,
fields: fieldsWithHandlers,
fieldValidationErrors,
handleFormSubmit,
} = useFieldValues({
componentName: COMPONENT_NAME,
fields,
handleBlur,
handleChange,
handleSubmit,
validationErrors,
});

const headerText = getSignInTabText();
Expand Down Expand Up @@ -75,6 +78,7 @@ const SignIn = ({
buttons={buttons}
fields={fieldsWithHandlers}
headerText={headerText}
validationErrors={fieldValidationErrors}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const props = {
handleBlur: jest.fn(),
handleChange: jest.fn(),
handleSubmit: jest.fn(),
hasValidationErrors: false,
Header: SignIn.Header,
isPending: false,
socialProviders: undefined,
Expand Down
Loading

0 comments on commit 6d14bf3

Please sign in to comment.