From c26bd6c52fb6d72e68475532592638160015b3ee Mon Sep 17 00:00:00 2001 From: Tharun Rajendran Date: Tue, 13 Jul 2021 12:02:03 +0530 Subject: [PATCH] Password Field Improvements (#36160) * Password: added show password functionality added autcomplete props created password component Fixes #28721 * addressed review changes and added unit tests * wrapped passwordField component in forwardRef * fix validation and tests --- .../ForgottenPassword/ChangePassword.tsx | 19 ++++---- .../ChangePasswordPage.test.tsx | 4 +- .../app/core/components/Login/LoginForm.tsx | 9 ++-- .../PasswordField/PasswordField.test.tsx | 22 ++++++++++ .../PasswordField/PasswordField.tsx | 44 +++++++++++++++++++ .../app/core/components/Signup/SignupPage.tsx | 13 +++--- .../features/profile/ChangePasswordForm.tsx | 17 +++---- 7 files changed, 97 insertions(+), 31 deletions(-) create mode 100644 public/app/core/components/PasswordField/PasswordField.test.tsx create mode 100644 public/app/core/components/PasswordField/PasswordField.tsx diff --git a/public/app/core/components/ForgottenPassword/ChangePassword.tsx b/public/app/core/components/ForgottenPassword/ChangePassword.tsx index c85ca19f0f6..69c813b4a50 100644 --- a/public/app/core/components/ForgottenPassword/ChangePassword.tsx +++ b/public/app/core/components/ForgottenPassword/ChangePassword.tsx @@ -1,7 +1,8 @@ import React, { FC, SyntheticEvent } from 'react'; -import { Tooltip, Form, Field, Input, VerticalGroup, Button } from '@grafana/ui'; +import { Tooltip, Form, Field, VerticalGroup, Button } from '@grafana/ui'; import { selectors } from '@grafana/e2e-selectors'; import { submitButton } from '../Login/LoginForm'; +import { PasswordField } from '../PasswordField/PasswordField'; interface Props { onSubmit: (pw: string) => void; onSkip?: (event?: SyntheticEvent) => void; @@ -21,21 +22,19 @@ export const ChangePassword: FC = ({ onSubmit, onSkip }) => { {({ errors, register, getValues }) => ( <> - - v === getValues().newPassword || 'Passwords must match!', })} /> diff --git a/public/app/core/components/ForgottenPassword/ChangePasswordPage.test.tsx b/public/app/core/components/ForgottenPassword/ChangePasswordPage.test.tsx index 57f6ff8ce62..8ef3dfde83a 100644 --- a/public/app/core/components/ForgottenPassword/ChangePasswordPage.test.tsx +++ b/public/app/core/components/ForgottenPassword/ChangePasswordPage.test.tsx @@ -48,8 +48,8 @@ describe('ChangePassword Page', () => { render(); fireEvent.click(screen.getByRole('button', { name: 'Submit' })); - expect(await screen.findByText('New password is required')).toBeInTheDocument(); - expect(screen.getByText('Confirmed password is required')).toBeInTheDocument(); + expect(await screen.findByText('New Password is required')).toBeInTheDocument(); + expect(screen.getByText('Confirmed Password is required')).toBeInTheDocument(); await act(async () => { await userEvent.type(screen.getByLabelText('New password'), 'admin'); diff --git a/public/app/core/components/Login/LoginForm.tsx b/public/app/core/components/Login/LoginForm.tsx index 2a840e0cdf5..e7dc1d4d589 100644 --- a/public/app/core/components/Login/LoginForm.tsx +++ b/public/app/core/components/Login/LoginForm.tsx @@ -4,6 +4,7 @@ import { selectors } from '@grafana/e2e-selectors'; import { FormModel } from './LoginCtrl'; import { Button, Form, Input, Field } from '@grafana/ui'; import { css } from '@emotion/css'; +import { PasswordField } from '../PasswordField/PasswordField'; interface Props { children: ReactElement; @@ -39,11 +40,11 @@ export const LoginForm: FC = ({ children, onSubmit, isLoggingIn, password /> -