Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update passwordValidator and passwordRequiredValidatorText prop #470

Merged
merged 3 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions login-workflow/src/screens/LoginScreen/LoginScreen.tsx
ektaghag-eaton marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ const EMAIL_REGEX = /^[A-Z0-9._%+'-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i;
* @category Component
*/

type LoginScreenPropsPublic = Omit<LoginScreenProps, 'passwordValidator'> & { passwordRequiredValidatorText?: string };

export const LoginScreen: React.FC<React.PropsWithChildren<LoginScreenPropsPublic>> = (props) => {
export const LoginScreen: React.FC<React.PropsWithChildren<LoginScreenProps>> = (props) => {
const { t } = useLanguageLocale();
const auth = useAuthContext();
const { actions, navigate, routeConfig, rememberMeDetails } = auth;
Expand Down Expand Up @@ -76,7 +74,12 @@ export const LoginScreen: React.FC<React.PropsWithChildren<LoginScreenPropsPubli
initialUsernameValue = rememberMeDetails?.email || '',
passwordLabel = t('bluiCommon:LABELS.PASSWORD'),
passwordTextFieldProps,
passwordRequiredValidatorText = t('bluiCommon:MESSAGES.PASSWORD_REQUIRED_ERROR'),
passwordValidator = (password: string): string | boolean => {
if (password.length < 1) {
return t('bluiCommon:MESSAGES.PASSWORD_REQUIRED_ERROR');
}
return true;
},
showRememberMe = true,
rememberMeLabel = t('bluiCommon:ACTIONS.REMEMBER'),
rememberMeInitialValue = rememberMeDetails?.rememberMe || false,
Expand Down Expand Up @@ -108,12 +111,7 @@ export const LoginScreen: React.FC<React.PropsWithChildren<LoginScreenPropsPubli
initialUsernameValue={initialUsernameValue}
passwordLabel={passwordLabel}
passwordTextFieldProps={passwordTextFieldProps}
passwordValidator={(password: string): string | boolean => {
if (password.length < 1) {
return passwordRequiredValidatorText;
}
return true;
}}
passwordValidator={passwordValidator}
showRememberMe={showRememberMe}
rememberMeLabel={rememberMeLabel}
rememberMeInitialValue={rememberMeInitialValue}
Expand Down
12 changes: 12 additions & 0 deletions login-workflow/src/screens/LoginScreen/LoginScreenBase.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ describe('LoginScreenBase', () => {
expect(screen.getByText('Password')).toBeInTheDocument();
});

test('disables login button when username and password are invalid', () => {
const usernameInput = screen.getByLabelText('Email Address');
const passwordInput = screen.getByLabelText('Password');
const loginButton = screen.getByText('Log In');

fireEvent.change(usernameInput, { target: { value: 'us' } });
fireEvent.change(passwordInput, { target: { value: 'p' } });
fireEvent.blur(passwordInput);

expect(loginButton).toBeDisabled();
});

test('disables login button when username and password are invalid', () => {
const usernameInput = screen.getByLabelText('Email Address');
const passwordInput = screen.getByLabelText('Password');
Expand Down
4 changes: 2 additions & 2 deletions login-workflow/src/screens/LoginScreen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ export type LoginScreenProps = WorkflowCardBaseProps & {

/**
* The function used to validate the password
* @param {string} foo - validates username
* @param {string} password - validates password
* @returns boolean | string
*/
passwordValidator?: (foo: string) => boolean | string;
passwordValidator?: (password: string) => boolean | string;

// configure Remember Me
/**
Expand Down
Loading