Skip to content

Commit

Permalink
Merge pull request #470 from etn-ccis/fix/BLUI-4703-access-login-props
Browse files Browse the repository at this point in the history
Update passwordValidator and passwordRequiredValidatorText prop
  • Loading branch information
daileytj authored Sep 18, 2023
2 parents 6738fcc + f83db23 commit 40c45b6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
18 changes: 8 additions & 10 deletions login-workflow/src/screens/LoginScreen/LoginScreen.tsx
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

0 comments on commit 40c45b6

Please sign in to comment.